1. 修复蓝牙开关监听bug

This commit is contained in:
范鹏 2024-09-14 10:26:06 +08:00
parent d3364ecec5
commit 0de95780e6
2 changed files with 23 additions and 22 deletions

View File

@ -37,6 +37,8 @@
onLaunch: async function() {
//
this.updateMiniProgram()
//
this.onBluetoothState()
//
const checkResult = await this.checkSetting()
console.log(checkResult)

View File

@ -121,8 +121,6 @@ export const useBluetoothStore = defineStore('ble', {
if (initResult) {
// 更新蓝牙初始化状态
this.updateInitBluetooth(true)
// 监听蓝牙开关状态
this.onBluetoothState()
// 监听蓝牙连接状态
this.onBluetoothConnectStatus()
// 监听设备特征值变化
@ -542,30 +540,33 @@ export const useBluetoothStore = defineStore('ble', {
uni.stopBluetoothDevicesDiscovery()
},
// 蓝牙状态提示
getBluetoothStatus() {
if(this.bluetoothStatus === 1) {
uni.showModal({
title: '提示',
content: '蓝牙尚未打开,请先打开蓝牙',
showCancel: false,
success(res) {
if (res.confirm) {
wx.openSystemBluetoothSetting({
success (res) {
console.log(res)
}
})
async getBluetoothStatus () {
if (this.bluetoothStatus === 1) {
const initResult = await this.initBluetooth()
if (!initResult) {
uni.showModal({
title: '提示',
content: '蓝牙尚未打开,请先打开蓝牙',
showCancel: false,
success (res) {
if (res.confirm) {
wx.openSystemBluetoothSetting({
success (res) {
console.log(res)
}
})
}
}
}
})
} else if(this.bluetoothStatus === 2 || this.bluetoothStatus === 3) {
})
}
} else if (this.bluetoothStatus === 2 || this.bluetoothStatus === 3) {
uni.showModal({
title: '提示',
content: '小程序蓝牙功能被禁用,请打开小程序蓝牙权限',
showCancel: false,
confirmText: '去设置',
success(res) {
if(res.confirm) {
success (res) {
if (res.confirm) {
uni.openSetting()
}
}
@ -594,8 +595,6 @@ export const useBluetoothStore = defineStore('ble', {
await that.initBluetooth()
} else if(that.bluetoothStatus === 3 && bluetooth !== false) {
that.bluetoothStatus = 1
await that.initBluetooth()
that.onBluetoothState()
}
console.log('蓝牙权限', bluetooth, that.bluetoothStatus)
resolve(bluetooth)