处理636的兼容

This commit is contained in:
17792275749
2025-04-08 14:08:04 +08:00
parent 62091ee0c1
commit 0e4a1aa622
8 changed files with 170 additions and 177 deletions
+56 -63
View File
@@ -7,6 +7,7 @@ Page({
initBluetooth: "0",
customerType: "1",
deviceInfo: null,
id: "",
realname: "",
@@ -69,35 +70,55 @@ Page({
}
}
if(options.initBluetooth === "1") {
this.initBluetooth();
this.getDevice();
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('deviceInfo ===》deviceConnect', res);
console.log('userInfo ===》deviceConnect', res);
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);
console.log("userInfo ===》codeUpdateMTU", res);
$.ajax("weighingScale/list/device", {}, "GET", false).then((res) => {
if(res.result && res.result.length) {
let deviceConnect = res.result.some(item => item.macAddress === app.globalData.ppScale.device.mac);
if(deviceConnect) {
this.setData({
deviceConnect: true
})
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
}
}
this.setData({
deviceConnect: true
})
});
});
}
},
// 获取已经绑定的设备列表
getDevice() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
if(res.result && res.result.length) {
this.setData({
deviceInfo: res.result[0]
})
this.initBluetooth();
} else {
wx.showModal({
title: "提示",
content: "当前暂未绑定设备,需要绑定吗?",
confirmText: "去绑定",
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
} else if (res.cancel) {
wx.navigateBack({
delta: 1
})
}
}
})
}
})
},
// 初始化蓝牙
initBluetooth() {
wx.openBluetoothAdapter({
@@ -115,56 +136,27 @@ Page({
});
},
async refreshToken(fn, flag) {
let bodyToken = wx.getStorageSync('bodyToken');
let bodyTokenTime = wx.getStorageSync('bodyTokenTime');
if (!bodyToken || bodyTokenTime * 1000 < +new Date() || flag) {
let res = await app.globalData.ppScale.plugin.refreshToken({
url: "https://uniquehealth.lefuenergy.com",
data: {
"appKey": app.globalData.ppScale.options.key,
"appSecret": app.globalData.ppScale.options.secret
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) => {
console.log("deviceInfo ===> devicesList", res);
let fIndex = res.findIndex(item => item.deviceId === this.data.deviceInfo.deviceId);
if (fIndex >= 0) {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
return;
}
});
if (res.data.code == 200) {
wx.setStorageSync('bodyToken', res.data.data.token);
wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
fn();
}
} else {
fn();
}
},
getDeviceSettingList() {
let bodyToken = wx.getStorageSync("bodyToken");
app.globalData.ppScale.plugin.getDeviceSettingList({
url: "https://uniquehealth.lefuenergy.com",
data: {
appKey: app.globalData.ppScale.options.key
},
header: {
"token": bodyToken,
"Accept-Language": wx.getStorageSync("lang") || 'zh'
}
}).then((res) => {
if (res.data.code == 200) {
app.globalData.ppScale.plugin.Blue.setDeviceSetting(res.data.data);
app.globalData.ppScale.device.setting = res.data.data;
let deviceNames = res.data.data.map(item => item.deviceName);
app.globalData.ppScale.plugin.Blue.start(deviceNames, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[0]);
});
} else if (res.data.code == 401 || res.data.code == 4008) {
// 401 token过期 / 4008 token为空
// 重新请求token解析数据
this.refreshToken(() => {
this.getDeviceSettingList();
}, true);
}
});
},
// 姓名输入
realnameInput(e) {
@@ -247,7 +239,7 @@ Page({
icon: "none",
title: "请靠近设备并点亮后再试"
})
this.initBluetooth();
this.getDeviceSettingList();
return false;
}
if(!realname) {
@@ -426,7 +418,8 @@ Page({
icon: "none",
title: "删除失败,请靠近设备并点亮后再试"
})
this.initBluetooth();
app.globalData.ppScale.plugin.Blue.stop();
this.getDeviceSettingList();
}
},