refactor(api): ♻️ 优化用户分页请求和响应处理

This commit is contained in:
Ray.Hao
2026-01-10 10:50:19 +08:00
parent 3006cba16e
commit 967accfd48
3 changed files with 12 additions and 5 deletions

View File

@@ -9,7 +9,7 @@
"plugins": ["stylelint-prettier"],
"overrides": [
{
"files": ["**/*.{vue,html}"],
"files": ["**/*.{vue,html}"],
"customSyntax": "postcss-html"
},
{

View File

@@ -21,11 +21,14 @@ const UserAPI = {
* @param queryParams 查询参数
*/
getPage(queryParams: UserPageQuery) {
return request<PageResult<UserPageVO[]>>({
url: `${USER_BASE_URL}/page`,
return request<any>({
url: `${USER_BASE_URL}`,
method: "GET",
data: queryParams,
});
}).then((res: { data: UserPageVO[]; page?: { total?: number } }) => ({
list: res.data,
total: res.page?.total ?? 0,
}));
},
/**
* 添加用户

View File

@@ -54,7 +54,11 @@ function request<T = any>(options: RequestOptions): Promise<T> {
success: (res: any) => {
// 请求成功
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data.data);
if (res.data && typeof res.data === "object" && "page" in res.data && res.data.page != null) {
resolve({ data: res.data.data, page: res.data.page } as any);
} else {
resolve(res.data.data);
}
}
// 未授权错误
else if (res.statusCode === 401) {