From 472eeaad3e5081f196a157ad75df5925d57a1044 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Thu, 29 May 2025 14:43:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2wifi=E6=B7=BB=E5=8A=A0loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../replaceNetwork_1/replaceNetwork_1.js | 5 ++ pages/replaceNetwork/replaceNetwork.js | 54 ++++++++++--------- pages/userInfo/userInfo.js | 19 +++++-- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/components/replaceNetwork_1/replaceNetwork_1.js b/components/replaceNetwork_1/replaceNetwork_1.js index c95e9d1..f6550d1 100644 --- a/components/replaceNetwork_1/replaceNetwork_1.js +++ b/components/replaceNetwork_1/replaceNetwork_1.js @@ -18,9 +18,14 @@ Component({ // 组件的方法 methods: { getWiFiList() { + wx.showLoading({ + title: "正在获取Wi-Fi列表...", + mask: true + }); app.globalData.ppScale.activeProtocol.dataFindSurroundDevice((res) => { console.log("connectedDevice ===》dataFindSurroundDevice", res); + wx.hideLoading(); this.setData({ wifiList: res }) diff --git a/pages/replaceNetwork/replaceNetwork.js b/pages/replaceNetwork/replaceNetwork.js index 5b7afb2..fc56120 100644 --- a/pages/replaceNetwork/replaceNetwork.js +++ b/pages/replaceNetwork/replaceNetwork.js @@ -21,7 +21,6 @@ Page({ onLoad(options) { this.checkBluetoothPermissionAndInit(); - app.globalData.ppScale.plugin.bus.subscribe("devicesModel", (res) => { console.log("searchDevice ===》devicesModel", res); app.globalData.ppScale.device.mac = res.deviceMac; @@ -35,9 +34,10 @@ Page({ app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => { console.log("connectedDevice ===》codeUpdateMTU", res); - app.globalData.ppScale.device.name = this.data.device.name; app.globalData.ppScale.device.connection = this.data.device; + + wx.hideLoading(); this.selectComponent('#replaceNetwork1Component').getWiFiList(); }); }); @@ -58,23 +58,24 @@ Page({ }, checkBluetoothPermissionAndInit() { - this.setData({ - initText: "正在检查蓝牙权限..." + wx.showLoading({ + title: "正在检查蓝牙权限...", + mask: true }); wx.getSetting({ success: (res) => { if (res.authSetting['scope.bluetooth']) { + wx.hideLoading(); this.openBluetoothAdapter(); } else { wx.authorize({ scope: 'scope.bluetooth', success: () => { + wx.hideLoading(); this.openBluetoothAdapter(); }, fail: (err) => { - this.setData({ - initText: "蓝牙权限被拒绝。" - }); + wx.hideLoading(); wx.showModal({ title: '提示', content: '您拒绝了蓝牙权限,将无法连接蓝牙秤。是否前往设置开启?', @@ -104,35 +105,32 @@ Page({ } }, fail: (err) => { - this.setData({ - initText: "获取权限设置失败。" - }); + wx.hideLoading(); wx.showToast({ title: '获取权限设置失败', icon: 'none' }); - wx.navigateBack({ - delta: 1 - }); + setTimeout(() => { + wx.navigateBack({ + delta: 1 + }); + }, 1500) } }); }, openBluetoothAdapter() { - this.setData({ - initText: "正在初始化蓝牙..." + wx.showLoading({ + title: "正在初始化蓝牙...", + mask: true }); wx.openBluetoothAdapter({ success: () => { - this.setData({ - initText: "蓝牙初始化成功" - }); + wx.hideLoading(); this.getDeviceSettingList(); }, fail: (err) => { - this.setData({ - initText: "蓝牙初始化失败。" - }); + wx.hideLoading(); if (err.errCode === 10001) { wx.showModal({ title: "提示", @@ -174,9 +172,11 @@ Page({ getDeviceSettingList() { let params = {}; $.ajax("weighingScale/list/device", params, "GET", true, "获取设备列表").then((res) => { - this.setData({ - initText: "设备搜索中..." - }) + wx.showLoading({ + title: "正在寻找设备...", + mask: true + }); + app.globalData.ppScale.device.list = []; let seviceList = app.globalData.ppScale.device.setting.find((item) => { return item.deviceName === res.result[0].type @@ -189,6 +189,11 @@ Page({ let fIndex = res_.findIndex(item => item.deviceId === res.result[0].deviceId); if (fIndex >= 0) { app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery(); + wx.hideLoading(); + wx.showLoading({ + title: "正在连接设备...", + mask: true + }); this.setData({ device: res_[fIndex] }) @@ -243,6 +248,7 @@ Page({ // 卸载事件监听 onUnload() { + app.globalData.ppScale.plugin.Blue.disconnect(); if (this._connectStateWatcher) { app.unwatch('ppScale.device.connectState', this._connectStateWatcher); } diff --git a/pages/userInfo/userInfo.js b/pages/userInfo/userInfo.js index af8bcf4..ab4b547 100644 --- a/pages/userInfo/userInfo.js +++ b/pages/userInfo/userInfo.js @@ -55,7 +55,8 @@ Page({ app.globalData.ppScale.device.name = this.data.device.name; app.globalData.ppScale.device.connection = this.data.device; - this.selectComponent('#replaceNetwork1Component').getWiFiList(); + + wx.hideLoading(); }); }); }); @@ -229,9 +230,15 @@ Page({ recentData: [], }, (res) => { if(res == 0) { - this.triggerEvent('deviceEvent', { - status: true - }); + wx.showToast({ + title: "用户信息更新成功。", + icon: "none" + }) + setTimeout(() => { + wx.navigateBack({ + delta: 1 + }) + }, 1500) } else { console.log("dataSyncUserInfo", res) wx.showToast({ @@ -410,6 +417,10 @@ Page({ // 点击设备重连 connectedDevice() { + wx.showLoading({ + title: "正在重新连接设备...", + mask: true + }); let device = this.data.device; if(device) { app.globalData.ppScale.plugin.Blue.createBLEConnection(device);