feat(equipment): 设备列表接入真实接口并调整字段映射

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-08-24 15:44:55 +08:00
co-authored by Claude Sonnet 4.6
parent 17113759b8
commit 6ffda3f3f3
3 changed files with 69 additions and 61 deletions
+35 -34
View File
@@ -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<ScaleDevice[]>('weighingScale/list/device')
const getDeviceList = (userId: string) =>
get<ScaleDevice[]>('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<string, any> = {}
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