This commit is contained in:
lik
2026-09-03 11:35:21 +08:00
parent f8f7afceb8
commit b4c8bf0add
45 changed files with 2989 additions and 426 deletions
+16 -1
View File
@@ -3,7 +3,7 @@ const request = require('./request.js')
const API = {
user: {
wxGetPhoneNumber: (data) => request.post('/user/wxgetphonenumber', data),
wxSignin: (data) => request.post('/user/wxsignin', data),
wxSignin: (data) => request.post('/user/wxsignin', data, { skipAuthWait: true }),
signout: (data) => request.post('/user/signout', data),
update: (data) => request.post('/user/update', data),
userInfo: (data) => request.post('/user/userInfo', data),
@@ -11,6 +11,9 @@ const API = {
},
escort: {
// 管理端:按条件查询全部记录
getAllRecords: (params) => request.get('/health/escort-record', params),
// 当前登录用户的记录
getMyRecords: (params) => request.get('/health/escort-record/my', params),
getAttendantRecords: (params) => request.get('/health/escort-record/attendant', params),
getRecordById: (id) => request.get(`/health/escort-record/${id}`),
@@ -20,9 +23,21 @@ const API = {
deleteRecord: (id) => request.delete(`/health/escort-record/${id}`),
},
healthProfile: {
getProfiles: (params) => request.get('/health/health-profile', params),
getProfileById: (id) => request.get(`/health/health-profile/${id}`),
createProfile: (data) => request.post('/health/health-profile', data),
updateProfile: (id, data) => request.put(`/health/health-profile/${id}`, data),
deleteProfile: (id) => request.delete(`/health/health-profile/${id}`),
},
resource: {
getServices: (params) => request.get('/health/service', params),
getAgreement: (params) => request.get('/health/agreement', params),
getHospitalInfo: (params) => request.get('/health/hospital-info', params),
getHospitalRanking: (params) => request.get('/health/hospital-ranking', params),
getDepartmentRankings: (params) => request.get('/health/department-rankings', params),
getAiQuickQuestions: (params) => request.get('/health/ai-quick-questions', params),
},
ai: {
+13
View File
@@ -0,0 +1,13 @@
// 根据出生年月(YYYY-MM-DD)计算年龄
function calcAge(birth) {
if (!birth) return 0
const d = new Date(birth)
if (isNaN(d.getTime())) return 0
const now = new Date()
let age = now.getFullYear() - d.getFullYear()
const m = now.getMonth() - d.getMonth()
if (m < 0 || (m === 0 && now.getDate() < d.getDate())) age--
return age > 0 ? age : 0
}
module.exports = { calcAge }
+19 -5
View File
@@ -1,17 +1,31 @@
class Request {
constructor(baseURL = 'https://api.huashengtec.com') {
//constructor(baseURL = 'http://127.0.0.1:9010') {
//constructor(baseURL = 'http://127.0.0.1:9004') {
this.baseURL = baseURL
}
request(options) {
return new Promise((resolve, reject) => {
const { url, method = 'GET', data = {}, header = {}, ...rest } = options
async request(options) {
const { url, method = 'GET', data = {}, header = {}, skipAuthWait = false, ...rest } = options
// 等待登录完成后再携带 token,避免页面请求早于 app.js 登录的竞态
// skipAuthWait: 登录请求自身使用,否则会等待自己导致死锁
let token = ''
try {
const app = getApp()
const token = app?.globalData?.user?.security?.token || ''
if (skipAuthWait) {
token = app?.globalData?.user?.security?.token || ''
} else if (app && app.ensureLogin) {
const user = await app.ensureLogin()
token = user?.security?.token || ''
} else {
token = app?.globalData?.user?.security?.token || ''
}
} catch (e) {
// 登录失败仍继续请求,由服务端返回未授权错误
}
return new Promise((resolve, reject) => {
data.appId = 'wxapp-escort-admin'
wx.request({
+94
View File
@@ -0,0 +1,94 @@
// utils/store.js
// 轻量全局缓存(内存级,冷启动自然为空)
// - cacheProfile / getProfile / removeProfile:健康档案缓存(id → 原始文档)
// - notifyProfileChange:档案变更通知,列表页订阅后刷新
// 注意:拉取列表回填缓存时务必用 cacheProfile(静默),
// 只有真实的增删改才走 notifyProfileChange,避免"回填→通知→再拉取"死循环
const cache = {}
const listeners = {}
/**
* 订阅事件,返回取消订阅函数
*/
function on(event, cb) {
if (!listeners[event]) listeners[event] = []
listeners[event].push(cb)
return () => off(event, cb)
}
/**
* 取消订阅
*/
function off(event, cb) {
const list = listeners[event]
if (!list) return
const idx = list.indexOf(cb)
if (idx > -1) list.splice(idx, 1)
}
function emit(event, data) {
;(listeners[event] || []).slice().forEach(cb => {
try {
cb(data)
} catch (err) {
console.error(`[store] ${event} 订阅回调异常`, err)
}
})
}
// ---- 通用键值 ----
function get(key) {
return cache[key]
}
function set(key, value) {
cache[key] = value
}
function remove(key) {
delete cache[key]
}
// ---- 健康档案缓存 ----
/**
* 静默回填缓存(不触发变更通知)
*/
function cacheProfile(profile) {
if (profile && profile._id) {
cache[`profile:${profile._id}`] = profile
}
}
function getProfile(id) {
return id ? cache[`profile:${id}`] : null
}
/**
* 删除缓存
*/
function removeProfile(id) {
if (id) delete cache[`profile:${id}`]
}
/**
* 档案变更通知(增删改成功后调用)
* @param {string} action - 'create' | 'update' | 'remove'
* @param {string} id - 档案ID
*/
function notifyProfileChange(action, id) {
emit('profile-change', { action, id })
}
module.exports = {
on,
off,
get,
set,
remove,
cacheProfile,
getProfile,
removeProfile,
notifyProfileChange
}