[AI Generated]: feat(Views): 新增连接设备页三态(idle/searching/found/empty)及登录跳转

This commit is contained in:
17792275749
2026-05-11 15:14:54 +08:00
parent f7e7f7c561
commit 55911b1fce
6 changed files with 439 additions and 7 deletions
@@ -1,4 +1,84 @@
// 是否 mock 能搜索到设备,false 则走空状态
const MOCK_HAS_DEVICES = true
// 模拟搜索耗时(毫秒)
const MOCK_SEARCH_DURATION = 2000
Page({
data: {},
onLoad() {}
data: {
/**
* 页面状态
* - idle: 未搜索(进入页面默认态)
* - searching:搜索中
* - found: 搜索完成且有设备
* - empty: 搜索完成但无设备
*/
status: 'idle',
/* 已连接的设备(null 表示没有) */
connectedDevice: null,
/* 未连接的设备列表 */
deviceList: [],
},
onLoad() {
},
onUnload() {
/* 清除搜索定时器,防止页面卸载后还触发 setData */
if (this._searchTimer) {
clearTimeout(this._searchTimer)
this._searchTimer = null
}
},
/* 开始搜索 / 重新搜索 */
onStartSearch() {
this.setData({
status: 'searching',
connectedDevice: null,
deviceList: [],
})
/* 模拟搜索,后续接入蓝牙真实 API 时删除 */
this._searchTimer = setTimeout(() => {
if (MOCK_HAS_DEVICES) {
this.setData({
status: 'found',
connectedDevice: {
id: 'mock-connected',
name: '智能体重秤 Pro',
icon: '',
},
deviceList: [
{ id: 'mock-1', name: '体重秤 Basic', icon: '' },
{ id: 'mock-2', name: '体脂秤 Plus', icon: '' },
],
})
} else {
this.setData({ status: 'empty' })
}
}, MOCK_SEARCH_DURATION)
},
/* 连接某台未连接设备 */
onConnect(e) {
const { id } = e.currentTarget.dataset
console.log('连接设备:', id)
/* TODO: 接入真实蓝牙连接逻辑 */
},
/* 断开已连接设备 */
onDisconnect() {
console.log('断开连接')
/* TODO: 接入真实蓝牙断开逻辑 */
},
/* 查看帮助 */
onOpenHelp() {
console.log('查看帮助')
/* TODO: 跳帮助页 */
},
})