Compare commits
2
Commits
news-LiLong
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3551fb332a | ||
|
|
6e3ccd73a8 |
@@ -138,6 +138,7 @@ App({
|
||||
mac: null, // 选中的设备mac地址/SN码
|
||||
connection: null, // 默认选中连接的设备
|
||||
connectState: null, // 当前连接设备的状态
|
||||
version: null, // 当前连接设备的固件版本
|
||||
},
|
||||
reconnect: {
|
||||
count: 0, // 当前已重连次数
|
||||
|
||||
@@ -19,43 +19,40 @@ Component({
|
||||
return;
|
||||
}
|
||||
|
||||
ppScale.plugin.bus.subscribe("deviceInfo", (res) => {
|
||||
console.log("===》deviceInfo", res);
|
||||
const res = ppScale.device.version;
|
||||
// 解析固件版本号:格式 "006.005.004.305" → [mcu, ble, wifi, res]
|
||||
const [mcuVer, bleVer, wifiVer, resVer] = (res.firmwareRevision || "").split(".");
|
||||
|
||||
// 解析固件版本号:格式 "006.005.004.305" → [mcu, ble, wifi, res]
|
||||
const [mcuVer, bleVer, wifiVer, resVer] = (res.firmwareRevision || "").split(".");
|
||||
$.ajax("weighingScale/v2/firmware/version", {
|
||||
type: res.modelNumber
|
||||
}, "GET", false, "").then(serverRes => {
|
||||
if (serverRes.result) {
|
||||
/**
|
||||
* 判断服务端版本是否大于设备端版本(需要升级)
|
||||
* @param {string} deviceVer - 设备端单段版本,如 "006"
|
||||
* @param {string} serverVer - 服务端完整版本,如 "0.0.6"
|
||||
* @returns {boolean} true 表示服务端版本更新,需要升级
|
||||
*/
|
||||
const isServerNewer = (deviceVer, serverVer) => {
|
||||
// 设备端单段数字化(去前导零),如 "006" → 6
|
||||
const deviceNum = parseInt(deviceVer, 10);
|
||||
// 服务端版本各段累乘1000合并为整数,如 "0.0.6" → 6,"1.0.2" → 1002
|
||||
const serverNum = (serverVer || "").split(".").map(v => parseInt(v, 10)).reduce((acc, v) => acc * 1000 + v, 0);
|
||||
return serverNum > deviceNum;
|
||||
};
|
||||
|
||||
$.ajax("weighingScale/v2/select/user", {
|
||||
type: res.modelNumber
|
||||
}, "GET", false, "").then(serverRes => {
|
||||
if (serverRes.result) {
|
||||
/**
|
||||
* 判断服务端版本是否大于设备端版本(需要升级)
|
||||
* @param {string} deviceVer - 设备端单段版本,如 "006"
|
||||
* @param {string} serverVer - 服务端完整版本,如 "0.0.6"
|
||||
* @returns {boolean} true 表示服务端版本更新,需要升级
|
||||
*/
|
||||
const isServerNewer = (deviceVer, serverVer) => {
|
||||
// 设备端单段数字化(去前导零),如 "006" → 6
|
||||
const deviceNum = parseInt(deviceVer, 10);
|
||||
// 服务端版本各段累乘1000合并为整数,如 "0.0.6" → 6,"1.0.2" → 1002
|
||||
const serverNum = (serverVer || "").split(".").map(v => parseInt(v, 10)).reduce((acc, v) => acc * 1000 + v, 0);
|
||||
return serverNum > deviceNum;
|
||||
};
|
||||
const needUpdate = isServerNewer(mcuVer, serverRes.result.mcuVersion) || isServerNewer(bleVer, serverRes.result.bleVersion) || isServerNewer(wifiVer, serverRes.result.wifiVersion) || isServerNewer(resVer, serverRes.result.resVersion);
|
||||
|
||||
const needUpdate = isServerNewer(mcuVer, serverRes.result.mcuVersion) || isServerNewer(bleVer, serverRes.result.bleVersion) || isServerNewer(wifiVer, serverRes.result.wifiVersion) || isServerNewer(resVer, serverRes.result.resVersion);
|
||||
|
||||
if (needUpdate) {
|
||||
// status: false = 成功,true = 失败
|
||||
activeProtocol.codeOtaUpdate((status) => {
|
||||
console.log("OTA 升级结果:", status);
|
||||
});
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
wx.showToast({ title: '获取最新版本失败', icon: 'none' });
|
||||
});
|
||||
});
|
||||
if (needUpdate) {
|
||||
// status: false = 成功,true = 失败
|
||||
activeProtocol.codeOtaUpdate((status) => {
|
||||
console.log("OTA 升级结果:", status);
|
||||
});
|
||||
}
|
||||
}
|
||||
}).catch(() => {
|
||||
wx.showToast({ title: '获取最新版本失败', icon: 'none' });
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -123,6 +123,11 @@ Page({
|
||||
device: device
|
||||
})
|
||||
ppScale.plugin.Blue.createBLEConnection(device);
|
||||
|
||||
ppScale.plugin.bus.subscribe("deviceInfo", (res) => {
|
||||
console.log("===》deviceInfo", res);
|
||||
ppScale.device.version = res;
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -20,13 +20,6 @@
|
||||
<view>更换网络</view>
|
||||
<view></view>
|
||||
</view>
|
||||
<view class="list arrowAfter">
|
||||
<view>
|
||||
<image src="/images/my/3.png" />
|
||||
</view>
|
||||
<view>隐私协议</view>
|
||||
<view></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user