Skip to content

Commit

Permalink
fix(projects): add getDataByPage for useTable. fixed #499
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jun 20, 2024
1 parent f7de3fd commit 425c69a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/hooks/common/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ export function useTable<A extends NaiveUI.TableApiFn>(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,
Expand All @@ -184,6 +202,7 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
mobilePagination,
updatePagination,
getData,
getDataByPage,
searchParams,
updateSearchParams,
resetSearchParams
Expand Down
4 changes: 2 additions & 2 deletions src/views/manage/menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { bool: visible, setTrue: openModal } = useBoolean();
const wrapperRef = ref<HTMLElement | null>(null);
const { columns, columnChecks, data, loading, pagination, getData } = useTable({
const { columns, columnChecks, data, loading, pagination, getData, getDataByPage } = useTable({
apiFn: fetchGetMenuList,
columns: () => [
{
Expand Down Expand Up @@ -257,7 +257,7 @@ init();
:operate-type="operateType"
:row-data="editingData"
:all-pages="allPages"
@submitted="getData"
@submitted="getDataByPage"
/>
</NCard>
</div>
Expand Down
16 changes: 13 additions & 3 deletions src/views/manage/role/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -129,7 +139,7 @@ function edit(id: number) {

<template>
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getDataByPage" />
<NCard :title="$t('page.manage.role.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
<template #header-extra>
<TableHeaderOperation
Expand Down Expand Up @@ -158,7 +168,7 @@ function edit(id: number) {
v-model:visible="drawerVisible"
:operate-type="operateType"
:row-data="editingData"
@submitted="getData"
@submitted="getDataByPage"
/>
</NCard>
</div>
Expand Down
16 changes: 13 additions & 3 deletions src/views/manage/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ import UserSearch from './modules/user-search.vue';
const appStore = useAppStore();
const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
const {
columns,
columnChecks,
data,
getData,
getDataByPage,
loading,
mobilePagination,
searchParams,
resetSearchParams
} = useTable({
apiFn: fetchGetUserList,
showTotal: true,
apiParams: {
Expand Down Expand Up @@ -160,7 +170,7 @@ function edit(id: number) {

<template>
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
<UserSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
<UserSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getDataByPage" />
<NCard :title="$t('page.manage.user.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
<template #header-extra>
<TableHeaderOperation
Expand Down Expand Up @@ -189,7 +199,7 @@ function edit(id: number) {
v-model:visible="drawerVisible"
:operate-type="operateType"
:row-data="editingData"
@submitted="getData"
@submitted="getDataByPage"
/>
</NCard>
</div>
Expand Down

0 comments on commit 425c69a

Please sign in to comment.