فهرست منبع

脑机关机游戏处理

chaooo 1 سال پیش
والد
کامیت
7324a2913c
4فایلهای تغییر یافته به همراه39 افزوده شده و 24 حذف شده
  1. 2 1
      src/components/connection/index.vue
  2. 2 0
      src/pages/games/report/index.vue
  3. 3 1
      src/pages/games/report/main.json
  4. 32 22
      src/utils/connection.js

+ 2 - 1
src/components/connection/index.vue

@@ -164,8 +164,9 @@ export default {
 
       //$this.toy_UUID = "";
 
-      // 状态为1的时候重置为1 小乌龟
+      // 重新连接失败
       if ($game_close_status === 1) {
+        console.log("---------------------------------------------------------------------")
         // 重置默认条件
         $this.connect_toy = 0;
         //$this.connect_show = false;

+ 2 - 0
src/pages/games/report/index.vue

@@ -7,6 +7,8 @@
       <web-view :src="webUrl" @load="webLoading"></web-view>
     </div>
     <van-toast id="van-toast"/>
+    <van-dialog id="van-dialog"/>
+    <van-notify id="van-notify"/>
   </div>
 </template>
 <script>

+ 3 - 1
src/pages/games/report/main.json

@@ -6,6 +6,8 @@
     "van-toast": "/static/vant/toast/index",
     "van-tab": "/static/vant/tab/index",
     "van-tabs": "/static/vant/tabs/index",
-    "van-count-down": "/static/vant/count-down/index"
+    "van-count-down": "/static/vant/count-down/index",
+    "van-dialog": "/static/vant/dialog/index",
+    "van-notify": "/static/vant/notify/index"
   }
 }

+ 32 - 22
src/utils/connection.js

@@ -463,17 +463,18 @@ export default {
 
         //todo 接收脑机关机指令
         if (hexStr.toUpperCase().indexOf("AADD5A00000000A5") >= 0) {
-          Notify({
-            type: 'danger',
-            duration: 0,
-            message: '智脑机已关机,训练结束',
-            onOpened() {
-              setTimeout(() => {
+          let $game_status = game_store.getters.getGameStatus();
+          if ($game_status === 1 || $game_status === 2) {
+            Notify({
+              type: 'danger',
+              duration: 0,
+              message: '智脑机已关机,训练结束',
+              onOpened() {
                 $this.endTheGame();
-                that.clearStatus($this);
-              }, 2000)
-            }
-          });
+              }
+            });
+          }
+          that.clearStatus($this);
           $comments = "脑环关机的应答";
         }
       }
@@ -494,26 +495,32 @@ export default {
    */
   watchBLEstatus($this) {
     let that = this;
+    if($this && $this.$options.name){
+      LOG_DEBUG("微信自身监听低功耗蓝牙连接状态:", $this.$options.name);
+    }
     // 微信自身监听低功耗蓝牙连接状态的改变事件
     wx.onBLEConnectionStateChange((res) => {
       // 该方法回调中可以用于处理连接意外断开等异常情况
       ble_store.setters.setBluetoothLinkStatus(res.connected);
      LOG_DEBUG("监听脑机连接状态:", res.connected);
-      if (res.connected === false) {
+      if (!res.connected) {
         //判断游戏是否游戏中
         let $game_status = game_store.getters.getGameStatus();
+        LOG_DEBUG("智脑机已断开连接,游戏状态:", $game_status);
         if ($game_status === 1 || $game_status === 2) {
           if($this && $this.$options.name && $this.$options.name === "StartGames"){
             $this.endTheGame();
           }
-          Notify({
-            type: 'danger',
-            duration: 0,
-            message: '智脑机已断开连接,正在尝试重新连接',
-            onOpened() {
-              that.reconnect(res.deviceId, $this)
-            }
-          });
+          // if($this && $this.$options.name && $this.$options.name === "StartGames"){
+          //   Notify({
+          //     type: 'danger',
+          //     duration: 0,
+          //     message: '智脑机已断开连接,正在尝试重新连接',
+          //     onOpened() {
+          //       that.reconnect(res.deviceId, $this)
+          //     }
+          //   });
+          // }
         } else {
           that.clearStatus($this);
         }
@@ -544,6 +551,7 @@ export default {
     let $connect_count = 0;
     let $rec = setInterval(() => {
       let $game_status = game_store.getters.getGameStatus();
+      LOG_DEBUG("正在尝试重新连接,游戏状态:", $game_status);
       if ($game_status === 1 || $game_status === 2) {
         let $code = ble_store.getters.getDeviceSn();
         wx.createBLEConnection({
@@ -557,18 +565,20 @@ export default {
               that.getBLEDeviceServices($deviceInfo.deviceId)
               that.notifyDatas($this)
             } else {
-              //that.openNotify($this)
               that.watchBLEstatus($this);
             }
-            // that.sendToyPower();
           },
           fail() {
             Notify({type: 'danger', message: `第${$connect_count}次重新连接失败`});
+            LOG_WECHAT($code, `第${$connect_count}次重新连接失败`);
             game_store.setters.setGameCloseStatus(1);
           }
         })
         if ($connect_count >= 3) {
-          $this.endTheGame();
+          let $game_status = game_store.getters.getGameStatus();
+          if ($game_status === 1 || $game_status === 2) {
+            $this.endTheGame();
+          }
           that.clearStatus($this);
           clearInterval($rec)
         }