补充图片

This commit is contained in:
17792275749
2025-04-24 19:59:00 +08:00
parent 4ad8d2a841
commit 230490b995
15 changed files with 178 additions and 102 deletions
+62 -62
View File
@@ -3,7 +3,7 @@ import $ from "../../utils/request";
Page({
data: {
deviceConnect: false,
// deviceConnect: false,
deviceInfo: null,
},
@@ -11,58 +11,58 @@ Page({
onLoad(options) {
this.getDevice();
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('deviceInfo ===》deviceConnect', res);
// app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
// console.log('deviceInfo ===》deviceConnect', res);
app.globalData.ppScale.plugin.ScaleAction.startDataProgress();
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
// app.globalData.ppScale.plugin.ScaleAction.startDataProgress();
// app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("deviceInfo ===》codeUpdateMTU", res);
// app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
// console.log("deviceInfo ===》codeUpdateMTU", res);
this.setData({
deviceConnect: true
})
});
});
// this.setData({
// deviceConnect: true
// })
// });
// });
},
// 初始化蓝牙
initBluetooth() {
wx.openBluetoothAdapter({
success: () => {
this.getDeviceSettingList();
},
fail: (err) => {
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
content: "请打开手机蓝牙",
});
}
},
});
},
// initBluetooth() {
// wx.openBluetoothAdapter({
// success: () => {
// this.getDeviceSettingList();
// },
// fail: (err) => {
// if (err.errCode === 10001) {
// wx.showModal({
// title: "提示",
// content: "请打开手机蓝牙",
// });
// }
// },
// });
// },
getDeviceSettingList() {
let seviceList = [];
app.globalData.ppScale.device.setting.map(item => {
if(this.data.deviceInfo.type === item.deviceName) {
seviceList.push(item);
}
})
if(seviceList && seviceList.length) {
app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
app.globalData.ppScale.plugin.Blue.start(seviceList[0].deviceName, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
let fIndex = res.findIndex(item => item.deviceId === this.data.deviceInfo.deviceId);
if (fIndex > -1) {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
}
});
}
},
// getDeviceSettingList() {
// let seviceList = [];
// app.globalData.ppScale.device.setting.map(item => {
// if(this.data.deviceInfo.type === item.deviceName) {
// seviceList.push(item);
// }
// })
// if(seviceList && seviceList.length) {
// app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
// app.globalData.ppScale.plugin.Blue.start(seviceList[0].deviceName, false);
// app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
// let fIndex = res.findIndex(item => item.deviceId === this.data.deviceInfo.deviceId);
// if (fIndex > -1) {
// app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
// app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
// }
// });
// }
// },
// 获取已经绑定的设备列表
getDevice() {
@@ -71,14 +71,14 @@ Page({
this.setData({
deviceInfo: res.result[0]
})
this.initBluetooth();
// this.initBluetooth();
})
},
delDevice() {
if(this.data.deviceConnect) {
app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
console.log("deviceInfo === codeClearDeviceData", res);
// if(this.data.deviceConnect) {
// app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
// console.log("deviceInfo === codeClearDeviceData", res);
let scaleDeviceId = this.data.deviceInfo.macAddress.replace(/:/g, '');
let params = {
@@ -95,18 +95,18 @@ Page({
})
}, 1500);
});
})
} else {
wx.showToast({
icon: "none",
title: "删除失败,请靠近设备并点亮后再试"
})
app.globalData.ppScale.plugin.Blue.stop();
this.getDeviceSettingList();
}
// })
// } else {
// wx.showToast({
// icon: "none",
// title: "删除失败,请靠近设备并点亮后再试"
// })
// app.globalData.ppScale.plugin.Blue.stop();
// this.getDeviceSettingList();
// }
},
onUnload() {
app.globalData.ppScale.plugin.Blue.stop();
}
// onUnload() {
// app.globalData.ppScale.plugin.Blue.stop();
// }
})