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
+16 -4
View File
@@ -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;
}
}
}
}
}
+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
+18 -23
View File
@@ -1,9 +1,9 @@
<view class="equipment">
<!-- 运维模式提示行 -->
<view class="ops-bar">
<view class="ops-mode">当前为:运维模式</view>
<view class="ops-btn ops-btn--blue" bind:tap="onCloseOps">关闭运维模式</view>
</view>
<!-- <view class="ops-bar">-->
<!-- <view class="ops-mode">当前为:运维模式</view>-->
<!-- <view class="ops-btn ops-btn&#45;&#45;blue" bind:tap="onCloseOps">关闭运维模式</view>-->
<!-- </view>-->
<!-- 顶部卡片(渐变背景 + 设备图片占位) -->
<view class="top-banner">
@@ -21,13 +21,6 @@
<view class="ops-btn ops-btn--red" bind:tap="onUnpairAll">取消全部配对</view>
</view>
<view class="device-action-btn" bind:tap="onTapUser">
<view>
<image src="/images/equipment/users.png"/>
</view>
<view>用户</view>
</view>
<!-- 设备列表 -->
<block wx:if="{{ devices && devices.length }}">
<block wx:for="{{ devices }}" wx:key="id">
@@ -40,9 +33,9 @@
<view class="device-unpair" bind:tap="onTapUnpair">取消配对</view>
</view>
<view class="device-status">
<view class="device-status--connected">
<view class="device-status_ {{item.status ? 'connected' : ''}}">
<view class="status-dot"></view>
<view class="status-text">{{ item.status }}</view>
<view class="status-text">{{ item.status ? '已连接' : '未连接' }}</view>
</view>
</view>
</view>
@@ -50,12 +43,12 @@
<view class="device-meta">
<view class="meta-row">
<view class="meta-label">型号</view>
<view class="meta-value">{{ item.model }}</view>
<view class="meta-label">设备ID</view>
<view class="meta-value">{{ item.deviceId }}</view>
</view>
<view class="meta-row">
<view class="meta-label">设备编号</view>
<view class="meta-value">{{ item.serial }}</view>
<view class="meta-label">设备SN</view>
<view class="meta-value">{{ item.sn }}</view>
</view>
</view>
@@ -70,14 +63,16 @@
<view>
<image src="/images/equipment/users.png"/>
</view>
<view>用户({{ item.subUserNum }})</view>
<view>用户({{ item.userNum }})</view>
</view>
<view class="device-action-btn">
<view>
<image src="/images/equipment/reload.png"/>
<block wx:if="{{item.status}}">
<view class="device-action-btn">
<view>
<image src="/images/equipment/reload.png"/>
</view>
<view>数据补传</view>
</view>
<view>数据补传</view>
</view>
</block>
</view>
</view>
</block>