feat: 添加登录失败处理及记录格式化功能

增加登录失败状态处理和重试机制
将记录格式化逻辑提取到工具函数
优化云数据库查询性能
This commit is contained in:
chenglijuan
2026-04-18 22:34:35 +08:00
parent 54556374b1
commit d5478429c0
7 changed files with 138 additions and 86 deletions
+6 -26
View File
@@ -1,5 +1,5 @@
// records.js
const { appointmentDB } = require('../../utils/cloud')
const { appointmentDB, formatRecord } = require('../../utils/cloud')
const app = getApp()
Page({
@@ -11,18 +11,12 @@ Page({
},
onLoad() {
if (!app.globalData.isLoggedIn) {
wx.showToast({ title: '请先登录', icon: 'none' })
setTimeout(() => {
wx.navigateBack()
}, 1500)
return
}
this.loadRecords()
},
onShow() {
if (app.globalData.isLoggedIn) {
// 仅从预约页返回时刷新,避免 onLoad + onShow 双重加载
if (this.data._loaded) {
this.loadRecords()
}
},
@@ -32,26 +26,12 @@ Page({
try {
const openid = app.globalData.userInfo.openid
const records = await appointmentDB.getList(openid)
// 格式化时间
const formatted = records.map(item => {
const date = item.createTime
let createTimeStr = ''
if (date) {
if (typeof date === 'object' && date.$date) {
createTimeStr = new Date(date.$date).toLocaleString('zh-CN')
} else {
createTimeStr = new Date(date).toLocaleString('zh-CN')
}
}
return { ...item, createTime: createTimeStr }
})
this.setData({ records: formatted, loading: false })
const formatted = records.map(item => formatRecord(item))
this.setData({ records: formatted, loading: false, _loaded: true })
this.filterRecords()
} catch (err) {
console.error('加载预约记录失败', err)
this.setData({ records: [], loading: false })
this.setData({ records: [], loading: false, _loaded: true })
this.filterRecords()
}
},