feat(projects): mock manage list data with pagination
This commit is contained in:
parent
c7e2c55996
commit
1a6be003e2
@ -104,7 +104,9 @@ export function useTable<TableData extends BaseData, Fn extends ApiFn, CustomCol
|
|||||||
async function getData() {
|
async function getData() {
|
||||||
startLoading();
|
startLoading();
|
||||||
|
|
||||||
const response = await apiFn(searchParams);
|
const formattedParams = formatSearchParams(searchParams);
|
||||||
|
|
||||||
|
const response = await apiFn(formattedParams);
|
||||||
|
|
||||||
const { data: tableData, pageNum, pageSize, total } = transformer(response as Awaited<ReturnType<Fn>>);
|
const { data: tableData, pageNum, pageSize, total } = transformer(response as Awaited<ReturnType<Fn>>);
|
||||||
|
|
||||||
@ -115,6 +117,18 @@ export function useTable<TableData extends BaseData, Fn extends ApiFn, CustomCol
|
|||||||
endLoading();
|
endLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatSearchParams(params: Record<string, unknown>) {
|
||||||
|
const formattedParams: Record<string, unknown> = {};
|
||||||
|
|
||||||
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
|
if (value !== null && value !== undefined) {
|
||||||
|
formattedParams[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return formattedParams;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update search params
|
* update search params
|
||||||
*
|
*
|
||||||
|
@ -64,7 +64,7 @@ export const generatedRoutes: GeneratedRoute[] = [
|
|||||||
meta: {
|
meta: {
|
||||||
title: 'function_hide-child',
|
title: 'function_hide-child',
|
||||||
i18nKey: 'route.function_hide-child',
|
i18nKey: 'route.function_hide-child',
|
||||||
icon: 'material-symbols:filter-list-off',
|
icon: 'material-symbols:filter-list-off'
|
||||||
},
|
},
|
||||||
redirect: '/function/hide-child/one',
|
redirect: '/function/hide-child/one',
|
||||||
children: [
|
children: [
|
||||||
|
@ -13,11 +13,17 @@ import RoleSearch from './modules/role-search.vue';
|
|||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const { bool: drawerVisible, setTrue: openDrawer } = useBoolean();
|
const { bool: drawerVisible, setTrue: openDrawer } = useBoolean();
|
||||||
|
|
||||||
const { columns, filteredColumns, data, loading, pagination, getData, searchParams, resetSearchParams } = useTable<
|
const {
|
||||||
Api.SystemManage.Role,
|
columns,
|
||||||
typeof fetchGetRoleList,
|
filteredColumns,
|
||||||
'index' | 'operate'
|
data,
|
||||||
>({
|
loading,
|
||||||
|
pagination,
|
||||||
|
getData,
|
||||||
|
searchParams,
|
||||||
|
updateSearchParams,
|
||||||
|
resetSearchParams
|
||||||
|
} = useTable<Api.SystemManage.Role, typeof fetchGetRoleList, 'index' | 'operate'>({
|
||||||
apiFn: fetchGetRoleList,
|
apiFn: fetchGetRoleList,
|
||||||
apiParams: {
|
apiParams: {
|
||||||
current: 1,
|
current: 1,
|
||||||
@ -38,6 +44,16 @@ const { columns, filteredColumns, data, loading, pagination, getData, searchPara
|
|||||||
total
|
total
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
onPaginationChanged(pg) {
|
||||||
|
const { page, pageSize } = pg;
|
||||||
|
|
||||||
|
updateSearchParams({
|
||||||
|
current: page,
|
||||||
|
size: pageSize
|
||||||
|
});
|
||||||
|
|
||||||
|
getData();
|
||||||
|
},
|
||||||
columns: () => [
|
columns: () => [
|
||||||
{
|
{
|
||||||
type: 'selection',
|
type: 'selection',
|
||||||
@ -179,6 +195,7 @@ function getIndex(index: number) {
|
|||||||
:flex-height="!appStore.isMobile"
|
:flex-height="!appStore.isMobile"
|
||||||
:scroll-x="702"
|
:scroll-x="702"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
remote
|
||||||
:pagination="pagination"
|
:pagination="pagination"
|
||||||
:row-key="item => item.id"
|
:row-key="item => item.id"
|
||||||
class="sm:h-full"
|
class="sm:h-full"
|
||||||
|
@ -13,11 +13,17 @@ import UserSearch from './modules/user-search.vue';
|
|||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const { bool: drawerVisible, setTrue: openDrawer } = useBoolean();
|
const { bool: drawerVisible, setTrue: openDrawer } = useBoolean();
|
||||||
|
|
||||||
const { columns, filteredColumns, data, loading, pagination, getData, searchParams, resetSearchParams } = useTable<
|
const {
|
||||||
Api.SystemManage.User,
|
columns,
|
||||||
typeof fetchGetUserList,
|
filteredColumns,
|
||||||
'index' | 'operate'
|
data,
|
||||||
>({
|
loading,
|
||||||
|
pagination,
|
||||||
|
getData,
|
||||||
|
searchParams,
|
||||||
|
updateSearchParams,
|
||||||
|
resetSearchParams
|
||||||
|
} = useTable<Api.SystemManage.User, typeof fetchGetUserList, 'index' | 'operate'>({
|
||||||
apiFn: fetchGetUserList,
|
apiFn: fetchGetUserList,
|
||||||
apiParams: {
|
apiParams: {
|
||||||
current: 1,
|
current: 1,
|
||||||
@ -41,6 +47,16 @@ const { columns, filteredColumns, data, loading, pagination, getData, searchPara
|
|||||||
total
|
total
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
onPaginationChanged(pg) {
|
||||||
|
const { page, pageSize } = pg;
|
||||||
|
|
||||||
|
updateSearchParams({
|
||||||
|
current: page,
|
||||||
|
size: pageSize
|
||||||
|
});
|
||||||
|
|
||||||
|
getData();
|
||||||
|
},
|
||||||
columns: () => [
|
columns: () => [
|
||||||
{
|
{
|
||||||
type: 'selection',
|
type: 'selection',
|
||||||
@ -209,6 +225,7 @@ function getIndex(index: number) {
|
|||||||
:flex-height="!appStore.isMobile"
|
:flex-height="!appStore.isMobile"
|
||||||
:scroll-x="962"
|
:scroll-x="962"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
remote
|
||||||
:pagination="pagination"
|
:pagination="pagination"
|
||||||
:row-key="item => item.id"
|
:row-key="item => item.id"
|
||||||
class="sm:h-full"
|
class="sm:h-full"
|
||||||
|
Loading…
Reference in New Issue
Block a user