feat(miniprogram): 适老化修复 — Phase 2e
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

M6: 创建 utils/date.ts 统一日期工具函数(formatDate/formatDateTime/toRelativeDate 等)
M8: 28 个 SCSS 文件 font-size 20px → 22px 全量适老化
M7: request.ts 增加 403 权限不足/5xx 服务器错误/网络超时异常统一拦截
This commit is contained in:
iven
2026-05-05 00:22:49 +08:00
parent 8d288cadfa
commit bef2ea7169
30 changed files with 129 additions and 34 deletions

View File

@@ -60,7 +60,18 @@ async function doRefresh(): Promise<boolean> {
async function request<T>(method: string, path: string, data?: unknown): Promise<T> {
const headers = await getHeaders();
const url = `${BASE_URL}${path}`;
const res = await Taro.request({ url, method: method as any, data, header: headers, timeout: 15000 });
let res: Taro.request.SuccessCallbackResult;
try {
res = await Taro.request({ url, method: method as any, data, header: headers, timeout: 15000 });
} catch (err: any) {
const msg = err?.errMsg || '';
if (msg.includes('timeout')) {
Taro.showToast({ title: '网络超时,请重试', icon: 'none' });
throw new Error('网络超时');
}
Taro.showToast({ title: '网络异常,请检查连接', icon: 'none' });
throw new Error('网络异常');
}
if (res.statusCode === 401) {
const refreshed = await tryRefreshToken();
@@ -73,6 +84,16 @@ async function request<T>(method: string, path: string, data?: unknown): Promise
throw new Error('登录已过期');
}
if (res.statusCode === 403) {
Taro.showToast({ title: '权限不足', icon: 'none' });
throw new Error('权限不足');
}
if (res.statusCode >= 500) {
Taro.showToast({ title: '服务器繁忙,请稍后重试', icon: 'none' });
throw new Error('服务器错误');
}
const body = res.data as ApiResponse<T>;
if (!body.success) throw new Error(body.message || '请求失败');
return body.data as T;