83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
const app = getApp();
|
|
import $ from "../../utils/request";
|
|
|
|
Page({
|
|
onLoad(options) {
|
|
let ssid = options.ssid;
|
|
let password = options.password;
|
|
app.globalData.ppScale.activeProtocol.dataConfigNetWork({
|
|
domain: app.globalData.ppScale.domain,
|
|
ssid: options.ssid,
|
|
password: options.password
|
|
}, (res) => {
|
|
console.log("setNetwork.js dataConfigNetWork", res);
|
|
|
|
if(res === 23) {
|
|
app.globalData.ppScale.wifi.ssid = ssid;
|
|
app.globalData.ppScale.wifi.password = password;
|
|
|
|
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);
|
|
|
|
wx.navigateTo({
|
|
url: "/pages/setNetworkSuccessful/setNetworkSuccessful"
|
|
})
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: res.message
|
|
})
|
|
setTimeout(() => {
|
|
wx.switchTab({
|
|
url: "/pages/home/home"
|
|
})
|
|
}, 1500)
|
|
}
|
|
}).catch(err => {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: err.message
|
|
})
|
|
setTimeout(() => {
|
|
wx.switchTab({
|
|
url: "/pages/home/home"
|
|
})
|
|
}, 1500)
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: "Mac 地址与 deviceId 获取失败,请重新绑定"
|
|
})
|
|
setTimeout(() => {
|
|
wx.switchTab({
|
|
url: "/pages/home/home"
|
|
})
|
|
}, 1500)
|
|
}
|
|
} else {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: "配网失败,错误码:" + res
|
|
})
|
|
setTimeout(() => {
|
|
wx.switchTab({
|
|
url: "/pages/home/home"
|
|
})
|
|
}, 1500)
|
|
}
|
|
})
|
|
}
|
|
}) |