Ver código fonte

功能完善

rong air 4 anos atrás
pai
commit
a8490c43d9

+ 13 - 8
src/components/device/device.vue

@@ -143,6 +143,7 @@ export default {
       device: {},
       _deviceId: "",
       _device_index: false,
+      toy_id: 0
     };
   },
   watch: {
@@ -212,6 +213,7 @@ export default {
       $this._device_index = $this.toy_action - 1;
       //获取玩具
       let $toy = $this.toy_list[$this.toy_action - 1];
+      $this.toy_id = $toy.id
       let $hex = $toy["hex"].substr($toy["hex"].length - 2, 2);
       let toy_hex = "0x" + $hex;
       game_store.commit("setToyHex", toy_hex);
@@ -229,14 +231,14 @@ export default {
 
 
       //判断是否游戏中
-      let $game_status = game_store.getters.getGameStatus;
-      console.log("choose_ok_game_status", $game_status);
-      if ($game_status == 1) {
-        $this.change_toy_connect_status(4)
-        mpvue.navigateTo({
-          url: "/pages/start/main",
-        });
-      }
+      // let $game_status = game_store.getters.getGameStatus;
+      // console.log("choose_ok_game_status", $game_status);
+      // if ($game_status == 1) {
+      //   $this.change_toy_connect_status(4)
+      //   mpvue.navigateTo({
+      //     url: "/pages/start/main",
+      //   });
+      // }
     },
     //修改玩具连接状态
     change_toy_connect_status($status = 0) {
@@ -284,6 +286,9 @@ export default {
           if (!device.name && !device.localName) {
             return;
           }
+          if (device.localName && (device.localName != '')) {
+            device.name = device.localName
+          }
           console.log(device["name"]);
           if (device["name"] == $this.code) {
             $this.stopBluetoothDevicesDiscovery();

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

@@ -186,9 +186,10 @@ export default {
       $this.pay_type = $event
       let $params = {
         type: $event,
-        device_id: $this.deviceId,
+        device_id: $this.toy_id,
         access_token: wx.getStorageSync('token')
       }
+      console.log('游戏开始参数:', $params)
       gameStart($params).then(
         (res) => {
           let $data = res.data

+ 11 - 7
src/components/index/personal.vue

@@ -128,7 +128,7 @@
     </van-popup>
 
     <!--    窗口弹出-->
-    <van-popup :show="pop_show" @close="close_pop" round :close-on-click-overlay="false">
+    <van-popup :show="pop_show" @close="close_pop" round>
       <div class="err_container flex flex-direction align-center justify-around">
         <view>
           <text class="title">
@@ -150,7 +150,7 @@
 </template>
 
 <script>
-import { userUpdateLoginTime} from "../../requests/user";
+import {userUpdateLoginTime} from "../../requests/user";
 import {couponReceiveFirst} from "../../requests/coupons";
 import Toast from '../../../static/vant/toast/toast';
 import {reload_userinfo} from "../../utils/user";
@@ -207,13 +207,17 @@ export default {
     },
   },
   mounted() {
-    reload_userinfo($this)
-    $this.userinfo = wx.getStorageSync('userinfo')
-    if ($this.userinfo.login_time == 0) {
+    let $userinfo = wx.getStorageSync('userinfo')
+    if ($userinfo['login_time'] == 0) {
+      console.log('第一次登录')
       $this.first = true
-    } else if ($this.userinfo.play_time == 0) {
-      $this.pop_show = true
+    } else {
+      $this.first = false
     }
+    $this.userinfo = $userinfo
+    // else if ($this.userinfo.play_time == 0) {
+    //   $this.pop_show = true
+    // }
   }
   ,
   onShow() {

+ 3 - 3
src/pages/game_record/index.vue

@@ -26,11 +26,11 @@
       <!--    列表模块-->
       <van-cell-group>
         <div class="record_list">
-          <van-cell is-link :title="item.toy"
-                    :value="item.time"
+          <van-cell is-link :title="item.name"
+                    :value="item.play_time"
                     v-for="(item,index) in items"
                     :key="index"
-                    @click="to_report(item.id)"/>
+                    @click="to_report(item.game_record_id)"/>
         </div>
       </van-cell-group>
     </div>

+ 2 - 2
src/pages/index/index.css

@@ -42,12 +42,12 @@
 
 /* 功能服务 */
 .service {
-  position: absolute;
+  position: relative;
   width: 100%;
   padding: 5px 7px 35px;
   margin-top: 20px;
   /* top: 520px; */
-  top: 540px;
+  top: 10px;
 }
 
 .service .content {

+ 1 - 1
src/pages/report/index.vue

@@ -152,7 +152,7 @@ export default {
   },
   onLoad(options) {
     $this.record_id = options.id ? options.id : game_store.getters.getGameRecordId
-
+    console.log($this.record_id)
   }
 }
 </script>

+ 17 - 9
src/pages/start/index.vue

@@ -227,6 +227,8 @@ export default {
       //停止控制游戏
       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();
       //取消监听低功耗蓝牙设备
@@ -401,11 +403,15 @@ export default {
         let $userinfo = wx.getStorageSync('userinfo')
         $play_time = $userinfo['play_time'] - $current_time
       }
+      console.log('当前结束时间', $current_time)
+      console.log('游玩时间:', $this.play_time)
       let $params = {
-        record_id: game_store.getters.getGameRecordId,
+        game_record_id: game_store.getters.getGameRecordId,
         type: $this.mode,
         play_time: $play_time
       }
+      console.log("结束游戏参数", $params)
+      //
       gameEnd($params).then((res) => {
         let $data = res.data
       })
@@ -444,14 +450,16 @@ export default {
   onLoad() {
   },
   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)
-
-    let $play_time = $this.timeData.minutes * 60 + $this.timeData.seconds
-    console.log($play_time)
-    game_store.commit('setPlayTime', $play_time)
+    // 返回 的时候 暂停
+    // 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)
+
+    // let $play_time = $this.timeData.minutes * 60 + $this.timeData.seconds
+    // console.log($play_time)
+    // game_store.commit('setPlayTime', $play_time)
+    this.pop_show = false
   }
 }
 </script>

+ 56 - 5
src/utils/bluetooth.js

@@ -124,10 +124,8 @@ export default {
       },
       fail: function (err) {
         console.log('发送连接玩具指令失败')
-        wx.showModal({
-          showCancel: false,
-          title: '提示',
-          content: '指令发送失败',
+        Toast.fail({
+          message:"玩具连接失败"
         })
         console.log(err)
       }
@@ -485,11 +483,15 @@ export default {
         //连接成功 打开核销窗口
         // $this.pay_window = true
         $this.change_toy_connect_status(2)
+        let $game_status = game_store.getters.getGameStatus;
+        if ($game_status == 1) {
+          $this.change_toy_connect_status(4)
+        }
         wx.offBLECharacteristicValueChange()
       } else {
         $count++
         if ($count == 10) {
-                  Toast.clear()
+          Toast.clear()
           $this.change_toy_connect_status(3)
           wx.offBLECharacteristicValueChange()
         }
@@ -543,5 +545,54 @@ export default {
     )
     return hexArr.join('');
   },
+  //断开发送数据
+  shutdownSendControl(deviceId, serviceId, Cid) {
+    let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x0a) ^ 0xFFFFFFFF) & 0xFF
+    let $CheckSum = "0x" + CheckSum.toString(16)
+
+    // 向蓝牙设备发送指令
+    let buffer = new ArrayBuffer(8)
+    let dataView = new DataView(buffer)
+    dataView.setUint8(0, '0xaa')
+    dataView.setUint8(1, '0xcc')
+    dataView.setUint8(2, '0x03')
+    dataView.setUint8(3, '0x00')
+    dataView.setUint8(4, '0x00')
+    dataView.setUint8(5, '0x00')
+    dataView.setUint8(6, '0x0a')
+    dataView.setUint8(7, $CheckSum)
+    // 向低功耗蓝牙设备特征值中写入二进制数据
+    console.log(buffer)
+    wx.writeBLECharacteristicValue({
+      deviceId: deviceId,
+      serviceId: serviceId,
+      characteristicId: Cid,
+      value: buffer,
+      success: function (res) {
+        console.log('断开连接玩具指令成功')
+        // wx.showLoading({
+        //   title: '正在创建连接',
+        // })
+
+        let $game_status = game_store.getters.getGameStatus;
+        if ($game_status == 1) {
+          Toast.loading({
+            duration: 0,
+            message: "正在创建连接",
+            forbidClick: true
+          })
+        }
+      },
+      fail: function (err) {
+        console.log('发送连接玩具指令失败')
+        wx.showModal({
+          showCancel: false,
+          title: '提示',
+          content: '指令发送失败',
+        })
+        console.log(err)
+      }
+    })
+  }
 
 }