2025年12月3日14:14:55

This commit is contained in:
17792275749
2025-12-03 14:14:57 +08:00
parent 3070b2b821
commit efa959d6d3
8 changed files with 247 additions and 204 deletions
+4 -2
View File
@@ -10,10 +10,12 @@ App({
// 秤的所有信息 // 秤的所有信息
ppScale: { ppScale: {
version: "",
plugin: null, plugin: null,
activeProtocol: null, activeProtocol: null,
domain: "http://device.shuziweidao.com:80/gateway", domain1: "http://device.shuziweidao.com:80/gateway", // 老版本 没有鉴权
// domain: "http://192.168.1.12:8889", domain2: "http://device.shuziweidao.com:80/weight", // 新版本 有鉴权
wifi: { wifi: {
ssid: "", ssid: "",
password: "" password: ""
+2 -2
View File
@@ -32,8 +32,8 @@
"style": "v2", "style": "v2",
"plugins": { "plugins": {
"ppScale-plugin": { "ppScale-plugin": {
"version": "1.2.15", "version": "0.0.16",
"provider": "wx0ffb48417ce6345c" "provider": "wx0826af4e4908f524"
} }
}, },
"permission": { "permission": {
@@ -61,89 +61,98 @@ Component({
progress: 2 progress: 2
}) })
app.globalData.ppScale.activeProtocol.dataConfigNetWork({ let version = app.globalData.ppScale.version;
domain: app.globalData.ppScale.domain, if (version === 'domain1') {
ssid: this.data.selectWifi.ssid, app.globalData.ppScale.activeProtocol.dataConfigNetWork({
password: this.data.selectWifiPWD domain: app.globalData.ppScale.domain1,
}, (res) => { ssid: this.data.selectWifi.ssid,
console.log("setNetwork.js dataConfigNetWork", res); password: this.data.selectWifiPWD
}, (res) => {
console.log("setNetwork.js dataConfigNetWork 1", res);
this.netWorkCallBack(res);
})
}
if (version === 'domain2') {
app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
domain: app.globalData.ppScale.domain2,
ssid: this.data.selectWifi.ssid,
password: this.data.selectWifiPWD,
userName: "apiUser",
userPassword: "3acebb95eb49577e9c2a2082589b9bd6",
}, (res) => {
console.log("setNetwork.js dataConfigUserNetWork 2", res);
this.netWorkCallBack(res);
})
}
},
if(res === 23) { netWorkCallBack(res) {
app.globalData.ppScale.wifi.ssid = this.data.selectWifi.ssid; if(res === 23) {
app.globalData.ppScale.wifi.password = this.data.selectWifiPWD; app.globalData.ppScale.wifi.ssid = this.data.selectWifi.ssid;
app.globalData.ppScale.wifi.password = this.data.selectWifiPWD;
let mac = app.globalData.ppScale.device.mac;
let deviceId = app.globalData.ppScale.device.connection.deviceId;
if(mac && deviceId) {
let scaleDeviceId = mac.replace(/:/g, '');
let params = {
equipmentName: app.globalData.ppScale.device.name,
scaleDeviceId: scaleDeviceId,
deviceId: deviceId
};
$.ajax("weighingScale/binding/device", params, "POST").then(res => {
if (res.success) {
app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => {
console.log("setNetwork.js codeSetBindingState", res);
if(res == 0) { let mac = app.globalData.ppScale.device.mac;
this.triggerEvent('deviceEvent', { let deviceId = app.globalData.ppScale.device.connection.deviceId;
status: true if(mac && deviceId) {
}); let scaleDeviceId = mac.replace(/:/g, '');
} else { let params = {
app.globalData.ppScale.plugin.Blue.stop(); equipmentName: app.globalData.ppScale.device.name,
wx.showToast({ scaleDeviceId: scaleDeviceId,
title: "绑定失败,请重试。", deviceId: deviceId
icon: "none" };
}) $.ajax("weighingScale/binding/device", params, "POST").then(res => {
setTimeout(() => { if (res.success) {
wx.navigateBack({ app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => {
delta: 2 console.log("setNetwork.js codeSetBindingState", res);
})
}, 1500) if(res == 0) {
} this.triggerEvent('deviceEvent', {
}) status: true
} else { });
app.globalData.ppScale.plugin.Blue.stop(); } else {
wx.showToast({ app.globalData.ppScale.plugin.Blue.stop();
icon: "none", wx.showToast({
title: res.message title: "绑定失败,请重试。",
}) icon: "none"
setTimeout(() => {
wx.navigateBack({
delta: 2
}) })
}, 1500) setTimeout(() => {
} wx.navigateBack({
}).catch(err => { delta: 2
})
}, 1500)
}
})
} else {
app.globalData.ppScale.plugin.Blue.stop(); app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
title: err.message title: res.message
}) })
setTimeout(() => { setTimeout(() => {
wx.navigateBack({ wx.navigateBack({
delta: 2 delta: 2
}) })
}, 1500) }, 1500)
}) }
} else { }).catch(err => {
app.globalData.ppScale.plugin.Blue.stop(); app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
title: "Mac 地址与 deviceId 获取失败,请重新绑定" title: err.message
}) })
setTimeout(() => { setTimeout(() => {
wx.navigateBack({ wx.navigateBack({
delta: 2 delta: 2
}) })
}, 1500) }, 1500)
} })
} else { } else {
app.globalData.ppScale.plugin.Blue.stop(); app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
title: "配网失败,错误码:" + res title: "Mac 地址与 deviceId 获取失败,请重新绑定"
}) })
setTimeout(() => { setTimeout(() => {
wx.navigateBack({ wx.navigateBack({
@@ -151,7 +160,18 @@ Component({
}) })
}, 1500) }, 1500)
} }
}) } else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
} }
} }
}); });
+51 -31
View File
@@ -32,42 +32,62 @@ Component({
setNerwork() { setNerwork() {
let ssid = this.properties.ssid; let ssid = this.properties.ssid;
let password = this.properties.password; let password = this.properties.password;
app.globalData.ppScale.activeProtocol.dataConfigNetWork({ let version = app.globalData.ppScale.version;
domain: app.globalData.ppScale.domain, if (version === 'domain1') {
ssid: ssid, app.globalData.ppScale.activeProtocol.dataConfigNetWork({
password: password domain: app.globalData.ppScale.domain1,
}, (res) => { ssid: this.data.selectWifi.ssid,
console.log("setNetwork.js dataConfigNetWork", res); password: this.data.selectWifiPWD
}, (res) => {
console.log("setNetwork.js dataConfigNetWork 1", res);
this.netWorkCallBack(res);
})
}
if (version === 'domain2') {
app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
domain: app.globalData.ppScale.domain2,
ssid: ssid,
password: password,
userName: "apiUser",
userPassword: "3acebb95eb49577e9c2a2082589b9bd6"
}, (res) => {
console.log("setNetwork.js dataConfigUserNetWork 2", res);
this.netWorkCallBack(res);
})
}
},
if(res === 23) { netWorkCallBack(res) {
app.globalData.ppScale.wifi.ssid = ssid; if(res === 23) {
app.globalData.ppScale.wifi.password = password; app.globalData.ppScale.wifi.ssid = ssid;
app.globalData.ppScale.wifi.password = password;
let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, ''); let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, '');
if(scaleDeviceId) { if(scaleDeviceId) {
let params = { let params = {
equipmentCode: scaleDeviceId, equipmentCode: scaleDeviceId,
wifiName: ssid wifiName: ssid
}; };
$.ajax("weighingScale/edit/device", params, "POST").then((res) => { $.ajax("weighingScale/edit/device", params, "POST").then((res) => {
this.triggerEvent('wifiEvent', {
status: true
});
})
}
} else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
})
setTimeout(() => {
this.triggerEvent('wifiEvent', { this.triggerEvent('wifiEvent', {
status: false status: true
}); });
}, 1500) })
} }
}) } else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
})
setTimeout(() => {
this.triggerEvent('wifiEvent', {
status: false
});
}, 1500)
}
} }
} }
}); });
+87 -86
View File
@@ -13,109 +13,110 @@ Page({
}, },
onLoad() { onLoad() {
ppScale.plugin.bus.subscribe("devicesModel", (res) => { ppScale.plugin.bus.subscribe("deviceInfo", (res) => {
console.log("===》devicesModel", res); console.log("===》deviceInfo", res);
ppScale.device.mac = res.deviceMac; ppScale.device.mac = res.serialNumber;
});
ppScale.plugin.bus.subscribe("deviceConnect", (res) => { ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('===》deviceConnect', res); console.log('===》deviceConnect', res);
ppScale.plugin.ScaleAction.startDataProgress(true);
ppScale.activeProtocol = ppScale.plugin.ScaleAction.getActiveProtocol();
ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("===》codeUpdateMTU", res);
ppScale.activeProtocol.codeFetchBindingState((res) => {
console.log("===》codeFetchBindingState", res);
ppScale.activeProtocol.codeSyncTime((codeSyncTime) => { ppScale.plugin.ScaleAction.startDataProgress(true);
console.log("===》codeSyncTime", codeSyncTime) ppScale.activeProtocol = ppScale.plugin.ScaleAction.getActiveProtocol();
wx.hideLoading(); ppScale.activeProtocol.codeUpdateMTU((res) => {
if (res === 1) { console.log("===》codeUpdateMTU", res);
wx.showModal({
title: '提示', ppScale.activeProtocol.codeFetchBindingState((res) => {
content: '当前设备已被绑定,你确定要覆盖绑定吗?', console.log("===》codeFetchBindingState", res);
success: (res) => {
if (res.confirm) { ppScale.activeProtocol.codeSyncTime((codeSyncTime) => {
wx.showLoading({ console.log("===》codeSyncTime", codeSyncTime)
title: "正在初始化设备...",
mask: true wx.hideLoading();
}); if (res === 1) {
ppScale.activeProtocol.codeClearDeviceData("00", (res) => { wx.showModal({
console.log("deviceInfo === codeClearDeviceData", res); title: '提示',
wx.hideLoading(); content: '当前设备已被绑定,你确定要覆盖绑定吗?',
success: (res) => {
if(res === 0) { if (res.confirm) {
let scaleDeviceId = ppScale.device.mac.replace(/:/g, ''); wx.showLoading({
let params = { title: "正在初始化设备...",
equipmentCode: scaleDeviceId, mask: true
}; });
$.ajax("weighingScale/del/device", params, "POST", true, "正在初始化设备...").then(res => { ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
ppScale.plugin.Blue.stop(); console.log("deviceInfo === codeClearDeviceData", res);
wx.showToast({ wx.hideLoading();
icon: "none",
title: "设备初始化成功,请重新绑定。", if(res === 0) {
}) let scaleDeviceId = ppScale.device.mac.replace(/:/g, '');
// device.list = []; let params = {
// device.mac = null; equipmentCode: scaleDeviceId,
setTimeout(() => { };
wx.navigateBack({ $.ajax("weighingScale/del/device", params, "POST", true, "正在初始化设备...").then(res => {
delta: 1
})
}, 1500);
});
} else {
ppScale.plugin.Blue.stop(); ppScale.plugin.Blue.stop();
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
title: "设备初始化失败。", title: "设备初始化成功,请重新绑定。",
}) })
} // device.list = [];
}) // device.mac = null;
} else if (res.cancel) { setTimeout(() => {
// device.mac = null; wx.navigateBack({
ppScale.plugin.Blue.stop(); delta: 1
} })
}, 1500);
});
} else {
ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "设备初始化失败。",
})
}
})
} else if (res.cancel) {
// device.mac = null;
ppScale.plugin.Blue.stop();
} }
}) }
} else { })
ppScale.device.name = this.data.device.name; } else {
ppScale.device.connection = this.data.device; ppScale.device.name = this.data.device.name;
if(this.data.progressNext) { ppScale.device.connection = this.data.device;
let scaleDeviceId = ppScale.device.mac.replace(/:/g, ''); ppScale.version = this.data.device.name.includes("YX") ? "domain2" : "domain1";
let params = { if(this.data.progressNext) {
sn: scaleDeviceId, let scaleDeviceId = ppScale.device.mac.replace(/:/g, '');
}; let params = {
$.ajax("weighingScale/getUserInfoBySn", params, "GET", true, "正在同步用户信息...").then(res => { sn: scaleDeviceId,
if(res.result) { };
wx.setStorageSync("userInfo", res.result); $.ajax("weighingScale/getUserInfoBySn", params, "GET", true, "正在同步用户信息...").then(res => {
this.setProgress(); if(res.result) {
} else { wx.setStorageSync("userInfo", res.result);
wx.removeStorageSync("userInfo"); this.setProgress();
wx.showToast({ } else {
title: "暂无用户信息,请手动补充", wx.removeStorageSync("userInfo");
icon: "none"
})
setTimeout(() => {
this.setProgress();
}, 1500)
}
}).catch(() => {
wx.showToast({ wx.showToast({
title: "用户信息同步失败,请手动补充", title: "暂无用户信息,请手动补充",
icon: "none" icon: "none"
}) })
setTimeout(() => { setTimeout(() => {
this.setProgress(); this.setProgress();
}, 1500) }, 1500)
}
}).catch(() => {
wx.showToast({
title: "用户信息同步失败,请手动补充",
icon: "none"
}) })
} setTimeout(() => {
this.setProgress();
}, 1500)
})
} }
}) }
}) })
}); })
}); });
}); });
}, },
+1 -2
View File
@@ -27,9 +27,8 @@ Page({
}, },
delDevice() { delDevice() {
let scaleDeviceId = this.data.deviceInfo.macAddress.replace(/:/g, '');
let params = { let params = {
equipmentCode: scaleDeviceId, equipmentCode: this.data.deviceInfo.equipmentCode,
}; };
$.ajax("weighingScale/del/device", params, "POST", true, "正在解绑设备...").then(res_ => { $.ajax("weighingScale/del/device", params, "POST", true, "正在解绑设备...").then(res_ => {
wx.showToast({ wx.showToast({
+1
View File
@@ -36,6 +36,7 @@ Page({
app.globalData.ppScale.device.name = this.data.device.name; app.globalData.ppScale.device.name = this.data.device.name;
app.globalData.ppScale.device.connection = this.data.device; app.globalData.ppScale.device.connection = this.data.device;
app.globalData.ppScale.version = this.data.device.name.includes("YX") ? "domain2" : "domain1";
wx.hideLoading(); wx.hideLoading();
this.selectComponent('#replaceNetwork1Component').getWiFiList(); this.selectComponent('#replaceNetwork1Component').getWiFiList();
+22 -22
View File
@@ -1,24 +1,24 @@
{ {
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "bodyWeight", "projectname": "bodyWeight",
"setting": { "setting": {
"compileHotReLoad": true, "compileHotReLoad": true,
"urlCheck": false, "urlCheck": false,
"bigPackageSizeSupport": true, "bigPackageSizeSupport": true,
"coverView": true, "coverView": true,
"lazyloadPlaceholderEnable": false, "lazyloadPlaceholderEnable": false,
"skylineRenderEnable": false, "skylineRenderEnable": false,
"preloadBackgroundData": false, "preloadBackgroundData": false,
"autoAudits": false, "autoAudits": false,
"useApiHook": true, "useApiHook": true,
"useApiHostProcess": true, "useApiHostProcess": true,
"showShadowRootInWxmlPanel": true, "showShadowRootInWxmlPanel": true,
"useStaticServer": false, "useStaticServer": false,
"useLanDebug": false, "useLanDebug": false,
"showES6CompileOption": false, "showES6CompileOption": false,
"checkInvalidKey": true, "checkInvalidKey": true,
"ignoreDevUnusedFiles": true "ignoreDevUnusedFiles": true
}, },
"libVersion": "3.8.6", "libVersion": "3.11.3",
"condition": {} "condition": {}
} }