处理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
+43 -1
View File
@@ -23,7 +23,49 @@ App({
secret: "eQ50JYimMp0X7uhNLj6D3lTEk4TUUvEG7dvaqKM9t1U=" secret: "eQ50JYimMp0X7uhNLj6D3lTEk4TUUvEG7dvaqKM9t1U="
}, },
device: { device: {
setting: [], // 即将要搜索周边秤的配置 setting: [{
"advLength": 999,
"calorieStatus": 0,
"createBy": null,
"deviceAccuracyType": 2,
"deviceCalcuteType": 3,
"deviceConnectType": 2,
"deviceFuncType": 223,
"deviceName": "CF568_G",
"devicePowerType": 3,
"deviceProtocolType": 3,
"deviceType": 1,
"deviceUnitType": "0,1,11",
"id": 65,
"imgUrl": null,
"macAddressStart": 6,
"remark": null,
"sign": "FF",
"status": 0,
"uhStatus": 1,
"updateBy": null
}, {
"advLength": 999,
"calorieStatus": 0,
"createBy": null,
"deviceAccuracyType": 2,
"deviceCalcuteType": 4,
"deviceConnectType": 2,
"deviceFuncType": 65759,
"deviceName": "CF636_G",
"devicePowerType": 3,
"deviceProtocolType": 3,
"deviceType": 1,
"deviceUnitType": "0,1,2",
"id": 216,
"imgUrl": null,
"macAddressStart": 6,
"remark": null,
"sign": "FF",
"status": 0,
"uhStatus": 1,
"updateBy": null
}], // 即将要搜索周边秤的配置
list: [], // 根据配置搜索到秤的列表 list: [], // 根据配置搜索到秤的列表
mac: null, // 选中的设备mac地址/SN码 mac: null, // 选中的设备mac地址/SN码
name: "", // 设备名称 name: "", // 设备名称
+2 -2
View File
@@ -38,8 +38,8 @@
"style": "v2", "style": "v2",
"plugins": { "plugins": {
"ppScale-plugin": { "ppScale-plugin": {
"version": "1.2.14", "version": "0.0.11",
"provider": "wx0ffb48417ce6345c" "provider": "wx0826af4e4908f524"
} }
}, },
"sitemapLocation": "sitemap.json", "sitemapLocation": "sitemap.json",
+20 -57
View File
@@ -5,12 +5,11 @@ Page({
data: { data: {
deviceConnect: false, deviceConnect: false,
deviceInfo: null deviceInfo: null,
}, },
onLoad(options) { onLoad(options) {
this.getDevice(); this.getDevice();
this.initBluetooth();
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => { app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('deviceInfo ===》deviceConnect', res); console.log('deviceInfo ===》deviceConnect', res);
@@ -21,18 +20,9 @@ Page({
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => { app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("deviceInfo ===》codeUpdateMTU", res); console.log("deviceInfo ===》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({ this.setData({
deviceConnect: true deviceConnect: true
}) })
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
}
}
})
}); });
}); });
}, },
@@ -54,55 +44,26 @@ 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
}
});
if (res.data.code == 200) {
wx.setStorageSync('bodyToken', res.data.data.token);
wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
fn();
}
} else {
fn();
}
},
getDeviceSettingList() { getDeviceSettingList() {
let bodyToken = wx.getStorageSync("bodyToken"); let seviceList = [];
app.globalData.ppScale.plugin.getDeviceSettingList({ app.globalData.ppScale.device.setting.map(item => {
url: "https://uniquehealth.lefuenergy.com", if(this.data.deviceInfo.type === item.deviceName) {
data: { seviceList.push(item);
appKey: app.globalData.ppScale.options.key
},
header: {
"token": bodyToken,
"Accept-Language": wx.getStorageSync("lang") || 'zh'
} }
}).then((res) => { })
if (res.data.code == 200) { if(seviceList && seviceList.length) {
app.globalData.ppScale.plugin.Blue.setDeviceSetting(res.data.data); app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
app.globalData.ppScale.device.setting = res.data.data; app.globalData.ppScale.plugin.Blue.start(seviceList[0].deviceName, false);
let deviceNames = res.data.data.map(item => item.deviceName); app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
app.globalData.ppScale.plugin.Blue.start(deviceNames, false); console.log("deviceInfo ===> devicesList", res);
app.globalData.ppScale.plugin.bus.subscribe("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.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[0]); app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
}); return;
} else if (res.data.code == 401 || res.data.code == 4008) {
// 401 token过期 / 4008 token为空
// 重新请求token解析数据
this.refreshToken(() => {
this.getDeviceSettingList();
}, true);
} }
}); });
}
}, },
// 获取已经绑定的设备列表 // 获取已经绑定的设备列表
@@ -112,6 +73,7 @@ Page({
this.setData({ this.setData({
deviceInfo: res.result[0] deviceInfo: res.result[0]
}) })
this.initBluetooth();
}) })
}, },
@@ -120,7 +82,7 @@ Page({
app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (res) => { app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
console.log("deviceInfo === codeClearDeviceData", res); console.log("deviceInfo === codeClearDeviceData", res);
let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, ''); let scaleDeviceId = this.data.deviceInfo.macAddress.replace(/:/g, '');
let params = { let params = {
equipmentCode: scaleDeviceId, equipmentCode: scaleDeviceId,
}; };
@@ -141,7 +103,8 @@ Page({
icon: "none", icon: "none",
title: "删除失败,请靠近设备并点亮后再试" title: "删除失败,请靠近设备并点亮后再试"
}) })
this.initBluetooth(); app.globalData.ppScale.plugin.Blue.stop();
this.getDeviceSettingList();
} }
}, },
+37 -1
View File
@@ -24,12 +24,48 @@ Page({
wx.navigateTo({ wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=1&customerType=1" url: "/pages/userInfo/userInfo?initBluetooth=1&customerType=1"
}) })
} else {
wx.login({
success: (res) => {
if (res.code) {
this.checkOpenIdLogin(res.code);
} else { } else {
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
title: "请先登录" title: "登录失败,请稍后再试!",
}) })
} }
}
})
}
},
// 微信一键登录
checkOpenIdLogin(code) {
let params = {
code: code
};
$.ajax("weighingScale/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token);
if(res.result.token && res.result.user) {
this.setData({
token: res.result.token,
userInfo: res.result.user
})
this.getDevice();
} else {
wx.showToast({
icon: "none",
title: "请先补全个人信息"
})
setTimeout(() => {
wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=0&customerType=1"
})
}, 1500)
}
})
}, },
// 打开设备详情 // 打开设备详情
+1 -44
View File
@@ -114,51 +114,8 @@ Page({
this.setData({ this.setData({
initText: "设备搜索中..." initText: "设备搜索中..."
}); });
let seviceList = [{ let seviceList = app.globalData.ppScale.device.setting;
"advLength": 999,
"calorieStatus": 0,
"createBy": null,
"deviceAccuracyType": 2,
"deviceCalcuteType": 3,
"deviceConnectType": 2,
"deviceFuncType": 223,
"deviceName": "CF568_G",
"devicePowerType": 3,
"deviceProtocolType": 3,
"deviceType": 1,
"deviceUnitType": "0,1,11",
"id": 65,
"imgUrl": null,
"macAddressStart": 6,
"remark": null,
"sign": "FF",
"status": 0,
"uhStatus": 1,
"updateBy": null
}, {
"advLength": 999,
"calorieStatus": 0,
"createBy": null,
"deviceAccuracyType": 2,
"deviceCalcuteType": 4,
"deviceConnectType": 2,
"deviceFuncType": 65759,
"deviceName": "CF636_G",
"devicePowerType": 3,
"deviceProtocolType": 3,
"deviceType": 1,
"deviceUnitType": "0,1,2",
"id": 216,
"imgUrl": null,
"macAddressStart": 6,
"remark": null,
"sign": "FF",
"status": 0,
"uhStatus": 1,
"updateBy": null
}];
app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList); app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
app.globalData.ppScale.device.setting = seviceList;
let deviceNames = seviceList.map(item => item.deviceName); let deviceNames = seviceList.map(item => item.deviceName);
app.globalData.ppScale.plugin.Blue.start(deviceNames, false); app.globalData.ppScale.plugin.Blue.start(deviceNames, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => { app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
+4 -2
View File
@@ -14,11 +14,13 @@ Page({
app.globalData.ppScale.wifi.password = password; app.globalData.ppScale.wifi.password = password;
let mac = app.globalData.ppScale.device.mac; let mac = app.globalData.ppScale.device.mac;
if(mac) { let deviceId = app.globalData.ppScale.device.connection.deviceId;
if(mac && deviceId) {
let scaleDeviceId = mac.replace(/:/g, ''); let scaleDeviceId = mac.replace(/:/g, '');
let params = { let params = {
equipmentName: app.globalData.ppScale.device.name, equipmentName: app.globalData.ppScale.device.name,
scaleDeviceId: scaleDeviceId, scaleDeviceId: scaleDeviceId,
deviceId: deviceId
}; };
$.ajax("weighingScale/binding/device", params, "POST").then(res => { $.ajax("weighingScale/binding/device", params, "POST").then(res => {
app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => { app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => {
@@ -42,7 +44,7 @@ Page({
} else { } else {
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
title: "Mac 地址获取失败,请重新绑定" title: "Mac 地址与 deviceId 获取失败,请重新绑定"
}) })
setTimeout(() => { setTimeout(() => {
wx.switchTab({ wx.switchTab({
+50 -57
View File
@@ -7,6 +7,7 @@ Page({
initBluetooth: "0", initBluetooth: "0",
customerType: "1", customerType: "1",
deviceInfo: null,
id: "", id: "",
realname: "", realname: "",
@@ -69,33 +70,53 @@ Page({
} }
} }
if(options.initBluetooth === "1") { if(options.initBluetooth === "1") {
this.initBluetooth(); this.getDevice();
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => { 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.plugin.ScaleAction.startDataProgress();
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol(); app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => { 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({ this.setData({
deviceConnect: true 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 { } else {
app.globalData.ppScale.plugin.Blue.disconnect(); wx.showModal({
title: "提示",
content: "当前暂未绑定设备,需要绑定吗?",
confirmText: "去绑定",
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
} else if (res.cancel) {
wx.navigateBack({
delta: 1
})
} }
} }
}) })
});
});
} }
})
}, },
// 初始化蓝牙 // 初始化蓝牙
@@ -115,55 +136,26 @@ 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
}
});
if (res.data.code == 200) {
wx.setStorageSync('bodyToken', res.data.data.token);
wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
fn();
}
} else {
fn();
}
},
getDeviceSettingList() { getDeviceSettingList() {
let bodyToken = wx.getStorageSync("bodyToken"); let seviceList = [];
app.globalData.ppScale.plugin.getDeviceSettingList({ app.globalData.ppScale.device.setting.map(item => {
url: "https://uniquehealth.lefuenergy.com", if(this.data.deviceInfo.type === item.deviceName) {
data: { seviceList.push(item);
appKey: app.globalData.ppScale.options.key
},
header: {
"token": bodyToken,
"Accept-Language": wx.getStorageSync("lang") || 'zh'
} }
}).then((res) => { })
if (res.data.code == 200) { if(seviceList && seviceList.length) {
app.globalData.ppScale.plugin.Blue.setDeviceSetting(res.data.data); app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
app.globalData.ppScale.device.setting = res.data.data; app.globalData.ppScale.plugin.Blue.start(seviceList[0].deviceName, false);
let deviceNames = res.data.data.map(item => item.deviceName); app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
app.globalData.ppScale.plugin.Blue.start(deviceNames, false); console.log("deviceInfo ===> devicesList", res);
app.globalData.ppScale.plugin.bus.subscribe("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.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[0]); app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
}); return;
} else if (res.data.code == 401 || res.data.code == 4008) {
// 401 token过期 / 4008 token为空
// 重新请求token解析数据
this.refreshToken(() => {
this.getDeviceSettingList();
}, true);
} }
}); });
}
}, },
// 姓名输入 // 姓名输入
@@ -247,7 +239,7 @@ Page({
icon: "none", icon: "none",
title: "请靠近设备并点亮后再试" title: "请靠近设备并点亮后再试"
}) })
this.initBluetooth(); this.getDeviceSettingList();
return false; return false;
} }
if(!realname) { if(!realname) {
@@ -426,7 +418,8 @@ Page({
icon: "none", icon: "none",
title: "删除失败,请靠近设备并点亮后再试" title: "删除失败,请靠近设备并点亮后再试"
}) })
this.initBluetooth(); app.globalData.ppScale.plugin.Blue.stop();
this.getDeviceSettingList();
} }
}, },