const app = getApp(); import $ from "../../utils/request"; Component({ properties: { ssid: { type: String, value: "" }, password: { type: String, value: "" } }, data: { }, // 生命周期方法 lifetimes: { attached() { this.setNerwork(); }, detached() { } }, // 组件的方法 methods: { setNerwork() { let ssid = this.properties.ssid; let password = this.properties.password; let version = app.globalData.ppScale.version; if (version === 'domain1') { app.globalData.ppScale.activeProtocol.dataConfigNetWork({ domain: app.globalData.ppScale.domain1, ssid: ssid, password: password }, (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); }); } }, netWorkCallBack(res) { if(res === 23) { app.globalData.ppScale.wifi.ssid = this.properties.ssid; app.globalData.ppScale.wifi.password = this.properties.password; let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, ''); if(scaleDeviceId) { let params = { equipmentCode: scaleDeviceId, wifiName: this.properties.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(() => { this.triggerEvent('wifiEvent', { status: false }); }, 1500) } } } });