Browse Source

修正下发验证码bug

xiaohaizhao 6 months ago
parent
commit
490565eb6c

+ 15 - 1
Bluetooth/index/index.vue

@@ -119,7 +119,14 @@ export default {
     startBluetooth(services = []) {
       let that = this;
       uni.onBluetoothDeviceFound(function ({ devices }) {
-		that.devices = that.devices.concat(devices);
+        let index = that.devices.findIndex(
+          (v) => v.deviceId == devices[0].deviceId
+        );
+        if (index == -1) {
+          that.devices = that.devices.concat(devices);
+        } else {
+          that.devices[index] = devices[0];
+        }
         that.empty = that.devices.length == 0;
       });
       uni.startBluetoothDevicesDiscovery({
@@ -166,6 +173,7 @@ export default {
                     showCancel: false,
                     confirmText: "确认",
                   });
+                  that.connected = "";
                   that.closeBLEConnection();
                 } else {
                   let services = res.services.find(
@@ -219,6 +227,7 @@ export default {
                                 that.$Http.setBluetooth(device);
                               } else {
                                 that.closeBLEConnection();
+                                that.connected = "";
                               }
                             },
                           });
@@ -229,6 +238,7 @@ export default {
                             confirmText: "确认",
                           });
                           that.closeBLEConnection();
+                          that.connected = "";
                         }
                       },
                     });
@@ -238,22 +248,26 @@ export default {
                       showCancel: false,
                       confirmText: "确认",
                     });
+                    that.connected = "";
                   }
                 }
               },
               fail(err) {
                 console.error("获取蓝牙服务失败", err);
                 that.handleFail(fail);
+                that.connected = "";
               },
             });
           } else {
             console.log("设备连接失败", that.codes[res.errCode]);
             that.handleFail(res);
+            that.connected = "";
           }
         },
         fail: (fail) => {
           console.log("连接失败", fail);
           that.handleFail(fail);
+          that.connected = "";
         },
       });
     },

+ 9 - 8
control/components/prodnum-FW01B/prodnum-FW01B.vue

@@ -73,22 +73,22 @@ export default {
           第二域名: "string",
         });
         setTimeout(() => {
-          this.authentication();
+          this.authentication(this);
         }, 100);
         this.$refs.refCD.init();
       }
     },
   },
   methods: {
-    authentication() {
+    authentication(that) {
       try {
         uni.showLoading({
           title: "身份验证中...",
           mask: true,
         });
-        const E013 = this.list.find((v) => v.paramName == "E013");
+        const E013 = that.list.find((v) => v.paramName == "E013");
         if (E013) {
-          this.$refs.refCD.send({ password: this.control.bluetoothcode }, E013);
+          that.$refs.refCD.send({ password: that.control.bluetoothcode }, E013);
         }
       } catch (error) {
         console.error("下发身份验证失败", error);
@@ -152,14 +152,15 @@ export default {
               content: `身份验证失败`,
               confirmText: "重新验证",
               cancelText: "断开连接",
-              complete: ({ confirm }) => {
+              complete: ({ confirm, cancel }) => {
                 if (confirm) {
-                  that.authentication().bind(that);
-                } else {
+                  that.authentication(that);
+                }
+                if (cancel) {
                   uni.closeBLEConnection({
                     deviceId: that.connected,
                   });
-                  uni.closeBluetoothAdapter();
+                  that.$Http.setDetailMode(0);
                 }
               },
             });

+ 7 - 1
control/modules/connectingDevice.vue

@@ -31,7 +31,13 @@ export default {
   },
   data() {
     return {
-      Bluetooth: {},
+      Bluetooth: {
+        device:{
+          RSSI:0,
+          name:"",
+          deviceId:"",
+        }
+      },
       circulation: null,
     };
   },