- 新增 server/:Node + Express + SQLite + node-cron 实现登录、纪念日 CRUD 和定时订阅消息推送 - 新增 .gitea/workflows/deploy.yml:推送即触发群晖 Docker 部署,监听 15002 - utils/api.js:自动按 envVersion 切换本地/线上 BASE_URL - app.js 与 add-anniversary.js 移除 wx.cloud 调用,改走自建后端 - cloudfunctions/ 暂保留以便回滚 - 一并提交此前未入库的首页 / 设置页 / 日历 / 万年历等改造 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+69
-34
@@ -1,13 +1,17 @@
|
||||
// index.js
|
||||
const storage = require('../../utils/storage')
|
||||
const dateUtils = require('../../utils/date')
|
||||
const { TYPE_NAMES } = require('../../utils/constants')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
persons: [],
|
||||
originalPersons: [], // 原始数据备份
|
||||
originalPersons: [],
|
||||
searchKeyword: '',
|
||||
currentFilter: 'all'
|
||||
currentFilter: 'all',
|
||||
totalCount: 0,
|
||||
upcomingCount: 0,
|
||||
todayText: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -15,7 +19,6 @@ Page({
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// 每次显示页面时刷新数据
|
||||
this.loadPersons()
|
||||
},
|
||||
|
||||
@@ -25,32 +28,24 @@ Page({
|
||||
loadPersons() {
|
||||
const persons = storage.getPersons()
|
||||
const anniversaries = storage.getAnniversaries()
|
||||
|
||||
// 为每个人员添加纪念日信息
|
||||
|
||||
const personsWithAnniversaries = persons.map(person => {
|
||||
const personAnniversaries = anniversaries.filter(a => a.personId === person.id)
|
||||
|
||||
// 找到最近的纪念日
|
||||
|
||||
let nextAnniversary = null
|
||||
if (personAnniversaries.length > 0) {
|
||||
const today = new Date()
|
||||
const upcoming = personAnniversaries
|
||||
.map(a => {
|
||||
// 如果是农历,需要特殊处理
|
||||
const date = new Date(a.solarYear, a.solarMonth - 1, a.solarDay)
|
||||
return {
|
||||
...a,
|
||||
date,
|
||||
daysUntil: dateUtils.getDaysUntil(date)
|
||||
}
|
||||
const { date, daysUntil } = dateUtils.getNextOccurrence(a.solarMonth, a.solarDay)
|
||||
return { ...a, date, daysUntil }
|
||||
})
|
||||
.filter(a => a.daysUntil >= 0)
|
||||
.sort((a, b) => a.daysUntil - b.daysUntil)
|
||||
|
||||
|
||||
if (upcoming.length > 0) {
|
||||
const next = upcoming[0]
|
||||
nextAnniversary = {
|
||||
type: next.type,
|
||||
typeName: this.getTypeName(next.type, next.customTypeName),
|
||||
dateText: dateUtils.formatDate(next.date, 'MM月DD日'),
|
||||
daysUntil: next.daysUntil,
|
||||
daysUntilText: this.formatDaysUntil(next.daysUntil)
|
||||
@@ -58,14 +53,9 @@ Page({
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...person,
|
||||
anniversaryCount: personAnniversaries.length,
|
||||
nextAnniversary
|
||||
}
|
||||
return { ...person, anniversaryCount: personAnniversaries.length, nextAnniversary }
|
||||
})
|
||||
|
||||
// 按最近的纪念日排序
|
||||
const sorted = personsWithAnniversaries.sort((a, b) => {
|
||||
if (!a.nextAnniversary && !b.nextAnniversary) return 0
|
||||
if (!a.nextAnniversary) return 1
|
||||
@@ -73,10 +63,18 @@ Page({
|
||||
return a.nextAnniversary.daysUntil - b.nextAnniversary.daysUntil
|
||||
})
|
||||
|
||||
this.setData({
|
||||
persons: sorted,
|
||||
originalPersons: sorted
|
||||
})
|
||||
const today = new Date()
|
||||
const weekdays = ['日', '一', '二', '三', '四', '五', '六']
|
||||
const todayText = `${today.getMonth() + 1}月${today.getDate()}日 周${weekdays[today.getDay()]}`
|
||||
const upcomingCount = sorted.filter(p => p.nextAnniversary && p.nextAnniversary.daysUntil <= 7).length
|
||||
|
||||
this.setData({ originalPersons: sorted, totalCount: sorted.length, upcomingCount, todayText })
|
||||
|
||||
if (this.data.currentFilter === 'all' && !this.data.searchKeyword) {
|
||||
this.setData({ persons: sorted })
|
||||
} else {
|
||||
this.filterPersons()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -90,6 +88,14 @@ Page({
|
||||
return `还有${Math.floor(days / 30)}个月`
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取类型名称
|
||||
*/
|
||||
getTypeName(type, customName) {
|
||||
if (type === 'other' && customName) return customName
|
||||
return TYPE_NAMES[type] || '纪念日'
|
||||
},
|
||||
|
||||
/**
|
||||
* 搜索输入
|
||||
*/
|
||||
@@ -104,8 +110,9 @@ Page({
|
||||
*/
|
||||
onFilterTap(e) {
|
||||
const filter = e.currentTarget.dataset.filter
|
||||
this.setData({ currentFilter: filter })
|
||||
this.filterPersons()
|
||||
this.setData({ currentFilter: filter }, () => {
|
||||
this.filterPersons()
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -113,6 +120,7 @@ Page({
|
||||
*/
|
||||
filterPersons() {
|
||||
const { originalPersons, searchKeyword, currentFilter } = this.data
|
||||
const anniversaries = storage.getAnniversaries()
|
||||
|
||||
let filtered = [...originalPersons]
|
||||
|
||||
@@ -124,12 +132,39 @@ Page({
|
||||
)
|
||||
}
|
||||
|
||||
// 类型筛选(暂时保留,后续可以实现更精确的筛选)
|
||||
// if (currentFilter !== 'all') {
|
||||
// // 可以实现更精确的筛选逻辑
|
||||
// }
|
||||
// 类型筛选
|
||||
if (currentFilter !== 'all') {
|
||||
filtered = filtered.filter(person => {
|
||||
const personAnniversaries = anniversaries.filter(a => a.personId === person.id)
|
||||
|
||||
if (currentFilter === 'birthday') {
|
||||
// 生日筛选:只显示有生日类型的人(公历生日或农历生日)
|
||||
return personAnniversaries.some(a =>
|
||||
a.type === 'birthday' || a.type === 'lunar_birthday'
|
||||
)
|
||||
} else if (currentFilter === 'anniversary') {
|
||||
// 纪念日筛选:只显示有纪念日类型的人(结婚、订婚、其他)
|
||||
return personAnniversaries.some(a =>
|
||||
a.type === 'wedding' || a.type === 'engagement' || a.type === 'other'
|
||||
)
|
||||
} else if (currentFilter === 'upcoming') {
|
||||
// 即将到来:只显示7天内有纪念日的人
|
||||
return person.nextAnniversary && person.nextAnniversary.daysUntil <= 7
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
this.setData({ persons: filtered })
|
||||
// 排序:与 loadPersons() 保持一致,按最近的纪念日排序
|
||||
const sorted = filtered.sort((a, b) => {
|
||||
if (!a.nextAnniversary && !b.nextAnniversary) return 0
|
||||
if (!a.nextAnniversary) return 1
|
||||
if (!b.nextAnniversary) return -1
|
||||
return a.nextAnniversary.daysUntil - b.nextAnniversary.daysUntil
|
||||
})
|
||||
|
||||
this.setData({ persons: sorted })
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user