From 0de95780e6c479eb14af8278e70bec23771f1dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Sat, 14 Sep 2024 10:26:06 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E8=93=9D=E7=89=99?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E7=9B=91=E5=90=ACbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 2 ++ stores/bluetooth.js | 43 +++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/App.vue b/App.vue index a6c7d0f..cf7897b 100644 --- a/App.vue +++ b/App.vue @@ -37,6 +37,8 @@ onLaunch: async function() { // 检查强制升级 this.updateMiniProgram() + // 监听蓝牙开关状态 + this.onBluetoothState() // 检查蓝牙权限 const checkResult = await this.checkSetting() console.log(checkResult) diff --git a/stores/bluetooth.js b/stores/bluetooth.js index e28f2de..69e57d9 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -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)