reactor: 重构 XTable

This commit is contained in:
xingyu
2023-01-03 11:21:27 +08:00
parent a984eac965
commit f352c4d941
32 changed files with 250 additions and 285 deletions

View File

@ -1,7 +1,7 @@
<template>
<ContentWrap>
<!-- 列表 -->
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
<XTable @register="registerTable">
<!-- 操作新增 -->
<template #toolbar_buttons>
<XButton
@ -35,7 +35,7 @@
@click="handleDelete(row.id)"
/>
</template>
</vxe-grid>
</XTable>
</ContentWrap>
<XModal id="smsChannel" v-model="dialogVisible" :title="dialogTitle">
@ -72,8 +72,7 @@
import { ref, unref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { useXTable } from '@/hooks/web/useXTable'
import { FormExpose } from '@/components/Form'
// 业务相关的 import
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
@ -83,8 +82,7 @@ const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
// 列表相关的变量
const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
const { gridOptions, getList, deleteData } = useVxeGrid<SmsChannelApi.SmsChannelVO>({
const [registerTable, { reload, deleteData }] = useXTable({
allSchemas: allSchemas,
getListApi: SmsChannelApi.getSmsChannelPageApi,
deleteApi: SmsChannelApi.deleteSmsChannelApi
@ -127,7 +125,7 @@ const handleDetail = async (rowId: number) => {
// 删除操作
const handleDelete = async (rowId: number) => {
await deleteData(xGrid, rowId)
await deleteData(rowId)
}
// 提交按钮
@ -151,7 +149,7 @@ const submitForm = async () => {
} finally {
actionLoading.value = false
// 刷新列表
await getList(xGrid)
await reload()
}
}
})

View File

@ -1,7 +1,7 @@
<template>
<ContentWrap>
<!-- 列表 -->
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
<XTable @register="registerTable">
<!-- 操作导出 -->
<template #toolbar_buttons>
<XButton
@ -14,7 +14,7 @@
<template #actionbtns_default="{ row }">
<XTextButton preIcon="ep:view" :title="t('action.detail')" @click="handleDetail(row)" />
</template>
</vxe-grid>
</XTable>
</ContentWrap>
<XModal id="smsLog" v-model="dialogVisible" :title="dialogTitle">
@ -34,15 +34,13 @@
// 全局相关的 import
import { ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { useXTable } from '@/hooks/web/useXTable'
import { allSchemas } from './sms.log.data'
import * as SmsLoglApi from '@/api/system/sms/smsLog'
const { t } = useI18n() // 国际化
// 列表相关的变量
const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
const { gridOptions, exportList } = useVxeGrid<SmsLoglApi.SmsLogVO>({
const [registerTable, { exportList }] = useXTable({
allSchemas: allSchemas,
getListApi: SmsLoglApi.getSmsLogPageApi,
exportListApi: SmsLoglApi.exportSmsLogApi
@ -62,6 +60,6 @@ const handleDetail = (row: SmsLoglApi.SmsLogVO) => {
// 导出操作
const handleExport = async () => {
await exportList(xGrid, '短信日志.xls')
await exportList('短信日志.xls')
}
</script>

View File

@ -1,7 +1,7 @@
<template>
<ContentWrap>
<!-- 列表 -->
<vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
<XTable @register="registerTable">
<!-- 操作新增 -->
<template #toolbar_buttons>
<XButton
@ -41,7 +41,7 @@
@click="handleDelete(row.id)"
/>
</template>
</vxe-grid>
</XTable>
</ContentWrap>
<XModal id="smsTemplate" v-model="dialogVisible" :title="dialogTitle">
<!-- 对话框(添加 / 修改) -->
@ -113,8 +113,7 @@
import { ref, unref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeGridInstance } from 'vxe-table'
import { useXTable } from '@/hooks/web/useXTable'
import { FormExpose } from '@/components/Form'
import { ElForm, ElFormItem, ElInput } from 'element-plus'
// 业务相关的 import
@ -125,8 +124,7 @@ const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
// 列表相关的变量
const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
const { gridOptions, getList, deleteData } = useVxeGrid<SmsTemplateApi.SmsTemplateVO>({
const [registerTable, { reload, deleteData }] = useXTable({
allSchemas: allSchemas,
getListApi: SmsTemplateApi.getSmsTemplatePageApi,
deleteApi: SmsTemplateApi.deleteSmsTemplateApi
@ -170,7 +168,7 @@ const handleDetail = async (rowId: number) => {
// 删除操作
const handleDelete = async (rowId: number) => {
await deleteData(xGrid, rowId)
await deleteData(rowId)
}
// 提交按钮
@ -194,7 +192,7 @@ const submitForm = async () => {
} finally {
actionLoading.value = false
// 刷新列表
await getList(xGrid)
await reload()
}
}
})