1. 修复蓝牙开关监听bug
This commit is contained in:
parent
d3364ecec5
commit
0de95780e6
2
App.vue
2
App.vue
@ -37,6 +37,8 @@
|
||||
onLaunch: async function() {
|
||||
// 检查强制升级
|
||||
this.updateMiniProgram()
|
||||
// 监听蓝牙开关状态
|
||||
this.onBluetoothState()
|
||||
// 检查蓝牙权限
|
||||
const checkResult = await this.checkSetting()
|
||||
console.log(checkResult)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user