feat:登录注册完成

This commit is contained in:
李伊帆
2026-10-09 14:29:58 +08:00
parent da83a58948
commit ee3ecc00eb
106 changed files with 4937 additions and 59 deletions

View File

@@ -0,0 +1,69 @@
import { onUnmounted, ref } from 'vue'
import type { ScannedDeviceItem } from './scan.types'
const MOCK_DEVICES: ScannedDeviceItem[] = [
{
id: 'z2-purifier',
name: 'Z2 空气净化器',
serialMasked: '****A3B2',
canAdd: true,
},
{
id: 'unknown',
name: '未知设备',
serialMasked: '****7C91',
canAdd: false,
},
]
const SCAN_SECONDS = 20
export function useScanDevice() {
const currentStep = 2
const devices = ref<ScannedDeviceItem[]>(MOCK_DEVICES)
const selectedId = ref(MOCK_DEVICES[0]?.id ?? '')
const secondsLeft = ref(SCAN_SECONDS)
const scanning = ref(true)
const timer = setInterval(() => {
if (secondsLeft.value <= 0) {
scanning.value = false
return
}
secondsLeft.value -= 1
if (secondsLeft.value === 0) {
scanning.value = false
}
}, 1000)
onUnmounted(() => {
clearInterval(timer)
})
function onSelectDevice(id: string) {
selectedId.value = id
}
function onDeviceAction(device: ScannedDeviceItem) {
selectedId.value = device.id
if (!device.canAdd) {
uni.showToast({ title: '暂无法添加该设备', icon: 'none' })
return
}
const q = [
`name=${encodeURIComponent(device.name)}`,
`serial=${encodeURIComponent(device.serialMasked)}`,
].join('&')
uni.navigateTo({ url: `/pages/add-device/pair/index?${q}` })
}
return {
currentStep,
devices,
selectedId,
secondsLeft,
scanning,
onSelectDevice,
onDeviceAction,
}
}