feat(miniprogram): 适老化修复 — Phase 2e
M6: 创建 utils/date.ts 统一日期工具函数(formatDate/formatDateTime/toRelativeDate 等) M8: 28 个 SCSS 文件 font-size 20px → 22px 全量适老化 M7: request.ts 增加 403 权限不足/5xx 服务器错误/网络超时异常统一拦截
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
}
|
||||
|
||||
.cell-weekday {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
color: $tx3;
|
||||
display: block;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
@@ -109,7 +109,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 16px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: #f0e6ff;
|
||||
color: #7c3aed;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -185,7 +185,7 @@
|
||||
}
|
||||
|
||||
.confirm-dept-text {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
color: $pri;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
|
||||
.info-icon-serif {
|
||||
font-family: 'Georgia', 'Times New Roman', serif;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
color: $pri;
|
||||
background: $pri-l;
|
||||
width: 36px;
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
}
|
||||
|
||||
.dept-tag-text {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
color: $pri;
|
||||
}
|
||||
@@ -124,7 +124,7 @@
|
||||
}
|
||||
|
||||
.status-tag-text {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
}
|
||||
|
||||
.msg-time {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
color: $tx3;
|
||||
display: block;
|
||||
margin-top: 8px;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
|
||||
.msg-time {
|
||||
@include serif-number;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
color: $tx3;
|
||||
display: block;
|
||||
margin-top: 8px;
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
background: $bd-l;
|
||||
color: $tx3;
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
background: $bd-l;
|
||||
color: $tx3;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -120,7 +120,7 @@
|
||||
}
|
||||
|
||||
.agreement-check-mark {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
}
|
||||
|
||||
.product-stock {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
padding: 2px 10px;
|
||||
border-radius: $r-sm;
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
|
||||
.dm-card-badge {
|
||||
@include tag($acc-l, $acc);
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
@@ -244,6 +244,6 @@
|
||||
|
||||
.tx-remaining {
|
||||
@include serif-number;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
color: $tx3;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bd-l;
|
||||
color: $tx3;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bd-l;
|
||||
color: $tx3;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
@@ -117,7 +117,7 @@
|
||||
|
||||
.family-relation-tag {
|
||||
@include tag($pri-l, $pri-d);
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
padding: 2px 12px;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
background: $bg;
|
||||
color: $color;
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
}
|
||||
|
||||
.profile-name {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
color: $tx;
|
||||
display: block;
|
||||
@@ -121,7 +121,7 @@
|
||||
}
|
||||
|
||||
.menu-icon-text {
|
||||
font-size: 20px;
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.menu-label {
|
||||
|
||||
@@ -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;
|
||||
|
||||
74
apps/miniprogram/src/utils/date.ts
Normal file
74
apps/miniprogram/src/utils/date.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 统一日期工具函数 — 替代分散在各页面的内联日期格式化
|
||||
*/
|
||||
|
||||
/** 格式化为 YYYY-MM-DD */
|
||||
export function formatDate(iso: string | null | undefined): string {
|
||||
if (!iso) return '-';
|
||||
const d = new Date(iso);
|
||||
if (isNaN(d.getTime())) return '-';
|
||||
const y = d.getFullYear();
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${day}`;
|
||||
}
|
||||
|
||||
/** 格式化为 YYYY-MM-DD HH:mm */
|
||||
export function formatDateTime(iso: string | null | undefined): string {
|
||||
if (!iso) return '-';
|
||||
const d = new Date(iso);
|
||||
if (isNaN(d.getTime())) return '-';
|
||||
const date = formatDate(iso);
|
||||
const h = String(d.getHours()).padStart(2, '0');
|
||||
const min = String(d.getMinutes()).padStart(2, '0');
|
||||
return `${date} ${h}:${min}`;
|
||||
}
|
||||
|
||||
/** 格式化为 YYYY-MM-DD HH:mm:ss */
|
||||
export function formatDateTimeFull(iso: string | null | undefined): string {
|
||||
if (!iso) return '-';
|
||||
const d = new Date(iso);
|
||||
if (isNaN(d.getTime())) return '-';
|
||||
const base = formatDateTime(iso);
|
||||
const s = String(d.getSeconds()).padStart(2, '0');
|
||||
return `${base}:${s}`;
|
||||
}
|
||||
|
||||
/** 获取今天的 YYYY-MM-DD */
|
||||
export function today(): string {
|
||||
const d = new Date();
|
||||
const y = d.getFullYear();
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${day}`;
|
||||
}
|
||||
|
||||
/** 相对时间:今天/昨天/前天/更早 */
|
||||
export function toRelativeDate(iso: string | null | undefined): string {
|
||||
if (!iso) return '-';
|
||||
const d = new Date(iso);
|
||||
if (isNaN(d.getTime())) return '-';
|
||||
|
||||
const now = new Date();
|
||||
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const targetStart = new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
||||
const diffDays = Math.round((todayStart.getTime() - targetStart.getTime()) / 86400000);
|
||||
|
||||
if (diffDays === 0) return '今天';
|
||||
if (diffDays === 1) return '昨天';
|
||||
if (diffDays === 2) return '前天';
|
||||
return formatDate(iso);
|
||||
}
|
||||
|
||||
/** 格式化为中文月日 + 星期 */
|
||||
export function formatMonthDayWeek(iso: string | null | undefined): string {
|
||||
if (!iso) return '';
|
||||
const d = new Date(iso);
|
||||
if (isNaN(d.getTime())) return '';
|
||||
|
||||
const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
|
||||
const m = d.getMonth() + 1;
|
||||
const day = d.getDate();
|
||||
const w = weekdays[d.getDay()];
|
||||
return `${m}月${day}日 周${w}`;
|
||||
}
|
||||
Reference in New Issue
Block a user