Forráskód Böngészése

解决了脑环拉到后台,游戏无法结束的bug

yerong 4 éve
szülő
commit
87fe2e9cbc

+ 1 - 1
dist/wx

@@ -1 +1 @@
-Subproject commit 262c8f8c141ec4854231dfe9765e3fad46c3b2de
+Subproject commit 16dd035ba40d23236d0a98c4345e7f55a0c889da

+ 12 - 13
src/components/device/toy/connecting.vue

@@ -204,22 +204,21 @@ export default {
           let $res = $data.data
           if ($data.code == 0) {
             // if ($data.code) {
+            //设置游戏中
+            $this.connect_toy = 4
+            //设置游戏模式
+            game_store.setters.setMode($event)
+            // 设置游戏状态为游戏中
+            game_store.setters.setGameStatus(1)
+            // 设置游戏记录id
+            game_store.setters.setGameRecordId($res['game_record_id'])
+            //设置游戏时间长
+            wx.removeStorageSync('played_time')
+            game_store.setters.setPlayTime($res['play_time'])
+
             Toast.success({
               message: $data.errmsg,
               onClose() {
-                //调用父级得方法游戏开始得方法
-                // $this.$emit('game_start')
-                //设置游戏中
-                $this.connect_toy = 4
-                //设置游戏模式
-                game_store.setters.setMode($event)
-                // 设置游戏状态为游戏中
-                game_store.setters.setGameStatus(1)
-                // 设置游戏记录id
-                game_store.setters.setGameRecordId($res['game_record_id'])
-                //设置游戏时间长
-                wx.removeStorageSync('played_time')
-                game_store.setters.setPlayTime($res['play_time'])
                 mpvue.navigateTo({
                   url: "/pages/start/main",
                   success() {

+ 7 - 3
src/pages/agent/index/index.vue

@@ -97,12 +97,15 @@
       </van-cell>
 
     </div>
+    <van-toast id="van-toast"/>
+
   </div>
 </template>
 
 <script>
 import {agentDetail, agentIncomeDetail} from "../../../requests/agent";
 import utils from '@/utils/index'
+import Toast from '../../../../static/vant/toast/toast'
 
 var $this
 export default {
@@ -140,9 +143,10 @@ export default {
     },
     //  跳转代理商结算中心
     to_agent_cal_center() {
-      mpvue.navigateTo({
-        url: "/pages/agent/settlement_center/index/main"
-      })
+      Toast.fail('暂未开通')
+      // mpvue.navigateTo({
+      //   url: "/pages/agent/settlement_center/index/main"
+      // })
     },
     //  邀请卡库存
     to_agent_invite_card() {

+ 2 - 1
src/pages/agent/index/main.json

@@ -3,6 +3,7 @@
     "van-row": "../../../static/vant/row/index",
     "van-col": "../../../static/vant/col/index",
     "van-cell": "../../../static/vant/cell/index",
-    "van-icon": "../../../static/vant/icon/index"
+    "van-icon": "../../../static/vant/icon/index",
+    "van-toast": "../../../static/vant/toast/index"
   }
 }

+ 17 - 14
src/pages/report/index.vue

@@ -146,19 +146,22 @@ export default {
         message: "加载中",
         duration: 0
       })
-      gameDetail($record_id).then((res) => {
-        Toast.clear()
-        let $res = res.data;
-        $this.record = $res.data
-        //5分钟阶段
-        let $five_min = 5 * 60
-        $this.is_cut = $this.record.play_time > $five_min
-        if ($this.is_cut) {
-          //截断得数量
-          $this.data_section = Math.ceil($this.record.play_time / $five_min)
-        }
-        $this.record.play_time = formatSeconds($this.record.play_time)
-      })
+      setTimeout(() => {
+        gameDetail($record_id).then((res) => {
+          console.log('get_game_detail', res)
+          Toast.clear()
+          let $res = res.data;
+          $this.record = $res.data
+          //5分钟阶段
+          let $five_min = 5 * 60
+          $this.is_cut = $this.record.play_time > $five_min
+          if ($this.is_cut) {
+            //截断得数量
+            $this.data_section = Math.ceil($this.record.play_time / $five_min)
+          }
+          $this.record.play_time = formatSeconds($this.record.play_time)
+        })
+      }, 800)
     },
     get_game_line($record_id) {
       let $params = {
@@ -170,7 +173,7 @@ export default {
         setTimeout(() => {
           let $line_data = $res.data.line
           if ($this.is_cut) {
-          //需要截断数据
+            //需要截断数据
             let $more_than_count = $line_data.length % $this.data_section
             let i = 0
             //根据多出来的数 删除结尾得数量

+ 47 - 39
src/pages/start/index.vue

@@ -217,44 +217,48 @@ export default {
   methods: {
     //游戏结束方法
     game_finished() {
+      try {
+        bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+        //停止控制游戏
+        const countDown = $this.$mp.page.selectComponent('.control-count-down');
+        countDown.pause();
+        //取消监听低功耗蓝牙设备
+        wx.offBLECharacteristicValueChange()
+        Toast.success('已成功断开')
+        //设置游戏状态为 停止游戏
+        game_store.setters.setGameStatus(3)
+        //游戏结束重置游戏时间
+        wx.removeStorageSync('play_time')
+        //游戏结束重置游戏模式
+        game_store.setters.setMode(0)
+        //删除游戏得id
+        game_store.setters.removeToyHex()
+        //关闭游戏常亮
+        wx.setKeepScreenOn({
+          keepScreenOn: false
+        })
+        //游戏结束传送一下数据
+        $this.post_data()
 
-      //停止传输数据
-      // bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
-      // bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
-      //停止控制游戏
-      bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
-      const countDown = $this.$mp.page.selectComponent('.control-count-down');
-      countDown.pause();
-      //取消监听低功耗蓝牙设备
-      wx.offBLECharacteristicValueChange()
-      Toast.success('已成功断开')
-      //设置游戏状态为 停止游戏
-      game_store.setters.setGameStatus(3)
-      //游戏结束重置游戏时间
-      wx.removeStorageSync('play_time')
-      //游戏结束重置游戏模式
-      game_store.setters.setMode(0)
-      //删除游戏得id
-      game_store.setters.removeToyHex()
-      //关闭游戏常亮
-      wx.setKeepScreenOn({
-        keepScreenOn: false
-      })
-      //游戏结束传送一下数据
-      $this.post_data()
-      $this.game_over()
-      Toast.loading({
-        forbidClick: true,
-        message: "正在生成报告...",
-        duration: 0
-      })
-      setTimeout(() => {
-        Toast.clear()
-        $this.to_report()
-      }, 800)
+        Toast.loading({
+          forbidClick: true,
+          message: "正在生成报告...",
+          duration: 0
+        })
+        setTimeout(() => {
+          Toast.clear()
+          $this.game_over()
+          $this.to_report()
+        }, 800)
+      } catch (e) {
+        console.log('error', e)
+      }
     },
     // 时间到
     time_out() {
+      console.log('游戏结束')
+      $this.played_time = $this.play_time
+      //游戏结束
       $this.game_finished()
     },
     to_report() {
@@ -268,7 +272,6 @@ export default {
         keepScreenOn: true
       })
       wx.onBLECharacteristicValueChange((characteristic) => {
-        console.log('监听蓝牙时间获取数据')
         // console.log("收到" + $this.ab2hex(characteristic.value));
         let hexStr = $this.ab2hex(characteristic.value)
         let $data = bluetooth.get_big_data(hexStr)
@@ -277,7 +280,7 @@ export default {
         if (hexStr.substr(0, 6) == '555520') {
           //当s1为 00时 数据有效
           let $s1 = hexStr.substr(8, 2)
-          console.log("游戏中监听脑环是否带正:", $s1 == '00')
+          // console.log("游戏中监听脑环是否带正:", $s1 == '00')
           $this.device_ok = ($s1 == '00')
         }
 
@@ -328,12 +331,13 @@ export default {
     //  监听时间发生变动
     watch_time(e) {
       let $datetime = e.mp.detail
-      if ($datetime.seconds.length == 1) {
-        $datetime.seconds = '0' + $datetime.seconds
+      for (let $key in $datetime) {
+        if ($datetime[$key].toString().length == 1) {
+          $datetime[$key] = "0" + $datetime[$key]
+        }
       }
       $this.timeData = $datetime
       $this.played_time += 1
-      console.log("玩了:" + $this.played_time + "秒")
       //时间倒数
       if ($datetime.seconds == '00') {
         //  时间满一分钟 则提交一次数据
@@ -453,6 +457,7 @@ export default {
       $this.mode_item = mode_list[$this.mode - 1]
       let $origin_time = $play_time * 1000
       $this.mode_item['time'] = $origin_time - ($played_time * 1000)
+
       $this.start_game()
 
       //打开蓝牙监听
@@ -464,6 +469,9 @@ export default {
     $this = this;
   },
   onShow() {
+    if ($this.timeData.minutes == '00' && $this.timeData.seconds == '00'){
+      $this.game_finished()
+    }
   },
   onLoad(options) {
     if (options.end == 1) {

+ 2 - 3
src/utils/bluetooth.js

@@ -45,7 +45,6 @@ export default {
   },
   // 发送开启教具脑控指令
   sendControl(deviceId, serviceId, Cid) {
-    console.log("链接玩具,3参数:", deviceId, serviceId, Cid)
     const that = this
 
     // 玩具对应指令数组
@@ -631,14 +630,14 @@ export default {
         if (hexStr.substr(0, 6) == '555520') {
           //当s1为 00时 数据有效
           let $s1 = hexStr.substr(8, 2)
-          console.log("监听脑环是否带正:", $s1 == '00')
+          // console.log("监听脑环是否带正:", $s1 == '00')
           $this.device_bg = ($s1 == '00')
         }
 
         //  监听脑环电量
         let $power = that.get_device_elc(hexStr)
         if ($power) {
-          console.log("当前脑环电量:", $power)
+          // console.log("当前脑环电量:", $power)
           $this.device_power = $power
         }
         if ($power < 20 && $power > 0) {