ddcfe3334e
部署到群晖 / deploy (push) Successful in 44s
- Phase 1: 添加纪念日合并人物创建流程(方案 B) - Phase 2: 农历提醒按 lunarMonth/Day 计算每年公历 - Phase 3: 人员数据同步到后端(新增 /api/person) - Phase 4: 新设备启动从云端恢复数据 - Phase 5: 工具函数收敛 utils/format.js - Phase 6: 同步失败入队 + 启动重试 - Phase 7: 闰月生日完整支持(含 isLeapMonth + UI 警示) - 修复 lunarInfo 数据表错位(替换为权威源 jjonline/calendar.js) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
146 lines
3.4 KiB
JavaScript
146 lines
3.4 KiB
JavaScript
// person-detail.js
|
|
const storage = require('../../utils/storage')
|
|
const dateUtils = require('../../utils/date')
|
|
const fmt = require('../../utils/format')
|
|
|
|
Page({
|
|
data: {
|
|
personId: null,
|
|
person: {},
|
|
anniversaries: []
|
|
},
|
|
|
|
onLoad(options) {
|
|
if (!options.id) {
|
|
wx.showToast({ title: '参数错误', icon: 'none' })
|
|
wx.navigateBack()
|
|
return
|
|
}
|
|
|
|
this.setData({ personId: options.id })
|
|
this.loadPerson()
|
|
this.loadAnniversaries()
|
|
},
|
|
|
|
onShow() {
|
|
// 重新加载数据
|
|
this.loadPerson()
|
|
this.loadAnniversaries()
|
|
},
|
|
|
|
/**
|
|
* 加载人员信息
|
|
*/
|
|
loadPerson() {
|
|
const person = storage.getPersonById(this.data.personId)
|
|
if (person) {
|
|
this.setData({ person })
|
|
wx.setNavigationBarTitle({ title: person.name })
|
|
} else {
|
|
wx.showToast({ title: '人员不存在', icon: 'none' })
|
|
wx.navigateBack()
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 加载纪念日
|
|
*/
|
|
loadAnniversaries() {
|
|
const anniversaries = storage.getAnniversariesByPersonId(this.data.personId)
|
|
|
|
// 格式化纪念日数据
|
|
const formatted = anniversaries.map(a => {
|
|
const date = new Date(a.solarYear, a.solarMonth - 1, a.solarDay)
|
|
const daysUntil = dateUtils.getDaysUntil(date)
|
|
|
|
return {
|
|
...a,
|
|
date,
|
|
dateText: dateUtils.formatDate(date, 'YYYY年MM月DD日'),
|
|
daysUntil,
|
|
daysUntilAbs: Math.abs(daysUntil),
|
|
typeIcon: fmt.getTypeIcon(a.type),
|
|
typeName: fmt.getTypeName(a.type, a.customTypeName),
|
|
importanceText: fmt.getImportanceText(a.importance)
|
|
}
|
|
})
|
|
|
|
// 按日期排序
|
|
formatted.sort((a, b) => a.daysUntil - b.daysUntil)
|
|
|
|
this.setData({ anniversaries: formatted })
|
|
},
|
|
|
|
/**
|
|
* 编辑人员
|
|
*/
|
|
onEditPerson() {
|
|
wx.navigateTo({
|
|
url: `/pages/add-person/add-person?id=${this.data.personId}`
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 删除人员
|
|
*/
|
|
onDeletePerson() {
|
|
wx.showModal({
|
|
title: '确认删除',
|
|
content: `确定要删除"${this.data.person.name}"吗?相关纪念日也将被删除。`,
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
const success = storage.deletePersonWithAnniversaries(this.data.personId)
|
|
if (success) {
|
|
wx.showToast({ title: '删除成功', icon: 'success' })
|
|
setTimeout(() => wx.navigateBack(), 1500)
|
|
} else {
|
|
wx.showToast({ title: '删除失败,请重试', icon: 'none' })
|
|
}
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 添加纪念日
|
|
*/
|
|
onAddAnniversary() {
|
|
wx.navigateTo({
|
|
url: `/pages/add-anniversary/add-anniversary?personId=${this.data.personId}`
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 编辑纪念日
|
|
*/
|
|
onEditAnniversary(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
wx.navigateTo({
|
|
url: `/pages/add-anniversary/add-anniversary?personId=${this.data.personId}&id=${id}`
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 删除纪念日
|
|
*/
|
|
onDeleteAnniversary(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
const anniversary = this.data.anniversaries.find(a => a.id === id)
|
|
|
|
wx.showModal({
|
|
title: '确认删除',
|
|
content: '确定要删除这条纪念日吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
const success = storage.deleteAnniversary(id)
|
|
if (success) {
|
|
wx.showToast({ title: '删除成功', icon: 'success' })
|
|
this.loadAnniversaries()
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|