Explorar el Código

兼容一代脑机连接

chaooo hace 1 año
padre
commit
dedd14b487

+ 21 - 8
src/components/connection/brains/scan.vue

@@ -75,20 +75,33 @@ export default {
             let $code = "";
             if (scan.scanType === "QR_CODE") {
               // 二维码
-              $code = url.substring(url.indexOf("AI"));
-              if($code.indexOf("AI") === -1){
-                // 兼容一代脑机
+              if(url.indexOf("AI") >= 0){
+                $code = url.substring(url.indexOf("AI"));
+              }
+              // 兼容一代脑机
+              else if (url.toUpperCase().indexOf("JELLYFISH") >= 0){
                 $code = url.substring(url.toUpperCase().indexOf("JELLYFISH"));
+              } else {
+                $code = "0";
               }
             } else {
               // 一维码
               $code = scan.result.toUpperCase();
             }
-            ble_store.setters.setDeviceSn($code);
-            WechatLog.info(process.env.NODE_ENV, "扫码得到头环SN码:", $code);
-            console.log("扫码得到头环SN码:", $code);
-            // 检查微信蓝牙权限
-            this.openWechatBluetooth();
+            if ($code === "0"){
+              Dialog.alert({
+                title: '扫码错误',
+                message: '请扫描正确的脑机二维码',
+              }).then(() => {
+                $this.setScanStatus(0);
+              });
+            } else {
+              ble_store.setters.setDeviceSn($code);
+              WechatLog.info(process.env.NODE_ENV, "扫码得到头环SN码:", $code);
+              console.log("扫码得到头环SN码:", $code);
+              // 检查微信蓝牙权限
+              this.openWechatBluetooth();
+            }
           }
         },
         fail(err) {

+ 8 - 7
src/components/connection/index.vue

@@ -101,7 +101,7 @@ export default {
         this.$connection.SendOrder("09");
       }
     },
-    //关闭窗口
+    // 关闭窗口
     closePopup() {
       $this.popup_show = false;
     },
@@ -114,12 +114,12 @@ export default {
       if($this.toy_item && $this.toy_item.id > 0) {
         $this.setToyStatus(1);
         $this.$connection.sendToyConnection($this.toy_item);
-        //2022-5-25 09:07:59 设置10秒后是否已经连接
-        // setTimeout(() => {
-        //   if ($this.connect_toy !== 2) {
-        //     $this.setToyStatus(3);
-        //   }
-        // }, 10000);
+        // 设置10秒后是否已经连接
+        setTimeout(() => {
+          if ($this.connect_toy !== 2) {
+            $this.setToyStatus(3);
+          }
+        }, 10000);
       }
     },
     /**
@@ -172,6 +172,7 @@ export default {
         //$this.toy_UUID = "";
         // 清空链接的设备
         ble_store.setters.clearDeviceToy();
+        game_store.setters.setPlayedTime(0);
       }
       $this.$forceUpdate();
     }

+ 3 - 0
src/pages/games/start/index.vue

@@ -403,6 +403,7 @@ export default {
           $this.played_time_text = formatPlaySeconds($this.played_time);
         }
         if ($this.played_time === 0) {
+          $this.played_time_text = "--:--";
           $this.post_data();
           //判断是否隐藏 隐藏则不绘画
           $this.$connection.sendControlClose();
@@ -464,6 +465,8 @@ export default {
       gameEnd($params).then((res) => {
         let $data = res.data;
         $this.played_time = null;
+        $this.played_time_text = "--:--";
+        game_store.setters.setPlayedTime(0);
         //设置未结束游戏
         $this.is_end = false;
         $this.att_list = [];

+ 8 - 2
src/utils/connection.js

@@ -2,6 +2,7 @@ import ble_store from "../store/bluetooth";
 import game_store from "../store/game";
 import Toast from "../../static/vant/toast/toast";
 import Notify from "../../static/vant/notify/notify";
+import WechatLog from "../utils/wechat_log";
 
 function getDeviceWriteInfo() {
   let deviceId = ble_store.getters.getDeviceId();
@@ -356,7 +357,9 @@ export default {
             if (isJELLYFISH()){
               // 一代脑机
               $this.connect_toy = 2;
-              wx.showToast({title: "已连接到" + $this.toy_item.name });
+              if($this.toy_item && $this.toy_item.name){
+                wx.showToast({title: "已连接到" + $this.toy_item.name });
+              }
             } else {
               console.log("一对多")
               // 发送一对一连接 03 00 ${$toy_id} 01 0A
@@ -367,7 +370,9 @@ export default {
           }
           if (new RegExp("01").test($hex_index) === true) {
             console.log("一对一")
-            wx.showToast({title: "已连接到" + $this.toy_item.name });
+            if($this.toy_item && $this.toy_item.name){
+              wx.showToast({title: "已连接到" + $this.toy_item.name });
+            }
             //连接成功
             $this.connect_toy = 2;
             // 判断冥想模式不发送获取教具名字
@@ -598,6 +603,7 @@ export default {
           $this.connect_toy = 0;
           $this.device_status = 0;
           $this.$forceUpdate();
+          //
         },
       });
     },500);