From d6e59df4e9454cca13964a43b78076253185acb5 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Thu, 20 Aug 2026 17:20:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=A6=E7=BB=86=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=20v3=20=E6=B5=8B=E9=87=8F=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=E8=AE=BE=E5=A4=87=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 详细报告按 scaleType 区分 4/8 电极渲染,节段卡片 8 电极专属 - 设备列表改为接口驱动并新增空态 - 登录后统一跳首页,请求层兼容 code 0 返回风格 Co-Authored-By: Claude Opus 4.7 --- miniprogram/app.json | 2 +- miniprogram/app.ts | 6 +- .../pages/detailedReport/detailedReport.ts | 356 +++++++++++++++- .../pages/detailedReport/detailedReport.wxml | 403 +++++------------- miniprogram/pages/equipment/equipment.ts | 87 +++- miniprogram/pages/equipment/equipment.wxml | 94 ++-- miniprogram/pages/helpCenter/helpCenter.ts | 3 +- miniprogram/pages/helpCenter/helpCenter.wxml | 2 +- miniprogram/pages/login/login.ts | 10 +- miniprogram/utils/request/index.ts | 6 +- miniprogram/utils/request/types.ts | 4 +- 11 files changed, 581 insertions(+), 392 deletions(-) diff --git a/miniprogram/app.json b/miniprogram/app.json index e1b8129..99c2c69 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -1,8 +1,8 @@ { "pages": [ - "pages/connectedDevice/connectedDevice", "pages/login/login", "pages/supplementPersonal/supplementPersonal", + "pages/connectedDevice/connectedDevice", "pages/connectedWifi/connectedWifi", "pages/home/home", "pages/detailedReport/detailedReport", diff --git a/miniprogram/app.ts b/miniprogram/app.ts index ce0dc32..90b20b8 100644 --- a/miniprogram/app.ts +++ b/miniprogram/app.ts @@ -3,8 +3,10 @@ onLaunch() { // 已登录则跳过登录页 - const userInfo = wx.getStorageSync('userInfo') || null; - if (userInfo) { + const token = wx.getStorageSync('token') || null; + // const userInfo = wx.getStorageSync('userInfo') || null; + const userInfo = true; + if (token && userInfo) { wx.reLaunch({ url: '/pages/home/home' }) diff --git a/miniprogram/pages/detailedReport/detailedReport.ts b/miniprogram/pages/detailedReport/detailedReport.ts index a38b9b8..477eb6c 100644 --- a/miniprogram/pages/detailedReport/detailedReport.ts +++ b/miniprogram/pages/detailedReport/detailedReport.ts @@ -1,22 +1,366 @@ // pages/detailedReport/detailedReport.ts +import { get } from '../../utils/request/index' + +/** 身体成分单项指标(bodyDataList 元素) */ +interface LefuBodyDatum { + /** 指标 key,如 ppBMI、ppFat、ppMuscleKgLeftArm */ + bodyParamKey: string + /** 指标中文名称 */ + bodyParamName: string + /** UI 渲染颜色数组 */ + colorArray?: string[] + /** 当前标准等级 */ + currentStandard?: number + /** 当前测量值(字符串) */ + currentValue: string + /** 指标介绍 */ + introduction?: string + /** 标准范围数组 */ + standardArray?: number[] + /** 当前等级标题 */ + standardTitle?: string + /** 标准标题数组 */ + standardTitleArray?: string[] + /** 标准颜色 */ + standColor?: string + /** 标准评估结果 */ + standeEvaluation?: string + /** 标准建议 */ + standSuggestion?: string + /** 单位 */ + unit?: string +} + +/** 用户信息 */ +interface MeasureUserInfo { + userId?: string + realname?: string + sex?: number + height?: number + birthday?: string + avatar?: string | null + [key: string]: any +} + +/** 测量历史详情 */ +interface MeasureHistoryVO { + recordId?: string + /** 身高(cm) */ + height?: number + /** 体重(kg) */ + weight?: number + /** 与上次体重增减量(kg) */ + weightChange?: number + bmi?: number + /** BMI 类型:消瘦/正常/超重/肥胖 */ + bmiType?: string + standardWeight?: number + fatRate?: number + fatValue?: number + basalMetabolism?: number + /** 测量时间 */ + examTime?: string + sn?: string + userInfo?: MeasureUserInfo + /** 电极类型:0=4电极,1/5=8电极 */ + scaleType?: number + bodyDataList?: LefuBodyDatum[] +} + +/** 查询测量历史详情(recordId 不传时返回最近一次) */ +const getMeasureHistory = (params: { userId?: string; recordId?: string }) => + get('weighingScale/v3/getMeasureHistory', params) + +/** 指标行(身体成分/脂肪分析等卡片) */ +interface MetricRow { + label: string + value: string + unit: string + status: string + color: string +} + +/** 基础指标网格单元 */ +interface BasicCell { + label: string + value: string + unit: string +} + +/** 躯干/四肢节段单元(同时含质量与占比) */ +interface BodyPart { + label: string + massValue: string + massUnit: string + rateValue: string + rateUnit: string +} + +/** 指标卡片 */ +interface MetricCard { + title: string + rows: MetricRow[] +} + +/** 躯干/四肢卡片(每行 1~2 个节段单元) */ +interface BodyPartsCard { + title: string + rows: BodyPart[][] +} + +const EMPTY_BASIC_CELL: BasicCell = { label: '', value: '', unit: '' } + +const DEFAULT_STATUS_COLOR = '#B6B6B6' + +/** 将 bodyDataList 转为 key -> 指标 的映射 */ +const toMap = (list: LefuBodyDatum[] = []): Record => { + const map: Record = {} + list.forEach((d) => { + if (d && d.bodyParamKey) map[d.bodyParamKey] = d + }) + return map +} + +/** 按 key 取指标并转成行,缺失返回 null */ +const pick = (map: Record, key: string): MetricRow | null => { + const d = map[key] + if (!d) return null + return { + label: d.bodyParamName || key, + value: d.currentValue ?? '', + unit: d.unit || '', + status: d.standardTitle || '', + color: d.standColor || DEFAULT_STATUS_COLOR, + } +} + +/** 按一组 key 构建行,自动跳过缺失项 */ +const buildRows = (map: Record, keys: string[]): MetricRow[] => + keys.map((k) => pick(map, k)).filter((r): r is MetricRow => r !== null) + +/** 构建节段单元(质量 + 占比) */ +const buildPart = ( + map: Record, + label: string, + massKey: string, + rateKey: string, +): BodyPart => ({ + label, + massValue: map[massKey]?.currentValue ?? '--', + massUnit: map[massKey]?.unit ?? 'kg', + rateValue: map[rateKey]?.currentValue ?? '--', + rateUnit: map[rateKey]?.unit ?? '%', +}) + +/** 体重拆分整数 + 小数 */ +const splitWeight = (weight: number): { int: string; decimal: string } => { + const str = weight.toFixed(2) + const [int, dec] = str.split('.') + return { int, decimal: `.${dec}` } +} + +/** 根据 BMI 计算刻度圆圈位置(百分比) */ +const calcBmiLeft = (bmi?: number): number => { + if (bmi == null || isNaN(bmi)) return 0 + const pct = (bmi - 14) / (40 - 14) + return Math.min(Math.max(pct, 0), 1) * 100 +} + Page({ data: { // 导航栏背景色,根据滚动位置动态变化 navBgColor: 'rgba(255,255,255,0)', header: { - date: '2026-07-23 16:32', - bmi: 'BMI正常', - change: '较上次-0.3kg' + date: '', + weightInt: '--', + weightDecimal: '', + bmiText: '', + changeText: '', + }, + + bmiCircleLeft: 0, + + basicRows: [] as BasicCell[][], + + bodyComposition: { title: '身体成分', rows: [] } as MetricCard, + fatAnalysis: { title: '脂肪分析', rows: [] } as MetricCard, + physique: { title: '体态管理', rows: [] } as MetricCard, + weightControl: { title: '体重管控', rows: [] } as MetricCard, + + // 以下卡片为 8 电极专属 + isEightElectrode: false, + cellWater: { title: '细胞液分析', rows: [] } as MetricCard, + advancedComposition: { title: '进阶成分', rows: [] } as MetricCard, + bodyFat: { title: '躯干/四肢脂肪', rows: [] } as BodyPartsCard, + bodyMuscle: { title: '躯干/四肢肌肉', rows: [] } as BodyPartsCard, + }, + + onLoad(options: Record) { + const recordId = options.recordId || '' + const userInfo = (wx.getStorageSync('userInfo') || {}) as Record + const userId = userInfo.userId || '' + this.fetchHistory(userId, recordId) + }, + + async fetchHistory(userId: string, recordId: string) { + if (!userId && !recordId) return + try { + const res = await getMeasureHistory({ userId, recordId }) + this.applyResult(res.result) + } catch { + // 请求层已弹错误提示 } }, + applyResult(data: MeasureHistoryVO) { + const map = toMap(data.bodyDataList) + const isEight = data.scaleType === 1 || data.scaleType === 5 + + // 头部 + const hasWeight = data.weight != null && !isNaN(data.weight) + const weight = hasWeight ? splitWeight(data.weight as number) : { int: '--', decimal: '' } + const wc = data.weightChange + const changeText = + wc != null && wc !== 0 ? `较上次${wc > 0 ? '+' : ''}${wc}kg` : '' + const header = { + date: data.examTime || '--', + weightInt: weight.int, + weightDecimal: weight.decimal, + bmiText: data.bmiType ? `BMI${data.bmiType}` : '', + changeText, + } + + // 基础指标(2 行 x 3 列,第 6 格留空保持布局) + const basicKeys = ['ppWeightKg', 'ppBMI', 'ppFat', 'ppBodyScore', 'ppBodyHealth'] + const basicCells: BasicCell[] = basicKeys.map((k) => { + const d = map[k] + if (!d) return { ...EMPTY_BASIC_CELL } + return { label: d.bodyParamName || k, value: d.currentValue ?? '', unit: d.unit || '' } + }) + basicCells.push({ ...EMPTY_BASIC_CELL }) + const basicRows = [basicCells.slice(0, 3), basicCells.slice(3, 6)] + + // 身体成分 + const bodyComposition = { + title: '身体成分', + rows: buildRows(map, [ + 'ppWaterPercentage', + 'ppWaterKg', + 'ppProteinPercentage', + 'ppProteinKg', + 'ppBodyfatKg', + 'ppMuscleKg', + 'ppMusclePercentage', + 'ppBodySkeletalKg', + 'ppBodySkeletal', + 'ppBoneKg', + ]), + } + + // 脂肪分析 + const fatAnalysis = { + title: '脂肪分析', + rows: buildRows(map, [ + 'ppVisceralFat', + 'ppBodyFatSubCutPercentage', + 'ppBodyFatSubCutKg', + ]), + } + + // 体态管理(理想体重 key 随电极类型变化,推测腰臀比为 8 电极专属) + const idealWeightKey = isEight ? 'ppBodyStandardWeightKg' : 'ppIdealWeightKg' + const physiqueKeys = [idealWeightKey, 'ppLoseFatWeightKg', 'ppBodyAge', 'ppBodyType'] + if (isEight) physiqueKeys.push('ppWHR') + const physique = { title: '体态管理', rows: buildRows(map, physiqueKeys) } + + // 体重管控 + const weightControl = { + title: '体重管控', + rows: buildRows(map, [ + 'ppControlWeightKg', + 'ppFatControlKg', + 'ppBodyMuscleControl', + ]), + } + + // 8 电极专属卡片 + const cellWater = isEight + ? { title: '细胞液分析', rows: buildRows(map, ['ppWaterICWKg', 'ppWaterECWKg']) } + : { title: '细胞液分析', rows: [] } + + const advancedComposition = isEight + ? { + title: '进阶成分', + rows: buildRows(map, ['ppMineralKg', 'ppCellMassKg', 'ppSmi']), + } + : { title: '进阶成分', rows: [] } + + // 节段两列一行:[[左臂,右臂],[左腿,右腿],[躯干]] + const chunkParts = (parts: BodyPart[]): BodyPart[][] => [ + [parts[0], parts[1]], + [parts[2], parts[3]], + [parts[4]], + ] + + const fatPartLabels: [string, string, string][] = [ + ['左臂', 'ppBodyFatKgLeftArm', 'ppBodyFatRateLeftArm'], + ['右臂', 'ppBodyFatKgRightArm', 'ppBodyFatRateRightArm'], + ['左腿', 'ppBodyFatKgLeftLeg', 'ppBodyFatRateLeftLeg'], + ['右腿', 'ppBodyFatKgRightLeg', 'ppBodyFatRateRightLeg'], + ['躯干', 'ppBodyFatKgTrunk', 'ppBodyFatRateTrunk'], + ] + const bodyFat = isEight + ? { + title: '躯干/四肢脂肪', + rows: chunkParts( + fatPartLabels.map(([label, massKey, rateKey]) => + buildPart(map, label, massKey, rateKey), + ), + ), + } + : { title: '躯干/四肢脂肪', rows: [] } + + const musclePartLabels: [string, string, string][] = [ + ['左臂', 'ppMuscleKgLeftArm', 'ppMuscleRateLeftArm'], + ['右臂', 'ppMuscleKgRightArm', 'ppMuscleRateRightArm'], + ['左腿', 'ppMuscleKgLeftLeg', 'ppMuscleRateLeftLeg'], + ['右腿', 'ppMuscleKgRightLeg', 'ppMuscleRateRightLeg'], + ['躯干', 'ppMuscleKgTrunk', 'ppMuscleRateTrunk'], + ] + const bodyMuscle = isEight + ? { + title: '躯干/四肢肌肉', + rows: chunkParts( + musclePartLabels.map(([label, massKey, rateKey]) => + buildPart(map, label, massKey, rateKey), + ), + ), + } + : { title: '躯干/四肢肌肉', rows: [] } + + this.setData({ + header, + bmiCircleLeft: calcBmiLeft(data.bmi), + basicRows, + bodyComposition, + fatAnalysis, + physique, + weightControl, + isEightElectrode: isEight, + cellWater, + advancedComposition, + bodyFat, + bodyMuscle, + }) + }, + // 滚动时导航栏背景渐显 onScroll(e: WechatMiniprogram.ScrollViewScroll) { - const scrollTop = e.detail.scrollTop; - const opacity = Math.min(Math.max(scrollTop / 300, 0), 1); + const scrollTop = e.detail.scrollTop + const opacity = Math.min(Math.max(scrollTop / 300, 0), 1) this.setData({ navBgColor: `rgba(255,255,255,${opacity})`, - }); + }) }, }) diff --git a/miniprogram/pages/detailedReport/detailedReport.wxml b/miniprogram/pages/detailedReport/detailedReport.wxml index 679c372..ef55a86 100644 --- a/miniprogram/pages/detailedReport/detailedReport.wxml +++ b/miniprogram/pages/detailedReport/detailedReport.wxml @@ -23,13 +23,13 @@ - 88 - .88 + {{ header.weightInt }} + {{ header.weightDecimal }} kg - {{ header.bmi }} - {{ header.change }} + {{ header.bmiText }} + {{ header.changeText }} @@ -41,43 +41,16 @@ 基础指标 - - - 体重 - - 172 - kg - + + + + {{ cell.label }} + + {{ cell.value }} + {{ cell.unit }} + + - - BMI - - 22.4 - - - - 体脂率 - - 22.1 - % - - - - - - 身体得分 - - 73 - - - - - 健康评估 - - 一般 - - - @@ -86,7 +59,7 @@ - + 消瘦 @@ -107,58 +80,13 @@ - 身体成分 + {{ bodyComposition.title }} - - 水分率 - 50% - 不足 - - - 水分量 - 30.6kg - 标准 - - - 蛋白质率 - 10% - 超量 - - - 蛋白质量 - 8.2kg - 标准 - - - 脂肪量 - 14.3kg - 标准 - - - 肌肉量 - 38.8kg - 标准 - - - 肌肉率 - 69.2% - 标准 - - - 骨骼肌量 - 22.5kg - 标准 - - - 骨骼肌率 - 40% - 标准 - - - 骨量 - 2.3kg - 标准 + + {{ item.label }} + {{ item.value }}{{ item.unit }} + {{ item.status }} @@ -167,23 +95,13 @@ - 脂肪分析 + {{ fatAnalysis.title }} - - 内脏脂肪 - 6 - 不足 - - - 皮下脂肪率 - 22.5% - 标准 - - - 皮下脂肪量 - 12.6kg - 标准 + + {{ item.label }} + {{ item.value }}{{ item.unit }} + {{ item.status }} @@ -192,33 +110,13 @@ - 体态管理 + {{ physique.title }} - - 理想体重 - 62.1kg - 标准 - - - 去脂体重 - 41.7kg - 标准 - - - 身体年龄 - 20岁 - 标准 - - - 身体类型 - 缺乏运动型 - 标准 - - - 推测腰臀比 - 0.8% - 标准 + + {{ item.label }} + {{ item.value }}{{ item.unit }} + {{ item.status }} @@ -227,203 +125,94 @@ - 体重管控 + {{ weightControl.title }} - - 控制体重 - 3.9kg - 标准 - - - 脂肪控制量 - -0.5kg - 标准 - - - 肌肉控制量 - 4.4kg - 标准 + + {{ item.label }} + {{ item.value }}{{ item.unit }} + {{ item.status }} - - - - - 细胞液分析 - - - - 细胞内水量 - 19.1kg - 标准 - - - 细胞外水量 - 11.4kg - 标准 - - - + - - - - - 进阶成分 - - - - 无机盐量 - 2.9kg - 不足 + + + + + {{ cellWater.title }} - - 身体细胞量 - 27.4kg - 标准 - - - 骨骼肌质量指数 - 7.2kg/m² - 标准 + + + {{ item.label }} + {{ item.value }}{{ item.unit }} + {{ item.status }} + - - - - - - 躯干/四肢脂肪 - - - - - 左臂 - - 2.3 - kg - - 80.9 - % - - - - 右臂 - - 2.3 - kg - - 80.9 - % - - + + + + + {{ advancedComposition.title }} - - - 左腿 - - 6.3 - kg - - 100 - % - - - - 右腿 - - 6.3 - kg - - 100 - % - - - - - - 躯干 - - 18.4 - kg - - 97.8 - % - + + + {{ item.label }} + {{ item.value }}{{ item.unit }} + {{ item.status }} - - - - - - 躯干/四肢肌肉 - - - - - 左臂 - - 2.3 - kg - - 80.9 - % - - - - 右臂 - - 2.3 - kg - - 80.9 - % - - + + + + + {{ bodyFat.title }} - - - 左腿 - - 6.3 - kg - - 100 - % - - - - 右腿 - - 6.3 - kg - - 100 - % - - - - - - 躯干 - - 18.4 - kg - - 97.8 - % + + + + {{ part.label }} + + {{ part.massValue }} + {{ part.massUnit }} + + {{ part.rateValue }} + {{ part.rateUnit }} + - + + + + + + {{ bodyMuscle.title }} + + + + + {{ part.label }} + + {{ part.massValue }} + {{ part.massUnit }} + + {{ part.rateValue }} + {{ part.rateUnit }} + + + + + + + diff --git a/miniprogram/pages/equipment/equipment.ts b/miniprogram/pages/equipment/equipment.ts index ae55f35..dc903a7 100644 --- a/miniprogram/pages/equipment/equipment.ts +++ b/miniprogram/pages/equipment/equipment.ts @@ -1,29 +1,74 @@ -// pages/equipment/equipment.ts +import { get } from '../../utils/request/index' + +/** 体重设备(对应 /weighingScale/list/device 返回的 result 元素) */ +interface ScaleDevice { + /** 设备ID */ + id: string + /** 设备名称 */ + equipmentName: string + /** 设备SN */ + equipmentCode: string + /** 状态 */ + status: number + canteenId: string | null + /** MAC 地址 */ + macAddress: string + /** WiFi 名称 */ + wifiName: string + isSync: number + /** 成员人数 */ + subUserNum: number +} + +/** 获取体重设备列表 */ +const getDeviceList = () => + get('weighingScale/list/device') + +/** 展示用设备项 */ +interface DeviceItem { + id: string + name: string + status: string + connected: boolean + model: string + serial: string + subUserNum: number +} + Page({ data: { - devices: [ - { - id: 1, - name: '家庭蓝牙体脂秤 S1', - status: '已连接', - connected: true, - model: 'BS-A100', - serial: 'BL2024A00158', - }, - { - id: 2, - name: '家庭蓝牙体脂秤 S1', - status: '未连接', - connected: false, - model: 'BW-B200', - serial: 'BL2024B00321', - } - ], - loadingShow: true, + devices: [] as DeviceItem[], + loadingShow: false, loadingTitle: '正在连接设备', loadingContent: '请确保设备处于开启状态\n请勿离开...' }, + onLoad() { + this.loadDevices() + }, + + /** 拉取体重设备列表 */ + async loadDevices() { + try { + const res = await getDeviceList() + this.setData({ + devices: res.result.map(item => ({ + id: item.id, + name: item.equipmentName, + // status 具体枚举待确认,先按 1 = 已连接处理 + status: item.status === 1 ? '已连接' : '未连接', + connected: item.status === 1, + // 接口无独立「型号」字段,先用设备名称占位 + model: item.equipmentName, + serial: item.equipmentCode, + subUserNum: item.subUserNum, + })), + }) + } catch { + // 请求失败已由 request 层统一 toast + } + }, + /** 取消配对:使用小程序自带 showModal */ onTapUnpair() { wx.showModal({ @@ -63,7 +108,7 @@ Page({ }, onTapAdd() { - // 添加设备(待接入) + wx.navigateTo({ url: '/pages/connectedDevice/connectedDevice' }) }, /** 关闭运维模式 */ diff --git a/miniprogram/pages/equipment/equipment.wxml b/miniprogram/pages/equipment/equipment.wxml index 3298334..836b8d5 100644 --- a/miniprogram/pages/equipment/equipment.wxml +++ b/miniprogram/pages/equipment/equipment.wxml @@ -1,4 +1,4 @@ - + 当前为:运维模式 @@ -7,14 +7,14 @@ - + - + 已配对设备 @@ -22,65 +22,71 @@ - - - - - - - {{ item.name }} - 取消配对 - - - - - {{ item.status }} + + + + + + + + {{ item.name }} + 取消配对 + + + + + {{ item.status }} + - - - - 型号 - {{ item.model }} + + + 型号 + {{ item.model }} + + + 设备编号 + {{ item.serial }} + - - 设备编号 - {{ item.serial }} - - - - - - + + + + + + 设备WIFI - 设备WIFI - - - - + + + + + 用户({{ item.subUserNum }}) - 用户(4) - - - - + + + + + 数据补传 - 数据补传 - + + + + - + 添加设备 - + diff --git a/miniprogram/pages/helpCenter/helpCenter.ts b/miniprogram/pages/helpCenter/helpCenter.ts index 22fda9f..79bfef7 100644 --- a/miniprogram/pages/helpCenter/helpCenter.ts +++ b/miniprogram/pages/helpCenter/helpCenter.ts @@ -56,9 +56,8 @@ Page({ onTapQuestion(e: WechatMiniprogram.TouchEvent) { const id = e.currentTarget.dataset.id as string - const title = e.currentTarget.dataset.title as string wx.navigateTo({ - url: '/pages/questionDetails/questionDetails?id=' + id + '&title=' + encodeURIComponent(title) + url: '/pages/questionDetails/questionDetails?id=' + id }) } }) diff --git a/miniprogram/pages/helpCenter/helpCenter.wxml b/miniprogram/pages/helpCenter/helpCenter.wxml index 0ed8f18..7f5de3a 100644 --- a/miniprogram/pages/helpCenter/helpCenter.wxml +++ b/miniprogram/pages/helpCenter/helpCenter.wxml @@ -15,7 +15,7 @@ - + {{ item.title }} diff --git a/miniprogram/pages/login/login.ts b/miniprogram/pages/login/login.ts index c6980df..0097799 100644 --- a/miniprogram/pages/login/login.ts +++ b/miniprogram/pages/login/login.ts @@ -25,12 +25,12 @@ Page({ const { token, user } = res.result // 持久化登录凭证和用户信息 wx.setStorageSync('token', token) - if (user) { - wx.setStorageSync('userInfo', user) + // if (user) { + // wx.setStorageSync('userInfo', user) wx.reLaunch({ url: '/pages/home/home' }) - } else { - wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' }) - } + // } else { + // wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' }) + // } }).catch((err) => { wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' }) }).finally(() => { diff --git a/miniprogram/utils/request/index.ts b/miniprogram/utils/request/index.ts index fb26d6e..ac6da96 100644 --- a/miniprogram/utils/request/index.ts +++ b/miniprogram/utils/request/index.ts @@ -39,10 +39,12 @@ const request = ( success: (res) => { if (loading) _hideLoading() const body = res.data as ApiResponse - if (body.code === 200) { + const code = body.code + // 兼容两种后端返回风格:code 200(自定义)或 code 0(jeecg) + if (code === 200 || code === 0 || code === '0') { resolve(body) } else { - wx.showToast({ title: body.msg || '请求失败', icon: 'none' }) + wx.showToast({ title: body.msg || body.message || '请求失败', icon: 'none' }) reject(body) } }, diff --git a/miniprogram/utils/request/types.ts b/miniprogram/utils/request/types.ts index 62c7d3d..adccfd1 100644 --- a/miniprogram/utils/request/types.ts +++ b/miniprogram/utils/request/types.ts @@ -1,6 +1,8 @@ export interface ApiResponse { - code: number + code: number | string msg: string + message?: string + success?: boolean | string result: T }