feat:登录注册完成
This commit is contained in:
69
src/pages/add-device/scan/use-scan-device.ts
Normal file
69
src/pages/add-device/scan/use-scan-device.ts
Normal 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user