Quellcode durchsuchen

feature:修改黑胶设备的掉线监听问题

zeng.chen vor 5 Monaten
Ursprung
Commit
73cba7f7b9
2 geänderte Dateien mit 31 neuen und 29 gelöschten Zeilen
  1. 28 10
      pages/index/index.js
  2. 3 19
      pages/piano/cropper/cropper.js

+ 28 - 10
pages/index/index.js

@@ -80,6 +80,7 @@ Page({
     deviceListSelect: null,
     deviceList: [],
     _willConnectBle: null,
+    _hasShowModal: null,
     // deviceList: [{
     //   "connectType": 3,
     //   "devName": "猫王小王子OTR-X",
@@ -836,7 +837,27 @@ Page({
 
     that.addNotification()
   },
-
+  disconnectDev(event, device) {
+    let _this = this;
+    console.log("断开连接--", event.commonValue, event.deviceId);
+    if (event.deviceId === device.deviceId && event.commonValue === "offline" && !_this.data._hasShowModal) {
+      _this.data._hasShowModal = true
+      wx.showModal({
+        title: '提示',
+        content: '设备断开连接,请重新连接设备',
+        showCancel: false,
+        success: function (res) {
+          _this.data._hasShowModal = false;
+          if (res.confirm) {
+            if (getCurrentPages()[getCurrentPages().length - 1].disconnectDevCallback) {
+              getCurrentPages()[getCurrentPages().length - 1].disconnectDevCallback();
+            }
+          }
+        }
+      })
+    }
+    // 设备断开连接,请重新连接设备
+  },
   addNotification() {
     let that = this;
     event_bus.removeNotification(CmdEvent.eventName, that);
@@ -858,10 +879,11 @@ Page({
           console.log("有蓝牙设备上线")
           that.stopIntervalId1();
         } else {
-          let disDevice = deviceList.find(item => {
-            return item.state == "online" && item.connectType === 3
+          let onLineBle = deviceList.find(item => {
+            return item.state == "online" && item.connectType === 1
           })
-          if (!disDevice) {
+          if (!onLineBle) {
+            // 没有在线的蓝牙
             that.startBleTimer(isFirst);
           }
         }
@@ -875,17 +897,13 @@ Page({
         //   }
         // });
         if (!disDevice) {
-          console.log("没有在线的")
+          console.log("没有找到在线的对应的蓝牙设备")
           return;
         }
+        that.disconnectDev(event, disDevice)
         disDevice.state = event.commonValue;
         console.log("首页设备状态变化", disDevice.state, disDevice.deviceId)
 
-        let hasOnline = deviceList.find(item => {
-          return item.state == "online" && item.connectType == 1
-        })
-        console.log("发现有在线的", hasOnline)
-
         if (event.commonValue == "online") {
           // BtHelper.getInstance().connect()
           console.log("首页上线连接", disDevice)

+ 3 - 19
pages/piano/cropper/cropper.js

@@ -530,24 +530,9 @@ Page({
     });
     that.data._imgTopPic = image.pic
   },
-  disconnect(event) {
-    let _this = this;
-    console.log("断开连接--", event.commonValue, event.deviceId);
-    if (event.deviceId === _this.data._deviceId && event.commonValue === "offline" && !_this.data._hasShowModal) {
-      _this.data._hasShowModal = true
-      wx.showModal({
-        title: '提示',
-        content: '设备断开连接,请重新连接设备',
-        showCancel: false,
-        success: function (res) {
-          _this.data._hasShowModal = false;
-          if (res.confirm) {
-            route_util.goBackHomePage()
-          }
-        }
-      })
-    }
-    // 设备断开连接,请重新连接设备
+  disconnectDevCallback() {
+    route_util.goBackHomePage()
+    // 设备断开连接回调,请重新连接设备
   },
 
   /**
@@ -583,7 +568,6 @@ Page({
       switch (name) {
         case EnumCmdEvent.onoffline:
           wx.hideLoading();
-          _this.disconnect(event)
           break;
         case EnumCmdEvent.wallpaper:
           //0x78