- 新增 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:
@@ -1,6 +1,7 @@
|
||||
// add-anniversary.js
|
||||
const storage = require('../../utils/storage')
|
||||
const dateUtils = require('../../utils/date')
|
||||
const api = require('../../utils/api')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -188,11 +189,32 @@ Page({
|
||||
*/
|
||||
onRemindDaysChange(e) {
|
||||
const index = parseInt(e.detail.value)
|
||||
const days = [3, 7, 14, 30, 7][index]
|
||||
this.setData({
|
||||
remindDaysIndex: index,
|
||||
'formData.remindDays': days
|
||||
})
|
||||
this.setData({ remindDaysIndex: index })
|
||||
if (index === 4) {
|
||||
// 自定义天数
|
||||
wx.showModal({
|
||||
title: '自定义提前天数',
|
||||
editable: true,
|
||||
placeholderText: '请输入天数(1-365)',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const days = parseInt(res.content)
|
||||
if (!days || days < 1 || days > 365) {
|
||||
wx.showToast({ title: '请输入1-365之间的天数', icon: 'none' })
|
||||
this.setData({ remindDaysIndex: 1, 'formData.remindDays': 7 })
|
||||
return
|
||||
}
|
||||
this.setData({ 'formData.remindDays': days })
|
||||
} else {
|
||||
// 取消则回到默认7天
|
||||
this.setData({ remindDaysIndex: 1, 'formData.remindDays': 7 })
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const days = [3, 7, 14, 30][index]
|
||||
this.setData({ 'formData.remindDays': days })
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -214,8 +236,8 @@ Page({
|
||||
/**
|
||||
* 提交
|
||||
*/
|
||||
onSubmit() {
|
||||
const { formData, personId, anniversaryId } = this.data
|
||||
async onSubmit() {
|
||||
const { formData, personId, anniversaryId, personList } = this.data
|
||||
|
||||
// 验证关联人员
|
||||
if (!personId) {
|
||||
@@ -235,14 +257,36 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
// 如果开启了提醒,请求订阅消息授权
|
||||
if (formData.remindEnabled) {
|
||||
try {
|
||||
await this.requestSubscribe()
|
||||
} catch (err) {
|
||||
console.log('用户拒绝订阅消息')
|
||||
// 继续保存,即使用户拒绝订阅
|
||||
}
|
||||
}
|
||||
|
||||
// 获取人员名称
|
||||
const person = personList.find(p => p.id === personId)
|
||||
const personName = person ? person.name : ''
|
||||
|
||||
if (anniversaryId) {
|
||||
// 编辑模式
|
||||
const success = storage.updateAnniversary(anniversaryId, {
|
||||
personId,
|
||||
personName,
|
||||
...formData
|
||||
})
|
||||
|
||||
if (success) {
|
||||
// 同步到云端
|
||||
this.syncToCloud(anniversaryId, {
|
||||
personId,
|
||||
personName,
|
||||
...formData
|
||||
}, 'update')
|
||||
|
||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||
setTimeout(() => wx.navigateBack(), 1500)
|
||||
}
|
||||
@@ -250,14 +294,55 @@ Page({
|
||||
// 新增模式
|
||||
const newAnniversary = storage.addAnniversary({
|
||||
personId,
|
||||
personName,
|
||||
...formData
|
||||
})
|
||||
|
||||
if (newAnniversary) {
|
||||
// 同步到云端
|
||||
this.syncToCloud(newAnniversary.id, newAnniversary, 'add')
|
||||
|
||||
wx.showToast({ title: '添加成功', icon: 'success' })
|
||||
setTimeout(() => wx.navigateBack(), 1500)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 请求订阅消息授权
|
||||
*/
|
||||
requestSubscribe() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.requestSubscribeMessage({
|
||||
tmplIds: ['6J7Stt-lu7DKU6jblJ0nZGq_D81z5glnksf7qWfy5Yw'],
|
||||
success: (res) => {
|
||||
console.log('订阅消息授权结果:', res)
|
||||
resolve(res)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('订阅消息授权失败:', err)
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 同步到自建后端
|
||||
*/
|
||||
async syncToCloud(id, data, action) {
|
||||
try {
|
||||
const openid = wx.getStorageSync('openid')
|
||||
if (!openid) {
|
||||
console.log('未获取到openid,跳过云端同步')
|
||||
return
|
||||
}
|
||||
const res = await api.anniversary(action, { id, ...data })
|
||||
console.log('云端同步成功:', res)
|
||||
} catch (err) {
|
||||
console.error('云端同步失败:', err)
|
||||
// 不影响本地保存
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user