From efa959d6d3e9d261dffa6858795927b55b39b2ce Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Wed, 3 Dec 2025 14:14:57 +0800 Subject: [PATCH] =?UTF-8?q?2025=E5=B9=B412=E6=9C=883=E6=97=A514:14:55?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 6 +- app.json | 4 +- .../configureDevice_3/configureDevice_3.js | 138 ++++++++------ .../replaceNetwork_3/replaceNetwork_3.js | 82 +++++---- pages/configureDevice/configureDevice.js | 173 +++++++++--------- pages/deviceInfo/deviceInfo.js | 3 +- pages/replaceNetwork/replaceNetwork.js | 1 + project.private.config.json | 44 ++--- 8 files changed, 247 insertions(+), 204 deletions(-) diff --git a/app.js b/app.js index 11e0b89..ceb6977 100644 --- a/app.js +++ b/app.js @@ -10,10 +10,12 @@ App({ // 秤的所有信息 ppScale: { + version: "", + plugin: null, activeProtocol: null, - domain: "http://device.shuziweidao.com:80/gateway", - // domain: "http://192.168.1.12:8889", + domain1: "http://device.shuziweidao.com:80/gateway", // 老版本 没有鉴权 + domain2: "http://device.shuziweidao.com:80/weight", // 新版本 有鉴权 wifi: { ssid: "", password: "" diff --git a/app.json b/app.json index 84f9136..b609523 100644 --- a/app.json +++ b/app.json @@ -32,8 +32,8 @@ "style": "v2", "plugins": { "ppScale-plugin": { - "version": "1.2.15", - "provider": "wx0ffb48417ce6345c" + "version": "0.0.16", + "provider": "wx0826af4e4908f524" } }, "permission": { diff --git a/components/configureDevice_3/configureDevice_3.js b/components/configureDevice_3/configureDevice_3.js index 1d7f663..aa7d5d9 100644 --- a/components/configureDevice_3/configureDevice_3.js +++ b/components/configureDevice_3/configureDevice_3.js @@ -61,89 +61,98 @@ Component({ progress: 2 }) - app.globalData.ppScale.activeProtocol.dataConfigNetWork({ - domain: app.globalData.ppScale.domain, - ssid: this.data.selectWifi.ssid, - password: this.data.selectWifiPWD - }, (res) => { - console.log("setNetwork.js dataConfigNetWork", res); + let version = app.globalData.ppScale.version; + if (version === 'domain1') { + app.globalData.ppScale.activeProtocol.dataConfigNetWork({ + domain: app.globalData.ppScale.domain1, + ssid: this.data.selectWifi.ssid, + 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) { - 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); + netWorkCallBack(res) { + if(res === 23) { + app.globalData.ppScale.wifi.ssid = this.data.selectWifi.ssid; + app.globalData.ppScale.wifi.password = this.data.selectWifiPWD; - if(res == 0) { - this.triggerEvent('deviceEvent', { - status: true - }); - } else { - app.globalData.ppScale.plugin.Blue.stop(); - wx.showToast({ - title: "绑定失败,请重试。", - icon: "none" - }) - setTimeout(() => { - wx.navigateBack({ - delta: 2 - }) - }, 1500) - } - }) - } else { - app.globalData.ppScale.plugin.Blue.stop(); - wx.showToast({ - icon: "none", - title: res.message - }) - setTimeout(() => { - wx.navigateBack({ - delta: 2 + 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) { + this.triggerEvent('deviceEvent', { + status: true + }); + } else { + app.globalData.ppScale.plugin.Blue.stop(); + wx.showToast({ + title: "绑定失败,请重试。", + icon: "none" }) - }, 1500) - } - }).catch(err => { + setTimeout(() => { + wx.navigateBack({ + delta: 2 + }) + }, 1500) + } + }) + } else { app.globalData.ppScale.plugin.Blue.stop(); wx.showToast({ icon: "none", - title: err.message + title: res.message }) setTimeout(() => { wx.navigateBack({ delta: 2 }) }, 1500) - }) - } else { + } + }).catch(err => { app.globalData.ppScale.plugin.Blue.stop(); wx.showToast({ icon: "none", - title: "Mac 地址与 deviceId 获取失败,请重新绑定" + title: err.message }) setTimeout(() => { wx.navigateBack({ delta: 2 }) }, 1500) - } + }) } else { app.globalData.ppScale.plugin.Blue.stop(); wx.showToast({ icon: "none", - title: "配网失败,错误码:" + res + title: "Mac 地址与 deviceId 获取失败,请重新绑定" }) setTimeout(() => { wx.navigateBack({ @@ -151,7 +160,18 @@ Component({ }) }, 1500) } - }) + } else { + app.globalData.ppScale.plugin.Blue.stop(); + wx.showToast({ + icon: "none", + title: "配网失败,错误码:" + res + }) + setTimeout(() => { + wx.navigateBack({ + delta: 2 + }) + }, 1500) + } } } }); \ No newline at end of file diff --git a/components/replaceNetwork_3/replaceNetwork_3.js b/components/replaceNetwork_3/replaceNetwork_3.js index 180ce60..52b8979 100644 --- a/components/replaceNetwork_3/replaceNetwork_3.js +++ b/components/replaceNetwork_3/replaceNetwork_3.js @@ -32,42 +32,62 @@ Component({ setNerwork() { let ssid = this.properties.ssid; let password = this.properties.password; - app.globalData.ppScale.activeProtocol.dataConfigNetWork({ - domain: app.globalData.ppScale.domain, - ssid: ssid, - password: password - }, (res) => { - console.log("setNetwork.js dataConfigNetWork", res); + let version = app.globalData.ppScale.version; + if (version === 'domain1') { + app.globalData.ppScale.activeProtocol.dataConfigNetWork({ + domain: app.globalData.ppScale.domain1, + ssid: this.data.selectWifi.ssid, + 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) { - app.globalData.ppScale.wifi.ssid = ssid; - app.globalData.ppScale.wifi.password = password; + netWorkCallBack(res) { + if(res === 23) { + app.globalData.ppScale.wifi.ssid = ssid; + app.globalData.ppScale.wifi.password = password; - let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, ''); - if(scaleDeviceId) { - let params = { - equipmentCode: scaleDeviceId, - wifiName: ssid - }; - $.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(() => { + let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, ''); + if(scaleDeviceId) { + let params = { + equipmentCode: scaleDeviceId, + wifiName: ssid + }; + $.ajax("weighingScale/edit/device", params, "POST").then((res) => { 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) + } } } }); \ No newline at end of file diff --git a/pages/configureDevice/configureDevice.js b/pages/configureDevice/configureDevice.js index 5f3f268..31f03cf 100644 --- a/pages/configureDevice/configureDevice.js +++ b/pages/configureDevice/configureDevice.js @@ -13,109 +13,110 @@ Page({ }, onLoad() { - ppScale.plugin.bus.subscribe("devicesModel", (res) => { - console.log("===》devicesModel", res); - ppScale.device.mac = res.deviceMac; + ppScale.plugin.bus.subscribe("deviceInfo", (res) => { + console.log("===》deviceInfo", res); + ppScale.device.mac = res.serialNumber; + }); - ppScale.plugin.bus.subscribe("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.plugin.bus.subscribe("deviceConnect", (res) => { + console.log('===》deviceConnect', res); - ppScale.activeProtocol.codeSyncTime((codeSyncTime) => { - console.log("===》codeSyncTime", codeSyncTime) + ppScale.plugin.ScaleAction.startDataProgress(true); + ppScale.activeProtocol = ppScale.plugin.ScaleAction.getActiveProtocol(); - wx.hideLoading(); - if (res === 1) { - wx.showModal({ - title: '提示', - content: '当前设备已被绑定,你确定要覆盖绑定吗?', - success: (res) => { - if (res.confirm) { - wx.showLoading({ - title: "正在初始化设备...", - mask: true - }); - ppScale.activeProtocol.codeClearDeviceData("00", (res) => { - console.log("deviceInfo === codeClearDeviceData", res); - wx.hideLoading(); - - if(res === 0) { - let scaleDeviceId = ppScale.device.mac.replace(/:/g, ''); - let params = { - equipmentCode: scaleDeviceId, - }; - $.ajax("weighingScale/del/device", params, "POST", true, "正在初始化设备...").then(res => { - ppScale.plugin.Blue.stop(); - wx.showToast({ - icon: "none", - title: "设备初始化成功,请重新绑定。", - }) - // device.list = []; - // device.mac = null; - setTimeout(() => { - wx.navigateBack({ - delta: 1 - }) - }, 1500); - }); - } else { + ppScale.activeProtocol.codeUpdateMTU((res) => { + console.log("===》codeUpdateMTU", res); + + ppScale.activeProtocol.codeFetchBindingState((res) => { + console.log("===》codeFetchBindingState", res); + + ppScale.activeProtocol.codeSyncTime((codeSyncTime) => { + console.log("===》codeSyncTime", codeSyncTime) + + wx.hideLoading(); + if (res === 1) { + wx.showModal({ + title: '提示', + content: '当前设备已被绑定,你确定要覆盖绑定吗?', + success: (res) => { + if (res.confirm) { + wx.showLoading({ + title: "正在初始化设备...", + mask: true + }); + ppScale.activeProtocol.codeClearDeviceData("00", (res) => { + console.log("deviceInfo === codeClearDeviceData", res); + wx.hideLoading(); + + if(res === 0) { + let scaleDeviceId = ppScale.device.mac.replace(/:/g, ''); + let params = { + equipmentCode: scaleDeviceId, + }; + $.ajax("weighingScale/del/device", params, "POST", true, "正在初始化设备...").then(res => { ppScale.plugin.Blue.stop(); wx.showToast({ icon: "none", - title: "设备初始化失败。", + title: "设备初始化成功,请重新绑定。", }) - } - }) - } else if (res.cancel) { - // device.mac = null; - ppScale.plugin.Blue.stop(); - } + // device.list = []; + // device.mac = null; + setTimeout(() => { + wx.navigateBack({ + 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; - ppScale.device.connection = this.data.device; - if(this.data.progressNext) { - let scaleDeviceId = ppScale.device.mac.replace(/:/g, ''); - let params = { - sn: scaleDeviceId, - }; - $.ajax("weighingScale/getUserInfoBySn", params, "GET", true, "正在同步用户信息...").then(res => { - if(res.result) { - wx.setStorageSync("userInfo", res.result); - this.setProgress(); - } else { - wx.removeStorageSync("userInfo"); - wx.showToast({ - title: "暂无用户信息,请手动补充", - icon: "none" - }) - setTimeout(() => { - this.setProgress(); - }, 1500) - } - }).catch(() => { + } + }) + } else { + ppScale.device.name = this.data.device.name; + ppScale.device.connection = this.data.device; + ppScale.version = this.data.device.name.includes("YX") ? "domain2" : "domain1"; + if(this.data.progressNext) { + let scaleDeviceId = ppScale.device.mac.replace(/:/g, ''); + let params = { + sn: scaleDeviceId, + }; + $.ajax("weighingScale/getUserInfoBySn", params, "GET", true, "正在同步用户信息...").then(res => { + if(res.result) { + wx.setStorageSync("userInfo", res.result); + this.setProgress(); + } else { + wx.removeStorageSync("userInfo"); wx.showToast({ - title: "用户信息同步失败,请手动补充", + title: "暂无用户信息,请手动补充", icon: "none" }) setTimeout(() => { this.setProgress(); }, 1500) + } + }).catch(() => { + wx.showToast({ + title: "用户信息同步失败,请手动补充", + icon: "none" }) - } + setTimeout(() => { + this.setProgress(); + }, 1500) + }) } - }) + } }) - }); + }) }); }); }, diff --git a/pages/deviceInfo/deviceInfo.js b/pages/deviceInfo/deviceInfo.js index 6075a33..4292486 100644 --- a/pages/deviceInfo/deviceInfo.js +++ b/pages/deviceInfo/deviceInfo.js @@ -27,9 +27,8 @@ Page({ }, delDevice() { - let scaleDeviceId = this.data.deviceInfo.macAddress.replace(/:/g, ''); let params = { - equipmentCode: scaleDeviceId, + equipmentCode: this.data.deviceInfo.equipmentCode, }; $.ajax("weighingScale/del/device", params, "POST", true, "正在解绑设备...").then(res_ => { wx.showToast({ diff --git a/pages/replaceNetwork/replaceNetwork.js b/pages/replaceNetwork/replaceNetwork.js index 5d28cce..e74763f 100644 --- a/pages/replaceNetwork/replaceNetwork.js +++ b/pages/replaceNetwork/replaceNetwork.js @@ -36,6 +36,7 @@ Page({ app.globalData.ppScale.device.name = this.data.device.name; app.globalData.ppScale.device.connection = this.data.device; + app.globalData.ppScale.version = this.data.device.name.includes("YX") ? "domain2" : "domain1"; wx.hideLoading(); this.selectComponent('#replaceNetwork1Component').getWiFiList(); diff --git a/project.private.config.json b/project.private.config.json index b8e5312..e629413 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -1,24 +1,24 @@ { - "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", - "projectname": "bodyWeight", - "setting": { - "compileHotReLoad": true, - "urlCheck": false, - "bigPackageSizeSupport": true, - "coverView": true, - "lazyloadPlaceholderEnable": false, - "skylineRenderEnable": false, - "preloadBackgroundData": false, - "autoAudits": false, - "useApiHook": true, - "useApiHostProcess": true, - "showShadowRootInWxmlPanel": true, - "useStaticServer": false, - "useLanDebug": false, - "showES6CompileOption": false, - "checkInvalidKey": true, - "ignoreDevUnusedFiles": true - }, - "libVersion": "3.8.6", - "condition": {} + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "bodyWeight", + "setting": { + "compileHotReLoad": true, + "urlCheck": false, + "bigPackageSizeSupport": true, + "coverView": true, + "lazyloadPlaceholderEnable": false, + "skylineRenderEnable": false, + "preloadBackgroundData": false, + "autoAudits": false, + "useApiHook": true, + "useApiHostProcess": true, + "showShadowRootInWxmlPanel": true, + "useStaticServer": false, + "useLanDebug": false, + "showES6CompileOption": false, + "checkInvalidKey": true, + "ignoreDevUnusedFiles": true + }, + "libVersion": "3.11.3", + "condition": {} } \ No newline at end of file