From ecb7ade767bed920ae9b065cad315ef5493b1a0a Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 15 Nov 2022 14:30:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=88=97=E8=A1=A8=20=E5=88=A0=E9=99=A4=E8=A1=8C=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=9F=A5=E8=AF=A2=E5=8F=82=E6=95=B0=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/hooks/web/useVxeGrid.ts | 38 ++++++++++++++++--- .../src/views/system/operatelog/index.vue | 7 +--- .../src/views/system/post/index.vue | 23 +++-------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts index bf8f2ce7a..31b448061 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts @@ -1,4 +1,4 @@ -import { computed, reactive } from 'vue' +import { computed, nextTick, reactive } from 'vue' import { SizeType, VxeGridProps } from 'vxe-table' import { useAppStore } from '@/store/modules/app' import { VxeAllSchemas } from './useVxeCrudSchemas' @@ -112,17 +112,43 @@ export const useVxeGrid = (config?: UseVxeGridConfig) => { } }) - const delList = (ids: string | number | string[] | number[]) => { + // 刷新列表 + const getList = async (ref) => { + await nextTick() + ref.value?.commitProxy('query') + } + + // 获取查询参数 + const getSearchData = async (ref) => { + await nextTick() + const queryParams = Object.assign( + {}, + JSON.parse(JSON.stringify(ref.value?.getProxyInfo()?.form)) + ) + return queryParams + } + + // 删除 + const delList = async (ref, ids: string | number | string[] | number[]) => { + await nextTick() return new Promise(async () => { - message.delConfirm().then(() => { - config?.delListApi && config?.delListApi(ids) - message.success(t('common.delSuccess')) - }) + message + .delConfirm() + .then(() => { + config?.delListApi && config?.delListApi(ids) + message.success(t('common.delSuccess')) + }) + .finally(async () => { + // 刷新列表 + ref.value?.commitProxy('query') + }) }) } return { gridOptions, + getList, + getSearchData, delList } } diff --git a/yudao-ui-admin-vue3/src/views/system/operatelog/index.vue b/yudao-ui-admin-vue3/src/views/system/operatelog/index.vue index 884fd3b87..3c85c2f87 100644 --- a/yudao-ui-admin-vue3/src/views/system/operatelog/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/operatelog/index.vue @@ -57,7 +57,7 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // 列表 Grid Ref -const { gridOptions } = useVxeGrid({ +const { gridOptions, getSearchData } = useVxeGrid({ allSchemas: allSchemas, getListApi: OperateLogApi.getOperateLogPageApi }) @@ -77,10 +77,7 @@ const handleDetail = (row: OperateLogApi.OperateLogVO) => { // 导出操作 const handleExport = async () => { message.exportConfirm().then(async () => { - const queryParams = Object.assign( - {}, - JSON.parse(JSON.stringify(xGrid.value?.getRefMaps().refForm.value.data)) // TODO @星语:这个有没办法,封装个 util 获取哈? - ) + const queryParams = await getSearchData(xGrid) const res = await OperateLogApi.exportOperateLogApi(queryParams) download.excel(res, '岗位列表.xls') }) diff --git a/yudao-ui-admin-vue3/src/views/system/post/index.vue b/yudao-ui-admin-vue3/src/views/system/post/index.vue index a32faacc1..01d279973 100644 --- a/yudao-ui-admin-vue3/src/views/system/post/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/post/index.vue @@ -90,9 +90,10 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // 列表 Grid Ref -const { gridOptions } = useVxeGrid({ +const { gridOptions, getList, delList, getSearchData } = useVxeGrid({ allSchemas: allSchemas, - getListApi: PostApi.getPostPageApi + getListApi: PostApi.getPostPageApi, + delListApi: PostApi.deletePostApi }) // 弹窗相关的变量 const dialogVisible = ref(false) // 是否显示弹出层 @@ -116,10 +117,7 @@ const handleCreate = () => { // 导出操作 const handleExport = async () => { - const queryParams = Object.assign( - {}, - JSON.parse(JSON.stringify(xGrid.value?.getRefMaps().refForm.value.data)) - ) + const queryParams = await getSearchData(xGrid) const res = await PostApi.exportPostApi(queryParams) download.excel(res, '岗位列表.xls') } @@ -141,16 +139,7 @@ const handleDetail = async (rowId: number) => { // 删除操作 const handleDelete = async (rowId: number) => { - message - .delConfirm() - .then(async () => { - await PostApi.deletePostApi(rowId) - message.success(t('common.delSuccess')) - }) - .finally(() => { - // 刷新列表 - xGrid.value?.commitProxy('query') - }) + delList(xGrid, rowId) } // 提交新增/修改的表单 @@ -174,7 +163,7 @@ const submitForm = async () => { } finally { actionLoading.value = false // 刷新列表 - xGrid.value?.commitProxy('query') + getList(xGrid) } } })