Selaa lähdekoodia

添加了蓝牙初始化的代码信息返回,添加了ios初始化蓝牙的从机模式

智方网络_吖荣 4 vuotta sitten
vanhempi
commit
85e1ac07ce
2 muutettua tiedostoa jossa 30 lisäystä ja 7 poistoa
  1. 3 7
      src/components/device/device.vue
  2. 27 0
      src/utils/bluetooth.js

+ 3 - 7
src/components/device/device.vue

@@ -222,6 +222,7 @@ export default {
             console.log("头环码", $code);
             //打开蓝牙设备
             wx.openBluetoothAdapter({
+              mode:"peripheral",
               success(res) {
                 //判断已经打开连接了
                 if (res["errMsg"] == "openBluetoothAdapter:ok") {
@@ -229,15 +230,10 @@ export default {
                 }
               },
               fail(err) {
-                if (err["errCode"] == 10001) {
+                let $msg = bluetooth.GetopenBluetoothAdapterError(err["errCode"]);
                   Toast.fail({
-                    message: "请打开蓝牙和位置信息!",
+                    message: $msg,
                   });
-                } else {
-                  Toast.fail({
-                    message: "蓝牙连接失败",
-                  });
-                }
               },
             });
           }

+ 27 - 0
src/utils/bluetooth.js

@@ -735,4 +735,31 @@ export default {
     }
     return result;
   },
+
+  //根据错误代码返回字符串信息
+  GetopenBluetoothAdapterError(errCode){
+
+    let $errmsg = "";
+    if(errCode == 10000){
+      $errmsg = "未初始化蓝牙适配器"
+    }
+
+    if(errCode == 10001){
+      $errmsg = "当前蓝牙适配器不可用"
+    }
+
+    if(errCode == 10002){
+      $errmsg = "没有找到指定设备"
+    }
+
+    if(errCode == 10003){
+      $errmsg = "连接失败"
+    }
+
+    if(errCode == 10006){
+      $errmsg = "当前连接已断开"
+    }
+
+    return $errmsg;
+  }
 };