94 lines
2.2 KiB
TypeScript
94 lines
2.2 KiB
TypeScript
import { get } from '../../utils/request/index'
|
|
|
|
/** API 返回的设备记录 */
|
|
interface DeviceRecord {
|
|
id: string
|
|
userId: string
|
|
parentUserId: string | null
|
|
scaleDeviceId: string
|
|
deviceId: string | null
|
|
deviceType: string
|
|
dataType: number
|
|
userType: number
|
|
idCard: string
|
|
height: number
|
|
weight: number
|
|
birthday: string
|
|
sex: number
|
|
avatar: string | null
|
|
phone: string | null
|
|
thirdId: string
|
|
realname: string
|
|
bmi: number
|
|
createBy: string
|
|
createTime: string
|
|
updateBy: string
|
|
updateTime: string
|
|
delFlag: number
|
|
sn: string | null
|
|
workNo: string
|
|
remark: string | null
|
|
relationType: string | null
|
|
sex_dictText: string
|
|
}
|
|
|
|
/** 展示用设备项 */
|
|
interface DeviceItem {
|
|
id: string
|
|
scaleDeviceId: string
|
|
realname: string
|
|
/** 蓝牙连接状态,接口不返回,由业务层更新 */
|
|
connected: boolean
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
loading: false,
|
|
deviceList: [] as DeviceItem[],
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadData()
|
|
},
|
|
|
|
/** 拉取已绑定设备列表 */
|
|
loadData() {
|
|
this.setData({ loading: true })
|
|
get<DeviceRecord[]>('weighingScale/v3/list/device')
|
|
.then(res => {
|
|
const list: DeviceItem[] = res.result.map(item => ({
|
|
id: item.id,
|
|
scaleDeviceId: item.scaleDeviceId,
|
|
realname: item.realname,
|
|
connected: false,
|
|
}))
|
|
this.setData({ deviceList: list })
|
|
})
|
|
.finally(() => {
|
|
this.setData({ loading: false })
|
|
})
|
|
},
|
|
|
|
/* 点击「连接」→ 跳转设备搜索页 */
|
|
onTapConnect() {
|
|
wx.navigateTo({
|
|
url: '/pages/connectedDevice/connectedDevice'
|
|
})
|
|
},
|
|
|
|
/* 点击「成员管理」→ 跳转成员管理页 */
|
|
onTapMember(e: WechatMiniprogram.TouchEvent) {
|
|
const id = e.currentTarget.dataset.id as string
|
|
wx.navigateTo({
|
|
url: `/pages/equipmentMember/equipmentMember?id=${id}`
|
|
})
|
|
},
|
|
|
|
/* 点击「添加设备」→ 跳转设备搜索页 */
|
|
onTapAdd() {
|
|
wx.navigateTo({
|
|
url: '/pages/connectedDevice/connectedDevice'
|
|
})
|
|
},
|
|
})
|