xiaohaizhao 9 ay önce
ebeveyn
işleme
84b5a57956

+ 13 - 23
Bluetooth/index/index.vue

@@ -12,7 +12,9 @@
     <view class="head">
       <view class="title">蓝牙设备列表</view>
       <u-loading-icon v-if="beSearching" size="21" />
-      <view v-else class="anew" @click="startBluetooth"> 继续搜索 </view>
+      <view v-else class="anew" @click="startBluetooth(services)">
+        继续搜索
+      </view>
     </view>
     <My_listbox ref="List" :pullDown="false">
       <view class="device" v-for="item in devices" :key="item.deviceId">
@@ -90,8 +92,13 @@ export default {
     };
   },
   onLoad(options) {
-    if (options.services) this.services = JSON.parse(options.services);
-    this.startBluetooth();
+    if (options.services) {
+      this.services = JSON.parse(options.services);
+      this.startBluetooth(["FW01"]);
+    } else {
+      this.startBluetooth();
+    }
+
     this.$refs.List.setHeight();
   },
   onUnload() {
@@ -102,22 +109,21 @@ export default {
       this.services = [];
       this.stopBluetooth();
       setTimeout(() => {
-        this.startBluetooth();
+        this.startBluetooth([]);
       });
     },
     openSetting() {
       uni.openSetting();
     },
     /* 开始搜索 */
-    startBluetooth() {
+    startBluetooth(services = []) {
       let that = this;
-      this.connected = "";
       uni.onBluetoothDeviceFound(function ({ devices }) {
         that.devices = devices;
         that.empty = devices.length == 0;
       });
       uni.startBluetoothDevicesDiscovery({
-        services: this.services,
+        // services,
         success(res) {
           that.beSearching = true;
           that.$refs.List.setHeight();
@@ -148,7 +154,6 @@ export default {
       that.connected = item.deviceId;
       uni.createBLEConnection({
         deviceId: item.deviceId,
-        services: that.services || [],
         success(res) {
           if (res.errCode == 0) {
             uni.getBLEDeviceServices({
@@ -181,21 +186,6 @@ export default {
                         device.characteristic = res.characteristics[0];
                         const { write, notify } =
                           device.characteristic.properties;
-                        return uni.showModal({
-                          content: `${
-                            item.name || item.deviceId
-                          }连接成功\n是否进入设备操作页`,
-                          confirmText: "确认",
-                          cancelText: "重选",
-                          success: ({ confirm }) => {
-                            if (confirm) {
-                              console.log("设备连接完成");
-                              that.$Http.setBluetooth(device);
-                            } else {
-                              that.closeBLEConnection();
-                            }
-                          },
-                        });
                         if (write && notify) {
                           uni.showModal({
                             content: `${

+ 29 - 6
control/components/prodnum-FW01B/prodnum-FW01B.vue

@@ -3,6 +3,7 @@
     <connectingDevice ref="refCD" @onFeedback="onFeedback" />
     <block v-for="(item, index) in list" :key="item.w_functionid">
       <view
+        v-if="item.paramName != 'E013'"
         class="item"
         :hover-class="item.inputType == 'switch' ? '' : 'navigator-hover'"
         @click="item.inputType == 'switch' ? '' : onClick(item)"
@@ -70,6 +71,15 @@ export default {
         this.list = this.__proto__.getControlItem(names, newVal, {
           安装位置: "radio",
         });
+        try {
+          const E013 = this.list.find((v) => v.paramName == "E013");
+          if (E013) {
+            this.onSendMsg(E013.w_functionid, {
+              E013: E013.params.options[0].value,
+            });
+          }
+        } catch (error) {}
+
         this.$refs.refCD.init();
       }
     },
@@ -118,13 +128,26 @@ export default {
           MyInput.show = false;
           MyInput.stepIsCalculate = null;
         } else if (res.status == 0) {
-          uni.showModal({
-            title: "失败",
-            content: `“${item.funcname}”设置失败`,
-            showCancel: false,
-          });
+          if (item.paramName == "E013") {
+            uni.showModal({
+              title: "失败",
+              content: `身份验证失败,将断开连接`,
+              showCancel: false,
+            });
+
+            uni.closeBLEConnection({
+              deviceId: that.connected,
+              success(res) {},
+            });
+          } else {
+            uni.showModal({
+              title: "失败",
+              content: `“${item.funcname}”设置失败`,
+              showCancel: false,
+            });
+          }
         }
-        
+
         MyInput.$refs.uModal.loading = false;
         delete item.loading;
         delete item.msgid;

+ 11 - 3
control/modules/connectingDevice.vue

@@ -66,7 +66,17 @@ export default {
 
       this.startNotice();
     },
-
+    closeBLEConnection() {
+      let that = this;
+      uni.closeBLEConnection({
+        deviceId: that.Bluetooth.device.deviceId,
+        success(res) {
+          that.$Http.setDetailMode(0);
+          clearInterval(that.circulation);
+          that.circulation = null;
+        },
+      });
+    },
     /* 发送 */
     send(content = {}, item) {
       content.ts = Date.now();
@@ -96,7 +106,6 @@ export default {
         },
       });
     },
-
     /* 模拟接收 */
     fanhui(value) {
       let resHex = this.ab2hex(value);
@@ -128,7 +137,6 @@ export default {
         },
       });
     },
-
     handleFail(fail) {
       const codes = {
         0: "ok",