e2646346a6
新建 web/usercenter/:Next.js App Router + output:'export' 纯静态导出,
直接复用 design/ui_kits/usercenter React 源码(概览/订阅/兑换/邀请/设置)。
阶段 A(mock,本提交):
- 复刻五大页面,明/暗 × zh/en 四态;colors_and_type.css 原样链入;
顶栏主题切换 + 语言段控,移动端底部 Tab + 左右滑动切换。
- 设置页新增:偏好(语言/主题) + 设备管理(列表/移除/二次确认+刷新) +
TOTP 2FA(绑定二维码占位+密钥/验证/解禁),登录二段式 TOTP。
- 数据层 lib/api:ApiClient 抽象 + MockClient/HttpClient 双实现,构建期
NEXT_PUBLIC_API_MODE 切换;统一错误体 {code,message_zh,message_en} → 双语映射。
- 会话:access token 仅内存,refresh header token + localStorage,静默续期,
登出失效(取舍:静态导出无服务端 cookie 能力,详见 README)。
- 安全:构建期注入 SRI(sha384);_headers 严格 CSP + 安全基线;
红线词扫描(铁律13) CI 红线,零命中。
阶段 B(占位待联调):HttpClient 已写好域名池+退避重试+401 续期;
TOTP/登录二段式端点占位待 #1 契约增补;me/redeem/devices 切真实链路依赖 #2/#3/#4。
验证:npm run lint / redline / build 均通过,静态产物 out/ 无服务端依赖。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
19 lines
635 B
TypeScript
19 lines
635 B
TypeScript
// client.ts — 数据层入口:构建期环境开关切换 mock / http。
|
|
import type { ApiClient } from './types';
|
|
import { MockClient } from './mock';
|
|
import { HttpClient } from './http';
|
|
|
|
export * from './types';
|
|
|
|
let singleton: ApiClient | null = null;
|
|
|
|
export function apiMode(): 'mock' | 'http' {
|
|
return process.env.NEXT_PUBLIC_API_MODE === 'http' ? 'http' : 'mock';
|
|
}
|
|
|
|
/** 单例客户端:mock 模式保留内存状态(订阅重置/设备移除等可连续演示) */
|
|
export function getClient(): ApiClient {
|
|
if (!singleton) singleton = apiMode() === 'http' ? new HttpClient() : new MockClient();
|
|
return singleton;
|
|
}
|