From 756d57d8180f213457ba95ad6d19b4eee8182fa4 Mon Sep 17 00:00:00 2001 From: yuming Date: Tue, 2 Jun 2026 07:30:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E7=BA=AA=E5=BF=B5=E6=97=A5?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=EF=BC=9A=E5=8E=BB=E6=8E=89"=E5=86=9C?= =?UTF-8?q?=E5=8E=86=E7=94=9F=E6=97=A5"=E7=B1=BB=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E5=85=AC=E5=8E=86/=E5=86=9C=E5=8E=86=E6=94=B9=E7=94=B1=20isLun?= =?UTF-8?q?ar=20=E5=AD=97=E6=AE=B5=E5=86=B3=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - typeList 从 5 项简化到 4 项:生日 / 结婚纪念日 / 订婚纪念日 / 其他纪念日 - TYPE_NAMES / TYPE_ICONS 中 lunar_birthday 保留兼容映射(也映射到「生日」+ 🎂), 让线上历史数据自然回显,无需数据库迁移(方案 A) - getTypeIndex('lunar_birthday') = 0,老数据编辑时正确回显「生日」 - index.js 列表筛选和 wxml 图标判断本来已含 lunar_birthday 兼容,无需改 老数据自然淘汰:用户重新保存时新数据写 type='birthday',老数据 type 保留 直到下次编辑保存才升级。 Co-Authored-By: Claude Opus 4.7 (1M context) --- MAINTENANCE.md | 1 + pages/add-anniversary/add-anniversary.js | 17 +++++++++-------- server/src/reminder.js | 5 +++-- utils/constants.js | 7 ++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/MAINTENANCE.md b/MAINTENANCE.md index fbf9b43..bbcdbb9 100644 --- a/MAINTENANCE.md +++ b/MAINTENANCE.md @@ -233,6 +233,7 @@ git push 11. **农历 `lunarInfo` 数据表来源要可信**。早期版本数据有错位(多个年份的闰月信息错),导致 solarToLunar 算的春节日期跟实际差 1-2 个月。已替换为权威源 `github.com/jjonline/calendar.js` 的版本。如未来要扩展年份范围(>2100),务必同样从该源取。 12. **农历存字段必须含 `isLeapMonth`**。只存 `lunarMonth`/`lunarDay` 会丢闰月信息,闰月生日的人每年被错误提醒到普通月份。修复需同时改:数据库列、后端 FIELDS、前端 formData、`lunar.lunarToSolar` 第 4 参数透传。 13. **`solarToLunar` 月循环必须保留 `temp` 变量**。早期版本在闰月分支里 `offset -= leapDays`、非闰分支 `offset -= monthDays`,循环外的 `if (offset < 0)` 又根据 isLeap 重新判断要加哪个——闰月期间的"非初一日期"会被错算到下一个普通月(例如「闰二月初二」算成「三月初二」)。权威实现(jjonline/calendar.js)让循环内统一 `offset -= temp` 并把 `temp` 保留到循环外用,是更稳的写法。修改算法时一定要用 *闰月连续日期*(如 2023-03-22 到 2023-04-19)做端到端验证,不能只测闰月初一。 +14. **`lunarToSolar` 的 BASE 时间戳必须用 UTC**。早期版用 `new Date(1900, 0, 31)`(本地时间)作为基准,在 1900 年早期日期上某些 V8 版本有时区偏差,让每个农历月初对应公历都少 1 天(系统性误差,不容易发现,只在测「正常日期」时才暴露——闰月那次只测了初一,恰好正确)。改用 `Date.UTC(1900, 0, 31)` 算时间戳,再用 `getUTCFullYear/Month/Date` 提取后重新构造本地 Date 对象。**测算法务必跑「公历→农历→公历」互逆**,发现不互逆就是有 bug。 ## 与其他记忆的关系 diff --git a/pages/add-anniversary/add-anniversary.js b/pages/add-anniversary/add-anniversary.js index 895ba2d..d6f7c34 100644 --- a/pages/add-anniversary/add-anniversary.js +++ b/pages/add-anniversary/add-anniversary.js @@ -10,7 +10,7 @@ Page({ personId: null, personList: [], inputName: '', - typeList: ['公历生日', '农历生日', '结婚纪念日', '订婚纪念日', '其他纪念日'], + typeList: ['生日', '结婚纪念日', '订婚纪念日', '其他纪念日'], typeIndex: 0, showCustomType: false, dateValue: '', @@ -101,14 +101,15 @@ Page({ /** * 获取类型索引 + * 注:lunar_birthday 是老数据兼容,新 UI 没有这一项,统一映射到「生日」(0) */ getTypeIndex(type) { const indexMap = { birthday: 0, - lunar_birthday: 1, - wedding: 2, - engagement: 3, - other: 4 + lunar_birthday: 0, + wedding: 1, + engagement: 2, + other: 3 } return indexMap[type] || 0 }, @@ -139,9 +140,9 @@ Page({ */ onTypeChange(e) { const index = parseInt(e.detail.value) - const types = ['birthday', 'lunar_birthday', 'wedding', 'engagement', 'other'] - const isOther = index === 4 - + const types = ['birthday', 'wedding', 'engagement', 'other'] + const isOther = index === 3 + this.setData({ typeIndex: index, showCustomType: isOther, diff --git a/server/src/reminder.js b/server/src/reminder.js index f4b43a9..b322daa 100644 --- a/server/src/reminder.js +++ b/server/src/reminder.js @@ -7,8 +7,9 @@ const TEMPLATE_ID = process.env.WX_TEMPLATE_ID const MINIPROGRAM_STATE = process.env.WX_MINIPROGRAM_STATE || 'formal' const TYPE_NAMES = { - birthday: '公历生日', - lunar_birthday: '农历生日', + birthday: '生日', + // 老数据 type=lunar_birthday 兼容回显(公历/农历由 isLunar 决定) + lunar_birthday: '生日', wedding: '结婚纪念日', engagement: '订婚纪念日', other: '其他纪念日' diff --git a/utils/constants.js b/utils/constants.js index f2f6606..87bbed3 100644 --- a/utils/constants.js +++ b/utils/constants.js @@ -11,8 +11,9 @@ const ANNIVERSARY_TYPES = { } const TYPE_NAMES = { - birthday: '公历生日', - lunar_birthday: '农历生日', + birthday: '生日', + // lunar_birthday 已合并到 birthday(公历/农历由 isLunar 决定),保留映射用于兼容老数据回显 + lunar_birthday: '生日', wedding: '结婚纪念日', engagement: '订婚纪念日', other: '其他纪念日' @@ -20,7 +21,7 @@ const TYPE_NAMES = { const TYPE_ICONS = { birthday: '🎂', - lunar_birthday: '🌙', + lunar_birthday: '🎂', wedding: '💍', engagement: '💕', other: '📅'