feat(equipment): 设备列表接入真实接口并调整字段映射
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
17113759b8
commit
6ffda3f3f3
@@ -163,7 +163,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
|
|
||||||
.device-status--connected {
|
.device-status_ {
|
||||||
height: 40rpx;
|
height: 40rpx;
|
||||||
padding: 0 16rpx;
|
padding: 0 16rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -171,22 +171,34 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
border-radius: 20rpx;
|
border-radius: 20rpx;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: #EAFAF6;
|
background-color: #F2F3F6;
|
||||||
|
|
||||||
.status-dot {
|
.status-dot {
|
||||||
width: 12rpx;
|
width: 12rpx;
|
||||||
height: 12rpx;
|
height: 12rpx;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: #2AC79F;
|
background-color: #77849E;
|
||||||
margin-right: 8rpx;
|
margin-right: 8rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-text {
|
.status-text {
|
||||||
color: #2AC79F;
|
color: #77849E;
|
||||||
height: 22rpx;
|
height: 22rpx;
|
||||||
font-size: 22rpx;
|
font-size: 22rpx;
|
||||||
line-height: 22rpx;
|
line-height: 22rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.connected {
|
||||||
|
background-color: #EAFAF6;
|
||||||
|
|
||||||
|
&.status-dot {
|
||||||
|
background-color: #2AC79F;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.status-text {
|
||||||
|
color: #2AC79F;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +1,33 @@
|
|||||||
import { get } from '../../utils/request/index'
|
import { get } from '../../utils/request/index'
|
||||||
|
import type { UserInfo } from '../../api/index'
|
||||||
|
|
||||||
/** 体重设备(对应 /weighingScale/list/device 返回的 result 元素) */
|
/** 体重设备(对应 /weighingScale/list/device 返回的 result 元素) */
|
||||||
interface ScaleDevice {
|
interface ScaleDevice {
|
||||||
/** 设备ID */
|
/** 记录 ID */
|
||||||
id: string
|
id: string
|
||||||
/** 设备名称 */
|
/** 设备 SN */
|
||||||
equipmentName: string
|
scaleDeviceId: string
|
||||||
/** 设备SN */
|
/** 连接设备信息(JSON 字符串,含 name、deviceId) */
|
||||||
equipmentCode: string
|
connectDeviceInfo: string
|
||||||
|
/** 用户数量 */
|
||||||
|
userNum: number
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
status: number
|
status: false
|
||||||
canteenId: string | null
|
|
||||||
/** MAC 地址 */
|
|
||||||
macAddress: string
|
|
||||||
/** WiFi 名称 */
|
|
||||||
wifiName: string
|
|
||||||
isSync: number
|
|
||||||
/** 成员人数 */
|
|
||||||
subUserNum: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取体重设备列表 */
|
/** 获取体重设备列表 */
|
||||||
const getDeviceList = () =>
|
const getDeviceList = (userId: string) =>
|
||||||
get<ScaleDevice[]>('weighingScale/list/device')
|
get<ScaleDevice[]>('weighingScale/v3/list/device', { userId })
|
||||||
|
|
||||||
/** 展示用设备项 */
|
/** 展示用设备项 */
|
||||||
interface DeviceItem {
|
interface DeviceItem {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
status: string
|
status: boolean
|
||||||
connected: boolean
|
deviceId: string
|
||||||
model: string
|
sn: string
|
||||||
serial: string
|
userNum: number
|
||||||
subUserNum: number
|
connectDeviceInfo: string
|
||||||
}
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -43,26 +38,32 @@ Page({
|
|||||||
loadingContent: '请确保设备处于开启状态\n请勿离开...'
|
loadingContent: '请确保设备处于开启状态\n请勿离开...'
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onShow() {
|
||||||
this.loadDevices()
|
this.loadDevices()
|
||||||
},
|
},
|
||||||
|
|
||||||
/** 拉取体重设备列表 */
|
/** 拉取体重设备列表 */
|
||||||
async loadDevices() {
|
async loadDevices() {
|
||||||
|
const raw = wx.getStorageSync('userInfo') as UserInfo | null
|
||||||
|
if (!raw?.userId) return
|
||||||
try {
|
try {
|
||||||
const res = await getDeviceList()
|
const res = await getDeviceList(raw.userId)
|
||||||
this.setData({
|
this.setData({
|
||||||
devices: res.result.map(item => ({
|
devices: res.result.map(item => {
|
||||||
id: item.id,
|
let info: Record<string, any> = {}
|
||||||
name: item.equipmentName,
|
try {
|
||||||
// status 具体枚举待确认,先按 1 = 已连接处理
|
info = JSON.parse(item.connectDeviceInfo || '{}')
|
||||||
status: item.status === 1 ? '已连接' : '未连接',
|
} catch {}
|
||||||
connected: item.status === 1,
|
return {
|
||||||
// 接口无独立「型号」字段,先用设备名称占位
|
id: item.id,
|
||||||
model: item.equipmentName,
|
name: info.name ?? '',
|
||||||
serial: item.equipmentCode,
|
status: false,
|
||||||
subUserNum: item.subUserNum,
|
deviceId: info.deviceId ?? '',
|
||||||
})),
|
sn: item.scaleDeviceId,
|
||||||
|
userNum: item.userNum ?? 0,
|
||||||
|
connectDeviceInfo: item.connectDeviceInfo ?? '',
|
||||||
|
}
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
// 请求失败已由 request 层统一 toast
|
// 请求失败已由 request 层统一 toast
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<view class="equipment">
|
<view class="equipment">
|
||||||
<!-- 运维模式提示行 -->
|
<!-- 运维模式提示行 -->
|
||||||
<view class="ops-bar">
|
<!-- <view class="ops-bar">-->
|
||||||
<view class="ops-mode">当前为:运维模式</view>
|
<!-- <view class="ops-mode">当前为:运维模式</view>-->
|
||||||
<view class="ops-btn ops-btn--blue" bind:tap="onCloseOps">关闭运维模式</view>
|
<!-- <view class="ops-btn ops-btn--blue" bind:tap="onCloseOps">关闭运维模式</view>-->
|
||||||
</view>
|
<!-- </view>-->
|
||||||
|
|
||||||
<!-- 顶部卡片(渐变背景 + 设备图片占位) -->
|
<!-- 顶部卡片(渐变背景 + 设备图片占位) -->
|
||||||
<view class="top-banner">
|
<view class="top-banner">
|
||||||
@@ -21,13 +21,6 @@
|
|||||||
<view class="ops-btn ops-btn--red" bind:tap="onUnpairAll">取消全部配对</view>
|
<view class="ops-btn ops-btn--red" bind:tap="onUnpairAll">取消全部配对</view>
|
||||||
</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:if="{{ devices && devices.length }}">
|
||||||
<block wx:for="{{ devices }}" wx:key="id">
|
<block wx:for="{{ devices }}" wx:key="id">
|
||||||
@@ -40,9 +33,9 @@
|
|||||||
<view class="device-unpair" bind:tap="onTapUnpair">取消配对</view>
|
<view class="device-unpair" bind:tap="onTapUnpair">取消配对</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="device-status">
|
<view class="device-status">
|
||||||
<view class="device-status--connected">
|
<view class="device-status_ {{item.status ? 'connected' : ''}}">
|
||||||
<view class="status-dot"></view>
|
<view class="status-dot"></view>
|
||||||
<view class="status-text">{{ item.status }}</view>
|
<view class="status-text">{{ item.status ? '已连接' : '未连接' }}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -50,12 +43,12 @@
|
|||||||
|
|
||||||
<view class="device-meta">
|
<view class="device-meta">
|
||||||
<view class="meta-row">
|
<view class="meta-row">
|
||||||
<view class="meta-label">型号</view>
|
<view class="meta-label">设备ID</view>
|
||||||
<view class="meta-value">{{ item.model }}</view>
|
<view class="meta-value">{{ item.deviceId }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="meta-row">
|
<view class="meta-row">
|
||||||
<view class="meta-label">设备编号</view>
|
<view class="meta-label">设备SN</view>
|
||||||
<view class="meta-value">{{ item.serial }}</view>
|
<view class="meta-value">{{ item.sn }}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -70,14 +63,16 @@
|
|||||||
<view>
|
<view>
|
||||||
<image src="/images/equipment/users.png"/>
|
<image src="/images/equipment/users.png"/>
|
||||||
</view>
|
</view>
|
||||||
<view>用户({{ item.subUserNum }})</view>
|
<view>用户({{ item.userNum }})</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="device-action-btn">
|
<block wx:if="{{item.status}}">
|
||||||
<view>
|
<view class="device-action-btn">
|
||||||
<image src="/images/equipment/reload.png"/>
|
<view>
|
||||||
|
<image src="/images/equipment/reload.png"/>
|
||||||
|
</view>
|
||||||
|
<view>数据补传</view>
|
||||||
</view>
|
</view>
|
||||||
<view>数据补传</view>
|
</block>
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
|
|||||||
Reference in New Issue
Block a user