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

This commit is contained in:
李琦
2026-08-08 10:33:41 +08:00
parent a7dd202ff5
commit 26cdfd718f
13 changed files with 776 additions and 26 deletions

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

@@ -0,0 +1,78 @@
/**
* 按「接口所属后端」固定取值,禁止运行时猜测 / result||data 混取
*
* 写代码时先确认该请求打的是 xk-api 还是 Yii,再选用对应方法:
* - xk-api:unwrapXkApi / xkOk / xkPayload / xkMessage → code / result / message
* - Yii: unwrapYiiApi / yiiOk / yiiPayload / yiiMessage → errcode / data / msg
*
* 医生端拦截器多数已返回 body;也兼容完整 uni 响应(业务在 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,
}
}