diff --git a/stores/bluetooth.js b/stores/bluetooth.js index b39891b..e257ad1 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -12,6 +12,10 @@ import { getUserNoListRequest, updateLockUserNoRequest } from '@/api/key' let timer // 特性值回调 let characteristicValueCallback = null +// 搜索次数 +let searchNumber = 10 +// 搜索提示标志 +let searchTipFlag = true // 命令ID const cmdIds = { @@ -413,7 +417,21 @@ export const useBluetoothStore = defineStore('ble', { timer = setInterval(() => { uni.getBluetoothDevices({ success(res) { + searchNumber-- + if(searchNumber === 0 && searchTipFlag) { + uni.showModal({ + title: '提示', + content: '长时间未搜索到任何设备,请确认微信的附近设备权限开启后再试', + showCancel: false, + success() { + uni.navigateBack() + } + }) + } const deviceList = res.devices + if(deviceList.length !== 0) { + searchTipFlag = false + } that.deviceList = [] for(let i = 0; i < deviceList.length; i++) { if(deviceList[i]?.advertisServiceUUIDs) { @@ -437,6 +455,8 @@ export const useBluetoothStore = defineStore('ble', { }, // 停止搜索蓝牙设备 stopGetBluetoothDevices() { + searchNumber = 10 + searchTipFlag = true clearInterval(timer) uni.stopBluetoothDevicesDiscovery() }, @@ -624,11 +644,20 @@ export const useBluetoothStore = defineStore('ble', { const that = this let timer1 let timer2 + const flag = true return new Promise((resolve) => { uni.startBluetoothDevicesDiscovery({ success: function (res) { timer2 = setTimeout(() => { setTimeout(() => { + if(flag) { + uni.showModal({ + title: '提示', + content: '长时间未搜索到任何设备,请确认微信的附近设备权限开启后再试', + showCancel: false, + confirmText: '确定', + }) + } uni.stopBluetoothDevicesDiscovery() clearInterval(timer1) }, 10000) @@ -636,6 +665,9 @@ export const useBluetoothStore = defineStore('ble', { uni.getBluetoothDevices({ success(res) { const deviceList = res.devices + if(deviceList.length !== 0) { + flag = false + } for(let i = 0; i < deviceList.length; i++) { if(deviceList[i]?.name === that.currentLockInfo.name) { const uuid = deviceList[i]?.advertisServiceUUIDs[0]