chore: 更新 README 文档,调整版本信息及投票链接,优化请求工具函数

This commit is contained in:
Ray.Hao
2026-01-09 10:07:39 +08:00
parent 7ba2e279e8
commit ca9fca7f57
4 changed files with 44 additions and 78 deletions

View File

@@ -15,21 +15,6 @@ const http = axios.create({
paramsSerializer: (params) => qs.stringify(params),
});
type PageMeta = { pageNum: number; pageSize: number; total: number };
type PagedApiResponse<T = any> = ApiResponse<T> & { page: PageMeta | null };
function isPagedApiResponse<T>(payload: ApiResponse<T>): payload is PagedApiResponse<T> {
// Treat as paged response only when `page` is a non-null object (contains pagination meta).
// Some APIs return `page: null` for non-paged endpoints; checking for the presence
// of the `page` property alone causes unintended branching (e.g. captcha endpoint).
return (
payload != null &&
typeof payload === "object" &&
payload.page != null &&
typeof (payload as any).page === "object"
);
}
// ============================================
// 请求拦截器
// ============================================
@@ -65,10 +50,8 @@ http.interceptors.response.use(
if (code === ApiCodeEnum.SUCCESS) {
// 分页接口需要同时返回 data 与 page 元信息
if (isPagedApiResponse(response.data)) {
const { page } = response.data;
return { data, page: page ?? null };
}
const page = (response.data as any)?.page;
if (page != null) return { data, page };
return data;
}