diff --git a/app.js b/app.js index ded7944..11e0b89 100644 --- a/app.js +++ b/app.js @@ -153,7 +153,12 @@ App({ this.reconnectDevice() } wx.hideLoading(); - }); + }); + + // 同步时间 + this.globalData.ppScale.plugin.bus.subscribe("syncDeviceTimeSuccess", (res) => { + console.log("app.js ===> syncDeviceTimeSuccess", res); + }) // 设备自动断开监听 this.globalData.ppScale.plugin.bus.subscribe("deviceWillDisconnect", (res) => { diff --git a/pages/configureDevice/configureDevice.js b/pages/configureDevice/configureDevice.js index ed944b8..5f3f268 100644 --- a/pages/configureDevice/configureDevice.js +++ b/pages/configureDevice/configureDevice.js @@ -14,102 +14,106 @@ Page({ onLoad() { ppScale.plugin.bus.subscribe("devicesModel", (res) => { - console.log("searchDevice ===》devicesModel", res); + console.log("===》devicesModel", res); ppScale.device.mac = res.deviceMac; ppScale.plugin.bus.subscribe("deviceConnect", (res) => { - console.log('connectedDevice ===》deviceConnect', res); + console.log('===》deviceConnect', res); ppScale.plugin.ScaleAction.startDataProgress(true); ppScale.activeProtocol = ppScale.plugin.ScaleAction.getActiveProtocol(); ppScale.activeProtocol.codeUpdateMTU((res) => { - console.log("connectedDevice ===》codeUpdateMTU", res); + console.log("===》codeUpdateMTU", res); ppScale.activeProtocol.codeFetchBindingState((res) => { - console.log("connectedDevice ===》codeFetchBindingState", res); - - 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 => { + 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: "设备初始化成功,请重新绑定。", + }) + // device.list = []; + // device.mac = null; + setTimeout(() => { + wx.navigateBack({ + delta: 1 + }) + }, 1500); + }); + } else { ppScale.plugin.Blue.stop(); wx.showToast({ icon: "none", - title: "设备初始化成功,请重新绑定。", + title: "设备初始化失败。", }) - // 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 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"); + }) + } 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(() => { wx.showToast({ - title: "暂无用户信息,请手动补充", + title: "用户信息同步失败,请手动补充", icon: "none" }) setTimeout(() => { this.setProgress(); }, 1500) - } - }).catch(() => { - wx.showToast({ - title: "用户信息同步失败,请手动补充", - icon: "none" }) - setTimeout(() => { - this.setProgress(); - }, 1500) - }) + } } - } + }) }) }); }); diff --git a/pages/searchDevice/searchDevice.js b/pages/searchDevice/searchDevice.js index 6a54843..b6e7d0e 100644 --- a/pages/searchDevice/searchDevice.js +++ b/pages/searchDevice/searchDevice.js @@ -218,7 +218,7 @@ Page({ let deviceNames = seviceList.map(item => item.deviceName); app.globalData.ppScale.plugin.Blue.start(deviceNames, false); app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => { - console.log("searchDevice ===> devicesList", res); + // console.log("searchDevice ===> devicesList", res); this.setData({ devicesList: res });