Sfoglia il codice sorgente

微信小程序1.2.0版本
完成了脑环检测,线图流程

rong air 4 anni fa
parent
commit
63581bba09

+ 3 - 1
src/components/device/connected.vue

@@ -16,7 +16,8 @@
       </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/sign_green.png" alt="" class="sign_green">
+          <img src="https://img.shuimuai.com/web/sign_green.png" alt="" class="sign_green" v-if="device_bg == true">
+          <img src="https://img.shuimuai.com/web/sign_red.png" class="sign_green" alt="" v-else>
           <img src="https://img.shuimuai.com/web/brain.png" alt="" class="device_brain">
           <text class="text-gray device_text"> 水母智能脑环</text>
         </div>
@@ -48,6 +49,7 @@
 <script>
 export default {
   name: "connected",
+  props:['device_bg'],
   methods: {
     open_choose_toy() {
       this.$emit('open_choose_toy')

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

@@ -28,6 +28,7 @@
           <device_connected
             @open_choose_toy="open_choose_toy"
             @change_brain_status="change_device_status"
+            :device_bg="device_bg"
           ></device_connected>
         </div>
       </div>
@@ -118,6 +119,7 @@ import Toast from "../../../static/vant/toast/toast";
 import {game_devices} from "../../requests/game";
 import game_store from "@/store/game";
 import bluetooth from "@/utils/bluetooth";
+import ble_store from "../../store/bluetooth"
 import Dialog from '../../../static/vant/dialog/dialog';
 
 
@@ -136,7 +138,7 @@ export default {
       device_status: 0,
       connect_show: false,
       //设置图标的颜色
-      device_bg: true,
+      device_bg: false,
 
       choose_toy_window: {
         show: false,
@@ -240,6 +242,7 @@ export default {
 
       }, 1000)
 
+
     },
     //修改玩具连接状态
     change_toy_connect_status($status = 0) {
@@ -296,9 +299,7 @@ export default {
       try {
 
         wx.onBluetoothDeviceFound((res) => {
-          console.log(res)
           res.devices.forEach((device) => {
-            console.log(device)
             if (!device.name && !device.localName) {
               return;
             }
@@ -341,7 +342,8 @@ export default {
           //成功连接脑环蓝牙
           $this.change_device_status(2);
           bluetooth.watch_bluetooth_status($this)
-          // bluetooth.getBLEDeviceServices($this.device.deviceId)
+          bluetooth.getBLEDeviceServices($this.device.deviceId)
+          bluetooth.watchingDevice($this)
         },
         fail(err) {
           console.log("err", err);
@@ -379,7 +381,6 @@ export default {
     },
   },
   mounted() {
-
     $this.get_toy_list();
   },
   created() {
@@ -408,7 +409,11 @@ export default {
       //不在游戏状态
       $this.change_toy_connect_status(0)
       $this.connect_show = true
-      bluetooth.watch_bluetooth_status($this)
+      let $ble_status = ble_store.getters.getBluetoothLinkStatus()
+      if ($ble_status == false) {
+        //断开蓝牙连接
+        $this.change_device_status(0)
+      }
     }
   },
   onLoad(options) {

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

@@ -16,7 +16,7 @@
       </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/sign_green.png" alt="" class="sign_green" v-if="device_bg">
+          <img src="https://img.shuimuai.com/web/sign_green.png" alt="" class="sign_green" v-if="device_bg == true">
           <img src="https://img.shuimuai.com/web/sign_red.png" class="sign_green" alt="" v-else>
           <img src="https://img.shuimuai.com/web/brain.png" alt="" class="device_brain">
           <text class="text-gray device_text"> 已连接</text>
@@ -165,7 +165,7 @@ import bluetooth from "../../../utils/bluetooth";
 let $this;
 export default {
   name: "connected",
-  props: ['connect_toy', 'deviceId', 'toy_id', 'toy','device_bg'],
+  props: ['connect_toy', 'deviceId', 'toy_id', 'toy', 'device_bg'],
   data() {
     return {
       pay_window: false,
@@ -180,10 +180,18 @@ export default {
     //打开选择消费的选项框
     choose_pay_window() {
       // bluetooth.watching_toy($this, bluetooth.deviceId, bluetooth.serviceId, bluetooth.cid, Toast)
+      if (!$this.device_bg) {
+        Toast.fail("请佩戴好脑环开始游戏")
+        return false;
+      }
       $this.pay_window = true
     },
     //选择消费的时间或者次数
     choose_pay($event) {
+      if (!$this.device_bg) {
+        Toast.fail("请佩戴好脑环开始游戏")
+        return false;
+      }
       $this.pay_type = $event
       let $params = {
         type: $event,
@@ -212,7 +220,10 @@ export default {
                 //设置游戏时间长
                 wx.removeStorageSync('play_time')
                 mpvue.navigateTo({
-                  url: "/pages/start/main"
+                  url: "/pages/start/main",
+                  success() {
+                    wx.offBLECharacteristicValueChange()
+                  }
                 })
               }
             })

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

@@ -76,7 +76,7 @@ export default {
       $this.is_scan = false
       Dialog.alert({
         transition: 'fade',
-        message: '如需体验水母星球产品,请通过水母星球电源或代理商的邀请卡是扫码申请水母会员',
+        message: '如需体验水母星球产品,请通过水母星球店员或代理商的邀请卡是扫码申请水母会员',
         theme: 'round-button',
       })
     }

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

@@ -40,7 +40,7 @@
     </div>
     <view class="text-center text-xs">
       <!--      <text class="text-gray">如果您在我们实体店,请在店员的指导下连接水母智脑环</text>-->
-      <text class="text-gray">注册/登录前阅读并知晓</text><text class="text-primary" @click="change_protocol_show(true)">《用户隐私协议》</text>
+      <text class="text-gray">注册/登录前阅读并知晓</text><text class="text-primary" @click="change_protocol_show(true)">《用户隐私协议》</text>
     </view>
     <van-toast id="van-toast"/>
 

+ 50 - 15
src/pages/start/index.vue

@@ -32,10 +32,14 @@
     <div class="game_status padding-tb">
       <van-row>
         <van-col span="10" offset="2">
-          <div class="flex flex-direction align-center justify-center">
+          <div class="flex flex-direction align-center justify-center" v-if="device_ok == true">
             <img src="https://img.shuimuai.com/web/touhuanzhuangtai_2.png" alt="" class="device_img">
             <text class="text-default">已经正确佩戴</text>
           </div>
+          <div class="flex flex-direction align-center justify-center" v-else>
+            <img src="https://img.shuimuai.com/web/touhuanzhuangtai_3.png" alt="" class="device_img">
+            <text class="text-default">未正确佩戴</text>
+          </div>
         </van-col>
         <van-col span="10">
           <div class="flex flex-direction align-center justify-center">
@@ -210,17 +214,23 @@ export default {
       play_time: 0,
 
       //图标数据集合
-      att_list: [0],
-      med_list: [0],
+      att_list: [],
+      med_list: [],
       delta_list: [],
       alpha_list: [],
       beta_list: [],
       theta_list: [],
+      //临时数据集合
+      attList: [],
+      medList: [],
       //判断是否结束游戏
       is_end: false,
       //  消耗的时间
       played_time: 0,
-      played_time_text: ""
+      played_time_text: "",
+
+      //  检测佩戴是否正确
+      device_ok: true
     }
   },
   methods: {
@@ -247,7 +257,7 @@ export default {
       game_store.setters.removeToyHex()
       //关闭游戏常亮
       wx.setKeepScreenOn({
-        keepScreenOn:false
+        keepScreenOn: false
       })
       //游戏结束传送一下数据
       $this.post_data()
@@ -279,15 +289,25 @@ export default {
     start_game() {
       //设置屏幕常亮
       wx.setKeepScreenOn({
-        keepScreenOn:true
+        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)
+
+        //监听脑环是否带好
+        if (hexStr.substr(0, 6) == '555520') {
+          //当s1为 00时 数据有效
+          let $s1 = hexStr.substr(8, 2)
+          console.log("游戏中监听脑环是否带正:", $s1 == '00')
+          $this.device_ok = ($s1 == '00')
+        }
+
         //连接玩具
         if ($data) {
+          console.log($data)
           $this.att_list.push($data['att'])
           $this.med_list.push($data['med'])
           $this.delta_list.push(Math.round($data['delta'] / 10000))
@@ -295,6 +315,20 @@ export default {
           $this.theta_list.push(Math.round($data['theta'] / 10000))
           $this.beta_list.push(Math.round($data['beta']) / 1000000)
 
+          if ($this.att_list.length > 50) {
+            $this.att_list.shift()
+            $this.med_list.shift()
+            $this.delta_list.shift()
+            $this.alpha_list.shift()
+            $this.theta_list.shift()
+            $this.beta_list.shift()
+          }
+          console.log("专注度列表:", $this.att_list)
+          console.log("放松度列表:", $this.med_list)
+
+          $this.attList.push($data['att'])
+          $this.medList.push($data['med'])
+
           //通过专注放松度 画图
           let $option = util.getLineOption($this.att_list, $this.med_list)
           att_charts.setOption($option)
@@ -344,21 +378,18 @@ export default {
     post_data() {
       let $params = {
         game_record_id: game_store.getters.getGameRecordId(),
-        line: $this.att_list,
-        line_med: $this.med_list
+        line: $this.attList,
+        line_med: $this.medList
       }
+      console.log("提交的线图参数", $this.attList, $this.medList)
       if (!$params.line && !$params.line_med) {
         return false
       }
       gameAddLine($params).then((res) => {
         let $data = res.data
         if ($data.code == 0) {
-          $this.att_list = []
-          $this.med_list = []
-          $this.delta_list = []
-          $this.alpha_list = []
-          $this.theta_list = []
-          $this.beta_list = []
+          $this.attList = []
+          $this.medList = []
           console.log('推送数据成功')
         } else {
           console.log('推送数据失败')
@@ -380,11 +411,15 @@ export default {
         //设置未结束游戏
         $this.is_end = false
       })
+    },
+    //  处理游戏中数据的方法
+    do_datas($data) {
+
+
     }
   }
   ,
   mounted() {
-
     let $deviceId = $this._deviceId = game_store.getters.getDeviceId()
     let $serviceId = $this._serviceId = game_store.getters.getServiceId()
     let $cId = $this._characteristicId = game_store.getters.getCharacterId()

+ 6 - 0
src/pages/user_center/address/edit/index.vue

@@ -17,6 +17,7 @@
       placeholder="收货人手机号"
       @change="changePhone"
       required
+
     />
     <van-field
       :value="address_info.city"
@@ -26,6 +27,8 @@
       placeholder="选择省/市/区"
       is-link
       @click="address_show = true"
+      readonly
+      disabled
     />
     <van-field
       :value="address_info.detail"
@@ -83,6 +86,9 @@ export default {
     //保存并使用
     choose_ok() {
       console.log($this.post_info)
+      if (!$this.post_info.name && !$this.post_info.phone && !$this.post_info.province && !$this.post_info.city && !$this.post_info.area && !$this.post_info.detail) {
+        Notify({type: 'fail', message: '请填写必填项'});
+      }
       if ($this.post_info.address_id) {
         userUpdateAddress($this.post_info).then((res) => {
           let $res = res.data;

+ 15 - 0
src/store/bluetooth.js

@@ -0,0 +1,15 @@
+const getters = {
+  getBluetoothLinkStatus() {
+    return wx.getStorageSync("ble_link_status")
+  }
+}
+
+const setters = {
+  setBluetoothLinkStatus($bool) {
+    wx.setStorageSync('ble_link_status', $bool)
+  }
+}
+
+export default {
+  getters, setters
+}

+ 28 - 1
src/utils/bluetooth.js

@@ -1,4 +1,5 @@
 import game_store from "../store/game";
+import ble_store from "../store/bluetooth"
 
 export default {
   test_name: 'hello world',
@@ -318,6 +319,9 @@ export default {
     }
     //当s1为 00时 数据有效
     let $s1 = hex.substr(8, 2)
+    if ($s1 != '00') {
+      return false
+    }
 
     //专注度数据
     let $att = parseInt("0x" + hex.substr(12, 2))
@@ -384,6 +388,7 @@ export default {
     let that = this
     wx.onBLEConnectionStateChange((res) => {
       // 该方法回调中可以用于处理连接意外断开等异常情况
+      ble_store.setters.setBluetoothLinkStatus(res.connected)
       if (res.connected == false) {
         //断开玩具连接
         try {
@@ -447,7 +452,7 @@ export default {
             game_store.setters.setDeviceId(deviceId)
             game_store.setters.setServiceId(serviceId)
             game_store.setters.setCid(item.uuid)
-            $this.sendPause(deviceId, serviceId, item.uuid)
+            // $this.sendPause(deviceId, serviceId, item.uuid)
             //获取玩具的值
             // bluetooth.sendConnect($this.toy_hex, deviceId, serviceId, item.uuid)
           }
@@ -499,17 +504,20 @@ export default {
             $this.change_toy_connect_status(4)
           }
           wx.offBLECharacteristicValueChange()
+          that.watchingDevice($this)
         } else {
           $count++
           if ($count == 15) {
             Toast.clear()
             $this.change_toy_connect_status(3)
             wx.offBLECharacteristicValueChange()
+            that.watchingDevice($this)
           }
         }
         // 取消监听低功耗蓝牙设备
       } catch (e) {
         wx.offBLECharacteristicValueChange()
+        that.watchingDevice($this)
       }
     })
   },
@@ -607,6 +615,25 @@ export default {
         console.log(err)
       }
     })
+  },
+
+
+  // 监听脑环是否带正
+  watchingDevice($this) {
+    const that = this
+    wx.onBLECharacteristicValueChange(
+      (characteristic) => {
+        let hexStr = that.ab2hex(characteristic.value)
+
+        if (hexStr.substr(0, 6) == '555520') {
+          //当s1为 00时 数据有效
+          let $s1 = hexStr.substr(8, 2)
+          console.log("监听脑环是否带正:", $s1 == '00')
+          $this.device_bg = ($s1 == '00')
+        }
+
+      }
+    )
   }
 
 }