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

解决了大数据量导致无法结束游戏的bug,有待测试

yerong 4 лет назад
Родитель
Сommit
897f22e43e
3 измененных файлов с 33 добавлено и 32 удалено
  1. 27 27
      src/pages/start/index.vue
  2. 4 4
      src/store/game.js
  3. 2 1
      src/utils/bluetooth.js

+ 27 - 27
src/pages/start/index.vue

@@ -231,27 +231,20 @@ export default {
       game_store.setters.setGameStatus(3)
       //游戏结束重置游戏时间
       wx.removeStorageSync('play_time')
-      wx.removeStorageSync('hide_time')
       //游戏结束重置游戏模式
       game_store.setters.setMode(0)
       //删除游戏得id
       game_store.setters.removeToyHex()
 
+      // 结束游戏在提交报告函数里
+      $this.post_data()
+
       Toast.loading({
         forbidClick: true,
         mask: true,
         message: "正在生成报告...",
         duration: 0,
       })
-      // 结束游戏在提交报告函数里
-      $this.post_data()
-    },
-
-    // 时间到
-    time_out() {
-      console.log('游戏结束')
-      //游戏结束
-      $this.game_finished()
     },
     to_report() {
       mpvue.redirectTo({
@@ -282,6 +275,7 @@ export default {
     post_data() {
       //判断数据长度大于理想状态 需要对数组进行切割 逐个提交数据
       let $len = 300
+      console.log($this.attList.length, '结束游戏提交的数据量')
       if ($this.attList.length > $len) {
         let $count = Math.ceil($this.attList.length / $len)
 
@@ -294,9 +288,6 @@ export default {
               line: $this.attList.slice(index * $len, (index + 1) * $len),
               line_med: $this.medList.slice(index * $len, (index + 1) * $len)
             }
-            console.log($this.attList)
-            console.log(index * $len, (index + 1) * $len)
-            console.log($this.attList.slice(index * $len, (index + 1) * $len))
             gameAddLine($params).then((res) => {
               let $data = res.data
               if ($data.code == 0) {
@@ -329,11 +320,12 @@ export default {
             $this.attList = []
             $this.medList = []
           }
+          setTimeout(() => {
+            $this.game_over()
+            $this.to_report()
+          }, 800)
         })
-        setTimeout(() => {
-          $this.game_over()
-          $this.to_report()
-        }, 800)
+
         return 800
       }
     },
@@ -380,13 +372,17 @@ export default {
       $this.attList.push($data['att'])
       $this.medList.push($data['med'])
 
-      //通过专注放松度 画图
-      let $option = util.getLineOption($this.att_list, $this.med_list)
-      att_charts.setOption($option)
+      //判断是否隐藏 隐藏则不绘画
+      let $hide_status = game_store.getters.getHideStatus()
+      if (!$hide_status) {
+        //通过专注放松度 画图
+        let $option = util.getLineOption($this.att_list, $this.med_list)
+        att_charts.setOption($option)
 
-      //通过基本脑波发送数据
-      let $base_option = util.getBaseOption($this.delta_list, $this.theta_list, $this.alpha_list, $this.beta_list)
-      med_charts.setOption($base_option)
+        //通过基本脑波发送数据
+        let $base_option = util.getBaseOption($this.delta_list, $this.theta_list, $this.alpha_list, $this.beta_list)
+        med_charts.setOption($base_option)
+      }
     },
     //计算游玩时间
     calThePlayedTime() {
@@ -419,9 +415,9 @@ export default {
   }
   ,
   mounted() {
-    let $deviceId = $this._deviceId = game_store.getters.getDeviceId()
-    let $serviceId = $this._serviceId = game_store.getters.getServiceId()
-    let $cId = $this._characteristicId = game_store.getters.getCharacterId()
+    $this._deviceId = game_store.getters.getDeviceId()
+    $this._serviceId = game_store.getters.getServiceId()
+    $this._characteristicId = game_store.getters.getCharacterId()
 
     //判断是否结束游戏
     if ($this.is_end == true) {
@@ -441,14 +437,18 @@ export default {
     $this = this;
   },
   onShow() {
+    game_store.setters.setHideStatus(false)
     if ($this.played_time == 0) {
-      $this.time_out()
+      $this.game_finished()
     }
   },
   onLoad(options) {
     if (options.end == 1) {
       $this.is_end = true
     }
+  },
+  onHide() {
+    game_store.setters.setHideStatus(true)
   }
 }
 </script>

+ 4 - 4
src/store/game.js

@@ -39,8 +39,8 @@ const setters = {
     wx.setStorageSync('played_time', param)
   },
 //  记录推到后台得时间
-  setHideTime($param) {
-    wx.setStorageSync('hide_time', $param)
+  setHideStatus($param) {
+    wx.setStorageSync('hide_status', $param)
   }
 }
 
@@ -77,8 +77,8 @@ const getters = {
     return wx.getStorageSync('played_time')
   },
 //  获取一开始隐藏的时间
-  getHideTime() {
-    return wx.getStorageSync('hide_time')
+  getHideStatus() {
+    return wx.getStorageSync('hide_status')
   }
 }
 

+ 2 - 1
src/utils/bluetooth.js

@@ -641,7 +641,8 @@ export default {
               $this.do_datas($data)
             }
             if ($this.played_time == 0) {
-              $this.time_out()
+              //判断是否隐藏 隐藏则不绘画
+              that.shutdownSendControl(characteristic.deviceId, $this._serviceId, $this._characteristicId)
             }
           } catch (e) {
             console.log('调用方法失败', e)