xiaohaizhao hace 1 año
padre
commit
9b0dc24bdf
Se han modificado 3 ficheros con 89 adiciones y 84 borrados
  1. 0 3
      control/modules/connectingDevice.vue
  2. 2 2
      main.js
  3. 87 79
      pages/facility/detail.vue

+ 0 - 3
control/modules/connectingDevice.vue

@@ -109,9 +109,6 @@ export default {
         value: buffer,
         success(res) {
           console.log("发送信息", res);
-          uni.showModal({
-            title: "测试",
-          });
         },
         fail(err) {
           console.error("发送信息失败", err);

+ 2 - 2
main.js

@@ -29,8 +29,8 @@ import connectingDevice from './control/modules/connectingDevice';
 Vue.component('connectingDevice', connectingDevice);
 
 console.log("process.env.NODE_ENV",process.env.NODE_ENV)
-//挂载接口
-let isDev = ['development','production'].includes(process.env.NODE_ENV);
+//挂载接口 'production'
+let isDev = ['development'].includes(process.env.NODE_ENV);
 console.log('运行环境', isDev ? '开发' : '生产');
 
 const http = {};

+ 87 - 79
pages/facility/detail.vue

@@ -232,87 +232,95 @@ export default {
           });
           break;
         case 1:
-          /*    uni.openBluetoothAdapter({
-            mode: "peripheral",
-          }); */
-          uni.openBluetoothAdapter({
-            success: (result) => {
-              if (result.errno == 0) {
-                uni.navigateTo({
-                  url:
-                    "/Bluetooth/index/index?services=" +
-                    JSON.stringify([
-                      that.detail.prodnum,
-                      that.detail.w_productid,
-                    ]),
-                });
-                this.$Http.setBluetooth = function (Bluetooth) {
-                  this.mode = mode;
-                  let curPages = getCurrentPages();
-                  if (
-                    curPages[curPages.length - 1].__route__ ==
-                    "Bluetooth/index/index"
-                  )
-                    uni.navigateBack();
-                  this.$Http.setDetailMode = function (mode1) {
-                    this.mode = mode1;
-                    delete this.$Http.setDetailMode;
-                    uni.closeBluetoothAdapter();
-                  }.bind(this);
-                  this.$Http.Bluetooth = Bluetooth;
-                  delete this.$Http.setBluetooth;
-                }.bind(this);
-              } else {
-                uni.showModal({
-                  title: result.errno,
-                  content: result.Msg,
-                  showCancel: false,
-                  confirmText: "确定",
-                });
-              }
-            },
-            fail: (fail) => {
-              console.log("蓝牙初始化fail:", fail);
-              if (fail.errno == "103") {
-                uni.showModal({
-                  title: "提示",
-                  content: "未获取使用蓝牙功能授权,请授权后使用",
-                  showCancel: false,
-                  confirmText: "前去授权",
-                  success() {
-                    uni.openSetting({
-                      success({ authSetting }) {
-                        if (authSetting["scope.bluetooth"])
-                          that.changeMode(mode);
+          try {
+            if (that.$Http.Bluetooth.device.deviceId)
+              uni.closeBLEConnection({
+                deviceId: that.$Http.Bluetooth.device.deviceId,
+              });
+          } catch (error) {}
+          uni.closeBluetoothAdapter({
+            complete: (complete) => {
+              console.log("closeBluetoothAdapterComplete", complete);
+              uni.openBluetoothAdapter({
+                success: (result) => {
+                  if (result.errno == 0) {
+                    uni.navigateTo({
+                      url:
+                        "/Bluetooth/index/index?services=" +
+                        JSON.stringify([
+                          that.detail.prodnum,
+                          that.detail.w_productid,
+                        ]),
+                    });
+                    this.$Http.setBluetooth = function (Bluetooth) {
+                      this.mode = mode;
+                      let curPages = getCurrentPages();
+                      if (
+                        curPages[curPages.length - 1].__route__ ==
+                        "Bluetooth/index/index"
+                      )
+                        uni.navigateBack();
+                      this.$Http.setDetailMode = function (mode1) {
+                        this.mode = mode1;
+                        delete this.$Http.setDetailMode;
+                        uni.closeBluetoothAdapter();
+                      }.bind(this);
+                      this.$Http.Bluetooth = Bluetooth;
+                      delete this.$Http.setBluetooth;
+                    }.bind(this);
+                  } else {
+                    uni.showModal({
+                      title: result.errno,
+                      content: result.Msg,
+                      showCancel: false,
+                      confirmText: "确定",
+                    });
+                  }
+                },
+                fail: (fail) => {
+                  console.log("蓝牙初始化fail:", fail);
+                  if (fail.errno == "103") {
+                    uni.showModal({
+                      title: "提示",
+                      content: "未获取使用蓝牙功能授权,请授权后使用",
+                      showCancel: false,
+                      confirmText: "前去授权",
+                      success() {
+                        uni.openSetting({
+                          success({ authSetting }) {
+                            if (authSetting["scope.bluetooth"])
+                              that.changeMode(mode);
+                          },
+                        });
                       },
                     });
-                  },
-                });
-              } else {
-                const codes = {
-                  0: "ok",
-                  "-1": "已连接 ",
-                  10000: "未初始化蓝牙适配器",
-                  10001: "当前蓝牙适配器不可用",
-                  10002: "没有找到指定设备",
-                  10003: "连接失败",
-                  10004: "没有找到指定服务",
-                  10005: "没有找到指定特征值",
-                  10006: "当前连接已断开",
-                  10007: "当前特征值不支持此操作",
-                  10008: "其余所有系统上报的异常",
-                  10009: "系统版本低于 4.3 不支持 BLE",
-                  10010: "已连接",
-                  10011: "配对设备需要配对码",
-                  10012: "连接超时",
-                  10013: "连接 deviceId 为空或者是格式不正确",
-                };
-                uni.showModal({
-                  content: codes[fail.errCode] || fail.errMsg,
-                  showCancel: false,
-                  confirmText: "确认",
-                });
-              }
+                  } else {
+                    const codes = {
+                      0: "ok",
+                      "-1": "已连接 ",
+                      10000: "未初始化蓝牙适配器",
+                      10001: "当前蓝牙适配器不可用",
+                      10002: "没有找到指定设备",
+                      10003: "连接失败",
+                      10004: "没有找到指定服务",
+                      10005: "没有找到指定特征值",
+                      10006: "当前连接已断开",
+                      10007: "当前特征值不支持此操作",
+                      10008: "其余所有系统上报的异常",
+                      10009: "系统版本低于 4.3 不支持 BLE",
+                      10010: "已连接",
+                      10011: "配对设备需要配对码",
+                      10012: "连接超时",
+                      10013: "连接 deviceId 为空或者是格式不正确",
+                    };
+                    uni.showModal({
+                      content: codes[fail.errCode] || fail.errMsg,
+                      showCancel: false,
+                      confirmText: "确认",
+                    });
+                  }
+                },
+              });
             },
           });
           break;