2025年5月29日15:21:00
This commit is contained in:
@@ -65,13 +65,11 @@ Page({
|
||||
wx.getSetting({
|
||||
success: (res) => {
|
||||
if (res.authSetting['scope.bluetooth']) {
|
||||
wx.hideLoading();
|
||||
this.openBluetoothAdapter();
|
||||
} else {
|
||||
wx.authorize({
|
||||
scope: 'scope.bluetooth',
|
||||
success: () => {
|
||||
wx.hideLoading();
|
||||
this.openBluetoothAdapter();
|
||||
},
|
||||
fail: (err) => {
|
||||
@@ -126,7 +124,6 @@ Page({
|
||||
});
|
||||
wx.openBluetoothAdapter({
|
||||
success: () => {
|
||||
wx.hideLoading();
|
||||
this.getDeviceSettingList();
|
||||
},
|
||||
fail: (err) => {
|
||||
@@ -189,7 +186,6 @@ Page({
|
||||
let fIndex = res_.findIndex(item => item.deviceId === res.result[0].deviceId);
|
||||
if (fIndex >= 0) {
|
||||
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
|
||||
wx.hideLoading();
|
||||
wx.showLoading({
|
||||
title: "正在连接设备...",
|
||||
mask: true
|
||||
|
||||
+22
-22
@@ -275,23 +275,23 @@ Page({
|
||||
},
|
||||
|
||||
checkBluetoothPermissionAndInit() {
|
||||
this.setData({
|
||||
initText: "正在检查蓝牙权限..."
|
||||
});
|
||||
wx.showLoading({
|
||||
title: '正在检查蓝牙权限...',
|
||||
mask: true
|
||||
})
|
||||
wx.getSetting({
|
||||
success: (res) => {
|
||||
if (res.authSetting['scope.bluetooth']) {
|
||||
this.openBluetoothAdapter();
|
||||
} else {
|
||||
wx.hideLoading();
|
||||
wx.authorize({
|
||||
scope: 'scope.bluetooth',
|
||||
success: () => {
|
||||
this.openBluetoothAdapter();
|
||||
},
|
||||
fail: (err) => {
|
||||
this.setData({
|
||||
initText: "蓝牙权限被拒绝。"
|
||||
});
|
||||
wx.hideLoading();
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '您拒绝了蓝牙权限,将无法连接蓝牙秤。是否前往设置开启?',
|
||||
@@ -321,9 +321,7 @@ Page({
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
this.setData({
|
||||
initText: "获取权限设置失败。"
|
||||
});
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '获取权限设置失败',
|
||||
icon: 'none'
|
||||
@@ -336,20 +334,16 @@ Page({
|
||||
},
|
||||
|
||||
openBluetoothAdapter() {
|
||||
this.setData({
|
||||
initText: "正在初始化蓝牙..."
|
||||
wx.showLoading({
|
||||
title: "正在初始化蓝牙...",
|
||||
mask: true
|
||||
});
|
||||
wx.openBluetoothAdapter({
|
||||
success: () => {
|
||||
this.setData({
|
||||
initText: "蓝牙初始化成功"
|
||||
});
|
||||
this.getDeviceSettingList();
|
||||
},
|
||||
fail: (err) => {
|
||||
this.setData({
|
||||
initText: "蓝牙初始化失败。"
|
||||
});
|
||||
wx.hideLoading();
|
||||
if (err.errCode === 10001) {
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
@@ -391,9 +385,10 @@ Page({
|
||||
getDeviceSettingList() {
|
||||
let params = {};
|
||||
$.ajax("weighingScale/list/device", params, "GET", true, "获取设备列表").then((res) => {
|
||||
this.setData({
|
||||
initText: "设备搜索中..."
|
||||
})
|
||||
wx.showLoading({
|
||||
title: "正在寻找设备...",
|
||||
mask: true
|
||||
});
|
||||
app.globalData.ppScale.device.list = [];
|
||||
let seviceList = app.globalData.ppScale.device.setting.find((item) => {
|
||||
return item.deviceName === res.result[0].type
|
||||
@@ -406,6 +401,10 @@ Page({
|
||||
let fIndex = res_.findIndex(item => item.deviceId === res.result[0].deviceId);
|
||||
if (fIndex >= 0) {
|
||||
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
|
||||
wx.showLoading({
|
||||
title: "正在连接设备...",
|
||||
mask: true
|
||||
});
|
||||
this.setData({
|
||||
device: res_[fIndex]
|
||||
})
|
||||
@@ -417,17 +416,18 @@ Page({
|
||||
|
||||
// 点击设备重连
|
||||
connectedDevice() {
|
||||
let device = this.data.device;
|
||||
if(device) {
|
||||
wx.showLoading({
|
||||
title: "正在重新连接设备...",
|
||||
mask: true
|
||||
});
|
||||
let device = this.data.device;
|
||||
if(device) {
|
||||
app.globalData.ppScale.plugin.Blue.createBLEConnection(device);
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
app.globalData.ppScale.plugin.Blue.disconnect();
|
||||
if (this._connectStateWatcher) {
|
||||
app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user