1. 修复蓝牙开关监听bug
This commit is contained in:
parent
d3364ecec5
commit
0de95780e6
2
App.vue
2
App.vue
@ -37,6 +37,8 @@
|
|||||||
onLaunch: async function() {
|
onLaunch: async function() {
|
||||||
// 检查强制升级
|
// 检查强制升级
|
||||||
this.updateMiniProgram()
|
this.updateMiniProgram()
|
||||||
|
// 监听蓝牙开关状态
|
||||||
|
this.onBluetoothState()
|
||||||
// 检查蓝牙权限
|
// 检查蓝牙权限
|
||||||
const checkResult = await this.checkSetting()
|
const checkResult = await this.checkSetting()
|
||||||
console.log(checkResult)
|
console.log(checkResult)
|
||||||
|
|||||||
@ -121,8 +121,6 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
if (initResult) {
|
if (initResult) {
|
||||||
// 更新蓝牙初始化状态
|
// 更新蓝牙初始化状态
|
||||||
this.updateInitBluetooth(true)
|
this.updateInitBluetooth(true)
|
||||||
// 监听蓝牙开关状态
|
|
||||||
this.onBluetoothState()
|
|
||||||
// 监听蓝牙连接状态
|
// 监听蓝牙连接状态
|
||||||
this.onBluetoothConnectStatus()
|
this.onBluetoothConnectStatus()
|
||||||
// 监听设备特征值变化
|
// 监听设备特征值变化
|
||||||
@ -542,30 +540,33 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
uni.stopBluetoothDevicesDiscovery()
|
uni.stopBluetoothDevicesDiscovery()
|
||||||
},
|
},
|
||||||
// 蓝牙状态提示
|
// 蓝牙状态提示
|
||||||
getBluetoothStatus() {
|
async getBluetoothStatus () {
|
||||||
if(this.bluetoothStatus === 1) {
|
if (this.bluetoothStatus === 1) {
|
||||||
uni.showModal({
|
const initResult = await this.initBluetooth()
|
||||||
title: '提示',
|
if (!initResult) {
|
||||||
content: '蓝牙尚未打开,请先打开蓝牙',
|
uni.showModal({
|
||||||
showCancel: false,
|
title: '提示',
|
||||||
success(res) {
|
content: '蓝牙尚未打开,请先打开蓝牙',
|
||||||
if (res.confirm) {
|
showCancel: false,
|
||||||
wx.openSystemBluetoothSetting({
|
success (res) {
|
||||||
success (res) {
|
if (res.confirm) {
|
||||||
console.log(res)
|
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({
|
uni.showModal({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
content: '小程序蓝牙功能被禁用,请打开小程序蓝牙权限',
|
content: '小程序蓝牙功能被禁用,请打开小程序蓝牙权限',
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
confirmText: '去设置',
|
confirmText: '去设置',
|
||||||
success(res) {
|
success (res) {
|
||||||
if(res.confirm) {
|
if (res.confirm) {
|
||||||
uni.openSetting()
|
uni.openSetting()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -594,8 +595,6 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
await that.initBluetooth()
|
await that.initBluetooth()
|
||||||
} else if(that.bluetoothStatus === 3 && bluetooth !== false) {
|
} else if(that.bluetoothStatus === 3 && bluetooth !== false) {
|
||||||
that.bluetoothStatus = 1
|
that.bluetoothStatus = 1
|
||||||
await that.initBluetooth()
|
|
||||||
that.onBluetoothState()
|
|
||||||
}
|
}
|
||||||
console.log('蓝牙权限', bluetooth, that.bluetoothStatus)
|
console.log('蓝牙权限', bluetooth, that.bluetoothStatus)
|
||||||
resolve(bluetooth)
|
resolve(bluetooth)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user