|
@@ -2,11 +2,11 @@
|
|
import { ContentWrap } from '@/components/ContentWrap'
|
|
import { ContentWrap } from '@/components/ContentWrap'
|
|
import { Search } from '@/components/Search'
|
|
import { Search } from '@/components/Search'
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
-import { ElButton, ElTag } from 'element-plus'
|
|
|
|
|
|
+import { ElButton, ElButtonGroup, ElTooltip } from 'element-plus'
|
|
import { Table } from '@/components/Table'
|
|
import { Table } from '@/components/Table'
|
|
-import { getTableListApi, delTableListApi } from '@/api/table'
|
|
|
|
|
|
+import { getTableListApi, delTableListApi } from '@/api/manage/news'
|
|
import { useTable } from '@/hooks/web/useTable'
|
|
import { useTable } from '@/hooks/web/useTable'
|
|
-import { TableData } from '@/api/table/types'
|
|
|
|
|
|
+import { NewsTableData } from '@/api/manage/types'
|
|
import { ref, unref } from 'vue'
|
|
import { ref, unref } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { useRouter } from 'vue-router'
|
|
import { useEmitt } from '@/hooks/event/useEmitt'
|
|
import { useEmitt } from '@/hooks/event/useEmitt'
|
|
@@ -14,14 +14,17 @@ import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
|
import { TableSetting } from '@/components/TableSetting'
|
|
import { TableSetting } from '@/components/TableSetting'
|
|
import { usePageStore } from '@/store/modules/page'
|
|
import { usePageStore } from '@/store/modules/page'
|
|
import { set } from 'lodash-es'
|
|
import { set } from 'lodash-es'
|
|
-
|
|
|
|
|
|
+import { useIcon } from '@/hooks/web/useIcon'
|
|
|
|
+const EditIcon = useIcon({ icon: 'ep:edit' })
|
|
|
|
+const DetailIcon = useIcon({ icon: 'ep:document' })
|
|
|
|
+const DeleteIcon = useIcon({ icon: 'ep:delete' })
|
|
defineOptions({
|
|
defineOptions({
|
|
name: 'NewsPage'
|
|
name: 'NewsPage'
|
|
})
|
|
})
|
|
|
|
|
|
const { push } = useRouter()
|
|
const { push } = useRouter()
|
|
|
|
|
|
-const ids = ref<string[]>([])
|
|
|
|
|
|
+const id = ref<string>('')
|
|
|
|
|
|
const searchParams = ref({})
|
|
const searchParams = ref({})
|
|
const setSearchParams = (params: any) => {
|
|
const setSearchParams = (params: any) => {
|
|
@@ -33,22 +36,22 @@ const { tableRegister, tableState, tableMethods } = useTable({
|
|
fetchDataApi: async () => {
|
|
fetchDataApi: async () => {
|
|
const { currentPage, pageSize } = tableState
|
|
const { currentPage, pageSize } = tableState
|
|
const res = await getTableListApi({
|
|
const res = await getTableListApi({
|
|
- pageIndex: unref(currentPage),
|
|
|
|
|
|
+ pageNum: unref(currentPage),
|
|
pageSize: unref(pageSize),
|
|
pageSize: unref(pageSize),
|
|
...unref(searchParams)
|
|
...unref(searchParams)
|
|
})
|
|
})
|
|
return {
|
|
return {
|
|
list: res.data.list,
|
|
list: res.data.list,
|
|
- total: res.data.total
|
|
|
|
|
|
+ total: Number(res.data.totalCount)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
fetchDelApi: async () => {
|
|
fetchDelApi: async () => {
|
|
- const res = await delTableListApi(unref(ids))
|
|
|
|
|
|
+ const res = await delTableListApi(unref(id))
|
|
return !!res
|
|
return !!res
|
|
}
|
|
}
|
|
})
|
|
})
|
|
const { loading, dataList, total, currentPage, pageSize } = tableState
|
|
const { loading, dataList, total, currentPage, pageSize } = tableState
|
|
-const { getList, getElTableExpose, delList, setColumn } = tableMethods
|
|
|
|
|
|
+const { getList, delList, setColumn } = tableMethods
|
|
|
|
|
|
getList()
|
|
getList()
|
|
|
|
|
|
@@ -66,41 +69,9 @@ const { t } = useI18n()
|
|
const appStore = usePageStore()
|
|
const appStore = usePageStore()
|
|
const crudSchemas: CrudSchema[] = [
|
|
const crudSchemas: CrudSchema[] = [
|
|
{
|
|
{
|
|
- field: 'selection',
|
|
|
|
- search: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- form: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- detail: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- table: {
|
|
|
|
- type: 'selection',
|
|
|
|
- hidden: false
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- field: 'index',
|
|
|
|
- label: t('tableDemo.index'),
|
|
|
|
- type: 'index',
|
|
|
|
- search: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- table: {
|
|
|
|
- hidden: false
|
|
|
|
- },
|
|
|
|
- form: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- detail: {
|
|
|
|
- hidden: true
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- field: 'title',
|
|
|
|
- label: t('tableDemo.title'),
|
|
|
|
|
|
+ field: 'articleTitle',
|
|
|
|
+ label: '文章标题',
|
|
|
|
+ minWidth: 150,
|
|
search: {
|
|
search: {
|
|
component: 'Input'
|
|
component: 'Input'
|
|
},
|
|
},
|
|
@@ -118,35 +89,31 @@ const crudSchemas: CrudSchema[] = [
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- field: 'author',
|
|
|
|
- label: t('tableDemo.author'),
|
|
|
|
- search: {
|
|
|
|
- hidden: true
|
|
|
|
|
|
+ field: 'introduce',
|
|
|
|
+ label: '文章简介',
|
|
|
|
+ minWidth: 180,
|
|
|
|
+ form: {
|
|
|
|
+ component: 'Input',
|
|
|
|
+ componentProps: {
|
|
|
|
+ type: 'textarea'
|
|
|
|
+ },
|
|
|
|
+ colProps: {
|
|
|
|
+ span: 24
|
|
|
|
+ }
|
|
},
|
|
},
|
|
- table: {
|
|
|
|
- hidden: false
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- field: 'display_time',
|
|
|
|
- label: t('tableDemo.displayTime'),
|
|
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
},
|
|
},
|
|
table: {
|
|
table: {
|
|
hidden: false
|
|
hidden: false
|
|
- },
|
|
|
|
- form: {
|
|
|
|
- component: 'DatePicker',
|
|
|
|
- componentProps: {
|
|
|
|
- type: 'datetime',
|
|
|
|
- valueFormat: 'YYYY-MM-DD HH:mm:ss'
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- field: 'importance',
|
|
|
|
- label: t('tableDemo.importance'),
|
|
|
|
|
|
+ field: 'weight',
|
|
|
|
+ label: '权重',
|
|
|
|
+ width: 100,
|
|
|
|
+ headerAlign: 'center',
|
|
|
|
+ align: 'right',
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
},
|
|
},
|
|
@@ -154,50 +121,16 @@ const crudSchemas: CrudSchema[] = [
|
|
hidden: false
|
|
hidden: false
|
|
},
|
|
},
|
|
form: {
|
|
form: {
|
|
- component: 'Select',
|
|
|
|
- componentProps: {
|
|
|
|
- style: {
|
|
|
|
- width: '100%'
|
|
|
|
- },
|
|
|
|
- options: [
|
|
|
|
- {
|
|
|
|
- label: '重要',
|
|
|
|
- value: 3
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- label: '良好',
|
|
|
|
- value: 2
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- label: '一般',
|
|
|
|
- value: 1
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- detail: {
|
|
|
|
- slots: {
|
|
|
|
- default: (data: any) => {
|
|
|
|
- return (
|
|
|
|
- <ElTag
|
|
|
|
- type={
|
|
|
|
- data.importance === 1 ? 'success' : data.importance === 2 ? 'warning' : 'danger'
|
|
|
|
- }
|
|
|
|
- >
|
|
|
|
- {data.importance === 1
|
|
|
|
- ? t('tableDemo.important')
|
|
|
|
- : data.importance === 2
|
|
|
|
- ? t('tableDemo.good')
|
|
|
|
- : t('tableDemo.commonly')}
|
|
|
|
- </ElTag>
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ component: 'InputNumber',
|
|
|
|
+ value: 0
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- field: 'pageviews',
|
|
|
|
- label: t('tableDemo.pageviews'),
|
|
|
|
|
|
+ field: 'articleViews',
|
|
|
|
+ label: '当前浏览量',
|
|
|
|
+ width: 100,
|
|
|
|
+ headerAlign: 'center',
|
|
|
|
+ align: 'right',
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
},
|
|
},
|
|
@@ -210,8 +143,9 @@ const crudSchemas: CrudSchema[] = [
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- field: 'content',
|
|
|
|
- label: t('exampleDemo.content'),
|
|
|
|
|
|
+ field: 'articleContent',
|
|
|
|
+ label: '文章内容',
|
|
|
|
+ minWidth: 120,
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
},
|
|
},
|
|
@@ -233,9 +167,21 @@ const crudSchemas: CrudSchema[] = [
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ {
|
|
|
|
+ field: 'remark',
|
|
|
|
+ label: '备注',
|
|
|
|
+ minWidth: 120,
|
|
|
|
+ search: {
|
|
|
|
+ hidden: true
|
|
|
|
+ },
|
|
|
|
+ table: {
|
|
|
|
+ hidden: false
|
|
|
|
+ }
|
|
|
|
+ },
|
|
{
|
|
{
|
|
field: 'action',
|
|
field: 'action',
|
|
- width: '260px',
|
|
|
|
|
|
+ width: '160px',
|
|
|
|
+ fixed: 'right',
|
|
label: t('tableDemo.action'),
|
|
label: t('tableDemo.action'),
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
@@ -251,17 +197,17 @@ const crudSchemas: CrudSchema[] = [
|
|
slots: {
|
|
slots: {
|
|
default: (data: any) => {
|
|
default: (data: any) => {
|
|
return (
|
|
return (
|
|
- <>
|
|
|
|
- <ElButton type="primary" onClick={() => action(data.row, 'edit')}>
|
|
|
|
- {t('exampleDemo.edit')}
|
|
|
|
- </ElButton>
|
|
|
|
- <ElButton type="success" onClick={() => action(data.row, 'detail')}>
|
|
|
|
- {t('exampleDemo.detail')}
|
|
|
|
- </ElButton>
|
|
|
|
- <ElButton type="danger" onClick={() => delData(data.row)}>
|
|
|
|
- {t('exampleDemo.del')}
|
|
|
|
- </ElButton>
|
|
|
|
- </>
|
|
|
|
|
|
+ <ElButtonGroup>
|
|
|
|
+ <ElTooltip content="编辑">
|
|
|
|
+ <ElButton text icon={EditIcon} onClick={() => action(data.row, 'edit')} />
|
|
|
|
+ </ElTooltip>
|
|
|
|
+ <ElTooltip content="详情">
|
|
|
|
+ <ElButton text icon={DetailIcon} onClick={() => action(data.row, 'detail')} />
|
|
|
|
+ </ElTooltip>
|
|
|
|
+ <ElTooltip content="删除">
|
|
|
|
+ <ElButton text icon={DeleteIcon} type="danger" onClick={() => delData(data.row)} />
|
|
|
|
+ </ElTooltip>
|
|
|
|
+ </ElButtonGroup>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -305,16 +251,15 @@ const AddAction = () => {
|
|
|
|
|
|
const delLoading = ref(false)
|
|
const delLoading = ref(false)
|
|
|
|
|
|
-const delData = async (row: TableData | null) => {
|
|
|
|
- const elTableExpose = await getElTableExpose()
|
|
|
|
- ids.value = row ? [row.id] : elTableExpose?.getSelectionRows().map((v: TableData) => v.id) || []
|
|
|
|
|
|
+const delData = async (row: NewsTableData) => {
|
|
|
|
+ id.value = row?.id || ''
|
|
delLoading.value = true
|
|
delLoading.value = true
|
|
- await delList(unref(ids).length).finally(() => {
|
|
|
|
|
|
+ await delList(unref(id).length).finally(() => {
|
|
delLoading.value = false
|
|
delLoading.value = false
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-const action = (row: TableData, type: string) => {
|
|
|
|
|
|
+const action = (row: NewsTableData, type: string) => {
|
|
push(`/manage/news-${type}?id=${row.id}`)
|
|
push(`/manage/news-${type}?id=${row.id}`)
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
@@ -325,9 +270,6 @@ const action = (row: TableData, type: string) => {
|
|
|
|
|
|
<div class="mb-10px">
|
|
<div class="mb-10px">
|
|
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
|
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
|
- <ElButton :loading="delLoading" type="danger" @click="delData(null)">
|
|
|
|
- {{ t('exampleDemo.del') }}
|
|
|
|
- </ElButton>
|
|
|
|
<TableSetting page="NewsPage" :data="crudSchemas" @set-schemas="setSchemas" />
|
|
<TableSetting page="NewsPage" :data="crudSchemas" @set-schemas="setSchemas" />
|
|
</div>
|
|
</div>
|
|
|
|
|