fix(projects): add getDataByPage
for useTable
. fixed #499
This commit is contained in:
parent
f7de3fd0f1
commit
425c69acc2
@ -160,6 +160,24 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
|
|||||||
Object.assign(pagination, update);
|
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(() => {
|
scope.run(() => {
|
||||||
watch(
|
watch(
|
||||||
() => appStore.locale,
|
() => appStore.locale,
|
||||||
@ -184,6 +202,7 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
|
|||||||
mobilePagination,
|
mobilePagination,
|
||||||
updatePagination,
|
updatePagination,
|
||||||
getData,
|
getData,
|
||||||
|
getDataByPage,
|
||||||
searchParams,
|
searchParams,
|
||||||
updateSearchParams,
|
updateSearchParams,
|
||||||
resetSearchParams
|
resetSearchParams
|
||||||
|
@ -18,7 +18,7 @@ const { bool: visible, setTrue: openModal } = useBoolean();
|
|||||||
|
|
||||||
const wrapperRef = ref<HTMLElement | null>(null);
|
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,
|
apiFn: fetchGetMenuList,
|
||||||
columns: () => [
|
columns: () => [
|
||||||
{
|
{
|
||||||
@ -257,7 +257,7 @@ init();
|
|||||||
:operate-type="operateType"
|
:operate-type="operateType"
|
||||||
:row-data="editingData"
|
:row-data="editingData"
|
||||||
:all-pages="allPages"
|
:all-pages="allPages"
|
||||||
@submitted="getData"
|
@submitted="getDataByPage"
|
||||||
/>
|
/>
|
||||||
</NCard>
|
</NCard>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,17 @@ import RoleSearch from './modules/role-search.vue';
|
|||||||
|
|
||||||
const appStore = useAppStore();
|
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,
|
apiFn: fetchGetRoleList,
|
||||||
apiParams: {
|
apiParams: {
|
||||||
current: 1,
|
current: 1,
|
||||||
@ -129,7 +139,7 @@ function edit(id: number) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
<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">
|
<NCard :title="$t('page.manage.role.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
|
||||||
<template #header-extra>
|
<template #header-extra>
|
||||||
<TableHeaderOperation
|
<TableHeaderOperation
|
||||||
@ -158,7 +168,7 @@ function edit(id: number) {
|
|||||||
v-model:visible="drawerVisible"
|
v-model:visible="drawerVisible"
|
||||||
:operate-type="operateType"
|
:operate-type="operateType"
|
||||||
:row-data="editingData"
|
:row-data="editingData"
|
||||||
@submitted="getData"
|
@submitted="getDataByPage"
|
||||||
/>
|
/>
|
||||||
</NCard>
|
</NCard>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,17 @@ import UserSearch from './modules/user-search.vue';
|
|||||||
|
|
||||||
const appStore = useAppStore();
|
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,
|
apiFn: fetchGetUserList,
|
||||||
showTotal: true,
|
showTotal: true,
|
||||||
apiParams: {
|
apiParams: {
|
||||||
@ -160,7 +170,7 @@ function edit(id: number) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
<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">
|
<NCard :title="$t('page.manage.user.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
|
||||||
<template #header-extra>
|
<template #header-extra>
|
||||||
<TableHeaderOperation
|
<TableHeaderOperation
|
||||||
@ -189,7 +199,7 @@ function edit(id: number) {
|
|||||||
v-model:visible="drawerVisible"
|
v-model:visible="drawerVisible"
|
||||||
:operate-type="operateType"
|
:operate-type="operateType"
|
||||||
:row-data="editingData"
|
:row-data="editingData"
|
||||||
@submitted="getData"
|
@submitted="getDataByPage"
|
||||||
/>
|
/>
|
||||||
</NCard>
|
</NCard>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user