提交
提交
This commit is contained in:
+44
-10
@@ -17,11 +17,17 @@ function getCmd() {
|
||||
* @returns {object} 格式化后的记录
|
||||
*/
|
||||
function formatRecord(record) {
|
||||
if (!record) return record
|
||||
const date = record.createTime
|
||||
let createTimeStr = ''
|
||||
if (date) {
|
||||
if (typeof date === 'object' && date.$date) {
|
||||
if (typeof date === 'string') {
|
||||
// 后端API返回的时间字符串,直接格式化
|
||||
createTimeStr = new Date(date).toLocaleString('zh-CN')
|
||||
} else if (typeof date === 'object' && date.$date) {
|
||||
createTimeStr = new Date(date.$date).toLocaleString('zh-CN')
|
||||
} else if (typeof date === 'number') {
|
||||
createTimeStr = new Date(date).toLocaleString('zh-CN')
|
||||
} else {
|
||||
createTimeStr = new Date(date).toLocaleString('zh-CN')
|
||||
}
|
||||
@@ -114,18 +120,46 @@ const appointmentDB = {
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取当前用户最新一条预约
|
||||
* 将后端API返回的预约记录映射为前端模板兼容的字段
|
||||
* 后端字段: id, visitDate, visitTime, createTime, ...
|
||||
* 前端字段: _id, date, time, createTime(格式化后), ...
|
||||
*/
|
||||
_mapApiRecord(record) {
|
||||
if (!record) return null
|
||||
return {
|
||||
...record,
|
||||
_id: record.id,
|
||||
date: record.visitDate,
|
||||
time: record.visitTime
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取当前用户最新一条预约(通过后端API)
|
||||
* @param {string} openid
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
async getLatest(openid) {
|
||||
const db = getDb()
|
||||
const res = await db.collection('appointments')
|
||||
.where({ _openid: openid })
|
||||
.orderBy('createTime', 'desc')
|
||||
.limit(1)
|
||||
.get()
|
||||
return res.data.length > 0 ? res.data[0] : null
|
||||
getLatest(openid) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url: 'https://xcx.yun.588580.xyz/api/wx-mini/appointment/latest',
|
||||
method: 'GET',
|
||||
data: { openid },
|
||||
success: (res) => {
|
||||
const result = res.data
|
||||
if (result && result.code === 0) {
|
||||
resolve(this._mapApiRecord(result.data) || null)
|
||||
} else {
|
||||
console.error('获取最新预约失败', result)
|
||||
reject(new Error(result ? result.message : '请求失败'))
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('请求后端获取最新预约失败', err)
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user