- 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) <noreply@anthropic.com>
This commit is contained in:
@@ -233,6 +233,7 @@ git push
|
|||||||
11. **农历 `lunarInfo` 数据表来源要可信**。早期版本数据有错位(多个年份的闰月信息错),导致 solarToLunar 算的春节日期跟实际差 1-2 个月。已替换为权威源 `github.com/jjonline/calendar.js` 的版本。如未来要扩展年份范围(>2100),务必同样从该源取。
|
11. **农历 `lunarInfo` 数据表来源要可信**。早期版本数据有错位(多个年份的闰月信息错),导致 solarToLunar 算的春节日期跟实际差 1-2 个月。已替换为权威源 `github.com/jjonline/calendar.js` 的版本。如未来要扩展年份范围(>2100),务必同样从该源取。
|
||||||
12. **农历存字段必须含 `isLeapMonth`**。只存 `lunarMonth`/`lunarDay` 会丢闰月信息,闰月生日的人每年被错误提醒到普通月份。修复需同时改:数据库列、后端 FIELDS、前端 formData、`lunar.lunarToSolar` 第 4 参数透传。
|
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)做端到端验证,不能只测闰月初一。
|
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。
|
||||||
|
|
||||||
## 与其他记忆的关系
|
## 与其他记忆的关系
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Page({
|
|||||||
personId: null,
|
personId: null,
|
||||||
personList: [],
|
personList: [],
|
||||||
inputName: '',
|
inputName: '',
|
||||||
typeList: ['公历生日', '农历生日', '结婚纪念日', '订婚纪念日', '其他纪念日'],
|
typeList: ['生日', '结婚纪念日', '订婚纪念日', '其他纪念日'],
|
||||||
typeIndex: 0,
|
typeIndex: 0,
|
||||||
showCustomType: false,
|
showCustomType: false,
|
||||||
dateValue: '',
|
dateValue: '',
|
||||||
@@ -101,14 +101,15 @@ Page({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取类型索引
|
* 获取类型索引
|
||||||
|
* 注:lunar_birthday 是老数据兼容,新 UI 没有这一项,统一映射到「生日」(0)
|
||||||
*/
|
*/
|
||||||
getTypeIndex(type) {
|
getTypeIndex(type) {
|
||||||
const indexMap = {
|
const indexMap = {
|
||||||
birthday: 0,
|
birthday: 0,
|
||||||
lunar_birthday: 1,
|
lunar_birthday: 0,
|
||||||
wedding: 2,
|
wedding: 1,
|
||||||
engagement: 3,
|
engagement: 2,
|
||||||
other: 4
|
other: 3
|
||||||
}
|
}
|
||||||
return indexMap[type] || 0
|
return indexMap[type] || 0
|
||||||
},
|
},
|
||||||
@@ -139,9 +140,9 @@ Page({
|
|||||||
*/
|
*/
|
||||||
onTypeChange(e) {
|
onTypeChange(e) {
|
||||||
const index = parseInt(e.detail.value)
|
const index = parseInt(e.detail.value)
|
||||||
const types = ['birthday', 'lunar_birthday', 'wedding', 'engagement', 'other']
|
const types = ['birthday', 'wedding', 'engagement', 'other']
|
||||||
const isOther = index === 4
|
const isOther = index === 3
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
typeIndex: index,
|
typeIndex: index,
|
||||||
showCustomType: isOther,
|
showCustomType: isOther,
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ const TEMPLATE_ID = process.env.WX_TEMPLATE_ID
|
|||||||
const MINIPROGRAM_STATE = process.env.WX_MINIPROGRAM_STATE || 'formal'
|
const MINIPROGRAM_STATE = process.env.WX_MINIPROGRAM_STATE || 'formal'
|
||||||
|
|
||||||
const TYPE_NAMES = {
|
const TYPE_NAMES = {
|
||||||
birthday: '公历生日',
|
birthday: '生日',
|
||||||
lunar_birthday: '农历生日',
|
// 老数据 type=lunar_birthday 兼容回显(公历/农历由 isLunar 决定)
|
||||||
|
lunar_birthday: '生日',
|
||||||
wedding: '结婚纪念日',
|
wedding: '结婚纪念日',
|
||||||
engagement: '订婚纪念日',
|
engagement: '订婚纪念日',
|
||||||
other: '其他纪念日'
|
other: '其他纪念日'
|
||||||
|
|||||||
+4
-3
@@ -11,8 +11,9 @@ const ANNIVERSARY_TYPES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TYPE_NAMES = {
|
const TYPE_NAMES = {
|
||||||
birthday: '公历生日',
|
birthday: '生日',
|
||||||
lunar_birthday: '农历生日',
|
// lunar_birthday 已合并到 birthday(公历/农历由 isLunar 决定),保留映射用于兼容老数据回显
|
||||||
|
lunar_birthday: '生日',
|
||||||
wedding: '结婚纪念日',
|
wedding: '结婚纪念日',
|
||||||
engagement: '订婚纪念日',
|
engagement: '订婚纪念日',
|
||||||
other: '其他纪念日'
|
other: '其他纪念日'
|
||||||
@@ -20,7 +21,7 @@ const TYPE_NAMES = {
|
|||||||
|
|
||||||
const TYPE_ICONS = {
|
const TYPE_ICONS = {
|
||||||
birthday: '🎂',
|
birthday: '🎂',
|
||||||
lunar_birthday: '🌙',
|
lunar_birthday: '🎂',
|
||||||
wedding: '💍',
|
wedding: '💍',
|
||||||
engagement: '💕',
|
engagement: '💕',
|
||||||
other: '📅'
|
other: '📅'
|
||||||
|
|||||||
Reference in New Issue
Block a user