Skip to content

Commit 425c69a

Browse files
committed
fix(projects): add getDataByPage for useTable. fixed #499
1 parent f7de3fd commit 425c69a

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

src/hooks/common/table.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
160160
Object.assign(pagination, update);
161161
}
162162

163+
/**
164+
* get data by page number
165+
*
166+
* @param pageNum the page number. default is 1
167+
*/
168+
async function getDataByPage(pageNum: number = 1) {
169+
updatePagination({
170+
page: pageNum
171+
});
172+
173+
updateSearchParams({
174+
current: pageNum,
175+
size: pagination.pageSize!
176+
});
177+
178+
await getData();
179+
}
180+
163181
scope.run(() => {
164182
watch(
165183
() => appStore.locale,
@@ -184,6 +202,7 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
184202
mobilePagination,
185203
updatePagination,
186204
getData,
205+
getDataByPage,
187206
searchParams,
188207
updateSearchParams,
189208
resetSearchParams

src/views/manage/menu/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const { bool: visible, setTrue: openModal } = useBoolean();
1818
1919
const wrapperRef = ref<HTMLElement | null>(null);
2020
21-
const { columns, columnChecks, data, loading, pagination, getData } = useTable({
21+
const { columns, columnChecks, data, loading, pagination, getData, getDataByPage } = useTable({
2222
apiFn: fetchGetMenuList,
2323
columns: () => [
2424
{
@@ -257,7 +257,7 @@ init();
257257
:operate-type="operateType"
258258
:row-data="editingData"
259259
:all-pages="allPages"
260-
@submitted="getData"
260+
@submitted="getDataByPage"
261261
/>
262262
</NCard>
263263
</div>

src/views/manage/role/index.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ import RoleSearch from './modules/role-search.vue';
1010
1111
const appStore = useAppStore();
1212
13-
const { columns, columnChecks, data, loading, getData, mobilePagination, searchParams, resetSearchParams } = useTable({
13+
const {
14+
columns,
15+
columnChecks,
16+
data,
17+
loading,
18+
getData,
19+
getDataByPage,
20+
mobilePagination,
21+
searchParams,
22+
resetSearchParams
23+
} = useTable({
1424
apiFn: fetchGetRoleList,
1525
apiParams: {
1626
current: 1,
@@ -129,7 +139,7 @@ function edit(id: number) {
129139

130140
<template>
131141
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
132-
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
142+
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getDataByPage" />
133143
<NCard :title="$t('page.manage.role.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
134144
<template #header-extra>
135145
<TableHeaderOperation
@@ -158,7 +168,7 @@ function edit(id: number) {
158168
v-model:visible="drawerVisible"
159169
:operate-type="operateType"
160170
:row-data="editingData"
161-
@submitted="getData"
171+
@submitted="getDataByPage"
162172
/>
163173
</NCard>
164174
</div>

src/views/manage/user/index.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ import UserSearch from './modules/user-search.vue';
1010
1111
const appStore = useAppStore();
1212
13-
const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
13+
const {
14+
columns,
15+
columnChecks,
16+
data,
17+
getData,
18+
getDataByPage,
19+
loading,
20+
mobilePagination,
21+
searchParams,
22+
resetSearchParams
23+
} = useTable({
1424
apiFn: fetchGetUserList,
1525
showTotal: true,
1626
apiParams: {
@@ -160,7 +170,7 @@ function edit(id: number) {
160170

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

0 commit comments

Comments
 (0)