refactor: Xtable

This commit is contained in:
xingyu 2023-01-03 16:35:07 +08:00
parent f2d2dc4d9e
commit 8488933ec4

View File

@ -7,12 +7,7 @@
<span>字典分类</span> <span>字典分类</span>
</div> </div>
</template> </template>
<vxe-grid <XTable @register="registerType" @cell-click="cellClickEvent">
ref="xTypeGrid"
v-bind="typeGridOptions"
@cell-click="cellClickEvent"
class="xtable-scrollbar"
>
<!-- 操作新增类型 --> <!-- 操作新增类型 -->
<template #toolbar_buttons> <template #toolbar_buttons>
<XButton <XButton
@ -39,7 +34,7 @@
@click="handleTypeDelete(row.id)" @click="handleTypeDelete(row.id)"
/> />
</template> </template>
</vxe-grid> </XTable>
<!-- @星语分页和列表重叠在一起了 --> <!-- @星语分页和列表重叠在一起了 -->
</el-card> </el-card>
<!-- ====== 字典数据 ====== --> <!-- ====== 字典数据 ====== -->
@ -55,7 +50,7 @@
</div> </div>
<div v-if="tableTypeSelect"> <div v-if="tableTypeSelect">
<!-- 列表 --> <!-- 列表 -->
<vxe-grid ref="xDataGrid" v-bind="dataGridOptions" class="xtable-scrollbar"> <XTable @register="registerData">
<!-- 操作新增数据 --> <!-- 操作新增数据 -->
<template #toolbar_buttons> <template #toolbar_buttons>
<XButton <XButton
@ -82,7 +77,7 @@
@click="handleDataDelete(row.id)" @click="handleDataDelete(row.id)"
/> />
</template> </template>
</vxe-grid> </XTable>
</div> </div>
</el-card> </el-card>
<XModal id="dictModel" v-model="dialogVisible" :title="dialogTitle"> <XModal id="dictModel" v-model="dialogVisible" :title="dialogTitle">
@ -130,8 +125,8 @@
import { ref, unref, reactive } from 'vue' import { ref, unref, reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid' import { useXTable } from '@/hooks/web/useXTable'
import { VxeGridInstance, VxeTableEvents } from 'vxe-table' import { VxeTableEvents } from 'vxe-table'
import { FormExpose } from '@/components/Form' import { FormExpose } from '@/components/Form'
import { ElInput, ElTag, ElCard } from 'element-plus' import { ElInput, ElTag, ElCard } from 'element-plus'
import * as DictTypeSchemas from './dict.type' import * as DictTypeSchemas from './dict.type'
@ -143,28 +138,18 @@ import { DictDataVO, DictTypeVO } from '@/api/system/dict/types'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const xTypeGrid = ref<VxeGridInstance>() // Grid Ref const [registerType, { reload: typeGetList, deleteData: typeDeleteData }] = useXTable({
const {
gridOptions: typeGridOptions,
getList: typeGetList,
deleteData: typeDeleteData
} = useVxeGrid<DictTypeVO>({
allSchemas: DictTypeSchemas.allSchemas, allSchemas: DictTypeSchemas.allSchemas,
getListApi: DictTypeApi.getDictTypePageApi, getListApi: DictTypeApi.getDictTypePageApi,
deleteApi: DictTypeApi.deleteDictTypeApi deleteApi: DictTypeApi.deleteDictTypeApi
}) })
const xDataGrid = ref<VxeGridInstance>() // Grid Ref
const queryParams = reactive({ const queryParams = reactive({
dictType: null dictType: null
}) })
const { const [registerData, { reload: dataGetList, deleteData: dataDeleteData }] = useXTable({
gridOptions: dataGridOptions,
getList: dataGetList,
deleteData: dataDeleteData
} = useVxeGrid<DictDataVO>({
allSchemas: DictDataSchemas.allSchemas, allSchemas: DictDataSchemas.allSchemas,
queryParams: queryParams, params: queryParams,
getListApi: DictDataApi.getDictDataPageApi, getListApi: DictDataApi.getDictDataPageApi,
deleteApi: DictDataApi.deleteDictDataApi deleteApi: DictDataApi.deleteDictDataApi
}) })
@ -199,7 +184,7 @@ const tableTypeSelect = ref(false)
const cellClickEvent: VxeTableEvents.CellClick = async ({ row }) => { const cellClickEvent: VxeTableEvents.CellClick = async ({ row }) => {
tableTypeSelect.value = true tableTypeSelect.value = true
queryParams.dictType = row['type'] queryParams.dictType = row['type']
await dataGetList(xDataGrid) await dataGetList()
parentType.value = row['type'] parentType.value = row['type']
} }
// //
@ -219,11 +204,11 @@ const setDialogTile = (type: string) => {
// //
const handleTypeDelete = async (rowId: number) => { const handleTypeDelete = async (rowId: number) => {
await typeDeleteData(xTypeGrid, rowId) await typeDeleteData(rowId)
} }
const handleDataDelete = async (rowId: number) => { const handleDataDelete = async (rowId: number) => {
await dataDeleteData(xDataGrid, rowId) await dataDeleteData(rowId)
} }
// //
@ -247,7 +232,7 @@ const submitTypeForm = async () => {
dialogVisible.value = false dialogVisible.value = false
} finally { } finally {
actionLoading.value = false actionLoading.value = false
typeGetList(xTypeGrid) typeGetList()
} }
} }
}) })
@ -272,7 +257,7 @@ const submitDataForm = async () => {
dialogVisible.value = false dialogVisible.value = false
} finally { } finally {
actionLoading.value = false actionLoading.value = false
dataGetList(xDataGrid) dataGetList()
} }
} }
}) })