Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master' into master

yerong 4 anni fa
parent
commit
0bd1c93a42
1 ha cambiato i file con 112 aggiunte e 88 eliminazioni
  1. 112 88
      src/components/device/device.vue

+ 112 - 88
src/components/device/device.vue

@@ -14,17 +14,26 @@
       <!--      </div>-->
       <div v-if="connect_toy == 0">
         <!--      未连接部分-->
-        <div class="connect_box" v-if="device_status == 0">
+        <div
+          class="connect_box"
+          v-if="device_status == 0"
+        >
           <device_unconnect @open_scan="open_scan"></device_unconnect>
         </div>
 
         <!--      连接中-->
-        <div class="connecting_box" v-if="device_status != 0 && connect_show == false">
+        <div
+          class="connecting_box"
+          v-if="device_status != 0 && connect_show == false"
+        >
           <device_connecting :status="device_status"></device_connecting>
         </div>
 
         <!-- 已链接 -->
-        <div class="connected_box" v-if="connect_show">
+        <div
+          class="connected_box"
+          v-if="connect_show"
+        >
           <device_connected
             @open_choose_toy="open_choose_toy"
             @change_brain_status="change_device_status"
@@ -70,8 +79,15 @@
       </div>
       <!-- 内容 -->
       <div class="padding toy_list">
-        <van-row gutter="14" class="toy_list_content">
-          <van-col span="12" v-for="(toy, index) in toy_list" :key="index" class="text-center">
+        <van-row
+          gutter="14"
+          class="toy_list_content"
+        >
+          <van-col
+            v-for="(toy, index) in toy_list"
+            :key="index"
+            class="text-center"
+          >
             <div
               class="toy_item flex flex-direction justify-center align-center"
               @click="choose_toy(index)"
@@ -81,7 +97,11 @@
                   : 'toy_item_normal_bg'
               "
             >
-              <img :src="toy.img" alt="" class="toy_img"/>
+              <img
+                :src="toy.img"
+                alt=""
+                class="toy_img"
+              />
               <text class="toy_text padding-top">{{ toy.name }}</text>
             </div>
           </van-col>
@@ -89,10 +109,8 @@
       </div>
       <!-- 结尾 -->
       <div class="toy_actions padding text-center">
-        <view class="text-gray toy_action_text padding"
-        >选择你最感兴趣的项目,点击“选好了”以后将会自动连接
-        </view
-        >
+        <view class="text-gray toy_action_text padding">选择你最感兴趣的项目,点击“选好了”以后将会自动连接
+        </view>
         <button
           class="cu-btn lg cu-btn-primary text-white text-center padding"
           @click="choose_ok"
@@ -101,8 +119,8 @@
         </button>
       </div>
     </van-popup>
-    <van-toast id="van-toast"/>
-    <van-dialog id="van-dialog"/>
+    <van-toast id="van-toast" />
+    <van-dialog id="van-dialog" />
 
   </div>
 </template>
@@ -118,12 +136,11 @@ import device_connected from "@/components/device/connected";
 import toy_connecting from "@/components/device/toy/connecting";
 //获取个人信息
 import Toast from "../../../static/vant/toast/toast";
