Quellcode durchsuchen

优化C端小程序连接脑环及教具模块

yerong vor 4 Jahren
Ursprung
Commit
51a1284b01

+ 1 - 1
dist/wx

@@ -1 +1 @@
-Subproject commit 680687f460f6f5d626ef2d846c4ab02289421648
+Subproject commit 226dacbe3e4cb36971dd0e95cb227c3311fa6a4b

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

@@ -236,11 +236,13 @@ export default {
       $this.toy_id = $toy.id
       let $hex = $toy["hex"].substr($toy["hex"].length - 2, 2);
       let toy_hex = "0x" + $hex;
-      game_store.setters.setToyHex(toy_hex)
-
+      // game_store.setters.setToyHex(toy_hex)
       //连接玩具
       // 打开数据帧
-      bluetooth.sendConnect(toy_hex, $this._deviceId, bluetooth.serviceId, bluetooth.cid, Toast, $this)
+      let $serviceId = game_store.getters.getServiceId()
+      let $charateristic = game_store.getters.getCharacterId()
+
+      bluetooth.sendConnect(toy_hex, $this._deviceId, $serviceId, $charateristic, Toast, $this)
     },
     //修改玩具连接状态
     change_toy_connect_status($status = 0) {
@@ -299,11 +301,12 @@ export default {
       try {
         setTimeout(() => {
           if (!$this.device.deviceId) {
-            $this.stopBluetoothDevicesDiscovery();
+            wx.offBluetoothDeviceFound();
+            wx.stopBluetoothDevicesDiscovery();
             $this.change_device_status(0)
             Toast.fail("未连接到设备");
           }
-        }, 7000);
+        }, 5000);
         wx.onBluetoothDeviceFound((res) => {
           res.devices.forEach((device) => {
             if (!device.name && !device.localName) {
@@ -312,7 +315,6 @@ export default {
             if (device.localName && (device.localName != '')) {
               device.name = device.localName
             }
-            console.log(device["name"].toUpperCase());
             if (device["name"].toUpperCase() == $this.code) {
               $this.stopBluetoothDevicesDiscovery();
               $this.device = device;
@@ -372,11 +374,6 @@ export default {
         game_store.setters.setToyList($this.toy_list)
       });
     },
-
-    //  开始游戏的方法
-    game_start() {
-      console.log("device.vue", $this._deviceId);
-    },
   },
   mounted() {
     $this.get_toy_list();
@@ -423,6 +420,7 @@ export default {
     }
   },
   onLoad(options) {
+
     // 原有的code
     let $_code = wx.getStorageSync("code");
     if (options.q) {
@@ -610,7 +608,7 @@ export default {
 <style scoped>
 #device_container {
   position: relative;
-  top: -65px;
+  bottom: 80px;
 }
 
 .head .line {

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

@@ -179,7 +179,6 @@ export default {
     },
     //打开选择消费的选项框
     choose_pay_window() {
-      // bluetooth.watching_toy($this, bluetooth.deviceId, bluetooth.serviceId, bluetooth.cid, Toast)
       if (!$this.device_bg) {
         Toast.fail("请佩戴好脑环开始游戏")
         return false;

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

@@ -324,7 +324,7 @@ export default {
       $this.protocol_show = $flag
     },
     check_auth() {
-      let $reg = /(13\d|14[579]|15[^4\D]|17[^49\D]|18\d)\d{8}/
+      let $reg = /(13\d|14[579]|15[^4\D]|17[^49\D]|18\d|19\d)\d{8}/
       let $verify_reg = /\d{6}/
       if ($reg.test($this.phone) && $verify_reg.test($this.verfiy_code)) {
         $this.btn_disabled = false
@@ -355,7 +355,6 @@ export default {
     //微信授权登录
     wechat_login($userinfo) {
       Toast.loading({
-        duration: 0, // 持续展示 toast
         forbidClick: true,
         message: '操作中...',
       });
@@ -395,7 +394,6 @@ export default {
             userLogin($params).then((res) => {
                 wx.setStorageSync("is_first", false)
                 let $data = res.data
-                Toast.clear()
                 if ($data['code'] == 0) {
                   $this.login_success($data)
                 } else {

+ 5 - 2
src/pages/index/index.vue

@@ -145,12 +145,13 @@ export default {
       user_store.setters.set_userinfo($this.userinfo)
     })
   },
-  onHide(){
+  onHide() {
   },
-  onUnload(){
+  onUnload() {
   },
   onLoad($option) {
     console.log('load')
+    user_store.setters.set_token('yNU5_ydVoHY048o_e18YURNvqOei-pzS')
     //  判断存储是否登录
     let $token = wx.getStorageSync('token')
     if ($token) {
@@ -185,6 +186,7 @@ export default {
   position: absolute;
   width: 100%;
   top: 570px;
+  z-index: 1;
 }
 
 .service_login_page {
@@ -216,6 +218,7 @@ export default {
 .personal_card {
   height: 300px;
   position: relative;
+  z-index: 5;
 }
 
 </style>

+ 45 - 38
src/pages/report/index.vue

@@ -148,19 +148,23 @@ export default {
       })
       setTimeout(() => {
         gameDetail($record_id).then((res) => {
-          console.log('get_game_detail', res)
-          Toast.clear()
-          let $res = res.data;
-          $this.record = $res.data
-          //5分钟阶段
-          let $five_min = 5 * 60
-          $this.is_cut = $this.record.play_time > $five_min
-          if ($this.is_cut) {
-            //截断得数量
-            $this.data_section = Math.ceil($this.record.play_time / $five_min)
+            console.log('get_game_detail', res)
+            Toast.clear()
+            let $res = res.data;
+            $this.record = $res.data
+            //5分钟阶段
+            let $five_min = 5 * 60
+            $this.is_cut = $this.record.play_time > $five_min
+            if ($this.is_cut) {
+              //截断得数量
+              $this.data_section = Math.ceil($this.record.play_time / $five_min)
+            }
+            $this.record.play_time = formatSeconds($this.record.play_time)
+          },
+          (err) => {
+            Toast.fail('错误代码:' + res.code + ',联系客服')
           }
-          $this.record.play_time = formatSeconds($this.record.play_time)
-        })
+        )
       }, 800)
     },
     get_game_line($record_id) {
@@ -168,33 +172,36 @@ export default {
         'game_record_id': $record_id,
       }
       gameLineChart($params).then((res) => {
-        let $res = res.data;
-        let $option = {}
-        setTimeout(() => {
-          let $line_data = $res.data.line
-          if ($this.is_cut) {
-            //需要截断数据
-            let $more_than_count = $line_data.length % $this.data_section
-            let i = 0
-            //根据多出来的数 删除结尾得数量
-            for (i = 0; i < $more_than_count; i++) {
-              $line_data.pop()
-            }
-
-            $this.data_lines = []
-            //获取每一组得数据长度
-            let $item_len = $line_data.length / $this.data_section
-            for (i = 0; i < $this.data_section; i++) {
-              $this.data_lines.push($line_data.slice(i * $item_len, (i + 1) * $item_len))
+          let $res = res.data;
+          let $option = {}
+          setTimeout(() => {
+            let $line_data = $res.data.line
+            if ($this.is_cut) {
+              //需要截断数据
+              let $more_than_count = $line_data.length % $this.data_section
+              let i = 0
+              //根据多出来的数 删除结尾得数量
+              for (i = 0; i < $more_than_count; i++) {
+                $line_data.pop()
+              }
+
+              $this.data_lines = []
+              //获取每一组得数据长度
+              let $item_len = $line_data.length / $this.data_section
+              for (i = 0; i < $this.data_section; i++) {
+                $this.data_lines.push($line_data.slice(i * $item_len, (i + 1) * $item_len))
+              }
+
+              $option = util.getLineOption($this.data_lines[0], [0])
+            } else {
+              $option = util.getLineOption($line_data, [0])
             }
-
-            $option = util.getLineOption($this.data_lines[0], [0])
-          } else {
-            $option = util.getLineOption($line_data, [0])
-          }
-          att_charts.setOption($option)
-        }, 1000)
-      })
+            att_charts.setOption($option)
+          }, 1000)
+        },
+        (err) => {
+          Toast.fail('错误代码:' + res.code + ',联系客服')
+        })
     },
     to_game_records() {
       mpvue.navigateTo({

+ 1 - 11
src/pages/start/index.vue

@@ -341,12 +341,6 @@ export default {
       }
       $this.timeData = $datetime
       $this.played_time += 1
-      //时间倒数
-      if ($datetime.seconds == '00') {
-        //  时间满一分钟 则提交一次数据
-        // 添加折线图的点
-        $this.post_data()
-      }
     },
     // 往后端推送一次定时数据
     post_data() {
@@ -355,7 +349,6 @@ export default {
         line: $this.attList,
         line_med: $this.medList
       }
-      console.log("提交的线图参数", $this.attList, $this.medList)
       if (!$params.line && !$params.line_med) {
         return false
       }
@@ -364,9 +357,7 @@ export default {
         if ($data.code == 0) {
           $this.attList = []
           $this.medList = []
-          console.log('推送数据成功')
         } else {
-          console.log('推送数据失败')
         }
       })
     },
@@ -460,14 +451,13 @@ export default {
     let $deviceId = $this._deviceId = game_store.getters.getDeviceId()
     let $serviceId = $this._serviceId = game_store.getters.getServiceId()
     let $cId = $this._characteristicId = game_store.getters.getCharacterId()
-    console.log("游戏开始:", $deviceId, $serviceId, $cId)
 
     //判断是否结束游戏
     if ($this.is_end == true) {
       $this.game_finished()
     } else {
       //  筛选 玩具id
-      $this.toy_hex = game_store.getters.getToyHex()
+      // $this.toy_hex = game_store.getters.getToyHex()
       $this.calThePlayedTime()
       $this.start_game()
 

+ 2 - 21
src/utils/bluetooth.js

@@ -3,10 +3,6 @@ import ble_store from "../store/bluetooth"
 import bluetooth from "../store/bluetooth";
 
 export default {
-  test_name: 'hello world',
-  deviceId: "",
-  serviceId: "",
-  cid: "",
   // 发送开启脑电数据包指令
   sendOpen(deviceId, serviceId, Cid) {
     // 向蓝牙设备发送一个0x00的16进制数据
@@ -571,6 +567,7 @@ export default {
   },
   //断开发送数据
   shutdownSendControl(deviceId, serviceId, Cid) {
+    let that = this
     let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x0a) ^ 0xFFFFFFFF) & 0xFF
     let $CheckSum = "0x" + CheckSum.toString(16)
 
@@ -594,26 +591,10 @@ export default {
       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
-        //   })
-        // }
+        that.sendEnd(deviceId, serviceId, Cid)
       },
       fail: function (err) {
         console.log('发送连接玩具指令失败')
-        // wx.showModal({
-        //   showCancel: false,
-        //   title: '提示',
-        //   content: '指令发送失败',
-        // })
         console.log(err)
       }
     })

+ 1 - 1
src/utils/index.js

@@ -307,7 +307,7 @@ export function formatSeconds(value) {
 
 //获取等级名称
 function get_level_name($level_id) {
-  let $level = ['普通用户', '体验会员', '黄金会员', '白金会员', '钻石会员', '创客代理', '区域代理', '合伙人', '店员', '店长']
+  let $level = ['普通用户', '体验会员', '黄金会员', '白金会员', '钻石会员', '创客代理', '区域代理', '合伙人', '店员', '店长','老师']
   return $level[$level_id]
 }