[AI Generated]: chore(*): 统一页面后缀为TS+LESS并清理searchDevice页
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/** 设备项模型 */
|
||||
interface DeviceItem {
|
||||
/** 设备唯一 id */
|
||||
id: string
|
||||
/** 设备名称 */
|
||||
name: string
|
||||
/** 设备图标 */
|
||||
icon: string
|
||||
/** 是否已连接 */
|
||||
connected: boolean
|
||||
}
|
||||
|
||||
/** 页面状态 */
|
||||
type DeviceStatus = 'idle' | 'searching' | 'found' | 'empty'
|
||||
|
||||
// 是否 mock 能搜索到设备,false 则走空状态
|
||||
const MOCK_HAS_DEVICES = true
|
||||
|
||||
// 模拟搜索耗时(毫秒)
|
||||
const MOCK_SEARCH_DURATION = 2000
|
||||
|
||||
Page({
|
||||
/* 搜索定时器引用,onUnload 时清理 */
|
||||
_searchTimer: null as number | null,
|
||||
|
||||
data: {
|
||||
/**
|
||||
* 页面状态
|
||||
* - idle: 未搜索(进入页面默认态)
|
||||
* - searching:搜索中
|
||||
* - found: 搜索完成且有设备
|
||||
* - empty: 搜索完成但无设备
|
||||
*/
|
||||
status: 'idle' as DeviceStatus,
|
||||
|
||||
/* 设备列表(包含已连接和未连接,每项含 connected: boolean) */
|
||||
deviceList: [] as DeviceItem[],
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
/* 清除搜索定时器,防止页面卸载后还触发 setData */
|
||||
if (this._searchTimer) {
|
||||
clearTimeout(this._searchTimer)
|
||||
this._searchTimer = null
|
||||
}
|
||||
},
|
||||
|
||||
/* 开始搜索 / 重新搜索 */
|
||||
onStartSearch() {
|
||||
this.setData({
|
||||
status: 'searching',
|
||||
deviceList: [],
|
||||
})
|
||||
|
||||
/* 模拟搜索,后续接入蓝牙真实 API 时删除 */
|
||||
this._searchTimer = setTimeout(() => {
|
||||
if (MOCK_HAS_DEVICES) {
|
||||
this.setData({
|
||||
status: 'found',
|
||||
deviceList: [
|
||||
{ id: 'mock-connected', name: '智能体重秤 Pro', icon: '', connected: true },
|
||||
{ id: 'mock-1', name: '体重秤 Basic', icon: '', connected: false },
|
||||
{ id: 'mock-2', name: '体脂秤 Plus', icon: '', connected: false },
|
||||
],
|
||||
})
|
||||
} else {
|
||||
this.setData({ status: 'empty' })
|
||||
}
|
||||
}, MOCK_SEARCH_DURATION)
|
||||
},
|
||||
|
||||
/* 连接某台设备:同时只能一台已连接,自动断开其他设备 */
|
||||
onConnect(e: WechatMiniprogram.TouchEvent) {
|
||||
const { id } = e.currentTarget.dataset
|
||||
const deviceList = this.data.deviceList.map(item => ({
|
||||
...item,
|
||||
connected: item.id === id,
|
||||
}))
|
||||
this.setData({ deviceList })
|
||||
/* TODO: 接入真实蓝牙连接逻辑 */
|
||||
},
|
||||
|
||||
/* 断开当前已连接设备 */
|
||||
onDisconnect() {
|
||||
const deviceList = this.data.deviceList.map(item => ({
|
||||
...item,
|
||||
connected: false,
|
||||
}))
|
||||
this.setData({ deviceList })
|
||||
/* TODO: 接入真实蓝牙断开逻辑 */
|
||||
},
|
||||
|
||||
/* 查看帮助 */
|
||||
onOpenHelp() {
|
||||
console.log('查看帮助')
|
||||
/* TODO: 跳帮助页 */
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user