Browse Source

feature: 处理wifi连接细节,增加交互流畅性

Damon 7 months atrás
parent
commit
9e737d8c45

+ 21 - 22
pages/deviceConnect3/deviceConnect3.js

@@ -63,7 +63,6 @@ Page({
       // {"type":"2","result":true,"data":{"deviceId":"7C:DF:A1:FD:3A:F2","serviceId":"0000FFFF-0000-1000-8000-00805F9B34FB",
       // "characteristicId":"0000FF01-0000-1000-8000-00805F9B34FB"}}
       case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
-        wx.hideLoading();
         if (options.result) {
           console.log('初始化成功');
           that.OnClickStart();
@@ -82,8 +81,7 @@ Page({
         // {"type":"4","result":true,"data":{"progress":100,"ssid":"muzen\u0000"}}
         ///连接结果
       case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
-        wx.hideLoading();
-        if (!options.result)
+        if (!options.result) {
           errTi = setTimeout(() => {
             that.setData({
               ruterStatus: 2
@@ -91,27 +89,9 @@ Page({
             clearTimeout(errTi);
             clearInterval(percentIn);
           }, 5000);
-        else {
+        } else {
           // 配网成功
           if (options.data.progress == 100) {
-            clearTimeout(errTi);
-            clearInterval(percentIn);
-            // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
-
-            that.setData({
-              percent: 100,
-              ruterStatus: 1,
-            });
-
-            // 记住密码
-            wx.setStorage({
-              key: "wifiInfo",
-              data: JSON.stringify({
-                "password": app.globalData.pwdData,
-                "ssid": app.globalData.ssid
-              }),
-            });
-
             var deviceId = that.data.name;
             var device = {
               connectType: 3,
@@ -123,6 +103,25 @@ Page({
               imageUrl: "./../../img/min.png",
             }
             getCurrentPages()[0].addWifiDevice(device);
+            // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
+            // 记住密码
+            wx.setStorage({
+              key: "wifiInfo",
+              data: JSON.stringify({
+                "password": app.globalData.pwdData,
+                "ssid": app.globalData.ssid
+              }),
+            });
+
+            setTimeout(() => {
+              clearTimeout(errTi);
+              clearInterval(percentIn);
+              that.setData({
+                percent: 100,
+                ruterStatus: 1,
+              });
+            }, 500);
+
           }
         }
         break;

+ 43 - 12
pages/index/index.js

@@ -457,17 +457,36 @@ Page({
     }
 
     var deviceList = that.getDeviceList();
-    var deviceId = deviceList[index].deviceId;
+    var deviceListSelect = that.getDeviceListSelect();
+    if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
+      return;
+    };
+
+    ///是否删除的当前播放这个
+    var isCurrentIndex = false;
+    var deviceListSelect = that.getDeviceListSelect();
+    if (deviceListSelect != null && deviceList.length > deviceListSelect) {
+      isCurrentIndex = (deviceListSelect == index);
+    };
+
     ///删除当前设备
+    var deviceId = deviceList[index].deviceId;
     deviceList = deviceList.filter((item, i) => {
       return deviceId !== item.deviceId;
     });
 
     store.setStore("deviceList", deviceList);
-    that.setData({
-      deviceListSelect: null,
-      deviceList: deviceList,
-    });
+    if (isCurrentIndex) {
+      that.setData({
+        deviceListSelect: null,
+        deviceList: deviceList,
+      });
+    } else {
+      that.setData({
+        deviceList: deviceList,
+      });
+    }
+
   },
 
   /// 断开连接wifi
@@ -486,17 +505,30 @@ Page({
       return;
     }
 
+    ///是否删除的当前播放这个
+    var isCurrentIndex = false;
+    var deviceListSelect = that.getDeviceListSelect();
+    if (deviceListSelect != null && deviceList.length > deviceListSelect) {
+      isCurrentIndex = (deviceListSelect == index);
+    };
+
     deviceList = deviceList.filter((item, i) => {
       return deviceId !== item.deviceId;
     });
 
     store.setStore("deviceList", deviceList);
-    that.setData({
-      deviceList: deviceList,
-      deviceMacId: null,
-      actionIndex: null,
-      deviceListSelect: null,
-    });
+    if (isCurrentIndex) {
+      that.setData({
+        deviceList: deviceList,
+        deviceMacId: null,
+        actionIndex: null,
+        deviceListSelect: null,
+      });
+    } else {
+      that.setData({
+        deviceList: deviceList,
+      });
+    }
   },
 
   /// 新添加蓝牙设备
@@ -526,7 +558,6 @@ Page({
     var deviceId = device.deviceId;
     var addDeviceList = lexin_add.addWifiDevice(device);
     that.updateDeviceList(addDeviceList, false, false);
-
     that.setData({
       deviceListSelect: null,
       connectDeviceIding: deviceId,

+ 2 - 1
utils/lexin/connect.js

@@ -27,7 +27,8 @@ function searchOnlineDevice(payloads, changeCallback, resetCallback) {
           var mac = lexin_util.getMacByDeviceId(deviceId);
           var index = payloads.uuid.indexOf(mac);
           if (index !== -1) {
-            if (device.state != payloads.state) {
+            var connectDeviceIding = pages[0].getConnectDeviceIding();
+            if (connectDeviceIding != device.deviceId && device.state != payloads.state) {
               isChanged = true;
               device.state = payloads.state;
             }

+ 3 - 0
utils/lexin/message.js

@@ -30,6 +30,7 @@ function getDeviceInfo(payloads) {
   var other = payloads.other;
   var SrcDeviceName = payloads.SrcDeviceName;
 
+  console.log("gasdfqwerqwerqr==333==");
   ///连上就调用2次 payloads.SrcDeviceName:AIrSMArT_7cdfa1fcbb24
   const app = getApp();
   const strings = require('../strings');
@@ -79,11 +80,13 @@ function getDeviceInfo(payloads) {
     }
 
     /// 去更新选中目标
+    console.log("gasdfqwerqwerqr==444==" + currentDeviceId);
     if (!strings.isEmpty(currentDeviceId)) {
       for (var i = 0; i < deviceList.length; i++) {
         var device = deviceList[i];
         var deviceId = device.deviceId;
         if (deviceId == currentDeviceId) {
+          console.log("gasdfqwerqwerqr==555==" + JSON.stringify(device));
           pages[0].refreshCurrentDevice(device);
           break;
         }

+ 9 - 21
utils/lexin/subscribe.js

@@ -8,10 +8,10 @@ function subscribeSingleDevice(device) {
   //  /AIrSMArT_210052355545/status/onoffline 魅族款 APP
   // /AIrSMArT_861210052355545/status/onoffline 魅族款 小程序
   var deviceId = device.deviceId;
+  var pages = getCurrentPages();
   const strings = require('../strings');
   var deviceList = pages[0].getDeviceList();
-
-  var isOnline = false;
+  // 猫王XOG-CyberRadio: BLUFI_864423060242830
   if (!strings.isEmpty(deviceList)) {
     var deviceListSelect = pages[0].getDeviceListSelect();
     ///当前已连接
@@ -21,27 +21,15 @@ function subscribeSingleDevice(device) {
         return;
       }
     }
-
-    for (var i = 0; i < deviceList.length; i++) {
-      var tempDevice = deviceList[i];
-      if (deviceId == tempDevice.deviceId && tempDevice.state == "online") {
-        isOnline = true;
-        break;
-      }
-    }
   }
-
   ///在线处理
-  if (isOnline) {
-    var pages = getCurrentPages();
-    pages[0].actionDevice(tempDevice);
-  } else {
-    const lexin_util = require('../lexin/util');
-    var mac = lexin_util.getMacByDeviceId(deviceId);
-    var topic = `/AIrSMArT_${mac}/status/onoffline`;
-    const app = getApp();
-    app.subscribe(topic);
-  }
+  pages[0].actionDevice(device);
+
+  // const lexin_util = require('../lexin/util');
+  // var mac = lexin_util.getMacByDeviceId(deviceId);
+  // var topic = `/AIrSMArT_${mac}/status/onoffline`;
+  // const app = getApp();
+  // app.subscribe(topic);
 };
 
 // 订阅在线设备