From 425c69acc28f09a23fd274180c31d21b0a77606c Mon Sep 17 00:00:00 2001 From: Soybean Date: Thu, 20 Jun 2024 19:27:39 +0800 Subject: [PATCH] fix(projects): add `getDataByPage` for `useTable`. fixed #499 --- src/hooks/common/table.ts | 19 +++++++++++++++++++ src/views/manage/menu/index.vue | 4 ++-- src/views/manage/role/index.vue | 16 +++++++++++++--- src/views/manage/user/index.vue | 16 +++++++++++++--- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/hooks/common/table.ts b/src/hooks/common/table.ts index 5ac0e5e6..3a6d6a52 100644 --- a/src/hooks/common/table.ts +++ b/src/hooks/common/table.ts @@ -160,6 +160,24 @@ export function useTable(config: NaiveUI.NaiveTabl Object.assign(pagination, update); } + /** + * get data by page number + * + * @param pageNum the page number. default is 1 + */ + async function getDataByPage(pageNum: number = 1) { + updatePagination({ + page: pageNum + }); + + updateSearchParams({ + current: pageNum, + size: pagination.pageSize! + }); + + await getData(); + } + scope.run(() => { watch( () => appStore.locale, @@ -184,6 +202,7 @@ export function useTable(config: NaiveUI.NaiveTabl mobilePagination, updatePagination, getData, + getDataByPage, searchParams, updateSearchParams, resetSearchParams diff --git a/src/views/manage/menu/index.vue b/src/views/manage/menu/index.vue index e34c5c41..81424b18 100644 --- a/src/views/manage/menu/index.vue +++ b/src/views/manage/menu/index.vue @@ -18,7 +18,7 @@ const { bool: visible, setTrue: openModal } = useBoolean(); const wrapperRef = ref(null); -const { columns, columnChecks, data, loading, pagination, getData } = useTable({ +const { columns, columnChecks, data, loading, pagination, getData, getDataByPage } = useTable({ apiFn: fetchGetMenuList, columns: () => [ { @@ -257,7 +257,7 @@ init(); :operate-type="operateType" :row-data="editingData" :all-pages="allPages" - @submitted="getData" + @submitted="getDataByPage" /> diff --git a/src/views/manage/role/index.vue b/src/views/manage/role/index.vue index 34989f34..5b956090 100644 --- a/src/views/manage/role/index.vue +++ b/src/views/manage/role/index.vue @@ -10,7 +10,17 @@ import RoleSearch from './modules/role-search.vue'; const appStore = useAppStore(); -const { columns, columnChecks, data, loading, getData, mobilePagination, searchParams, resetSearchParams } = useTable({ +const { + columns, + columnChecks, + data, + loading, + getData, + getDataByPage, + mobilePagination, + searchParams, + resetSearchParams +} = useTable({ apiFn: fetchGetRoleList, apiParams: { current: 1, @@ -129,7 +139,7 @@ function edit(id: number) {