Files
Neo-ZQYY/docs/miniprogram-dev/api-audit/_hardcode-summary.md

6.6 KiB
Raw Blame History

小程序全页面硬编码汇总与处置方案

生成时间2026-03-18 | 最后更新2026-03-18 覆盖页面18 个(全部业务页面)


一、分类说明

类别 说明 行动
已修复 已完成修改
📋 已决策-暂不动 用户已确认处置方式,当前不改 联调时处理
🔒 保留 合理的 UI 文案/默认值/样式常量 不动

二、 已修复的硬编码

2.1 时间/日期硬编码 → 动态计算

# 页面 字段 原值 修改结果
1 customer-service-records currentYear 2026 new Date().getFullYear()
2 customer-service-records currentMonth 2 new Date().getMonth() + 1
3 customer-service-records maxYearMonth 202602 动态计算当前年月
4 customer-service-records minYearMonth 202601 动态计算(当前年月 - 12 个月)
5 performance-records currentYear 2026 new Date().getFullYear()
6 performance-records currentMonth 2 new Date().getMonth() + 1
7 performance-records monthLabel '2026年2月' 动态拼接

2.2 用户信息 → 从 globalData.authUser 读取

# 页面 字段 原值 修改结果
8 performance-records coachName '小燕' onLoad()app.globalData.authUser.nickname 读取
9 performance-records coachLevel '星级' onLoad()app.globalData.authUser.coachLevel 读取
10 performance-records storeName '球会名称店' onLoad()app.globalData.authUser.storeName 读取
11 my-profile mockUserProfile {name:'小燕',...} onShow()app.globalData.authUser 读取,删除 mock import

2.3 全局 UI 常量抽取

# 页面 原代码 修改结果
12 my-profile confirmColor: '#e34d59' CONFIRM_DANGER_COLORfrom ui-constants.ts
13 task-detail confirmColor: '#e34d59' CONFIRM_DANGER_COLORfrom ui-constants.ts
14 notes confirmColor: '#e34d59' CONFIRM_DANGER_COLORfrom ui-constants.ts

新建 utils/ui-constants.tsCONFIRM_DANGER_COLOR 引用 vi-colors.tsGLOBAL_COLORS.error

2.4 死代码 / 无效路由清理

# 页面 问题 修改结果
15 customer-detail 未使用的 mockCustomerDetail import 已删除
16 apply 无效路由 /pages/mvp/mvp /pages/task-list/task-list
17 no-permission 无效路由 /pages/mvp/mvp /pages/task-list/task-list
18 reviewing 无效路由 /pages/mvp/mvp /pages/task-list/task-list
19 router 死路由 'settings': '' 已删除

2.5 交互优化

# 页面 问题 修改结果
20 chat-history iconGradient 随机分配 改为按对话 ID 哈希固定(hashIndex() 函数)

2.6 类型定义扩展

# 文件 修改
21 typings/index.d.ts authUser 接口新增 role?storeName?coachLevel?avatar? 字段

三、📋 已决策-暂不动

3.1 Mock 数据(联调时替换)

# 页面 字段 用户决策
1 customer-service-records customerPhone/relationIndex Mock 数据,联调时从接口取
2 performance-records mock 数据不一致totalCount/totalHours/totalIncome 联调时 API 替换,暂不修

3.2 筛选选项(全平台共用,暂前端硬编码)

# 页面 常量 用户决策
3 board-coach SKILL_OPTIONS 后端需配置接口(已记录 REQ-1
4 board-coach SORT_OPTIONS 全平台共用,暂保持
5 board-customer 维度/项目选项 全平台共用,暂保持

3.3 其他已决策项

# 页面 项目 用户决策
6 no-permission 管理员姓名 厉超 保持硬编码(只有一个管理员)
7 login dev_test_openid 上线前处理(已记录 REQ-3

后端接口需求已记录于 docs/miniprogram-dev/API-requirement.mdREQ-1 ~ REQ-5


四、🔒 保留不动的硬编码

以下硬编码属于合理的 UI 文案、样式常量或默认值,无需修改:

4.1 UI 文案(各页面通用)

所有页面的以下文案保留不动:

  • 加载态:加载中...
  • 错误态:加载失败,请重试 / 重新加载 / 重试
  • 空态:暂无数据 / 暂无备注记录 / 暂无对话记录 / 暂无助教数据
  • 底部提示:— 已加载全部记录 —
  • 导航栏标题(各页面 .json 中的 navigationBarTitleText
  • 业务术语标签:定档 / 折前 / 预估 / 召回 / 回访

4.2 statusBarHeight 回退值

所有页面的 statusBarHeight 默认值(2044)作为 wx.getWindowInfo() 的兜底值,保留不动。

4.3 setTimeout 模拟延迟

所有页面的 setTimeout(400~600ms) 模拟网络延迟,联调时统一替换为真实 API 调用。当前阶段保留不动(改了也没意义,联调时整体重构 loadData())。

4.4 路由路径

各页面中的 wx.navigateTo / wx.reLaunch / wx.switchTab 路径硬编码,属于小程序标准做法,保留不动。

4.5 样式映射常量

  • board-coach: LEVEL_CLASS / SKILL_CLASS / SORT_TO_DIM / TIME_OPTIONS
  • chat-history: ICON_GRADIENTS6 组 CSS 渐变色)
  • 各页面的 courseTypeClass / avatarGradient 等样式映射

4.6 表单校验规则

  • apply: 手机号正则 !/^\d{11}$/、球房 ID maxlength="5"
  • login: 错误提示文案(账号已被禁用 / 登录凭证无效 等)

4.7 Mock 数据本体

所有 mockXxx 数据(包括页面内联和 mock-data.ts 中的)在联调前保留不动。联调时统一替换为 API 调用。


五、变更统计

本轮共修复 21 项硬编码问题,涉及 14 个文件:

类别 数量
时间/日期动态化 7
用户信息 globalData 读取 4
UI 常量抽取 3
死代码/无效路由清理 5
交互优化(哈希固定) 1
类型定义扩展 1

涉及文件:performance-records.tscustomer-service-records.tsmy-profile.tstask-detail.tsnotes.tschat-history.tscustomer-detail.tsapply.tsno-permission.tsreviewing.tsrouter.tsui-constants.ts(新建)、vi-colors.ts(已有)、typings/index.d.ts