Sfoglia il codice sorgente

处理了切换脑环,以及一些ui问题

yerong 4 anni fa
parent
commit
6cec2771dd

+ 1 - 1
dist/wx

@@ -1 +1 @@
-Subproject commit be99bbb1e7101ee7f0eaaf3979cef9cf027b565b
+Subproject commit 167a7deca720350a765c488490fe40237fc49c64

+ 0 - 1
src/components/device/connecting.vue

@@ -49,5 +49,4 @@ export default {
 </script>
 
 <style scoped>
-
 </style>

+ 2 - 4
src/components/device/toy/connecting.vue

@@ -189,19 +189,17 @@ export default {
         device_id: $this.toy_id,
         access_token: wx.getStorageSync('token')
       }
-      console.log('游戏开始参数:', $params)
       gameStart($params).then(
         (res) => {
           let $data = res.data
           let $res = $data.data
-          console.log('游戏开始返回', $data)
           if ($data.code == 0) {
             // if ($data.code) {
             Toast.success({
               message: $data.errmsg,
               onClose() {
                 //调用父级得方法游戏开始得方法
-                $this.$emit('game_start')
+                // $this.$emit('game_start')
                 //设置游戏中
                 $this.connect_toy = 4
                 //设置游戏模式
@@ -211,7 +209,7 @@ export default {
                 // 设置游戏记录id
                 game_store.setters.setGameRecordId($res['game_record_id'])
                 //设置游戏时间长
-                game_store.setters.setPlayTime($res['play_time'])
+                wx.removeStorageSync('play_time')
                 mpvue.navigateTo({
                   url: "/pages/start/main"
                 })

+ 1 - 1
src/components/index/personal.vue

@@ -45,7 +45,7 @@
                 </template>
 
               </button>
-              <view class="text-xs padding-left">有效期至 {{ userinfo['validity_time'] }}</view>
+              <view class="text-xs padding-left" v-if="userinfo.level != 1">有效期至 {{ userinfo['validity_time'] }}</view>
             </div>
           </div>
         </van-col>

+ 41 - 43
src/pages/start/index.vue

@@ -187,20 +187,7 @@ export default {
     return {
       // 使用类型 1次数 2时间 0未选择
       mode: 0,
-      mode_list: [
-        {
-          id: 2,
-          name: "会员时间消费",
-          time: 30 * 60 * 1000,
-          err_title: "本次游玩时间已用完"
-        },
-        {
-          id: 1,
-          name: "次卡(10分钟)",
-          time: 10 * 60 * 1000,
-          err_title: "您的会员消费时间已用完",
-        }
-      ],
+
       timeData: {},
       mode_item: {},
       pop_show: false,
@@ -253,9 +240,11 @@ export default {
       //设置游戏状态为 停止游戏
       game_store.setters.setGameStatus(3)
       //游戏结束重置游戏时间
-      game_store.setters.setPlayTime(0)
+      wx.removeStorageSync('play_time')
       //游戏结束重置游戏模式
       game_store.setters.setMode(0)
+      //删除游戏得id
+      game_store.setters.removeToyHex()
       //游戏结束传送一下数据
       $this.post_data()
       $this.game_over()
@@ -328,7 +317,6 @@ export default {
       $this.timeData = $datetime
       $this.played_time += 1
       console.log("玩了:" + $this.played_time + "秒")
-      $this.played_time_text = formatSeconds($this.played_time)
       //时间倒数
       if ($datetime.seconds == '00') {
         //  时间满一分钟 则提交一次数据
@@ -363,12 +351,6 @@ export default {
     },
     //  结束游戏
     game_over() {
-      // let $current_time = $this.timeData.minutes * 60 + $this.timeData.seconds
-      // let $play_time = $this.play_time - $current_time
-      // if ($this.mode == 2) {
-      //   let $userinfo = wx.getStorageSync('userinfo')
-      //   $play_time = $userinfo['play_time'] * 60 - $current_time
-      // }
       let $params = {
         game_record_id: game_store.getters.getGameRecordId(),
         type: $this.mode,
@@ -396,7 +378,6 @@ export default {
     if ($this.is_end == true) {
       $this.game_finished()
     } else {
-      $this.start_game()
       //  筛选 玩具id
       $this.toy_hex = game_store.getters.getToyHex()
       // bluetooth.sendConnect($this.toy_hex, $this._deviceId, $this._serviceId, $this._characteristicId)
@@ -404,14 +385,29 @@ export default {
       //筛选模式
       $this.mode = game_store.getters.getMode()
 
-      //获取用户游玩时间
-      let $play_time = $this.play_time = game_store.getters.getPlayTime()
-      $this.mode_list.forEach(($val, $index) => {
-        $val['time'] = $play_time * 1000
-        if ($val['id'] == $this.mode && $val['id'] == 1) {
-          $this.mode_item = $val
+
+      let mode_list = [
+        {
+          id: 1,
+          name: "次卡(10分钟)",
+          time: 10 * 60 * 1000,
+          err_title: "您的会员消费时间已用完",
+        },
+        {
+          id: 2,
+          name: "会员时间消费",
+          time: 30 * 60 * 1000,
+          err_title: "本次游玩时间已用完"
         }
-      })
+
+      ]
+      //获取用户游玩时间
+      let $played_time = $this.play_time = game_store.getters.getPlayTime() ? game_store.getters.getPlayTime() : 0
+      $this.mode_item = mode_list[$this.mode - 1]
+      let $origin_time = mode_list[$this.mode - 1]['time']
+      $this.mode_item['time'] = $origin_time - ($played_time * 1000)
+      $this.start_game()
+
       bluetooth.watch_bluetooth_status($this)
     }
 
@@ -427,19 +423,21 @@ export default {
     }
   },
   onUnload() {
-    // 返回 的时候 暂停
-    const countDown = $this.$mp.page.selectComponent('.control-count-down');
-    countDown.pause();
-    //停止传输数据
-    bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
-    bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
-    wx.offBLECharacteristicValueChange()
-    //存储时间
-    let $play_time = $this.timeData.minutes * 60 + $this.timeData.seconds
-    game_store.setters.setPlayTime($play_time)
-    this.pop_show = false
-    //设置未结束游戏
-    $this.is_end = false
+    if (!$this.is_end) {
+      // 返回 的时候 暂停
+      const countDown = $this.$mp.page.selectComponent('.control-count-down');
+      countDown.pause();
+      //停止传输数据
+      bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
+      bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
+      wx.offBLECharacteristicValueChange()
+      //存储时间
+      game_store.setters.setPlayTime($this.played_time)
+      this.pop_show = false
+      //设置未结束游戏
+      $this.is_end = false
+    }
+
   }
 }
 </script>

+ 0 - 1
src/requests/game.js

@@ -1,5 +1,4 @@
 import fly from "./main";
-import store from "@/store/index"
 
 // 设备列表
 export function game_devices($params = {}) {

+ 3 - 0
src/store/game.js

@@ -23,6 +23,9 @@ const setters = {
   setToyHex(toy_hex) {
     wx.setStorageSync('toy_hex', toy_hex)
   },
+  removeToyHex(){
+    wx.removeStorageSync('toy_hex')
+  },
   setMode(mode) {
     wx.setStorageSync('mode', mode)
   },

+ 2 - 1
src/utils/bluetooth.js

@@ -381,6 +381,7 @@ export default {
 
 //  监听蓝牙连接状态
   watch_bluetooth_status($that) {
+    let that = this
     wx.onBLEConnectionStateChange((res) => {
       // 该方法回调中可以用于处理连接意外断开等异常情况
       if (res.connected == false) {
@@ -495,7 +496,7 @@ export default {
         wx.offBLECharacteristicValueChange()
       } else {
         $count++
-        if ($count == 10) {
+        if ($count == 15) {
           Toast.clear()
           $this.change_toy_connect_status(3)
           wx.offBLECharacteristicValueChange()