fix(admin): 用户管理页面优化,增加服务器端分页,避免拉全量用户数据,同时修复一些bug
This commit is contained in:
1 parent
950d661b4f
commit
6f9c25bb34
12 files changed
+816
-70
No files matched your search
@@ -4,13 +4,56 @@
|
||||
*/
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import type { AdminUserRow } from '../types/admin.types';
|
||||
import type { AdminDashboardBadges, AdminDashboardSummary } from '../types/dashboard.types';
|
||||
import type { PaginatedResult } from '@/shared/types/pagination.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
||||
|
||||
// Users
|
||||
export const listAdminUsers = () => requestJson<any[]>('/api/admin/users', auth());
|
||||
export const listAdminUsers = () => requestJson<AdminUserRow[]>('/api/admin/users', auth());
|
||||
|
||||
export interface ListAdminUsersPageParams {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
username?: string;
|
||||
email?: string;
|
||||
department?: string;
|
||||
role?: string;
|
||||
status?: string;
|
||||
real_name?: string;
|
||||
employee_id?: string;
|
||||
phone_number?: string;
|
||||
hideRejected?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页拉取用户列表(服务端筛选 + 分页,供用户管理页使用)。
|
||||
* @param params - 页码、每页条数与各字段模糊筛选
|
||||
*/
|
||||
export const listAdminUsersPage = (params: ListAdminUsersPageParams) => {
|
||||
const qs = new URLSearchParams();
|
||||
qs.set('page', String(params.page ?? 1));
|
||||
qs.set('page_size', String(params.pageSize ?? 20));
|
||||
const textFilters: Array<{ paramKey: keyof ListAdminUsersPageParams; queryKey: string }> = [
|
||||
{ paramKey: 'username', queryKey: 'username' },
|
||||
{ paramKey: 'email', queryKey: 'email' },
|
||||
{ paramKey: 'department', queryKey: 'department' },
|
||||
{ paramKey: 'role', queryKey: 'role' },
|
||||
{ paramKey: 'status', queryKey: 'status' },
|
||||
{ paramKey: 'real_name', queryKey: 'real_name' },
|
||||
{ paramKey: 'employee_id', queryKey: 'employee_id' },
|
||||
{ paramKey: 'phone_number', queryKey: 'phone_number' },
|
||||
];
|
||||
for (const { paramKey, queryKey } of textFilters) {
|
||||
const raw = params[paramKey];
|
||||
const value = typeof raw === 'string' ? raw.trim() : '';
|
||||
if (value) qs.set(queryKey, value);
|
||||
}
|
||||
if (params.hideRejected) qs.set('hide_rejected', 'true');
|
||||
return requestJson<PaginatedResult<AdminUserRow>>(`/api/admin/users?${qs.toString()}`, auth());
|
||||
};
|
||||
export const createAdminUser = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/users', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const updateAdminUser = (id: number, payload: Record<string, unknown>) =>
|
||||
|
||||
Reference in new issue
Block a user