diff --git a/miniprogram/pages/equipment/equipment.less b/miniprogram/pages/equipment/equipment.less index 12cb48f..af5ea13 100644 --- a/miniprogram/pages/equipment/equipment.less +++ b/miniprogram/pages/equipment/equipment.less @@ -163,7 +163,7 @@ display: flex; flex-wrap: nowrap; - .device-status--connected { + .device-status_ { height: 40rpx; padding: 0 16rpx; display: flex; @@ -171,22 +171,34 @@ align-items: center; border-radius: 20rpx; overflow: hidden; - background-color: #EAFAF6; + background-color: #F2F3F6; .status-dot { width: 12rpx; height: 12rpx; border-radius: 50%; - background-color: #2AC79F; + background-color: #77849E; margin-right: 8rpx; } .status-text { - color: #2AC79F; + color: #77849E; height: 22rpx; font-size: 22rpx; line-height: 22rpx; } + + &.connected { + background-color: #EAFAF6; + + &.status-dot { + background-color: #2AC79F; + } + + &.status-text { + color: #2AC79F; + } + } } } } diff --git a/miniprogram/pages/equipment/equipment.ts b/miniprogram/pages/equipment/equipment.ts index dc903a7..0b48968 100644 --- a/miniprogram/pages/equipment/equipment.ts +++ b/miniprogram/pages/equipment/equipment.ts @@ -1,38 +1,33 @@ import { get } from '../../utils/request/index' +import type { UserInfo } from '../../api/index' /** 体重设备(对应 /weighingScale/list/device 返回的 result 元素) */ interface ScaleDevice { - /** 设备ID */ + /** 记录 ID */ id: string - /** 设备名称 */ - equipmentName: string - /** 设备SN */ - equipmentCode: string + /** 设备 SN */ + scaleDeviceId: string + /** 连接设备信息(JSON 字符串,含 name、deviceId) */ + connectDeviceInfo: string + /** 用户数量 */ + userNum: number /** 状态 */ - status: number - canteenId: string | null - /** MAC 地址 */ - macAddress: string - /** WiFi 名称 */ - wifiName: string - isSync: number - /** 成员人数 */ - subUserNum: number + status: false } /** 获取体重设备列表 */ -const getDeviceList = () => - get('weighingScale/list/device') +const getDeviceList = (userId: string) => + get('weighingScale/v3/list/device', { userId }) /** 展示用设备项 */ interface DeviceItem { id: string name: string - status: string - connected: boolean - model: string - serial: string - subUserNum: number + status: boolean + deviceId: string + sn: string + userNum: number + connectDeviceInfo: string } Page({ @@ -43,26 +38,32 @@ Page({ loadingContent: '请确保设备处于开启状态\n请勿离开...' }, - onLoad() { + onShow() { this.loadDevices() }, /** 拉取体重设备列表 */ async loadDevices() { + const raw = wx.getStorageSync('userInfo') as UserInfo | null + if (!raw?.userId) return try { - const res = await getDeviceList() + const res = await getDeviceList(raw.userId) 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, - })), + devices: res.result.map(item => { + let info: Record = {} + try { + info = JSON.parse(item.connectDeviceInfo || '{}') + } catch {} + return { + id: item.id, + name: info.name ?? '', + status: false, + deviceId: info.deviceId ?? '', + sn: item.scaleDeviceId, + userNum: item.userNum ?? 0, + connectDeviceInfo: item.connectDeviceInfo ?? '', + } + }), }) } catch { // 请求失败已由 request 层统一 toast diff --git a/miniprogram/pages/equipment/equipment.wxml b/miniprogram/pages/equipment/equipment.wxml index 325f80b..cb1e968 100644 --- a/miniprogram/pages/equipment/equipment.wxml +++ b/miniprogram/pages/equipment/equipment.wxml @@ -1,9 +1,9 @@ - - 当前为:运维模式 - 关闭运维模式 - + + + + @@ -21,13 +21,6 @@ 取消全部配对 - - - - - 用户 - - @@ -40,9 +33,9 @@ 取消配对 - + - {{ item.status }} + {{ item.status ? '已连接' : '未连接' }} @@ -50,12 +43,12 @@ - 型号 - {{ item.model }} + 设备ID + {{ item.deviceId }} - 设备编号 - {{ item.serial }} + 设备SN + {{ item.sn }} @@ -70,14 +63,16 @@ - 用户({{ item.subUserNum }}) + 用户({{ item.userNum }}) - - - + + + + + + 数据补传 - 数据补传 - +