131 lines
5.1 KiB
JavaScript
131 lines
5.1 KiB
JavaScript
const app = getApp();
|
|
|
|
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;
|
|
app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
|
domain: app.globalData.ppScale.domain,
|
|
ssid: ssid,
|
|
password: password
|
|
}, (res) => {
|
|
console.log("setNetwork.js dataConfigNetWork", res);
|
|
|
|
if(res === 23) {
|
|
app.globalData.ppScale.wifi.ssid = ssid;
|
|
app.globalData.ppScale.wifi.password = password;
|
|
|
|
this.triggerEvent('wifiEvent', {
|
|
status: true
|
|
});
|
|
|
|
// 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.disconnect();
|
|
// wx.showToast({
|
|
// title: "绑定失败,请重试。",
|
|
// icon: "none"
|
|
// })
|
|
// setTimeout(() => {
|
|
// wx.navigateBack({
|
|
// delta: 2
|
|
// })
|
|
// }, 1500)
|
|
// }
|
|
// })
|
|
// } else {
|
|
// app.globalData.ppScale.plugin.Blue.disconnect();
|
|
// wx.showToast({
|
|
// icon: "none",
|
|
// title: res.message
|
|
// })
|
|
// setTimeout(() => {
|
|
// wx.navigateBack({
|
|
// delta: 2
|
|
// })
|
|
// }, 1500)
|
|
// }
|
|
// }).catch(err => {
|
|
// app.globalData.ppScale.plugin.Blue.disconnect();
|
|
// wx.showToast({
|
|
// icon: "none",
|
|
// title: err.message
|
|
// })
|
|
// setTimeout(() => {
|
|
// wx.navigateBack({
|
|
// delta: 2
|
|
// })
|
|
// }, 1500)
|
|
// })
|
|
// } else {
|
|
// app.globalData.ppScale.plugin.Blue.disconnect();
|
|
// wx.showToast({
|
|
// icon: "none",
|
|
// title: "Mac 地址与 deviceId 获取失败,请重新绑定"
|
|
// })
|
|
// setTimeout(() => {
|
|
// wx.navigateBack({
|
|
// delta: 2
|
|
// })
|
|
// }, 1500)
|
|
// }
|
|
} else {
|
|
app.globalData.ppScale.plugin.Blue.disconnect();
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: "配网失败,错误码:" + res
|
|
})
|
|
setTimeout(() => {
|
|
this.triggerEvent('wifiEvent', {
|
|
status: false
|
|
});
|
|
}, 1500)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}); |