104 lines
3.4 KiB
Vue
104 lines
3.4 KiB
Vue
<template>
|
||
<view class="scan-page">
|
||
<app-navbar title="扫描设备" />
|
||
<page-scroll-view class="scan-page__scroll">
|
||
<view class="scan-page__body">
|
||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||
<scan-hero />
|
||
<view class="scan-page__status">
|
||
<text class="scan-page__title">{{ pageTitle }}</text>
|
||
<view v-if="!bluetoothDisabled" class="scan-page__hint">
|
||
<view class="scan-page__hint-dot" />
|
||
<text class="scan-page__hint-text">{{ statusHint }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="scan-page__section-head">
|
||
<text class="scan-page__section-title">发现的设备</text>
|
||
<text class="scan-page__section-timer">
|
||
{{ scanning ? `${secondsLeft}秒后停止` : '扫描已停止' }}
|
||
</text>
|
||
</view>
|
||
|
||
<view v-if="bluetoothDisabled" class="scan-page__empty scan-page__empty--bt">
|
||
<text class="scan-page__empty-text">{{ scanError }}</text>
|
||
<view class="scan-page__bt-actions">
|
||
<view class="scan-page__bt-btn scan-page__bt-btn--primary" @tap="onOpenBluetoothSettings">
|
||
<text class="scan-page__bt-btn-text">去开启蓝牙</text>
|
||
</view>
|
||
<view class="scan-page__bt-btn" @tap="onRetryScan">
|
||
<text class="scan-page__bt-btn-text scan-page__bt-btn-text--muted">已开启,重试扫描</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view v-else-if="scanError" class="scan-page__empty">
|
||
<text class="scan-page__empty-text">{{ scanError }}</text>
|
||
</view>
|
||
<view v-else-if="devices.length === 0" class="scan-page__empty">
|
||
<text class="scan-page__empty-text">
|
||
{{ scanning ? '正在搜索附近蓝牙设备...' : '未发现附近设备,请确认设备已开机并靠近手机' }}
|
||
</text>
|
||
</view>
|
||
<view v-else class="scan-page__list">
|
||
<scan-device-item
|
||
v-for="item in devices"
|
||
:key="item.id"
|
||
:device="item"
|
||
:selected="selectedId === item.id"
|
||
@select="onSelectDevice"
|
||
@action="onDeviceAction"
|
||
/>
|
||
</view>
|
||
|
||
<scan-help-tip />
|
||
</view>
|
||
</page-scroll-view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed } from 'vue'
|
||
import { onLoad } from '@dcloudio/uni-app'
|
||
import BindSteps from '../components/bind-steps/index.vue'
|
||
import { BIND_STEPS } from '../use-add-device'
|
||
import ScanDeviceItem from './components/scan-device-item/index.vue'
|
||
import ScanHelpTip from './components/scan-help-tip/index.vue'
|
||
import ScanHero from './components/scan-hero/index.vue'
|
||
import { useScanDevice } from './use-scan-device'
|
||
|
||
const {
|
||
currentStep,
|
||
devices,
|
||
selectedId,
|
||
secondsLeft,
|
||
scanning,
|
||
scanError,
|
||
bluetoothDisabled,
|
||
applyBindHomeId,
|
||
onRetryScan,
|
||
onOpenBluetoothSettings,
|
||
onSelectDevice,
|
||
onDeviceAction,
|
||
} = useScanDevice()
|
||
|
||
onLoad((query) => {
|
||
applyBindHomeId(query?.homeId)
|
||
})
|
||
|
||
const pageTitle = computed(() =>
|
||
bluetoothDisabled.value ? '蓝牙未开启' : '正在扫描附近设备...',
|
||
)
|
||
|
||
const statusHint = computed(() => {
|
||
const count = devices.value.length
|
||
if (scanning.value) {
|
||
return `已发现 ${count} 台设备,继续扫描中`
|
||
}
|
||
return `已发现 ${count} 台设备,扫描已停止`
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
@import './scan.scss';
|
||
</style>
|