From 9794d1cfd7b461a2b66a4960f2ab2698f607e642 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 15 Nov 2022 14:39:39 +0800 Subject: [PATCH] refactor: reloadList --- .../src/hooks/web/useVxeGrid.ts | 4 ++-- .../src/views/system/errorCode/index.vue | 18 +++++------------- .../src/views/system/loginlog/index.vue | 7 ++----- .../src/views/system/notice/index.vue | 18 +++++------------- .../src/views/system/oauth2/client/index.vue | 18 +++++------------- .../src/views/system/oauth2/token/index.vue | 4 ++-- .../src/views/system/post/index.vue | 4 ++-- 7 files changed, 23 insertions(+), 50 deletions(-) diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts index 31b448061..50b822d3c 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeGrid.ts @@ -113,7 +113,7 @@ export const useVxeGrid = (config?: UseVxeGridConfig) => { }) // 刷新列表 - const getList = async (ref) => { + const reloadList = async (ref) => { await nextTick() ref.value?.commitProxy('query') } @@ -147,7 +147,7 @@ export const useVxeGrid = (config?: UseVxeGridConfig) => { return { gridOptions, - getList, + reloadList, getSearchData, delList } diff --git a/yudao-ui-admin-vue3/src/views/system/errorCode/index.vue b/yudao-ui-admin-vue3/src/views/system/errorCode/index.vue index 242f41d39..5dcff9156 100644 --- a/yudao-ui-admin-vue3/src/views/system/errorCode/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/errorCode/index.vue @@ -83,9 +83,10 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // grid Ref -const { gridOptions } = useVxeGrid({ +const { gridOptions, reloadList, delList } = useVxeGrid({ allSchemas: allSchemas, - getListApi: ErrorCodeApi.getErrorCodePageApi + getListApi: ErrorCodeApi.getErrorCodePageApi, + delListApi: ErrorCodeApi.deleteErrorCodeApi }) // 弹窗相关的变量 const dialogVisible = ref(false) // 是否显示弹出层 @@ -125,16 +126,7 @@ const handleDetail = async (rowId: number) => { // 删除操作 const handleDelete = async (rowId: number) => { - message - .delConfirm() - .then(async () => { - await ErrorCodeApi.deleteErrorCodeApi(rowId) - message.success(t('common.delSuccess')) - }) - .finally(() => { - // 刷新列表 - xGrid.value?.commitProxy('query') - }) + delList(xGrid, rowId) } // 提交新增/修改的表单 @@ -158,7 +150,7 @@ const submitForm = async () => { } finally { actionLoading.value = false // 刷新列表 - xGrid.value?.commitProxy('query') + reloadList(xGrid) } } }) diff --git a/yudao-ui-admin-vue3/src/views/system/loginlog/index.vue b/yudao-ui-admin-vue3/src/views/system/loginlog/index.vue index d17d575ca..abe983f8d 100644 --- a/yudao-ui-admin-vue3/src/views/system/loginlog/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/loginlog/index.vue @@ -42,7 +42,7 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // 列表 Grid Ref -const { gridOptions } = useVxeGrid({ +const { gridOptions, getSearchData } = useVxeGrid({ allSchemas: allSchemas, getListApi: getLoginLogPageApi }) @@ -61,10 +61,7 @@ const handleDetail = async (row: LoginLogVO) => { // 导出操作 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 exportLoginLogApi(queryParams) download.excel(res, '登录列表.xls') }) diff --git a/yudao-ui-admin-vue3/src/views/system/notice/index.vue b/yudao-ui-admin-vue3/src/views/system/notice/index.vue index c500ba785..a7d5a3546 100644 --- a/yudao-ui-admin-vue3/src/views/system/notice/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/notice/index.vue @@ -82,9 +82,10 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // 列表 Grid Ref -const { gridOptions } = useVxeGrid({ +const { gridOptions, reloadList, delList } = useVxeGrid({ allSchemas: allSchemas, - getListApi: NoticeApi.getNoticePageApi + getListApi: NoticeApi.getNoticePageApi, + delListApi: NoticeApi.deleteNoticeApi }) // 弹窗相关的变量 const dialogVisible = ref(false) // 是否显示弹出层 @@ -124,16 +125,7 @@ const handleDetail = async (rowId: number) => { // 删除操作 const handleDelete = async (rowId: number) => { - message - .delConfirm() - .then(async () => { - await NoticeApi.deleteNoticeApi(rowId) - message.success(t('common.delSuccess')) - }) - .finally(() => { - // 刷新列表 - xGrid.value?.commitProxy('query') - }) + delList(xGrid, rowId) } // 提交新增/修改的表单 @@ -157,7 +149,7 @@ const submitForm = async () => { } finally { actionLoading.value = false // 刷新列表 - xGrid.value?.commitProxy('query') + reloadList(xGrid) } } }) diff --git a/yudao-ui-admin-vue3/src/views/system/oauth2/client/index.vue b/yudao-ui-admin-vue3/src/views/system/oauth2/client/index.vue index 012221442..33599c117 100644 --- a/yudao-ui-admin-vue3/src/views/system/oauth2/client/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/oauth2/client/index.vue @@ -94,9 +94,10 @@ const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // 列表 Grid Ref -const { gridOptions } = useVxeGrid({ +const { gridOptions, reloadList, delList } = useVxeGrid({ allSchemas: allSchemas, - getListApi: ClientApi.getOAuth2ClientPageApi + getListApi: ClientApi.getOAuth2ClientPageApi, + delListApi: ClientApi.deleteOAuth2ClientApi }) // 弹窗相关的变量 const dialogVisible = ref(false) // 是否显示弹出层 @@ -135,16 +136,7 @@ const handleDetail = async (rowId: number) => { // 删除操作 const handleDelete = async (rowId: number) => { - message - .delConfirm() - .then(async () => { - await ClientApi.deleteOAuth2ClientApi(rowId) - message.success(t('common.delSuccess')) - }) - .finally(() => { - // 刷新列表 - xGrid.value?.commitProxy('query') - }) + delList(xGrid, rowId) } // 提交新增/修改的表单 @@ -168,7 +160,7 @@ const submitForm = async () => { } finally { actionLoading.value = false // 刷新列表 - xGrid.value?.commitProxy('query') + reloadList(xGrid) } } }) diff --git a/yudao-ui-admin-vue3/src/views/system/oauth2/token/index.vue b/yudao-ui-admin-vue3/src/views/system/oauth2/token/index.vue index ead384e89..f7bfff4c4 100644 --- a/yudao-ui-admin-vue3/src/views/system/oauth2/token/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/oauth2/token/index.vue @@ -39,7 +39,7 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // 列表 Grid Ref -const { gridOptions } = useVxeGrid({ +const { gridOptions, reloadList } = useVxeGrid({ allSchemas: allSchemas, getListApi: TokenApi.getAccessTokenPageApi }) @@ -65,7 +65,7 @@ const handleForceLogout = (rowId: number) => { }) .finally(() => { // 刷新列表 - xGrid.value?.commitProxy('query') + reloadList(xGrid) }) } 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 01d279973..bfcb3f8a4 100644 --- a/yudao-ui-admin-vue3/src/views/system/post/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/post/index.vue @@ -90,7 +90,7 @@ const { t } = useI18n() // 国际化 const message = useMessage() // 消息弹窗 // 列表相关的变量 const xGrid = ref() // 列表 Grid Ref -const { gridOptions, getList, delList, getSearchData } = useVxeGrid({ +const { gridOptions, reloadList, delList, getSearchData } = useVxeGrid({ allSchemas: allSchemas, getListApi: PostApi.getPostPageApi, delListApi: PostApi.deletePostApi @@ -163,7 +163,7 @@ const submitForm = async () => { } finally { actionLoading.value = false // 刷新列表 - getList(xGrid) + reloadList(xGrid) } } })