- app.js: 提取 registerBusListeners 方法,新增自动重连机制(3次上限) - configureDevice: bus 订阅迁移至 onShow,deviceConnect 按步骤区分处理逻辑 - configureDevice_2: setUserInfo 兼容 WIFISUCCESS 状态,WXML 覆盖六态 - configureDevice_3: 新增 reInitWifi 方法,最小化后重置 WiFi 列表 - replaceNetwork: 订阅迁移至 onShow,修复 selectComponent 空指针 - replaceNetwork_3: 修复 domain1 配网参数引用错误 - userInfo: 订阅迁移至 onShow,setUserInfo 兼容 WIFISUCCESS - searchDevice: 移除 onLoad 重复初始化,统一由 onShow 处理 - 所有 BLE 页面统一 onHide/onUnload 清理:resetReconnectCount + setGlobalData(null) + stop() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
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)
|
|
}
|
|
}
|
|
}
|
|
}); |