-import {game_devices} from "../../requests/game";
+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';
-
+import ble_store from "../../store/bluetooth";
+import Dialog from "../../../static/vant/dialog/dialog";
 
 let $this;
 export default {
@@ -138,6 +155,7 @@ export default {
     return {
       //设备状态 0为未连接,1:连接中,2:已连接 3:连接失败
       device_status: 0,
+      // device_status: 2,
       connect_show: false,
       //设置图标的颜色
       device_bg: false,
@@ -148,7 +166,7 @@ export default {
       },
       //'水柱音箱', '喷雾恐龙(大)', '喷雾恐龙(小)', '轨道车', '碰碰车', '小车(大)', '小车(中)', '小车(小)', '飞行器(大)', '飞行器(小)', '水母灯'
       toy_list: [],
-      toy_item:{},
+      toy_item: {},
       toy_action: 1,
       // connect_show: true,
       //连接玩具 0:未连接 1:连接中 2:已连接 3:连接失败 4:游戏中
@@ -160,16 +178,16 @@ export default {
       toy_id: 0,
 
       // 电量
-      device_power: 100
+      device_power: 100,
     };
   },
   methods: {
     //打开 扫描二维码
     open_scan() {
       // 打开蓝牙扫描 重置游戏状态
-      game_store.setters.setGameStatus(0)
+      game_store.setters.setGameStatus(0);
       //
-      $this.scan_to_bluetooth()
+      $this.scan_to_bluetooth();
     },
     //扫描连接蓝牙
     scan_to_bluetooth() {
@@ -179,10 +197,12 @@ export default {
           let $data = res;
           if ($data.result) {
             let url = decodeURIComponent($data.result);
-            let $code = url.match(/\?ring=(.*)/) ? url.match(/\?ring=(.*)/) : url.match(/\?code=(.*)/);
+            let $code = url.match(/\?ring=(.*)/)
+              ? url.match(/\?ring=(.*)/)
+              : url.match(/\?code=(.*)/);
             // 判断新的标识值
             $this.code = $code[1].toUpperCase();
-            console.log('头环码', $code)
+            console.log("头环码", $code);
             //打开蓝牙设备
             wx.openBluetoothAdapter({
               success(res) {
@@ -194,8 +214,8 @@ export default {
               fail(err) {
                 if (err["errCode"] == 10001) {
                   Toast.fail({
-                    message: "请打开手机蓝牙!"
-                  })
+                    message: "请打开手机蓝牙!",
+                  });
                 } else {
                   Toast.fail({
                     message: "蓝牙连接失败",
@@ -204,9 +224,8 @@ export default {
               },
             });
           }
-        }
+        },
       });
-
     },
     //关闭窗口的方法
     on_close() {
@@ -227,30 +246,37 @@ export default {
       $this.change_toy_connect_status(1);
       $this._device_index = $this.toy_action - 1;
       //获取玩具
-      let $toy = {}
+      let $toy = {};
       $this.toy_list.forEach(($val, $index) => {
-        if ($val['id']==$this.toy_action){
-          $this.toy_item = $toy = $val
+        if ($val["id"] == $this.toy_action) {
+          $this.toy_item = $toy = $val;
         }
-      })
-      $this.toy_id = $toy.id
+      });
+      $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)
       //连接玩具
       // 打开数据帧
-      let $serviceId = game_store.getters.getServiceId()
-      let $charateristic = game_store.getters.getCharacterId()
-
-      bluetooth.sendConnect(toy_hex, $this._deviceId, $serviceId, $charateristic, 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) {
       $this.connect_toy = $status;
       if ($status == 1) {
-        $this.connect_show = true
+        $this.connect_show = true;
       } else {
-        $this.connect_show = false
+        $this.connect_show = false;
       }
     },
     //  修改设备连接状态
@@ -259,26 +285,26 @@ export default {
       //当蓝牙连接已断开
       //当脑环断开
       if ($status == 0) {
-        game_store.setters.setGameStatus(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.setters.setGameStatus(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.setters.clearDeviceToy()
+        game_store.setters.clearDeviceToy();
         $this.connect_toy = $status;
         $this.connect_show = false;
         wx.closeBLEConnection({
           deviceId: $this._deviceId,
           success(res) {
             Toast.success({
-              message: "已成功断开"
+              message: "已成功断开",
             });
           },
         });
-        wx.closeBluetoothAdapter()
+        wx.closeBluetoothAdapter();
       } else if ($status == 2) {
-        $this.connect_show = true
+        $this.connect_show = true;
       }
     },
 
@@ -297,13 +323,13 @@ export default {
     },
     //打开蓝牙搜索
     onBluetoothDeviceFound() {
-      console.log("打开蓝牙搜索")
+      console.log("打开蓝牙搜索");
       try {
         setTimeout(() => {
           if (!$this.device.deviceId) {
             wx.offBluetoothDeviceFound();
             wx.stopBluetoothDevicesDiscovery();
-            $this.change_device_status(0)
+            $this.change_device_status(0);
             Toast.fail("未连接到设备");
           }
         }, 5000);
@@ -312,13 +338,13 @@ export default {
             if (!device.name && !device.localName) {
               return;
             }
-            if (device.localName && (device.localName != '')) {
-              device.name = device.localName
+            if (device.localName && device.localName != "") {
+              device.name = device.localName;
             }
             if (device["name"].toUpperCase() == $this.code) {
               $this.stopBluetoothDevicesDiscovery();
               $this.device = device;
-              game_store.setters.setDeviceId(device.deviceId)
+              game_store.setters.setDeviceId(device.deviceId);
               $this._deviceId = device.deviceId;
 
               $this.createBLEConnection();
@@ -326,7 +352,7 @@ export default {
           });
         });
       } catch (e) {
-        console.log('打开蓝牙error', e)
+        console.log("打开蓝牙error", e);
       }
     },
     // 停止蓝牙搜索
@@ -341,12 +367,12 @@ export default {
           console.log("成功连接");
           //成功连接脑环蓝牙
           $this.change_device_status(2);
-          bluetooth.watch_bluetooth_status($this)
-          bluetooth.getBLEDeviceServices($this.device.deviceId)
-          bluetooth.watchingDevice($this)
+          bluetooth.watch_bluetooth_status($this);
+          bluetooth.getBLEDeviceServices($this.device.deviceId);
+          bluetooth.watchingDevice($this);
         },
         fail(err) {
-          console.log(err)
+          console.log(err);
         },
       });
     },
@@ -371,7 +397,7 @@ export default {
           };
           $this.toy_list.push(_item);
         });
-        game_store.setters.setToyList($this.toy_list)
+        game_store.setters.setToyList($this.toy_list);
       });
     },
   },
