123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <template>
- <div>
- <div class="search__example--wrap">
- <com-search
- :data="searchData"
- @search-submit="searchSubmit"
- @reset-submit="resetSubmit"
- />
- </div>
- <div class="button__example--wrap">
- <el-button type="primary" icon="el-icon-circle-plus-outline" @click="open(false)">新增</el-button>
- <el-button
- type="danger"
- icon="el-icon-delete"
- @click="dels"
- >删除</el-button>
- </div>
- <com-table
- v-loading="loading"
- selection
- :columns="columns"
- :data="tableData"
- :pagination="{
- currentPage: defalutParams.pageIndex,
- total: total,
- onSizeChange: handleSizeChange,
- onCurrentChange: handleCurrentChange
- }"
- @selection-change="handleSelectionChange"
- >
- <template #importance="scope">
- <el-tag
- :type="scope.row.importance === 3
- ? 'success'
- : (scope.row.importance === 2
- ? 'warning'
- : 'danger')"
- >{{ scope.row.importance === 3
- ? '重要'
- : (scope.row.importance === 2
- ? '良好'
- : '一般') }}
- </el-tag>
- </template>
- <template #action="scope">
- <el-button type="primary" size="mini" @click="open(scope.row)">编辑</el-button>
- <el-button type="danger" size="mini" @click="dels(scope.row)">删除</el-button>
- </template>
- </com-table>
- <com-dialog v-model="dialogVisible" :title="title">
- <ifno-write :info="info" @close="close" @success="success" />
- </com-dialog>
- </div>
- </template>
- <script lang="ts">
- import { defineComponent, ref } from 'vue'
- import IfnoWrite from './components/IfnoWrite.vue'
- import { useExample } from '@/hooks/useExample'
- import { Message } from '_c/Message'
- import { getExampleListApi, delsExampApi } from './api'
- const searchData = [
- {
- label: '标题',
- value: '',
- itemType: 'input',
- field: 'title',
- placeholder: '请输入标题',
- clearable: true
- }
- ]
- const columns = [
- {
- key: 'title',
- label: '标题',
- showOverflowTooltip: true
- },
- {
- key: 'author',
- label: '作者'
- },
- {
- key: 'display_time',
- label: '创建时间'
- },
- {
- key: 'importance',
- label: '重要性',
- slots: {
- default: 'importance'
- }
- },
- {
- key: 'pageviews',
- label: '阅读数'
- },
- {
- key: 'action',
- label: '操作',
- width: '150px',
- slots: {
- default: 'action'
- }
- }
- ]
- export default defineComponent({
- // name: 'Example',
- components: {
- IfnoWrite
- },
- setup() {
- const info = ref<any>(null)
- const {
- defalutParams,
- tableData,
- loading,
- total,
- dialogVisible,
- title,
- currentChange,
- sizeChange,
- handleSelectionChange,
- selectionData,
- delData
- } = useExample()
- // 请求数据
- async function getExampleList(data?: any): Promise<void> {
- try {
- const res = await getExampleListApi({
- params: Object.assign(defalutParams, data || {})
- })
- if (res.code === '0000') {
- total.value = res.data.total
- tableData.value = res.data.list
- }
- } finally {
- loading.value = false
- }
- }
- // 查询
- function searchSubmit(data: any) {
- // 该方法重置了一些默认参数
- currentChange(1)
- getExampleList(data)
- }
- // 重置
- function resetSubmit(data: any) {
- // 该方法重置了一些默认参数
- currentChange(1)
- getExampleList(data)
- }
- // 展示多少条
- function handleSizeChange(val: number) {
- // 该方法重置了一些默认参数
- sizeChange(val)
- getExampleList()
- }
- // 展示第几页
- function handleCurrentChange(val: number) {
- // 该方法重置了一些默认参数
- currentChange(val)
- getExampleList()
- }
- // 删除多选
- function dels(item?: any) {
- delData(async() => {
- let ids: string[]
- if (item.id) {
- ids = [item.id]
- } else {
- ids = selectionData.value.map((v: any) => {
- return v.id
- })
- }
- const res = await delsExampApi({
- data: { ids }
- })
- if (res.code === '0000') {
- Message.success('删除成功!')
- getExampleList()
- }
- }, { hiddenVerify: item.id })
- }
- // 打开弹窗
- function open(row: any) {
- title.value = row ? '编辑' : '新增'
- info.value = row || null
- dialogVisible.value = true
- }
- // 弹窗关闭
- function close() {
- dialogVisible.value = false
- }
- // 成功之后的回调
- function success(type: string) {
- if (type === 'add') {
- currentChange(1)
- }
- close()
- getExampleList()
- }
- getExampleList()
- return {
- info, open,
- searchData, searchSubmit, resetSubmit,
- columns,
- defalutParams,
- loading,
- tableData,
- total,
- title,
- dialogVisible,
- handleSizeChange,
- handleCurrentChange,
- handleSelectionChange,
- dels,
- close, success
- }
- }
- })
- </script>
- <style>
- </style>
|