瀏覽代碼

feature: 连接展示加载中,加载处理

Damon 7 月之前
父節點
當前提交
06a55b5660

+ 5 - 1
pages/connectBle/connectBle.js

@@ -56,9 +56,13 @@ Page({
   async connectToDvice() {
   async connectToDvice() {
     var that = this;
     var that = this;
     ///断开蓝牙连接
     ///断开蓝牙连接
-    await BtHelper.getInstance().disconnect();
+    wx.showLoading({
+      title: '请稍后'
+    });
+    await getCurrentPages()[0].cancelCurrent();
     BtHelper.getInstance().connect(that.data.connectDevice, function (data) {
     BtHelper.getInstance().connect(that.data.connectDevice, function (data) {
       console.log("连接成功:", data)
       console.log("连接成功:", data)
+      wx.hideLoading();
       that.setStatus(data ? 3 : 4)
       that.setStatus(data ? 3 : 4)
       if (data) {
       if (data) {
         that.data.connectDevice.connectType = 1;
         that.data.connectDevice.connectType = 1;

+ 4 - 3
pages/deviceConnect2/deviceConnect2.js

@@ -62,7 +62,6 @@ Page({
             });
             });
           }
           }
         }
         }
-
         break;
         break;
 
 
       case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
       case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
@@ -132,13 +131,13 @@ Page({
       'isStart': true,
       'isStart': true,
     });
     });
   },
   },
-  Connect: function (e) {
+
+  async Connect: function (e) {
     // if(!this.data.islanya) {
     // if(!this.data.islanya) {
     //   return;
     //   return;
     // };
     // };
 
 
     // [{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24","RSSI":-51,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fcbb24","serviceData":{}}]
     // [{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24","RSSI":-51,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fcbb24","serviceData":{}}]
-
     const deviceIdData = this.data.devicesList;
     const deviceIdData = this.data.devicesList;
     if (deviceIdData.length < 1) {
     if (deviceIdData.length < 1) {
       wx.showToast({
       wx.showToast({
@@ -155,6 +154,8 @@ Page({
     this.setData({
     this.setData({
       isSubmit: true
       isSubmit: true
     });
     });
+
+    await getCurrentPages()[0].cancelCurrent();
     // 停止搜索
     // 停止搜索
     xBlufi.notifyStartDiscoverBle({
     xBlufi.notifyStartDiscoverBle({
       'isStart': false,
       'isStart': false,

+ 2 - 2
pages/deviceConnect3/deviceConnect3.js

@@ -29,9 +29,9 @@ Page({
     percent: 0,
     percent: 0,
     ruterStatus: 0, // 0 连接中 // 1 成功 // 2失败
     ruterStatus: 0, // 0 连接中 // 1 成功 // 2失败
   },
   },
-  onShow: function (options) {
 
 
-  },
+  onShow: function (options) {},
+
   onLoad: function (options) {
   onLoad: function (options) {
     _this = this;
     _this = this;
     _this.setData({
     _this.setData({

+ 24 - 6
pages/index/index.js

@@ -678,6 +678,7 @@ Page({
     if (item.connectType != "1") {
     if (item.connectType != "1") {
       return
       return
     }
     }
+
     ///去蓝牙连接处理
     ///去蓝牙连接处理
     if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
     if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
       // 蓝牙才能连接
       // 蓝牙才能连接
@@ -752,24 +753,41 @@ Page({
       title: '确定删除?',
       title: '确定删除?',
       success: function (res) {
       success: function (res) {
         if (res.confirm) {
         if (res.confirm) {
-          if (that.data.deviceList[index].connectType != 3) {
-            that.cancelBlue(index);
-          } else {
+          if (that.data.deviceList[index].connectType == 3) {
             that.cancelWifi(index);
             that.cancelWifi(index);
+          } else {
+            that.cancelBlue(index);
           }
           }
         }
         }
       }
       }
     });
     });
   },
   },
 
 
+  ///断开当前的
+  async cancelCurrent() {
+    var that = this;
+    var deviceListIndex = that.data.deviceListIndex;
+    if (deviceListIndex == null) {
+      return;
+    }
+    var deviceList = that.data.deviceList;
+    if (deviceList.length > deviceListIndex) {
+      if (deviceList[deviceListIndex].connectType == 3) {
+        await that.cancelWifi(deviceListIndex);
+      } else {
+        await that.cancelBlue(deviceListIndex);
+      }
+    }
+  },
+
   /// 断开蓝牙连接
   /// 断开蓝牙连接
-  cancelBlue(index) {
+  async cancelBlue(index) {
     const id = that.data.deviceList[index].deviceId;
     const id = that.data.deviceList[index].deviceId;
     const deviceList = that.data.deviceList.filter((item, i) => {
     const deviceList = that.data.deviceList.filter((item, i) => {
       return id !== item.deviceId
       return id !== item.deviceId
     });
     });
 
 
-    BtHelper.getInstance().disconnect();
+    await BtHelper.getInstance().disconnect();
     wx.setStorageSync("deviceList", JSON.stringify(deviceList));
     wx.setStorageSync("deviceList", JSON.stringify(deviceList));
     that.setData({
     that.setData({
       deviceList,
       deviceList,
@@ -784,7 +802,7 @@ Page({
   },
   },
 
 
   /// 断开连接wifi
   /// 断开连接wifi
-  cancelWifi(index) {
+  async cancelWifi(index) {
     const id = that.data.deviceList[index].deviceId;
     const id = that.data.deviceList[index].deviceId;
     let name = that.data.deviceListIndex !== null ? that.data.deviceList[that.data.deviceListIndex].name : null;
     let name = that.data.deviceListIndex !== null ? that.data.deviceList[that.data.deviceListIndex].name : null;