Просмотр исходного кода

反复断开脑机与教具连接状态问题

chaooo 1 год назад
Родитель
Сommit
cfac5259b5
4 измененных файлов с 20 добавлено и 20 удалено
  1. 2 2
      src/components/connection/index.vue
  2. 6 6
      src/pages/games/report/index.vue
  3. 11 11
      src/utils/connection.js
  4. 1 1
      src/utils/user.js

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

@@ -117,9 +117,9 @@ export default {
       if ($this.toy_item && $this.toy_item.id > 0) {
         $this.setToyStatus(1);
         $this.$connection.sendToyConnection($this.toy_item);
-        // 设置10秒后是否已经连接
+        // 设置10秒后,若还是在连接中,设置连接失败
         setTimeout(() => {
-          if ($this.connect_toy !== 2) {
+          if ($this.device_status*1 === 2 && $this.connect_toy === 1) {
             $this.setToyStatus(3);
           }
         }, 10000);

+ 6 - 6
src/pages/games/report/index.vue

@@ -1,11 +1,11 @@
 <template>
   <div class="reportContainer">
+    <div v-if="data_length<15" style="padding:400rpx 20rpx 0 20rpx;">
+      本次训练有效数据不足,无法分析并生成有效报告,请确保训练时脑机佩戴正确,网络状况良好,且训练时长不能太短。
+    </div>
     <div v-if="data_length>=15">
       <web-view :src="webUrl" @load="webLoading"></web-view>
     </div>
-    <div v-else style="padding:400rpx 20rpx 0 20rpx;">
-      本次训练有效数据不足,无法分析并生成有效报告,请确保训练时脑机佩戴正确,网络状况良好,且训练时长不能太短。
-    </div>
     <van-toast id="van-toast"/>
   </div>
 </template>
@@ -25,7 +25,6 @@ export default {
   },
   methods: {
     webLoading() {
-      console.log("报告页面web-view加载完成")
       wx.hideLoading();
     }
   },
@@ -45,12 +44,13 @@ export default {
       $this.data_length = options.size;
     }
     if($this.data_length < 15){
-      wx.hideLoading();
+      $this.webLoading();
+      console.log("报告页面-训练有效数据:", $this.data_length);
     } else {
       let mode = options.mode ? options.mode : wx.getStorageSync('report_mode')
       let $userinfo = wx.getStorageSync("userinfo")
       $this.webUrl = `${process.env.REPORT_URI}?mode=${mode}&token=${store.getters.get_token()}&record_id=${options.id}&nickName=${$userinfo.user_name}&mp=1`
-      console.log($this.webUrl);
+      console.log("报告页面web-view加载完成:", $this.webUrl);
     }
   },
   onUnload(){

+ 11 - 11
src/utils/connection.js

@@ -245,7 +245,7 @@ export default {
       that.SendOrder("09", "关闭脑控");
       ble_store.setters.setCurrentToyId("00");
     },1000);
-    //如果是一代脑机则发送00教具
+    //如果是一代脑机则发送 00 教具
     if (isJELLYFISH()) {
       setTimeout(()=>{
         that.sendConnectOneToMore('00');
@@ -263,11 +263,10 @@ export default {
     let { deviceId, serviceId, characteristicWriteId } = getDeviceWriteInfo();
     let $code = ble_store.getters.getDeviceSn();
     if (deviceId && serviceId && characteristicWriteId) {
-      let that = this;
       let $hex_header = "aa cc ";
       let $hex_sum = 0;
       let $hex_ary = $hex.split(" ");
-      $hex_ary.forEach(($val, $index) => {
+      $hex_ary.forEach(($val) => {
         $hex_sum += parseInt($val, 16);
       })
       let $checksum = ($hex_sum ^ parseInt("ffffffff", 16)) & parseInt("ff", 16);
@@ -283,7 +282,7 @@ export default {
         serviceId: serviceId,
         characteristicId: characteristicWriteId,
         value: buffer,
-        success: function (res) {
+        success: function () {
           LOG_WECHAT($code, "写入指令:", $hex, $comments);
         },
         fail: function (err) {
@@ -504,7 +503,9 @@ export default {
         //判断游戏是否游戏中
         let $game_status = game_store.getters.getGameStatus();
         if ($game_status === 1 || $game_status === 2) {
-          $this.endTheGame();
+          if($this && $this.$options.name && $this.$options.name === "StartGames"){
+            $this.endTheGame();
+          }
           Notify({
             type: 'danger',
             duration: 0,
@@ -519,7 +520,7 @@ export default {
           //关闭脑控
           // connect_toy = false;
           game_store.setters.setGameStatus(0);
-          // 清空链接得设备 三值
+          // 清空链接得设备
           ble_store.setters.clearDeviceToy();
           $this.connect_toy = 0;
           //$this.connect_show = false;
@@ -540,7 +541,7 @@ export default {
    */
   reconnect($deviceId, $this) {
     let that = this;
-    let $deviceInfo = getServicesAndCharateristc();
+    let $deviceInfo = getDeviceWriteInfo();
     //重连的次数
     let $connect_count = 0;
     let $rec = setInterval(() => {
@@ -563,7 +564,7 @@ export default {
             }
             // that.sendToyPower();
           },
-          fail(res) {
+          fail() {
             Notify({type: 'danger', message: `第${$connect_count}次重新连接失败`});
             game_store.setters.setGameCloseStatus(1);
           }
@@ -595,11 +596,10 @@ export default {
     //$this.connect_show = false;
     $this.device_bg = false;
     //$this.connect_status = false;
-
     // 断开教具及蓝牙连接
-    that.SendOrder("31", "断开教具及蓝牙连接");
     setTimeout(()=>{
-      that.SendOrder("09", "关闭脑控");
+      that.SendOrder("31", "断开教具及蓝牙连接");
+      // that.SendOrder("09", "关闭脑控");
       // 移除搜索到新设备的事件的全部监听函数
       wx.offBluetoothDeviceFound();
       // 停止搜寻附近的蓝牙外围设备。若已经找到需要的蓝牙设备并不需要继续搜索时,建议调用该接口停止蓝牙搜索。

+ 1 - 1
src/utils/user.js

@@ -84,7 +84,7 @@ function do_logout($this) {
         url: "/pages/index/main"
       })
       try {
-        $this.change_login_status()
+        $this.changeLoginStatus()
       } catch
         (e) {
         console.log(e)