rong air 4 lat temu
rodzic
commit
770deb6865

+ 11 - 2
src/components/device/device.vue

@@ -144,7 +144,7 @@ export default {
       toy_action: 1,
       // connect_show: true,
       //连接玩具 0:未连接 1:连接中 2:已连接 3:连接失败 4:游戏中
-        connect_toy: 0,
+      connect_toy: 0,
       code: "jellyfish1234",
       device: {},
       _deviceId: "",
@@ -253,12 +253,21 @@ export default {
     change_device_status($status = 0) {
       $this.status = $status;
       //当蓝牙连接已断开
+      //当脑环断开
       if ($status == 0) {
+        let $deviceId = game_store.getters.getDeviceId
+        let $serviceId = game_store.getters.getServiceId
+        let $cid = game_store.getters.getCharacterId
+        bluetooth.shutdownSendControl($deviceId, $serviceId, $cid)
+        // 清空链接得设备 三值
+        game_store.commit('clearDeviceToy')
         $this.connect_toy = $status;
         $this.connect_show = false;
         wx.closeBLEConnection({
           deviceId: $this._deviceId,
           success(res) {
+            wx.closeBluetoothAdapter()
+
             Toast.success({
               message: "已成功断开"
             });
@@ -326,7 +335,7 @@ export default {
           //成功连接脑环蓝牙
           $this.change_device_status(2);
           bluetooth.watch_bluetooth_status($this)
-          // $this.getBLEDeviceServices($this.device.deviceId)
+          // bluetooth.getBLEDeviceServices($this.device.deviceId)
         },
         fail(err) {
           console.log("err", err);

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

@@ -179,7 +179,7 @@ export default {
   background-position: center;
   background-size: 100% 100%;
   width: 100%;
-  height: 235px;
+  height: 250px;
 }
 
 .text-normal {

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

@@ -50,7 +50,7 @@
     <view class="chart">
       <mpvue-echarts :echarts="echarts" :onInit="attCharts" canvasId="demo-canvas"/>
     </view>
-    <view class="conclution">专注力良好,你的表现比一般人好。专注力波动较大,比较容易被外界干扰。你大多数时候不能很好地集中注意力,请继续加油。</view>
+    <view class="conclution">{{ record.content }}</view>
     <view class="bar">
       <view>
         <view class="line"></view>
@@ -290,7 +290,7 @@ image.boy {
 .conclution {
   width: 100%;
   padding: 5px 19px 20px;
-  font-size: 10px;
+  font-size: 12px;
   color: #6C6C6C;
   box-sizing: border-box;
 }
@@ -323,7 +323,7 @@ image.boy {
 /* 核销详情 */
 .sheet {
   color: #6D6D6D;
-  font-size: 10px;
+  font-size: 12px;
   display: flex;
   padding: 0 16px;
   box-sizing: border-box;

+ 34 - 14
src/pages/start/index.vue

@@ -11,7 +11,8 @@
             <van-count-down :time="mode_item.time" format="mm:ss" use-slot auto-start @finish="time_out"
                             @change="watch_time" class="control-count-down"
             >
-              <text>{{ timeData.minutes }}:{{ timeData.seconds }}</text>
+              <text v-if="mode == 1">{{ timeData.minutes }}:{{ timeData.seconds }}</text>
+              <text v-if="mode == 2">{{ played_time_text }}</text>
             </van-count-down>
           </view>
         </van-col>
@@ -130,7 +131,7 @@
 <script>
 import mpvueEcharts from 'mpvue-echarts'
 import echarts from '../../../static/echarts.min';
-import util from '../../utils/index'
+import util, {formatSeconds} from '../../utils/index'
 import bluetooth from "../../utils/bluetooth";
 import game_store from "@/store/game";
 import Toast from '../../../static/vant/toast/toast';
@@ -215,8 +216,8 @@ export default {
       play_time: 0,
 
       //图标数据集合
-      att_list: [],
-      med_list: [],
+      att_list: [0],
+      med_list: [0],
       delta_list: [],
       alpha_list: [],
       beta_list: [],
@@ -224,17 +225,19 @@ export default {
       //判断是否结束游戏
       is_end: false,
       //  消耗的时间
-      played_time: 0
+      played_time: 0,
+      played_time_text: ""
     }
   },
   methods: {
     //游戏结束方法
     game_finished() {
+
+      //停止传输数据
+      bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
+      bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
       //停止控制游戏
-      // 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();
       //取消监听低功耗蓝牙设备
@@ -255,7 +258,8 @@ export default {
     },
     // 时间到
     time_out() {
-      $this.pop_show = true
+      // $this.pop_show = true
+      $this.game_finished()
     },
     to_report() {
       mpvue.reLaunch({
@@ -264,20 +268,27 @@ export default {
     },
     //获取蓝牙设备服务
     getBLEDeviceServices(deviceId) {
+      console.log('获取蓝牙设备服务', deviceId)
       wx.getBLEDeviceServices({
         deviceId,
         success: (res) => {
+          console.log('获取蓝牙设备服务成功')
           for (let i = 0; i < res.services.length; i++) {
             if (res.services[i].isPrimary) {
               this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid)
               return
             }
           }
+        },
+        fail(res) {
+
+          console.log('获取蓝牙设备失败', res)
         }
       })
     },
     //获取蓝牙设备某个服务中所有特征值
     getBLEDeviceCharacteristics(deviceId, serviceId) {
+      console.log('获取蓝牙设备某个服务中所有特征值')
       wx.getBLEDeviceCharacteristics({
         deviceId,
         serviceId,
@@ -293,7 +304,6 @@ export default {
               })
             }
             if (item.properties.write) {
-              $this.canWrite = true
               $this._deviceId = deviceId
               $this._serviceId = serviceId
               $this._characteristicId = item.uuid
@@ -320,10 +330,16 @@ export default {
         }
       })
       // 操作之前先监听,保证第一时间获取数据
+      $this.start_game()
+    },
+
+    start_game() {
       wx.onBLECharacteristicValueChange((characteristic) => {
+        console.log('监听蓝牙时间获取数据')
         // console.log("收到" + $this.ab2hex(characteristic.value));
         let hexStr = $this.ab2hex(characteristic.value)
         let $data = bluetooth.get_big_data(hexStr)
+        //连接玩具
         if ($data) {
           $this.att_list.push($data['att'])
           $this.med_list.push($data['med'])
@@ -345,10 +361,10 @@ export default {
         if ($power) {
           $this.elc_power = $power
         }
-
-        //连接玩具
         bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+
       })
+
     },
 
     // ArrayBuffer转16进度字符串示例
@@ -368,7 +384,7 @@ 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') {
         //  时间满一分钟 则提交一次数据
@@ -383,6 +399,9 @@ export default {
         line: $this.att_list,
         line_med: $this.med_list
       }
+      if (!$params.line && !$params.line_med) {
+        return false
+      }
       gameAddLine($params).then((res) => {
         let $data = res.data
         if ($data.code == 0) {
@@ -428,6 +447,7 @@ export default {
       $this.game_finished()
     } else {
       $this._deviceId = game_store.getters.getDeviceId
+      console.log("游戏开始:当前device_id", $this._deviceId)
       $this.getBLEDeviceServices($this._deviceId)
 
       //  筛选 玩具id
@@ -655,7 +675,7 @@ export default {
   line-height: 24px;
 }
 
-.err_img{
+.err_img {
   width: 73px;
   height: 83px;
 }

+ 6 - 6
src/pages/user_center/vip_code/index.vue

@@ -15,9 +15,9 @@
         </view>
       </view>
       <img src="https://img.shuimuai.com/web/demo_code.png" class="qrcode margin-xl" alt="">
-<!--      <view class="text-center">-->
-<!--        <text class="text-normal ">{{ invite_code }}</text>-->
-<!--      </view>-->
+      <view class="text-center">
+        <text class="text-normal ">邀请卡:&emsp;{{ userinfo.invite_id }}</text>
+      </view>
     </div>
   </div>
 </template>
@@ -51,7 +51,7 @@ export default {
 </script>
 
 <style scoped>
-.uc_vip_code_container{
+.uc_vip_code_container {
   padding: 80px 0px;
 }
 
@@ -114,9 +114,9 @@ export default {
 
 }
 
-.qrcode{
+.qrcode {
   width: 139px;
-height: 139px;
+  height: 139px;
 
 }
 </style>

+ 20 - 6
src/store/game.js

@@ -21,6 +21,14 @@ export default new Vuex.Store({
     play_time: 0
   },
   mutations: {
+    clearDeviceToy(state) {
+      state.deviceId = ""
+      state.serviceId = ""
+      state.characteristicId = ""
+      wx.removeStorageSync('deviceId')
+      wx.removeStorageSync('serviceId')
+      wx.removeStorageSync('characteristicId')
+    },
     setDeviceId(state, deviceId) {
       state.deviceId = deviceId
       wx.setStorageSync('deviceId', deviceId)
@@ -34,21 +42,27 @@ export default new Vuex.Store({
       wx.setStorageSync('characteristicId', characteristicId)
     },
     setGameStatus(state, status) {
+      wx.setStorageSync('status', status)
       state.game_status = status
     },
     setToyList(state, toy_list) {
+      wx.setStorageSync('toy_list', toy_list)
       state.toy_list = toy_list
     },
     setToyHex(state, toy_hex) {
+      wx.setStorageSync('toy_hex', toy_hex)
       state.toy_hex = toy_hex
     },
     setMode(state, mode) {
+      wx.setStorageSync('mode', mode)
       state.mode = mode
     },
     setGameRecordId(state, param) {
+      wx.setStorageSync('game_record_id', param)
       state.game_record_id = param
     },
     setPlayTime(state, param) {
+      wx.setStorageSync('play_time', param)
       state.play_time = param
     }
   },
@@ -63,22 +77,22 @@ export default new Vuex.Store({
       return wx.getStorageSync('characteristicId')
     },
     getGameStatus(state) {
-      return state.game_status
+      return wx.getStorageSync('game_status')
     },
     getToyList(state) {
-      return state.toy_list
+      return wx.getStorageSync('toy_list')
     },
     getToyHex(state) {
-      return state.toy_hex
+      return wx.getStorageSync('toy_hex')
     },
     getMode(state) {
-      return state.mode
+      return wx.getStorageSync('mode')
     },
     getGameRecordId(state) {
-      return state.game_record_id
+      return wx.getStorageSync('game_record_id')
     },
     getPlayTime(state) {
-      return state.play_time
+      return wx.getStorageSync('play_time')
     }
   },
 

+ 4 - 0
src/utils/bluetooth.js

@@ -43,6 +43,7 @@ export default {
   },
   // 发送开启教具脑控指令
   sendControl(deviceId, serviceId, Cid) {
+    console.log("链接玩具,3参数:", deviceId, serviceId, Cid)
     const that = this
 
     // 玩具对应指令数组
@@ -413,6 +414,9 @@ export default {
             return
           }
         }
+      },
+      fail(res){
+        console.log('连接蓝牙成功,获取服务失败')
       }
     })
   },