Pārlūkot izejas kodu

蓝牙设备连接检测玩具连接状态,优化蓝牙发送数据

yerong 4 gadi atpakaļ
vecāks
revīzija
84780d6682

+ 1 - 1
dist/wx

@@ -1 +1 @@
-Subproject commit 1fbb004619cfa489833e1c5b2b779420d652d9af
+Subproject commit e2ba50bd1e30081e97b1427490c45a244b5a2cc5

+ 12 - 4
src/components/device/device.vue

@@ -38,6 +38,7 @@
             :connect_toy="connect_toy"
             :deviceId="_deviceId"
             :toy_id="toy_action"
+            :toy="toy_list[toy_action - 1]"
             @open_choose_toy="open_choose_toy"
             @change_toy_connect_status="change_toy_connect_status"
             @change_status="change_device_status"
@@ -219,7 +220,11 @@ export default {
       bluetooth.getBLEDeviceServices($this._deviceId)
       setTimeout(() => {
         console.log($this._deviceId, bluetooth.serviceId, bluetooth.cid)
-        bluetooth.getConnectedToy($this._deviceId, bluetooth.serviceId, bluetooth.cid)
+        bluetooth.sendConnect(toy_hex, $this._deviceId, bluetooth.serviceId, bluetooth.cid, Toast)
+        setTimeout(() => {
+          bluetooth.watching_toy($this, $this._deviceId, bluetooth.serviceId, bluetooth.cid, Toast)
+        }, 800)
+
       }, 1000)
 
 
@@ -227,17 +232,20 @@ export default {
       let $game_status = game_store.getters.getGameStatus;
       console.log("choose_ok_game_status", $game_status);
       if ($game_status == 1) {
-        $this.connect_toy = 4;
+        $this.change_toy_connect_status(4)
         mpvue.navigateTo({
           url: "/pages/start/main",
         });
-      } else {
-        $this.connect_toy = 2;
       }
     },
     //修改玩具连接状态
     change_toy_connect_status($status = 0) {
       $this.connect_toy = $status;
+      if ($status == 1) {
+        $this.connect_show = true
+      } else {
+        $this.connect_show = false
+      }
     },
     //  修改设备连接状态
     change_device_status($status = 0) {

+ 5 - 3
src/components/device/toy/connecting.vue

@@ -35,10 +35,10 @@
       </van-col>
       <van-col span="5" offset="0">
         <div class="device_bg flex flex-direction align-center justify-center">
-          <img src="https://img.shuimuai.com/web/uav.png" alt="" class="uav_toy">
+          <img :src="toy['img']" alt="" class="uav_toy">
           <text class="text-gray device_text">
             <template v-if="connect_toy == 1 || connect_toy == 3">
-              智能喷雾恐龙
+              {{ toy['name'] }}
             </template>
             <template v-if="connect_toy == 2 || connect_toy == 4">
               已连接
@@ -159,11 +159,12 @@
 import {gameStart} from "@/requests/game";
 import Toast from "../../../../static/vant/toast/toast";
 import game_store from '../../../store/game'
+import bluetooth from "../../../utils/bluetooth";
 
 let $this;
 export default {
   name: "connected",
-  props: ['connect_toy', 'deviceId', 'toy_id'],
+  props: ['connect_toy', 'deviceId', 'toy_id', 'toy'],
   data() {
     return {
       pay_window: false,
@@ -177,6 +178,7 @@ export default {
     },
     //打开选择消费的选项框
     choose_pay_window() {
+      // bluetooth.watching_toy($this, bluetooth.deviceId, bluetooth.serviceId, bluetooth.cid, Toast)
       $this.pay_window = true
     },
     //选择消费的时间或者次数

+ 6 - 6
src/components/index/login.vue

@@ -71,12 +71,12 @@ export default {
 
     }
     // 测试注释
-    // else {
-    //   // 跳转到关于水母页面
-    //   mpvue.reLaunch({
-    //     url: "/pages/none/main"
-    //   })
-    // }
+    else {
+      // 跳转到关于水母页面
+      mpvue.reLaunch({
+        url: "/pages/none/main"
+      })
+    }
   }
 }
 </script>

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

@@ -150,10 +150,9 @@
 </template>
 
 <script>
-import {userDetail} from "../../requests/user";
+import { userUpdateLoginTime} from "../../requests/user";
 import {couponReceiveFirst} from "../../requests/coupons";
 import Toast from '../../../static/vant/toast/toast';
-import {formatTime} from "../../utils";
 import {reload_userinfo} from "../../utils/user";
 
 var $this
@@ -174,6 +173,12 @@ export default {
         let $res = res.data;
         if ($res.code == 0) {
           $this.first = false
+          userUpdateLoginTime().then((res) => {
+            let $res = res.data
+            $this.userinfo['login_time'] = $res.data
+            $this.$store.commit('set_userinfo', $this.userinfo)
+            reload_userinfo($this)
+          })
           Toast.success($res.errmsg)
         } else {
           Toast.fail($res.errmsg)

+ 3 - 3
src/components/static/device.css

@@ -1,6 +1,6 @@
 #device_container {
   position: relative;
-  top: -80px;
+  top: -65px;
 }
 
 .head .line {
@@ -130,7 +130,7 @@
 
 /*玩具图片*/
 .toy_img {
-  width: 35px;
+  width: 65px;
   height: 65px;
 }
 
@@ -214,7 +214,7 @@
 }
 
 /* 测试标签 */
-/* toy_item_action_bg   toy_item_normal_bg  
+/* toy_item_action_bg   toy_item_normal_bg
 
   toy_list_content
 

+ 6 - 1
src/pages/game_record/index.css

@@ -30,5 +30,10 @@
   position: absolute;
   bottom: 50px;
   width: 100%;
-  background-color: rgba(255,255,255,0);
+  background-color: rgba(255, 255, 255, 0);
+}
+
+.record_list {
+  height: 350px;
+  overflow-y: scroll;
 }

+ 45 - 29
src/pages/game_record/index.vue

@@ -5,7 +5,7 @@
       <div class="header text-center">
         <view class="padding">
           <text class="title">
-            1小时23分12
+            {{ total }}
           </text>
         </view>
         <view>
@@ -25,17 +25,19 @@
 
       <!--    列表模块-->
       <van-cell-group>
-        <van-cell is-link :title="item.toy"
-                  :value="item.time"
-                  v-for="(item,index) in items"
-                  :key="index"
-                  @click="to_report(item.id)"/>
+        <div class="record_list">
+          <van-cell is-link :title="item.toy"
+                    :value="item.time"
+                    v-for="(item,index) in items"
+                    :key="index"
+                    @click="to_report(item.id)"/>
+        </div>
       </van-cell-group>
     </div>
 
     <!--    标签筛选-->
     <van-tabs :active="active_date" @change="change_date" class="filter_date">
-      <van-tab :title="date" v-for="(date,index) in dates" :key="index"></van-tab>
+      <van-tab :title="date.name" v-for="(date,index) in dates" :key="index"></van-tab>
     </van-tabs>
   </div>
 </template>
@@ -43,58 +45,72 @@
 <script>
 
 
+import {gameList} from "../../requests/game";
+
+var $this
 export default {
   name: "game_record_container",
   components: {},
   data() {
     return {
-      items: [
+      items: [],
+      total: 0,
+      dates: [
         {
           id: 1,
-          toy: "喷雾恐龙",
-          time: "35分12秒"
+          name: "全部"
         },
         {
           id: 2,
-          toy: "喷水音箱",
-          time: "20分02秒"
+          name: "今日",
+          start_time: Math.round(new Date(new Date(new Date().toLocaleDateString()).getTime()).getTime() / 1000),
+          end_time: Math.round(new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1).getTime() / 1000)
         },
         {
           id: 3,
-          toy: "飞行器",
-          time: "35分12秒"
+          name: "昨日",
+          start_time: Math.round(new Date(new Date(new Date().toLocaleDateString()).getTime() - 24 * 60 * 60 * 1000).getTime() / 1000),
+          end_time: Math.round(new Date(new Date(new Date().toLocaleDateString()).getTime() - 1000).getTime() / 1000)
         },
         {
           id: 4,
-          toy: "飞行器",
-          time: "35分12秒"
-        },
-      ],
-      dates: [
-        '今天',
-        '昨天',
-        '9月12日',
-        '9月10日',
-        '9月9日',
-        '9月8日',
-        '9月7日',
+          name: "近七日",
+          start_time: Math.round(new Date(new Date(new Date().toLocaleDateString()).getTime() - 7 * 24 * 60 * 60 * 1000).getTime() / 1000),
+          end_time: Math.round(new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1).getTime() / 1000)
+        }
       ],
       active_date: 0
     }
   },
   methods: {
     change_date($event) {
-      let $date = $event.mp.detail
-      console.log($date)
+      let $item = $this.dates[$event.mp.detail.index]
+      $this.get_game_list($item)
     },
     to_report($event) {
 
       mpvue.navigateTo({
-        url: "/pages/game_record/main?id=" + $event
+        url: "/pages/report/main?id=" + $event
       })
+    },
+    get_game_list($params = {}) {
+      gameList($params).then((res) => {
+          let $res = res.data;
+          $this.items = $res.data.list
+          let $total_second = $res.data.total
+          $this.total = $res.data.total
+        },
+        (err) => {
+          console.log(err)
+        }
+      )
     }
   },
   mounted() {
+    $this.get_game_list()
+  },
+  created() {
+    $this = this
   }
 }
 </script>

+ 25 - 11
src/pages/report/index.vue

@@ -64,10 +64,10 @@
           <text v-if="record.consumption_type==1">次卡</text>
           <text v-if="record.consumption_type==2">时间卡</text>
         </view>
-        <view>会员游玩时间: {{record.play_time}}秒</view>
+        <view>会员游玩时间: {{ record.play_time }}秒</view>
       </view>
       <view class="right">
-        <view>专注力训练时长: {{record.play_time}}秒</view>
+        <view>专注力训练时长: {{ record.play_time }}秒</view>
       </view>
     </view>
 
@@ -78,7 +78,7 @@
 import mpvueEcharts from 'mpvue-echarts'
 import echarts from '../../../static/echarts.min';
 import util from '../../utils/index'
-import {gameDetail} from "../../requests/game";
+import {gameDetail, gameLineChart} from "../../requests/game";
 import game_store from "../../store/game";
 
 var att_charts,
@@ -111,34 +111,48 @@ export default {
       attCharts: initAttChart,
       echarts,
       record: {},
-      userinfo: {}
+      userinfo: {},
+      record_id: 0
     }
   },
   methods: {
     //  获取游戏报告
-    get_report() {
-      let $record_id = game_store.getters.getGameRecordId
+    get_report($record_id) {
       gameDetail($record_id).then((res) => {
         let $res = res.data;
         $this.record = $res.data
       })
     },
-    to_game_records(){
+    get_game_line($record_id) {
+      let $params = {
+        'game_record_id': $record_id,
+      }
+      gameLineChart($params).then((res) => {
+        let $res = res.data;
+        setTimeout(() => {
+          let $option = util.getLineOption($res.data.line, [0])
+          att_charts.setOption($option)
+        }, 1000)
+      })
+    },
+    to_game_records() {
       mpvue.navigateTo({
-        url:"/pages/game_record/main"
+        url: "/pages/game_record/main"
       })
     }
   }
   ,
   mounted() {
-    $this.get_report()
     $this.userinfo = wx.getStorageSync('userinfo')
-    $this.userinfo['level_name'] = util.get_level_name($this.userinfo.level)
+    $this.get_report($this.record_id)
+    $this.get_game_line($this.record_id)
   },
   created() {
     $this = this;
   },
-  onLoad() {
+  onLoad(options) {
+    $this.record_id = options.id ? options.id : game_store.getters.getGameRecordId
+
   }
 }
 </script>

+ 6 - 3
src/pages/start/index.vue

@@ -229,6 +229,8 @@ export default {
       bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
       const countDown = $this.$mp.page.selectComponent('.control-count-down');
       countDown.pause();
+      //取消监听低功耗蓝牙设备
+      wx.offBLECharacteristicValueChange()
       Toast.success('已成功断开')
       //设置游戏状态为 停止游戏
       game_store.commit('setGameStatus', 0)
@@ -291,7 +293,7 @@ export default {
               game_store.commit('setCid', item.uuid)
               bluetooth.sendPause(deviceId, serviceId, item.uuid)
               //获取玩具的值
-              bluetooth.sendConnect($this.toy_hex, deviceId, serviceId, item.uuid)
+              // bluetooth.sendConnect($this.toy_hex, deviceId, serviceId, item.uuid, Toast)
             }
 
             if (item.properties.notify || item.properties.indicate) {
@@ -337,7 +339,8 @@ export default {
 
         //连接玩具
         console.log('玩具hexStr', hexStr)
-        let $flag = bluetooth.connect_toy(hexStr, $this._deviceId, $this._serviceId, $this._characteristicId)
+        bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+
         //连接不上设备
         if ($flag == false) {
           // $this.game_finished()
@@ -429,7 +432,7 @@ export default {
     //获取用户游玩时间
     let $play_time = $this.play_time = game_store.getters.getPlayTime
     $this.mode_list.forEach(($val, $index) => {
-      $val['time'] = $play_time  * 1000
+      $val['time'] = $play_time * 1000
       if ($val['id'] == $this.mode) {
         $this.mode_item = $val
       }

+ 1 - 0
src/pages/start/main.json

@@ -2,6 +2,7 @@
   "usingComponents": {
     "van-row": "../../static/vant/row/index",
     "van-col": "../../static/vant/col/index",
+    "van-toast": "../../static/vant/toast/index",
     "van-popup": "../../static/vant/popup/index",
     "van-count-down": "../../static/vant/count-down/index"
   }

+ 2 - 2
src/pages/user_center/edit/confirm_phone_finally/index.vue

@@ -60,8 +60,8 @@ export default {
   components: {},
   data() {
     return {
-      base_phone: "18802603801",
-      phone: "18802603801",
+      base_phone: "",
+      phone: "",
       sms: "",
       custom_style: `width: 330px;
             height: 49px;

+ 2 - 2
src/pages/user_center/edit/confirm_phone_first/index.vue

@@ -49,8 +49,8 @@ export default {
   components: {},
   data() {
     return {
-      base_phone: "13038899265",
-      phone: "13038899265",
+      base_phone: "",
+      phone: "",
       sms: "",
       custom_style: `width: 330px;
             height: 49px;

+ 0 - 3
src/pages/user_center/vip_code/index.vue

@@ -40,9 +40,6 @@ export default {
   },
   onLoad() {
     $this.userinfo = wx.getStorageSync('userinfo')
-    $this.userinfo['validity_time'] = utils.formatTime($this.userinfo['validity_time'])
-    $this.userinfo['level_name'] = utils.get_level_name($this.userinfo['level'])
-
   }
 }
 </script>

+ 5 - 0
src/requests/game.js

@@ -40,3 +40,8 @@ export function gameAddLine($params) {
   return fly.post('game/add-line', $params)
 }
 
+//获取游戏记录
+export function gameList($params = {}) {
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('game/game-list', $params)
+}

+ 79 - 28
src/utils/bluetooth.js

@@ -79,7 +79,7 @@ export default {
     })
   },
   // 发送连接玩具指令
-  sendConnect($hex, deviceId, serviceId, Cid) {
+  sendConnect($hex, deviceId, serviceId, Cid, Toast) {
     //获取最后两个字节
     const that = this
     // 玩具对应指令数组
@@ -109,9 +109,18 @@ export default {
       value: buffer,
       success: function (res) {
         console.log('发送连接玩具指令成功')
-        wx.showLoading({
-          title: '正在创建连接',
-        })
+        // 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('发送连接玩具指令失败')
@@ -197,7 +206,9 @@ export default {
     })
   },
   // 通过字节码获取玩具
-  connect_toy(hexStr, deviceId, serviceId, Cid) {
+  connect_toy(hexStr, deviceId, serviceId, Cid, Toast) {
+    console.log('开始连接玩具')
+    let $flag = ""
     let $toys = [
       {
         id: 1,
@@ -208,13 +219,13 @@ export default {
       {
         id: 1,
         hex: 'aadd0a0001',
-        msg: "已连接到水柱音箱",
+        msg: "已连接到智脑水舞",
         flag: true
       },
       {
         id: 2,
         hex: 'aadd0a0002',
-        msg: "已连接到喷雾恐龙(大)",
+        msg: "已连接到智脑恐龙",
         flag: true
       },
       {
@@ -226,19 +237,19 @@ export default {
       {
         id: 4,
         hex: 'aadd0a0004',
-        msg: "已连接到轨道车",
+        msg: "已连接到智脑赛车",
         flag: true
       },
       {
         id: 5,
         hex: 'aadd0a0005',
-        msg: "已连接到碰碰车",
+        msg: "已连接到智脑碰碰车",
         flag: true
       },
       {
         id: 6,
         hex: 'aadd0a0006',
-        msg: "已连接到小车(大)",
+        msg: "已连接到智脑SUV赛车",
         flag: true
       },
       {
@@ -256,7 +267,7 @@ export default {
       {
         id: 9,
         hex: 'aadd0a0009',
-        msg: '已连接到飞行器(大)',
+        msg: '已连接到智脑无人机',
         flag: true
       },
       {
@@ -281,31 +292,24 @@ export default {
 
     $toys.forEach(($val, $index) => {
       if (hexStr.substring(0, 10) == $val['hex']) {
+        Toast.clear()
         if ($val['flag']) {
-          wx.hideLoading()
-          wx.showToast({
-            title: $val['msg'],
-            icon: 'success',
-            duration: 1500
-          })
-          console.log($val['msg'])
-          this.sendControl(deviceId, serviceId, Cid)
+          Toast.success($val['msg'])
+          let $game_status = game_store.getters.getGameStatus;
+          if ($game_status == 1) {
+            this.sendControl(deviceId, serviceId, Cid)
+          }
         } else {
           if ($val['hex'] == 'aadd070000') {
             this.sendOpen(deviceId, serviceId, Cid)
           } else {
-            wx.hideLoading()
-            wx.showToast({
-              title: $val['msg'],
-              icon: 'nones',
-              duration: 1500
-            })
+            Toast.fail($val['msg'])
           }
         }
-        return $val['flag']
+        $flag = $val['flag']
       }
-
     })
+    return $flag
   },
 
   //  获取大包数据 进行绘制图表
@@ -452,6 +456,42 @@ export default {
       }
     })
   },
+  //监听玩具得状态
+  watching_toy($this, deviceId, serviceId, Cid, Toast) {
+    Toast.clear()
+    Toast.loading({
+      duration: 0,
+      forbidClick: false,
+      message: "检测连接中"
+    })
+    let that = this
+    let $count = 0
+    //关闭核销选项窗口
+    // $this.pay_window = false
+    wx.onBLECharacteristicValueChange((characteristic) => {
+      console.log("收到" + that.ab2hex(characteristic.value));
+      let hexStr = that.ab2hex(characteristic.value)
+      //连接玩具
+      let $flag = that.connect_toy(hexStr, deviceId, serviceId, Cid, Toast)
+      //连接不上设备
+      if ($flag) {
+        Toast.clear()
+        //连接成功 打开核销窗口
+        // $this.pay_window = true
+        $this.change_toy_connect_status(2)
+        wx.offBLECharacteristicValueChange()
+      } else {
+        $count++
+        if ($count == 10) {
+                  Toast.clear()
+          $this.change_toy_connect_status(3)
+          wx.offBLECharacteristicValueChange()
+        }
+      }
+      // 取消监听低功耗蓝牙设备
+    })
+  },
+
 
 //  获取当前连接得玩具
   getConnectedToy(deviceId, serviceId, Cid) {
@@ -486,5 +526,16 @@ export default {
         console.log(err)
       }
     })
-  }
+  },
+  // ArrayBuffer转16进度字符串示例
+  ab2hex(buffer) {
+    var hexArr = Array.prototype.map.call(
+      new Uint8Array(buffer),
+      function (bit) {
+        return ('00' + bit.toString(16)).slice(-2)
+      }
+    )
+    return hexArr.join('');
+  },
+
 }