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: [] 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({ title: '取消配对', content: '是否确认取消配对当前设备?', cancelText: '取消', confirmText: '确定', confirmColor: '#F24439' }) }, /** 底部操作:数据补传 / 设备连接 弹 loading */ onTapAction(e: WechatMiniprogram.TouchEvent) { const action = e.currentTarget.dataset.action as string if (action === '数据补传') { this.setData({ loadingShow: true, loadingTitle: '正在获取设备本地未上传数据', loadingContent: '请稍等...' }) } else if (action === '设备连接') { this.setData({ loadingShow: true, loadingTitle: '正在连接设备', loadingContent: '请确保设备处于开启状态\n请勿离开...' }) } }, onCloseLoading() { this.setData({ loadingShow: false }) }, /** 用户管理 */ onTapUser() { wx.navigateTo({ url: '/pages/userManagement/userManagement' }) }, onTapAdd() { wx.navigateTo({ url: '/pages/connectedDevice/connectedDevice' }) }, /** 关闭运维模式 */ onCloseOps() { // 关闭运维模式(待接入) }, /** 取消全部配对 */ onUnpairAll() { wx.showModal({ title: '取消全部配对', content: '是否确认取消全部设备的配对?', cancelText: '取消', confirmText: '确定', confirmColor: '#F24439' }) } })