Explorar el Código

功能完善11.17-16:32

rong air hace 4 años
padre
commit
e928f2f009

+ 32 - 25
src/components/device/device.vue

@@ -40,6 +40,7 @@
             :deviceId="_deviceId"
             :toy_id="toy_action"
             :toy="toy_list[toy_action - 1]"
+            :device_bg="device_bg"
             @open_choose_toy="open_choose_toy"
             @change_toy_connect_status="change_toy_connect_status"
             @change_status="change_device_status"
@@ -134,6 +135,8 @@ export default {
       //设备状态 0为未连接,1:连接中,2:已连接 3:连接失败
       device_status: 0,
       connect_show: false,
+      //设置图标的颜色
+      device_bg: true,
 
       choose_toy_window: {
         show: false,
@@ -199,7 +202,7 @@ export default {
               },
             });
           }
-        },
+        }
       });
     },
     //关闭窗口的方法
@@ -265,13 +268,12 @@ export default {
         wx.closeBLEConnection({
           deviceId: $this._deviceId,
           success(res) {
-            wx.closeBluetoothAdapter()
-
             Toast.success({
               message: "已成功断开"
             });
           },
         });
+        wx.closeBluetoothAdapter()
       }
     },
 
@@ -290,28 +292,33 @@ export default {
     },
     //打开蓝牙搜索
     onBluetoothDeviceFound() {
-      wx.onBluetoothDeviceFound((res) => {
-        res.devices.forEach((device) => {
-          if (!device.name && !device.localName) {
-            $this.stopBluetoothDevicesDiscovery();
-            $this.device_status = 0;
-            $this.connect_show = false;
-            Toast.fail("未连接到设备");
-            return;
-          }
-          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;
-            game_store.setters.setDeviceId(device.deviceId)
-            $this._deviceId = device.deviceId;
-            $this.createBLEConnection();
-          }
+      console.log("打开蓝牙搜索")
+      try {
+
+        wx.onBluetoothDeviceFound((res) => {
+          console.log(res)
+          res.devices.forEach((device) => {
+            console.log(device)
+            if (!device.name && !device.localName) {
+              return;
+            }
+            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;
+              game_store.setters.setDeviceId(device.deviceId)
+              $this._deviceId = device.deviceId;
+
+              $this.createBLEConnection();
+            }
+          });
         });
-      });
+      } catch (e) {
+        console.log('打开蓝牙error', e)
+      }
       setTimeout(() => {
         if (!$this.device.deviceId) {
           $this.stopBluetoothDevicesDiscovery();
@@ -576,9 +583,9 @@ export default {
 .device_bg {
   width: 90px;
   height: 100px;
-  background-image: url("https://img.shuimuai.com/web/device_bg.png");
   background-position: center;
   background-size: 100% 100%;
+  background-image: url("https://img.shuimuai.com/web/device_bg.png");
 }
 
 .left {

+ 3 - 2
src/components/device/toy/connecting.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">
+          <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>
@@ -164,7 +165,7 @@ import bluetooth from "../../../utils/bluetooth";
 let $this;
 export default {
   name: "connected",
-  props: ['connect_toy', 'deviceId', 'toy_id', 'toy'],
+  props: ['connect_toy', 'deviceId', 'toy_id', 'toy','device_bg'],
   data() {
     return {
       pay_window: false,

+ 0 - 2
src/components/user_center/order_list.vue

@@ -3,7 +3,6 @@
     <van-card
       v-for="(order,index) in orders"
       :key="index"
-      v-if="orders.length > 0"
     >
       <!--      抬头部分-->
       <div slot="title" class="flex justify-between">
@@ -50,7 +49,6 @@
 
       </div>
     </van-card>
-    <van-empty description="暂时没有数据"  v-else/>
   </div>
 </template>
 

+ 9 - 0
src/pages/report/index.vue

@@ -70,6 +70,7 @@
         <view>专注力训练时长: {{ record.play_time }}</view>
       </view>
     </view>
+    <van-toast id="van-toast"/>
 
   </div>
 </template>
@@ -80,6 +81,7 @@ import echarts from '../../../static/echarts.min';
 import util, {formatSeconds} from '../../utils/index'
 import {gameDetail, gameLineChart} from "../../requests/game";
 import game_store from "../../store/game";
+import Toast from '../../../static/vant/toast/toast';
 
 var att_charts,
   $this
@@ -118,7 +120,14 @@ export default {
   methods: {
     //  获取游戏报告
     get_report($record_id) {
+      $this.record = {}
+      Toast.loading({
+        forbidClick:true,
+        message:"加载中",
+        duration:0
+      })
       gameDetail($record_id).then((res) => {
+        Toast.clear()
         let $res = res.data;
         $this.record = $res.data
         $this.record.play_time = formatSeconds($this.record.play_time)

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

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

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

@@ -228,8 +228,8 @@ export default {
     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');
@@ -248,7 +248,15 @@ export default {
       //游戏结束传送一下数据
       $this.post_data()
       $this.game_over()
-      $this.to_report()
+      Toast.loading({
+        forbidClick: true,
+        message: "正在生成报告...",
+        duration: 0
+      })
+      setTimeout(() => {
+        Toast.clear()
+        $this.to_report()
+      }, 800)
     },
     //  关闭弹窗
     close_pop() {

+ 2 - 10
src/pages/user_center/orders/index.vue

@@ -1,6 +1,7 @@
 <template>
   <div class="uc_orders_container">
-    <order_list :orders="orders"></order_list>
+    <order_list :orders="orders" v-if="orders.length > 0"></order_list>
+    <van-empty description="暂无数据" v-else />
   </div>
 </template>
 
@@ -19,15 +20,6 @@ export default {
   data() {
     return {
       orders: [
-        {
-          "order_id": "12",
-          "sn": "DD202009281821264613",
-          "goods_name": "黄金会员",
-          "payment": "",
-          //1未付款 2已付款
-          "pay_status": "1",
-          "create_time": "1601288486"
-        }
       ],
     }
   },

+ 24 - 20
src/utils/bluetooth.js

@@ -483,30 +483,34 @@ export default {
     //关闭核销选项窗口
     // $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)
-        let $game_status = game_store.getters.getGameStatus();
-        if ($game_status == 1) {
-          $this.change_toy_connect_status(4)
-        }
-        wx.offBLECharacteristicValueChange()
-      } else {
-        $count++
-        if ($count == 15) {
+      try {
+        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.change_toy_connect_status(3)
+          //连接成功 打开核销窗口
+          // $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 == 15) {
+            Toast.clear()
+            $this.change_toy_connect_status(3)
+            wx.offBLECharacteristicValueChange()
+          }
         }
+        // 取消监听低功耗蓝牙设备
+      } catch (e) {
+        wx.offBLECharacteristicValueChange()
       }
-      // 取消监听低功耗蓝牙设备
     })
   },