feat: 修复部分功能(健康信息、VIP、医生端健康信息导入)

This commit is contained in:
李琦
2026-08-08 10:33:59 +08:00
parent 874d1e7731
commit 74272d61d2
16 changed files with 1799 additions and 781 deletions

78
utils/api-response.js Normal file
View File

@@ -0,0 +1,78 @@
/**
* 按「接口所属后端」固定取值,禁止运行时猜测 / result||data 混取
*
* 写代码时先确认该请求打的是 xk-api 还是 Yii再选用对应方法
* - xk-apiunwrapXkApi / xkOk / xkPayload / xkMessage → code / result / message
* - Yii unwrapYiiApi / yiiOk / yiiPayload / yiiMessage → errcode / data / msg
*
* 患者端 request 返回完整 uni 响应,业务包在 res.data
*/
/** 取出业务 bodyuni 完整响应 → res.data已是 body 则原样) */
export function getApiBody(res) {
if (res == null || typeof res !== 'object') {
return res
}
if ('statusCode' in res || 'errMsg' in res) {
return res.data
}
return res
}
/** xk-api 是否成功code === 0 */
export function xkOk(res) {
const body = getApiBody(res)
return !!(body && Number(body.code) === 0)
}
/** xk-api 业务数据(固定取 result */
export function xkPayload(res) {
const body = getApiBody(res)
return body ? body.result : undefined
}
/** xk-api 提示文案(固定取 message */
export function xkMessage(res) {
const body = getApiBody(res)
return (body && body.message) || ''
}
/** xk-api 一次解包 */
export function unwrapXkApi(res) {
const body = getApiBody(res)
return {
ok: xkOk(res),
payload: xkPayload(res),
message: xkMessage(res),
body: body,
}
}
/** Yii 是否成功errcode === 0 */
export function yiiOk(res) {
const body = getApiBody(res)
return !!(body && Number(body.errcode) === 0)
}
/** Yii 业务数据(固定取 data */
export function yiiPayload(res) {
const body = getApiBody(res)
return body ? body.data : undefined
}
/** Yii 提示文案(固定取 msg */
export function yiiMessage(res) {
const body = getApiBody(res)
return (body && body.msg) || ''
}
/** Yii 一次解包 */
export function unwrapYiiApi(res) {
const body = getApiBody(res)
return {
ok: yiiOk(res),
payload: yiiPayload(res),
message: yiiMessage(res),
body: body,
}
}