Browse Source

训练中教具断连,脑环关机扫码处理

chaooo 1 year ago
parent
commit
affc26d72e

+ 12 - 8
src/components/connection/brains/connecting.vue

@@ -89,14 +89,18 @@ export default {
           wx.offBluetoothDeviceFound();
           // 停止搜寻附近的蓝牙外围设备。若已经找到需要的蓝牙设备并不需要继续搜索时,建议调用该接口停止蓝牙搜索。
           wx.stopBluetoothDevicesDiscovery();
-          Dialog.confirm({
-            message: '脑机连接失败',
-            showCancelButton: true,
-            cancelButtonText: "查看指引",
-          }).catch(() => {
-            mpvue.navigateTo({
-              url: "/pages/banner/guide/main"
-            })
+          wx.showModal({
+            content: '脑机连接失败',
+            showCancel: true,
+            cancelText: "查看指引",
+            success(res) {
+              $this.setDeviceStatus(3);
+              if (res.cancel) {
+                mpvue.navigateTo({
+                  url: "/pages/banner/guide/main"
+                });
+              }
+            }
           });
         }
       }, 7000)

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

@@ -48,13 +48,6 @@ export default {
   created() {
     $this = this;
   },
-  // watch: {
-  //   'connect_toy': {
-  //     handler: function($status) {
-  //       LOG_DEBUG("监听connect_toy状态变化",$status);
-  //     }, immediate: true
-  //   }
-  // },
   methods: {
     /**
      * 获取设备扫码连接状态
@@ -63,6 +56,24 @@ export default {
       // 扫码成功连接中1,失败未连接0
       $this.device_status = $status * 1;
       LOG_DEBUG("接收到设备扫码连接状态:", $status);
+      // 设置10秒后,若还是在连接中,设置连接失败
+      setTimeout(() => {
+        if ($this.device_status*1 === 1) {
+          wx.showModal({
+            content: '脑机连接失败',
+            showCancel: true,
+            cancelText: "查看指引",
+            success(res) {
+              $this.setDeviceStatus(3);
+              if (res.cancel) {
+                mpvue.navigateTo({
+                  url: "/pages/banner/guide/main"
+                });
+              }
+            }
+          });
+        }
+      }, 10000);
     },
     /**
      * 获取设备连接状态

+ 27 - 5
src/pages/games/play/index.vue

@@ -40,18 +40,28 @@
         </van-col>
         <van-col span="8">
           <div class="flex flex-direction align-center justify-center">
+<!--            <view class="elc_power_container">-->
+<!--              <img src="https://img.shuimuai.com/web/dianchi_3.png" alt="" :style="{ width: device_power + '%' }"-->
+<!--                   class="device_elc"/>-->
+<!--            </view>-->
             <view class="elc_power_container">
-              <img src="https://img.shuimuai.com/web/dianchi_3.png" alt="" :style="{ width: device_power + '%' }"
-                   class="device_elc"/>
+              <view class="device_power" :style="{'background-size': device_power + '% 100%'}">
+                <text v-if="is_dev" v-text="device_power+'%'"></text>
+              </view>
             </view>
             <text class="text-default">脑机电量</text>
           </div>
         </van-col>
         <van-col span="8">
           <div class="flex flex-direction align-center justify-center">
+<!--            <view class="elc_power_container">-->
+<!--              <img src="https://img.shuimuai.com/web/dianchi_3.png" alt="" :style="{ width: toy_power + '%' }"-->
+<!--                   class="device_elc"/>-->
+<!--            </view>-->
             <view class="elc_power_container">
-              <img src="https://img.shuimuai.com/web/dianchi_3.png" alt="" :style="{ width: toy_power + '%' }"
-                   class="device_elc"/>
+              <view class="device_power" :style="{'background-size': toy_power + '% 100%'}">
+                <text v-if="is_dev" v-text="toy_power+'%'"></text>
+              </view>
             </view>
             <text class="text-default">教具电量</text>
           </div>
@@ -283,6 +293,8 @@ export default {
       play_time: 0,
       // 本次游玩时间倒计时
       countdown_text: "--:--",
+      // 是否开发环境
+      is_dev: false,
     };
   },
   onLoad(options) {
@@ -292,6 +304,7 @@ export default {
     }
   },
   mounted() {
+    this.is_dev = process.env.NODE_ENV === "development";
     let game_status = game_store.getters.getGameStatus()*1;
     if (game_status === 1) {
       $this.is_end = false;
@@ -680,7 +693,16 @@ export default {
   border-radius: 5px;
   height: 22px;
 }
-
+.device_power{
+  width: 100%;
+  height: 100%;
+  background-image: url(https://img.shuimuai.com/web/dianchi_3.png);
+  background-repeat: no-repeat;
+  background-size: 0 100%;
+  text-align: center;
+  font-size: 12px;
+  color: #fff;
+}
 .device_elc {
   height: 18px;
 }

+ 2 - 1
src/utils/connection.js

@@ -428,8 +428,9 @@ export default {
           //connect_toy = false
           wx.showModal({
             content: "教具已断开",
+            showCancel: false,
             success(res) {
-              if (res.confirm) {
+              if (res.confirm || res.cancel) {
                 let $game_status = game_store.getters.getGameStatus();
                 if ($game_status === 1 || $game_status === 2) {
                   $this.endTheGame();