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