[AI Generated]: refactor(*): 重构蓝牙生命周期管理,修复最小化后重连与进度跳步问题

- 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>
This commit is contained in:
17792275749
2026-03-09 17:34:08 +08:00
co-authored by Claude Opus 4.6
parent 6924a1ff5b
commit 81f9301c64
12 changed files with 487 additions and 192 deletions
@@ -88,8 +88,9 @@ Component({
// 组件的方法
methods: {
// 二次连接设备
// 手动重连设备
connectedDevice() {
app.resetReconnectCount();
this.triggerEvent('connectedDeviceEvent', {
device: this.data.device
});
@@ -154,7 +155,7 @@ Component({
// console.log("deviceInfo === codeClearDeviceData", res);
// })
if(this.data.connectState == this.data.BLUE_STATE.CONNECTSUCCESS) {
if(this.data.connectState == this.data.BLUE_STATE.CONNECTSUCCESS || this.data.connectState == this.data.BLUE_STATE.WIFISUCCESS) {
if(this.data.userId) {
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: this.data.userId,
@@ -5,14 +5,30 @@
<view>型号:{{device.name}}</view>
</view>
<view>
<block wx:if="{{device && connectState == BLUE_STATE.CONNECTSUCCESS}}">
<block wx:if="{{connectState == BLUE_STATE.CONNECTSUCCESS || connectState == BLUE_STATE.WIFISUCCESS}}">
<view style="background-color: #2AC79F;"></view>
<view style="color: #2AC79F;">连接成功</view>
</block>
<block wx:else>
<block wx:elif="{{connectState == BLUE_STATE.SCANING}}">
<view style="background-color: #3194FB;"></view>
<view style="color: #3194FB;">正在搜索...</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.READY}}">
<view style="background-color: #3194FB;"></view>
<view style="color: #3194FB;">蓝牙就绪</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.UNAVAILABLE}}">
<view style="background-color: #F24439;"></view>
<view style="color: #F24439;">蓝牙不可用</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.CONNECTFAILED}}">
<view style="background-color: #F24439;"></view>
<view bind:tap="connectedDevice" style="color: #F24439;">连接失败,点击重试</view>
</block>
<block wx:else>
<view style="background-color: #999999;"></view>
<view style="color: #999999;">未连接</view>
</block>
</view>
</view>
<view class="section">
@@ -37,6 +37,17 @@ Component({
})
},
// 最小化后重连,重置所有状态并重新获取 WiFi 列表
reInitWifi() {
this.setData({
progress: 0,
wifiList: [],
selectWifi: null,
selectWifiPWD: ""
});
this.initWifi();
},
selectDevice(e) {
this.setData({
progress: 1,
@@ -36,11 +36,11 @@ Component({
if (version === 'domain1') {
app.globalData.ppScale.activeProtocol.dataConfigNetWork({
domain: app.globalData.ppScale.domain1,
ssid: this.data.selectWifi.ssid,
password: this.data.selectWifiPWD
ssid: ssid,
password: password
}, (res) => {
console.log("setNetwork.js dataConfigNetWork 1", res);
this.netWorkCallBack(res);
})
}
@@ -53,7 +53,7 @@ Component({
userPassword: "3acebb95eb49577e9c2a2082589b9bd6"
}, (res) => {
console.log("setNetwork.js dataConfigUserNetWork 2", res);
this.netWorkCallBack(res);
})
}
@@ -61,14 +61,14 @@ Component({
netWorkCallBack(res) {
if(res === 23) {
app.globalData.ppScale.wifi.ssid = ssid;
app.globalData.ppScale.wifi.password = password;
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: ssid
wifiName: this.properties.ssid
};
$.ajax("weighingScale/edit/device", params, "POST").then((res) => {
this.triggerEvent('wifiEvent', {