diff --git a/app.js b/app.js index 09a6e9c..726024e 100644 --- a/app.js +++ b/app.js @@ -41,10 +41,5 @@ App({ wx.hideLoading(); }); - - plugin.bus.subscribe("devicesModel", (res) => { - console.log('app.js devicesModel', res); - this.globalData.ppScale.device.mac = res.deviceMac; - }); }, }) \ No newline at end of file diff --git a/pages/searchDevice/searchDevice.js b/pages/searchDevice/searchDevice.js index 0f3e5a9..00c08d3 100644 --- a/pages/searchDevice/searchDevice.js +++ b/pages/searchDevice/searchDevice.js @@ -110,6 +110,7 @@ Page({ // }, getDeviceSettingList() { + // app.globalData.ppScale.plugin.Blue.visibleLog(true); this.setData({ initText: "设备搜索中..." }); @@ -168,6 +169,11 @@ Page({ }); this.selectDevice(); }); + + app.globalData.ppScale.plugin.bus.subscribe("devicesModel", (res) => { + console.log("searchDevice ===》devicesModel", res); + app.globalData.ppScale.device.mac = res.deviceMac; + }); }, selectDevice() { diff --git a/pages/setNetwork/setNetwork.js b/pages/setNetwork/setNetwork.js index 8c79b80..cfead89 100644 --- a/pages/setNetwork/setNetwork.js +++ b/pages/setNetwork/setNetwork.js @@ -13,30 +13,43 @@ Page({ app.globalData.ppScale.wifi.ssid = ssid; app.globalData.ppScale.wifi.password = password; - let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, ''); - let params = { - equipmentName: app.globalData.ppScale.device.name, - scaleDeviceId: scaleDeviceId, - }; - $.ajax("weighingScale/binding/device", params, "POST").then(res => { - app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => { - console.log("setNetwork.js codeSetBindingState", res); - - wx.navigateTo({ - url: "/pages/setNetworkSuccessful/setNetworkSuccessful" + let mac = app.globalData.ppScale.device.mac; + if(mac) { + let scaleDeviceId = mac.replace(/:/g, ''); + let params = { + equipmentName: app.globalData.ppScale.device.name, + scaleDeviceId: scaleDeviceId, + }; + $.ajax("weighingScale/binding/device", params, "POST").then(res => { + app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => { + console.log("setNetwork.js codeSetBindingState", res); + + wx.navigateTo({ + url: "/pages/setNetworkSuccessful/setNetworkSuccessful" + }) }) + }).catch(err => { + wx.showToast({ + icon: "none", + title: err.message + }) + setTimeout(() => { + wx.switchTab({ + url: "/pages/home/home" + }) + }, 1500) }) - }).catch(err => { + } else { wx.showToast({ icon: "none", - title: err.message + title: "Mac 地址获取失败,请重新绑定" }) setTimeout(() => { wx.switchTab({ url: "/pages/home/home" }) }, 1500) - }) + } }) } }) \ No newline at end of file