@@ -379,10 +405,10 @@ export default {
     $this.get_toy_list();
     wx.getSystemInfo({
       success(res) {
-        console.log(res)
-        console.log(res.brand)
-      }
-    })
+        console.log(res);
+        console.log(res.brand);
+      },
+    });
   },
   created() {
     $this = this;
@@ -392,35 +418,36 @@ export default {
     let $game_status = game_store.getters.getGameStatus();
     if ($game_status == 1) {
       Dialog.confirm({
-        title: '系统提示',
-        message: '确认要退出游戏了吗?',
-      }).then(() => {
-        // on confirm
-        mpvue.navigateTo({
-          url: "/pages/start/main?end=1",
-        });
-      }).catch(() => {
-        // on cancel
-        mpvue.navigateTo({
-          url: "/pages/start/main",
+        title: "系统提示",
+        message: "确认要退出游戏了吗?",
+      })
+        .then(() => {
+          // on confirm
+          mpvue.navigateTo({
+            url: "/pages/start/main?end=1",
+          });
+        })
+        .catch(() => {
+          // on cancel
+          mpvue.navigateTo({
+            url: "/pages/start/main",
+          });
         });
-      });
-      $this.change_toy_connect_status(4)
+      $this.change_toy_connect_status(4);
     } else if ($game_status == 3) {
       //不在游戏状态
-      $this.change_toy_connect_status(0)
-      $this.connect_show = true
-      let $ble_status = ble_store.getters.getBluetoothLinkStatus()
-      bluetooth.watchingDevice($this)
-      bluetooth.watch_bluetooth_status($this)
+      $this.change_toy_connect_status(0);
+      $this.connect_show = true;
+      let $ble_status = ble_store.getters.getBluetoothLinkStatus();
+      bluetooth.watchingDevice($this);
+      bluetooth.watch_bluetooth_status($this);
       if ($ble_status == false) {
         //断开蓝牙连接
-        $this.change_device_status(0)
+        $this.change_device_status(0);
       }
     }
   },
   onLoad(options) {
-
     // 原有的code
     let $_code = wx.getStorageSync("code");
     if (options.q) {
@@ -438,13 +465,11 @@ export default {
 
 <!--共有样式-->
 <style>
-
 .second_device_text {
   position: relative;
   bottom: 5px;
 }
 
-
 .connect_img {
   width: 85px;
   height: 80px;
@@ -482,7 +507,6 @@ export default {
   border-radius: 50%;
 }
 
-
 .dot_container {
   height: 100px;
 }
@@ -631,11 +655,11 @@ export default {
 
 .toy_item {
   margin: 0px auto;
-  width: 120px;
+  /* width: 120px; */
+  width: 140px;
   height: 130px;
 }
 
-
 /*玩具图片*/
 .toy_img {
   width: 65px;
@@ -658,10 +682,10 @@ export default {
 }
 
 .toy_list_content {
-  width: 100%;
+  width: 130%;
   display: inline-block;
   display: flex;
   flex-wrap: wrap;
 }
-
+/* padding toy_list */
 </style>