فهرست منبع

12/16 报告五角图 & 会员vip改版

Foystor 3 سال پیش
والد
کامیت
4bc9a43a64

+ 1 - 1
src/App.vue

@@ -8,7 +8,7 @@ export default {
   //外发
   onShow(options){
       let query = options.query.other
-      console.log('进入小程序了',options)
+      // console.log('进入小程序了',options)
       // 有无参数
       if(query){
         console.log('外发给你')

+ 9 - 1
src/components/banner.vue

@@ -71,12 +71,20 @@ export default {
     },
     getBanners() {
       getBannerList().then((res) => {
+<<<<<<< HEAD
         if(res.data.code == 0){
           console.log("活动列表ID:", res);
           let $res = res.data;
           let $activities = $res.data;
           let $new_act = $activities.pop();
           console.log("轮播图", $new_act);
+=======
+        // console.log("活动列表ID:", res);
+        let $res = res.data;
+        let $activities = $res.data;
+        let $new_act = $activities.pop();
+        // console.log("轮播图", $new_act);
+>>>>>>> 40eff8c3bfb4c1bbb7dfe943fd86665d24cd02aa
 
           $this.banners[1].src = $new_act["img"]
             ? "https://img.shuimuai.com/" + $new_act["img"]
@@ -94,7 +102,7 @@ export default {
     //   getJointBanner().then((res) => {
     //     console.log("banner活动", res.data.data)
     //     let $banner_img = res.data.data
-        
+
     //     $this.banners[0].src = $banner_img[0].img
     //     $this.banners[2].src = $banner_img[1].img
     //   });

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

@@ -72,9 +72,9 @@ export default {
 }
 
 .device_elc {
-  height: 10 rpx;
-  border-radius: 5 rpx;
-  bottom: 3 rpx;
+  height: 5px;
+  border-radius: 2.5px;
+  bottom: 1.5px;
 }
 
 </style>

+ 185 - 78
src/components/device/device.vue

@@ -42,11 +42,12 @@
         <div class="connecting_toy">
           <toy_connecting
             :connect_toy="connect_toy"
-            :deviceId="_deviceId"
             :toy_id="toy_action"
             :toy="toy_item"
+            :toy_sn="toy_sn"
             :device_bg="device_bg"
             :device_power="device_power"
+            :toy_power="toy_power"
             @open_choose_toy="open_choose_toy"
             @change_toy_connect_status="change_toy_connect_status"
             @change_status="change_device_status"
@@ -113,18 +114,9 @@
         </button>
       </div>
     </van-popup>
-    <van-toast id="van-toast" />
-    <van-dialog id="van-dialog" />
-
-    <!--    <van-popup-->
-    <!--      :show="start_show"-->
-    <!--      :closeable="false"-->
-    <!--      position="bottom"-->
-    <!--      custom-style="height: 100%"-->
-    <!--      @close="onStartGameShowClose"-->
-    <!--    >-->
-    <!--      <gameIng v-if="game_status" @closePop="onStartGameShowClose"></gameIng>-->
-    <!--    </van-popup>-->
+    <van-toast id="van-toast"/>
+    <van-dialog id="van-dialog"/>
+
   </div>
 </template>
 
@@ -141,11 +133,9 @@ import toy_connecting from "@/components/device/toy/connecting";
 import gameIng from "@/pages/start/index";
 //获取个人信息
 import Toast from "../../../static/vant/toast/toast";
-import { game_devices } from "../../requests/game";
+import {game_devices, getDeviceBySn} 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 {getNowDate} from "../../utils";
 
 let $this;
 export default {
@@ -179,17 +169,59 @@ export default {
       //连接玩具 0:未连接 1:连接中 2:已连接 3:连接失败 4:游戏中
       connect_toy: 0,
       code: "jellyfish1234",
-      device: {},
-      _deviceId: "",
+      deviceId: "",
       _device_index: false,
       toy_id: 0,
+      toy_hex: "",
 
       // 电量
       device_power: 0,
+      //教具电量
+      toy_power: 0,
+      //教具名称
+      toy_sn: "教具",
+      //UUID
+      toy_UUID: "",
 
       //  开始游戏模块
       start_show: false,
       game_status: 0,
+
+      //当前发送的hex码
+      current_hex: "",
+      //判断是否已经连接教具
+      toy_connected: false,
+
+      device_finded: false,
+
+      device_data: {
+        //产品编码
+        sn: "",
+        //产品名称
+        product_name: "",
+        //产品型号       :"",
+        product_model: "",
+        //产品二维码
+        product_qrcode: "",
+        //生产年月日       :"",
+        production_date: "",
+        //制造工厂
+        manufacturing_plan: "",
+        //硬件版本       :"",
+        hardware_version: "",
+        //软件版本
+        software_version: "",
+        //蓝牙地址  mac_address
+        device_id: "",
+        //蓝牙PC地址
+        pc_device_id: "",
+        //ios蓝牙地址
+        ios_device_id: "",
+        //设备类型 1脑环 2玩具
+        type: "",
+        //UUID
+        UUID: "",
+      },
     };
   },
   methods: {
@@ -202,23 +234,43 @@ export default {
     },
     //扫描连接蓝牙
     scan_to_bluetooth() {
-      // console.log("在扫码时是否存在deviceId?:", this._deviceId);
       wx.scanCode({
         onlyFromCamera: true,
+        scanType: ['barCode', 'qrCode'],
         success: (res) => {
-          wx.vibrateShort({
-            type: "heavy",
-          });
-
           let $data = res;
           if ($data.result) {
             let url = decodeURIComponent($data.result);
-            let $code = url.match(/\?ring=(.*)/)
-              ? url.match(/\?ring=(.*)/)
-              : url.match(/\?code=(.*)/);
+            let $code = ""
+
+            //二维码
+            if (res.scanType == "QR_CODE") {
+              $code = url.match(/\?ring=(.*)/)
+                ? url.match(/\?ring=(.*)/)
+                : url.match(/\?code=(.*)/);
+              $code = $code[1].toUpperCase();
+            } else {
+              //一维码
+              $code = res.result.toUpperCase();
+            }
+
             // 判断新的标识值
-            $this.code = $code[1].toUpperCase();
+            $this.code = $code
+            //判断是新还是旧
+            game_store.setters.setIsNew($code.indexOf('AI') != -1)
+
             console.log("头环码", $code);
+            game_store.setters.setDeviceSn($this.code)
+            //设备信息
+            $this.device_data.product_qrcode = url;
+            $this.device_data.sn = $this.code
+            //产品名称、制造工厂
+            $this.device_data.product_name = "水母智脑环";
+            $this.device_data.manufacturing_plan = "深圳水母智脑科技有限公司"
+            // 设备类型
+            $this.device_data.type = 1
+            $this.device_data.production_date = getNowDate()
+
             //打开蓝牙设备
             wx.getSystemInfo({
               success(res) {
@@ -240,7 +292,7 @@ export default {
                             }
                           },
                           fail(err) {
-                            let $msg = bluetooth.GetopenBluetoothAdapterError(
+                            let $msg = $this.$bluetooth.GetopenBluetoothAdapterError(
                               err["errCode"]
                             );
                             setTimeout(() => {
@@ -253,7 +305,7 @@ export default {
                       }
                     },
                     fail(err) {
-                      let $msg = bluetooth.GetopenBluetoothAdapterError(
+                      let $msg = $this.$bluetooth.GetopenBluetoothAdapterError(
                         err["errCode"]
                       );
                       setTimeout(() => {
@@ -274,7 +326,7 @@ export default {
                       }
                     },
                     fail(err) {
-                      let $msg = bluetooth.GetopenBluetoothAdapterError(
+                      let $msg = $this.$bluetooth.GetopenBluetoothAdapterError(
                         err["errCode"]
                       );
                       setTimeout(() => {
@@ -289,6 +341,9 @@ export default {
             });
           }
         },
+        fail(res) {
+          console.log(res)
+        }
       });
     },
     //关闭窗口的方法
@@ -303,8 +358,8 @@ export default {
     open_choose_toy() {
       // $this.choose_toy_window.show = false;
       $this.choose_toy_window.show = true;
-
-      bluetooth.sendEnd();
+      $this.toy_connected = false
+      $this.$bluetooth.SendOrder("09");
     },
     // 选好玩具
     choose_ok() {
@@ -319,10 +374,18 @@ export default {
         }
       });
       $this.toy_id = $toy.id;
-      let $hex = $toy["hex"].substr($toy["hex"].length - 2, 2);
+      let $hex = $this.toy_hex = $toy["hex"].substr($toy["hex"].length - 2, 2);
       //连接玩具
+      $this.current_hex = `03 00 ${$hex} 00 0a`;
+
+      $this.$bluetooth.sendConnectOneToMore($hex);
 
-      bluetooth.sendConnect($hex);
+      //设置5秒后是否已经连接
+      setTimeout(() => {
+        if ($this.toy_connected == false) {
+          $this.change_toy_connect_status(3);
+        }
+      }, 10000)
     },
     //修改玩具连接状态
     change_toy_connect_status($status = 0) {
@@ -340,21 +403,33 @@ export default {
       //当脑环断开
       if ($status == 0) {
         game_store.setters.setGameStatus(0);
-        // bluetooth.shutdownSendControl();
         // 清空链接得设备 三值
-        game_store.setters.clearDeviceToy();
         $this.connect_toy = $status;
         $this.connect_show = false;
-        $this._deviceId = "";
+        $this.device_bg = false;
+
+        $this.$bluetooth.SendOrder("09")
+        let deviceId = game_store.getters.getDeviceId();
+        $this.change_toy_connect_status(0);
+        //断开蓝牙连接
         wx.closeBLEConnection({
-          deviceId: $this._deviceId,
+          deviceId: deviceId,
           success(res) {
             Toast.success({
               message: "已成功断开",
             });
+            game_store.setters.clearDeviceToy();
+            wx.closeBluetoothAdapter();
+          },
+          fail(res) {
+            console.log("断开连接error:", res)
           },
+          complete(res) {
+            $this.device = {}
+            $this.toy_UUID = "";
+            $this.$forceUpdate();
+          }
         });
-        wx.closeBluetoothAdapter();
       } else if ($status == 2) {
         $this.connect_show = true;
       }
@@ -365,8 +440,32 @@ export default {
       wx.startBluetoothDevicesDiscovery({
         allowDuplicatesKey: true,
         success: (res) => {
-          $this.onBluetoothDeviceFound();
-          $this.change_device_status(1);
+          //2021年10月21日15:07:57  通过sn 返回deviceId
+          getDeviceBySn($this.code).then((res) => {
+            let $data = res.data;
+            console.log($data.code)
+            $this.change_device_status(1);
+            $data = $data.data;
+            wx.getSystemInfo({
+              success(res) {
+                // 判断ios 和 安卓
+                if (res.platform == "ios") {
+                  $this.onBluetoothDeviceFound();
+                } else {
+                  if ($data.device_id) {
+                    console.log("finded")
+                    $this.device_finded = true
+                    $this.createBLEConnection($data.device_id)
+                  } else {
+                    $this.device_finded = false
+                    console.log('unfinded')
+                    $this.onBluetoothDeviceFound();
+                  }
+                }
+              }
+            });
+          })
+
         },
         fail(err) {
           $this.change_device_status(3);
@@ -375,29 +474,19 @@ export default {
     },
     //打开蓝牙搜索
     onBluetoothDeviceFound() {
-      // console.log(
-      //   "打开蓝牙搜索 device_status",
-      //   $this.device_status,
-      //   "是否有id _deviceId",
-      //   $this._deviceId
-      // );
       try {
         // 5秒后判断 这5秒在搜索设备,搜索到就赋值给_deviceId
-        setTimeout(() => {
-          if (!$this._deviceId) {
-            wx.stopBluetoothDevicesDiscovery();
-            $this.change_device_status(0);
-            Toast.fail("未连接到设备");
-          } else if ($this.device_status == 1) {
-            wx.stopBluetoothDevicesDiscovery();
-            $this.change_device_status(0);
-            Toast.fail("设备未连接到");
-            // console.log(
-            //   "设备未连接到device_status的状态为:",
-            //   $this.device_status
-            // );
-          }
-        }, 5000);
+        // setTimeout(() => {
+        //   if (!$this.device.deviceId) {
+        //     wx.stopBluetoothDevicesDiscovery();
+        //     $this.change_device_status(0);
+        //     Toast.fail("未连接到设备");
+        //   } else if ($this.device_status == 1) {
+        //     wx.stopBluetoothDevicesDiscovery();
+        //     $this.change_device_status(0);
+        //     Toast.fail("设备未连接到");
+        //   }
+        // }, 5000);
         // 小乌龟
         wx.onBluetoothDeviceFound((res) => {
           res.devices.forEach((device) => {
@@ -409,11 +498,8 @@ export default {
             }
             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("搜索设备", device)
+              $this.createBLEConnection(device.deviceId);
             }
           });
         });
@@ -426,16 +512,35 @@ export default {
       wx.stopBluetoothDevicesDiscovery();
     },
     //连接低功耗蓝牙设备。
-    createBLEConnection() {
+    createBLEConnection(deviceId) {
       wx.createBLEConnection({
-        deviceId: $this.device.deviceId,
+        deviceId: deviceId,
         success: (res) => {
           console.log("成功连接");
+          $this.$bluetooth.current_device_sn = $this.code
+          game_store.setters.setDeviceId(deviceId);
+
           //成功连接脑环蓝牙
           $this.change_device_status(2);
-          bluetooth.watch_bluetooth_status($this);
-          bluetooth.getBLEDeviceServices($this.device.deviceId);
-          bluetooth.watchingDevice($this);
+
+          $this.$bluetooth.getBLEDeviceServices(deviceId)
+          let $checkServices = setInterval(() => {
+            let $serviceId = game_store.getters.getServiceId();
+            if ($serviceId) {
+              clearInterval($checkServices)
+              $this.$bluetooth.openNotify($this)
+              $this.$bluetooth.watchingDevice($this)
+              $this.$bluetooth.watch_bluetooth_status($this);
+              //录入库
+              //读取信息逐个写入
+              if (!$this.device_finded) {
+                setTimeout(() => {
+                  $this.$bluetooth.SendOrder("02")
+                }, 3000)
+              }
+            }
+          }, 1500)
+
         },
         fail(err) {
           console.log(err);
@@ -487,22 +592,24 @@ export default {
       //不在游戏状态
       $this.connect_toy = 0;
       $this.connect_show = true;
-      bluetooth.watchingDevice($this);
-      bluetooth.watch_bluetooth_status($this);
+      $this.$bluetooth.watchingDevice($this);
+      $this.$bluetooth.watch_bluetooth_status($this);
       // let $ble_status = ble_store.getters.getBluetoothLinkStatus();
       // if ($ble_status == false) {
       //   //断开蓝牙连接
       //   $this.change_device_status(0);
       // }
+      $this.toy_UUID = "";
+      $this.$forceUpdate();
       // 状态为1的时候重置为1 小乌龟
       if ($game_close_status == 1) {
         // 重置默认条件
         $this.connect_toy = 0;
         $this.connect_show = false;
         $this.device_status = 0;
-        bluetooth.watch_bluetooth_status($this);
-        $this._deviceId = "";
-
+        $this.$bluetooth.watch_bluetooth_status($this);
+        $this.toy_UUID = "";
+        $this.$forceUpdate();
         // 清空链接的设备
         game_store.setters.clearDeviceToy();
 

+ 20 - 17
src/components/device/toy/connecting.vue

@@ -94,7 +94,7 @@
               {{ toy['name'] }}
             </template>
             <template v-if="connect_toy == 2 || connect_toy == 4">
-              已连接
+              {{ toy_sn }}
             </template>
           </text>
         </div>
@@ -285,18 +285,18 @@
 import { gameStart } from "@/requests/game";
 import Toast from "../../../../static/vant/toast/toast";
 import game_store from "../../../store/game";
-import bluetooth from "../../../utils/bluetooth";
 
 let $this;
 export default {
   name: "connected",
   props: [
     "connect_toy",
-    "deviceId",
     "toy_id",
     "toy",
     "device_bg",
     "device_power",
+    "toy_power",
+    "toy_sn",
   ],
   data() {
     return {
@@ -328,7 +328,7 @@ export default {
       $this.pay_type = $event;
       let $params = {
         type: $event,
-        device_id: $this.toy_id, 
+        device_id: $this.toy_id,
         access_token: wx.getStorageSync("token"),
       };
       gameStart($params).then(
@@ -342,23 +342,26 @@ export default {
             // 设置游戏模式
             game_store.setters.setMode($event);
             // 设置游戏状态为游戏中
-            game_store.setters.setGameStatus(1);
+            // game_store.setters.setGameStatus(1);
             // 设置游戏记录id
             game_store.setters.setGameRecordId($res["game_record_id"]);
 
+            //打开脑控
+            $this.$bluetooth.sendControl();
+
             Toast.success($data.errmsg);
-            setTimeout(() => {
-              mpvue.navigateTo({
-                url: "/pages/start/main",
-                success() {
-                  wx.offBLECharacteristicValueChange();
-                  // 记录消费方式 选择时间卡还是次卡
-                  game_store.setters.setPlayTime($res["play_time"]);
-                  game_store.setters.setOverPlayTime($res["play_time"]);
-                  $this.$emit("gameStart", true);
-                },
-              });
-            }, 800);
+            game_store.setters.setPlayTime($res["play_time"]);
+            game_store.setters.setOverPlayTime($res["play_time"]);
+            // setTimeout(() => {
+            //   mpvue.navigateTo({
+            //     url: "/pages/start/main",
+            //     success() {
+            //       // 记录消费方式 选择时间卡还是次卡
+                  
+            //       $this.$emit("gameStart", true);
+            //     },
+            //   });
+            // }, 800);
           } else {
             Toast.fail($data.errmsg);
           }

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

@@ -96,122 +96,7 @@
       round
     >
       <div class="protocol_content padding-lr">
-        <!-- <div>
-          <h1 style="font-size:22px; line-height:100%; margin:15px 0px; orphans:0; page-break-after:avoid; page-break-inside:avoid; text-align:center; widows:0">
-            <span style="font-family:宋体; font-size:22px; font-weight:bold">隐私协议</span></h1>
 
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">欢迎您使用</span><span style="font-family:宋体; font-size:12px">水母智脑小程序</span><span style="font-family:宋体; font-size:12px">(以下简称:“本应用”)!</span><br /><span style="font-family:宋体; font-size:12px">本应用尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确、更有个性化的服务,本应用会按照本隐私权政策的规定使用和披露您的个人信息。但本应用将以高度的勤勉、审慎义务对待这些信息。除本隐私权政策另有规定外,在未征得您事先许可的情况下,本应用不会将这些信息对外披露或向第三方提供。本应用会不时更新本隐私权政策。</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">您在同意本应用服务使用协议之时,即视为您已经同意本隐私权政策全部内容。本隐私权政策属于本应用服务使用协议不可分割的一部分。</span><br /><br />
-            <view style="width: 100%;height: 10px;"></view>
-            <span style="font-family:宋体; font-size:12px;">1.</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">适用范围</span><br /><span style="font-family:宋体; font-size:12px">(a)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">在您注册本应用帐号时,您根据本应用要求提供的个人注册信息;</span><br /><span style="font-family:宋体; font-size:12px">(b)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">在您使用本应用网络服务,或访问本应用平台网页时,本应用自动接收并记录的您的浏览器和计算机上的信息,包括但不限于您的IP地址、浏览器的类型、使用的语言、访问日期和时间、软硬件特征信息及您需求的网页记录等数据;</span><br /><span style="font-family:宋体; font-size:12px">(c)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">本应用通过合法途径从商业伙伴处取得的用户个人数据。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <br /><span style="font-family:宋体; font-size:12px">您了解并同意,以下信息不适用本隐私权政策:</span><br /><span style="font-family:宋体; font-size:12px">(a)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">您在使用本应用平台提供的搜索服务时输入的关键字信息;</span><br /><span style="font-family:宋体; font-size:12px">(b)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">本应用收集到的您在本应用发布的有关信息数据,包括但不限于参与活动、成交信息及评价详情;</span><br /><span style="font-family:宋体; font-size:12px">(c)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">违反法律规定或违反本应用规则行为及本应用已对您采取的措施。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <br /><span style="font-family:宋体; font-size:12px">2.</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">信息使用</span><br /><span style="font-family:宋体; font-size:12px">(a)本应用不会向任何无关第三方提供、出售、出租、分享或交易您的个人信息,除非事先得到您的许可,或该第三方和本应用(含本应用关联公司)单独或共同为您提供服务,且在该服务结束后,其将被禁止访问包括其以前能够访问的所有这些资料。</span><br /><span style="font-family:宋体; font-size:12px">(b)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">本应用亦不允许任何第三方以任何手段收集、编辑、出售或者无偿传播您的个人信息。任何本应用平台用户如从事上述活动,一经发现,本应用有权立即终止与该用户的服务协议。</span><br /><span style="font-family:宋体; font-size:12px">(c)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">为服务用户的目的,本应用可能通过使用您的个人信息,向您提供您感兴趣的信息,包括但不限于向您发出产品和服务信息,或者与本应用合作伙伴共享信息以便他们向您发送有关其产品和服务的信息(后者需要您的事先同意)。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <br /><span style="font-family:宋体; font-size:12px">3.</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">信息披露</span><br /><span style="font-family:宋体; font-size:12px">在如下情况下,本应用将依据您的个人意愿或法律的规定全部或部分的披露您的个人信息:</span><br /><span style="font-family:宋体; font-size:12px">(a)经您事先同意,向第三方披露;</span><br /><span style="font-family:宋体; font-size:12px">(b)为提供您所要求的产品和服务,而必须和第三方分享您的个人信息;</span><br /><span style="font-family:宋体; font-size:12px">(c)根据法律的有关规定,或者行政或司法机构的要求,向第三方或者行政、司法机构披露;</span><br /><span style="font-family:宋体; font-size:12px">(d)如您出现违反中国有关法律、法规或者本应用服务协议或相关规则的情况,需要向第三方披露;</span><br /><span style="font-family:宋体; font-size:12px">(e)如您是适格的知识产权投诉人并已提起投诉,应被投诉人要求,向被投诉人披露,以便双方处理可能的权利纠纷;</span><br /><span style="font-family:宋体; font-size:12px">(f)在本应用平台上创建的某一交易中,如交易任何一方履行或部分履行了交易义务并提出信息披露请求的,本应用有权决定向该用户提供其交易对方的联络方式等必要信息,以促成交易的完成或纠纷的解决。</span><br /><span style="font-family:宋体; font-size:12px">(g)</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">其它本应用根据法律、法规或者网站政策认为合适的披露。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <br /><span style="font-family:宋体; font-size:12px">4.</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">信息存储和交换</span><br /><span style="font-family:宋体; font-size:12px">本应用收集的有关您的信息和资料将保存在本应用及(或)其关联公司的服务器上,这些信息和资料可能传送至您所在国家、地区或本应用收集信息和资料所在地的境外并在境外被访问、存储和展示。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <br /><span style="font-family:宋体; font-size:12px">5.</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">Cookie的使用</span><br /><span style="font-family:宋体; font-size:12px">(a)在您未拒绝接受cookies的情况下,本应用会在您的计算机上设定或取用cookies</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">,以便您能登录或使用依赖于cookies的本应用平台服务或功能。本应用使用cookies可为您提供更加周到的个性化服务,包括推广服务。</span><br /><span style="font-family:宋体; font-size:12px">(b)您有权选择接受或拒绝接受cookies。您可以通过修改浏览器设置的方式拒绝接受cookies。但如果您选择拒绝接受cookies,则您可能无法登录或使用依赖于cookies的本应用网络服务或功能。</span><br /><span style="font-family:宋体; font-size:12px">(c)通过本应用所设cookies所取得的有关信息,将适用本政策。</span></p>
-          <p style="background-color:#ffffff; font-size:12px; line-height:115%; margin:0pt"><br /><span style="font-family:宋体; font-size:12px">6.</span><span style="font-family:宋体; font-size:12px">&#xa0;</span><span style="font-family:宋体; font-size:12px">信息安全</span><br /><span style="font-family:宋体; font-size:12px">(a)本应用帐号均有安全保护功能,请妥善保管您的用户名及密码信息。本应用将通过对用户密码进行加密等安全措施确保您的信息不丢失,不被滥用和变造。尽管有前述安全措施,但同时也请您注意在信息网络上不存在“完善的安全措施”。</span><br /><span style="font-family:宋体; font-size:12px">(b)在使用本应用网络服务进行网上交易时,您不可避免的要向交易对方或潜在的交易对</span><span style="font-family:宋体; font-size:12px">方披露自己的个人信息,</span><span style="font-family:宋体; font-size:12px">如</span><span style="font-family:宋体; font-size:12px">个人信息泄密,尤其是本应用用户名及密码发生泄露,请您立即联络本应用客服,以便本应用采取相应措施</span><span style="font-family:宋体; font-size:12px">。</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <br /><span style="font-family:宋体; font-size:12px">7.本隐私政策的更改</span><br /><br /><span style="font-family:宋体; font-size:12px">(a)如果决定更改隐私政策,我们会在本政策中、本公司网站中以及我们认为适当的位置发布这些更改,以便您了解我们如何收集、使用您的个人信息,哪些人可以访问这些信息,以及在什么情况下我们会透露这些信息。</span><br /><span style="font-family:宋体; font-size:12px">(b)本公司保留随时修改本政策的权利,因此请经常查看。如对本政策作出重大更改,本公司会通过网站通知的形式告知。</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <br /><span style="font-family:宋体; font-size:12px">&#xa0;</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">&#xa0;</span></p>
-          <h1 style="font-size:22px; line-height:100%; margin:17pt 0pt 16.5pt; orphans:0; page-break-after:avoid; page-break-inside:avoid; text-align:center; widows:0">
-            <span style="font-family:宋体; font-size:22px; font-weight:bold">服务协议</span></h1>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">一、总则</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">此份协议是注册用户接受</span><span style="font-family:宋体; font-size:12px">深圳水母智脑科技有限公司</span><span style="font-family:宋体; font-size:12px">(以下简称</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">)产品和服务时适用的通用条款。因此,请您在注册成为</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">用户前或接受</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的产品和服务之前,请您详细地阅读本注册用户协议的所有内容。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">1、注册用户了解并同意:</span></p>
-          <p style="font-size:12px; line-height:115%; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">只要注册用户点击“同意”按钮并完成注册,</span><span style="font-family:宋体; font-size:12px">水母智脑就视</span><span style="font-family:宋体; font-size:12px">注册用户已接受了本注册用户协议及</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的各项服务规则(包括填写实名的联系方式等等),并愿意受其约束。如果发生纠纷,注册用户不得以未仔细阅读为由进行抗辩。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">随着市场经营情况的变化,</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">有权随时更改本注册用户协议及相关服务规则。修改本注册用户协议时,</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">将于相关页面公告修改的事实,有权不对注册用户进行个别通知。注册用户应该在每次登录前查询网站的相关公告,以了解注册用户协议及其他服务规则的变化。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">2、若注册用户不同意本注册用户协议或相关服务规则,或者不同意</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">作出的修改,注册用户可以主动停止使用</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">提供的产品和服务,如果在</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">修改协议或服务规则后,注册用户仍继续使用</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">提供的产品和服务,即表示注册用户同意</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">对本注册用户协议及相关服务规则所做的所有修改。由于注册用户在注册用户协议变更后因未熟悉公告规定而引起的损失,</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">将不会承担任何责任。</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">3、</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的各项电子服务的所有权和运作权归</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">。</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">提供的服务将完全按照其发布的服务条款和操作规则严格执行。注册用户必须完全同意所有服务条款并完成注册程序,才能成为</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的注册用户。注册用户确认:本协议条款是处理双方权利义务的当然约定依据,除非违反国家强制性法律,否则始终有效。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">二、服务简介</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">1、</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">运用自己的</span><span style="font-family:宋体; font-size:12px">程序</span><span style="font-family:宋体; font-size:12px">系统通过互联网</span><span style="font-family:宋体; font-size:12px">产品</span><span style="font-family:宋体; font-size:12px">为注册用户提供网络服务。同时,注册用户必须自行配备上网的所需设备,包括个人电脑、调制解调器或其他必备上网装置。自行负担个人上网所支付的与此服务有关的电话费用、网络费用。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">2、基于</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">所提供的网络服务的重要性,注册用户应同意:提供详尽、准确的个人资料。不断更新注册资料,符合及时、详尽、准确的要求。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">3、</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">对注册用户的电子邮件、手机号等隐私资料进行保护,承诺不会在未获得注册用户许可的情况下擅自将注册用户的个人资料信息出租或出售给任何第三方,但以下情况除外:注册用户同意让第三方共享资料;注册用户同意公开其个人资料,享受为其提供的产品和服务;</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">需要听从法庭传票、法律命令或遵循法律程序;</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">发现注册用户违反了</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">服务条款或</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">其它使用规定。</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">4、关于注册用户隐私的具体协议以</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的隐私声明为准。如果注册用户提供的资料包含有不正确的信息,</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">保留结束注册用户使用网络服务资格的权利。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">三、账户密码和安全性</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">注册用户一旦注册成功,成为</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的合法的注册用户。您可随时根据需要改变您的密码。注册用户将对注册用户名和密码安全负全部责任。另外,每个注册用户都要对以其注册用户名进行的所有活动和事件负全责。注册用户若发现任何非法使用注册用户帐户或存在安全漏洞的情况,请立即通告</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">。</span></p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">四、拒绝提供担保</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">注册用户个人对网络服务的使用承担风险。</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">对此不作任何类型的担保,不论是明确的或隐含的,但是不对商业性的隐含担保、特定目的和不违反规定的适当担保作限制。</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">不担保服务一定能满足注册用户的要求,也不担保服务不会受中断,对服务的及时性,安全性,出错发生都不作担保。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">五、有限责任</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">对任何直接、间接、偶然、特殊及继起的损害不负责任,这些损害可能来自:不正当使用网络服务,在网上购买商品或进行同类型服务,在网上进行交易,非法使用网络服务或注册用户传送的信息有所变动。这些行为都有可能会导致</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的形象受损,所以</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">事先提出这种损害的可能性。</span></p>
-          <p style="font-size:12px; line-height:115%; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">六、通告</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">所有发给注册用户的通告都可通过重要页面的公告或电子邮件或常规的信件传送。</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的活动信息也将定期通过页面公告及电子邮件方式向注册用户发送。注册用户协议条款的修改、服务变更、或其它重要事件的通告会以电子邮箱或者短信进行通知。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">七、注册用户的建议奖励</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">注册用户在他们发表的一些良好建议以及一些比较有价值的策划方案时,</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">愿意展示用户的构想落于实现,这其中</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">会对一些比较好的注册用户反馈信息进行不等的产品奖励或者是积分奖励,但如出现用户策划与广告销售商之间的矛盾</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">不承担任何责任。</span></p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">八、责任限制</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">1、如因不可抗力或其他</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">无法控制的原因使</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">销售系统崩溃或无法正常使用导致网上交易无法完成或丢失有关的信息、记录等,</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">不承担责任。但是</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">会尽可能合理地协助处理善后事宜,并努力使客户免受经济损失。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">2、除了</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的使用条件中规定的其它限制和除外情况之外,在中国法律法规所允许的限度内,对于因交易而引起的或与之有关的任何直接的、间接的、特殊的、附带的、后果性的或惩罚性的损害,或任何其它性质的损害,</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">、</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">的董事、管理人员、雇员、代理或其它代表在任何情况下都不承担责任。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">九、法律管辖和适用</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">1、本协议的订立、执行和解释及争议的解决均应适用中国法律。</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">2、如发生</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">服务条款与中国法律相抵触时,则这些条款将完全按法律规定重新解释,而其它合法条款则依旧保持对注册用户产生法律效力和影响。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">3、本协议的规定是可分割的,如本协议任何规定被裁定为无效或不可执行,该规定可被删除而其余条款应予以执行。</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">4、如双方就本协议内容或其执行发生任何争议,双方应尽力友好协商解决;协商不成时,任何一方均可向</span><span style="font-family:宋体; font-size:12px">水母智脑</span><span style="font-family:宋体; font-size:12px">所在地的人民法院提起诉讼。</span></p>
-          <p style="font-size:12px; line-height:115%;  orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">十、其他规定</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">1、如本用户协议中的任何内容无论因何种原因完全或部分无效或不具有执行力,本用户协议的其余内容仍应有效并且对协议各方有约束力。</span>
-          </p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">2、本用户协议中的标题仅为方便而设,不具法律或契</span><span style="font-family:宋体; font-size:12px">约效果。</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">&#xa0;</span></p>
-          <p style="font-size:12px; line-height:115%; margin:0pt 0pt 10pt; orphans:0; text-align:justify; widows:0">
-            <span style="font-family:宋体; font-size:12px">深圳水母智脑科技有限公司</span></p>
-        </div> -->
         <div>
           <h1 style="margin-top:17pt; margin-bottom:16.5pt; text-align:center; page-break-inside:avoid; page-break-after:avoid; line-height:240%; widows:0; orphans:0; font-size:22pt">
             <span style="font-family:'宋体'">隐私协议</span></h1>
@@ -354,7 +239,7 @@ export default {
           phone: $this.phone,
           is_register: 0
       }}
-      
+
       userGetCode($params).then((res) => {
         let $data = res.data;
         Toast.success($data["errmsg"]);

+ 2 - 1
src/main.js

@@ -2,7 +2,7 @@ import Vue from 'vue'
 import App from './App'
 import Fly from 'flyio/dist/npm/wx'
 import store from '@/store/index'
-
+import bluetooth from "@/utils/bluetooth";
 
 
 var fly = new Fly()
@@ -17,6 +17,7 @@ fly.config.headers = {
 
 Vue.prototype.$fly = fly
 Vue.prototype.$store = store
+Vue.prototype.$bluetooth = bluetooth
 Vue.config.productionTip = false
 App.mpType = 'app'
 

+ 25 - 22
src/pages/index/index.vue

@@ -71,8 +71,8 @@
         </van-row>
       </div>
     </div>
-    <van-toast id="van-toast" />
-    <van-dialog id="van-dialog" />
+    <van-toast id="van-toast"/>
+    <van-dialog id="van-dialog"/>
     <!--     <button class="cu-btn lg cu-btn-primary text-white text-center margin-tb" @click="auth_msg">获取消息授权-->
     <!--    </button>-->
   </div>
@@ -86,10 +86,10 @@ import personal_container from "@/components/index/personal";
 import device_container from "@/components/device/device";
 import Toast from "../../../static/vant/toast/toast";
 import Dialog from "../../../static/vant/dialog/dialog";
-import { userDetail, setUserLogin } from "../../requests/user";
+import {userDetail, setUserLogin} from "../../requests/user";
 import user_store from "../../store/index";
 import game_store from "../../store/game";
-import game_util, { post_data } from "../../utils/game";
+import game_util, {post_data} from "../../utils/game";
 
 var $this;
 export default {
@@ -111,7 +111,8 @@ export default {
     };
   },
   methods: {
-    get_init_data() {},
+    get_init_data() {
+    },
     //切换到扫码
     change_status($status) {
       this.login_status = $status;
@@ -172,21 +173,22 @@ export default {
     });
   },
   onShow() {
-    if(wx.getStorageSync("is_other_first") == false){
-       wx.setStorageSync("is_other", false);
-    } else{
-       wx.setStorageSync("is_other", true);
+
+    if (wx.getStorageSync("is_other_first") == false) {
+      wx.setStorageSync("is_other", false);
+    } else {
+      wx.setStorageSync("is_other", true);
     }
-    
-    wx.getStorageInfo({
-      success(res) {
-        console.log("当前存储的数据", res.keys);
-        let $keys = res.keys;
-        $keys.forEach(($val, $index) => {
-          console.log($val, wx.getStorageSync($val));
-        });
-      },
-    });
+
+    // wx.getStorageInfo({
+    //   success(res) {
+    //     console.log("当前存储的数据", res.keys);
+    //     let $keys = res.keys;
+    //     $keys.forEach(($val, $index) => {
+    //       console.log($val, wx.getStorageSync($val));
+    //     });
+    //   },
+    // });
     userDetail().then((res) => {
       let $data = res.data;
       //判断如果是第一次登录就 弹出领取体验卡
@@ -194,10 +196,11 @@ export default {
       user_store.setters.set_userinfo($this.userinfo);
     });
   },
-  onHide() {},
+  onHide() {
+  },
   onLoad($option) {
     if (process.env.NODE_ENV == "development") {
-      // wx.setStorageSync("token", "ZbNv-hpdpmxk895iqUrEwe4kCJjEWCJD");
+      wx.setStorageSync("token", "ogsti72oUSkbPl4OL7gl9woLTxR6fk4V");
     }
 
     if (game_store.getters.getGameStatus() == 1) {
@@ -220,7 +223,7 @@ export default {
       // });
       // 存在token时候录入
       setUserLogin().then((res) => {
-        console.log("录入", res);
+        // console.log("录入", res);
       });
     }
   },

+ 123 - 72
src/pages/start/index.vue

@@ -1,5 +1,9 @@
 <template>
   <div id="playing_container">
+    <!--    <view style="width: 100%;height: 100px;color: white">-->
+    <!--      <view>脑环Mac:{{ deviceId }}</view>-->
+    <!--      <view>教具UUID:{{ toy_UUID }}</view>-->
+    <!--    </view>-->
     <!--    计费面板模块-->
     <div class="game_panel padding-top-sm">
       <van-row gutter="16">
@@ -42,8 +46,7 @@
     <div class="game_status padding-tb">
       <van-row>
         <van-col
-          span="10"
-          offset="2"
+          span="5"
         >
           <div
             class="flex flex-direction align-center justify-center"
@@ -68,30 +71,63 @@
             <text class="text-default">未正确佩戴</text>
           </div>
         </van-col>
-        <van-col span="10">
+        <van-col span="4">
           <div class="flex flex-direction align-center justify-center">
-            <view class="elc_power_container">
-              <img
-                src="https://img.shuimuai.com/web/dianchi_3.png"
-                alt=""
-                :style="{ width: device_power + '%' }"
-                class="device_elc"
-              />
-            </view>
+<!--            <view class="elc_power_container">-->
+<!--              <img-->
+<!--                src="https://img.shuimuai.com/web/dianchi_3.png"-->
+<!--                alt=""-->
+<!--                :style="{ width: device_power + '%' }"-->
+<!--                class="device_elc"-->
+<!--              />-->
+<!--            </view>-->
             <text class="text-default">{{ device_power }}%</text>
-            <text class="text-default">设备电量</text>
+            <text class="text-default">脑环电量</text>
           </div>
         </van-col>
-        <!-- <van-col span="2">
+         <van-col span="4">
           <div class="flex flex-direction align-center justify-center">
-            <view>
-              <text>-{{ rssi }}dbm</text>
-            </view>
-            <view>
-              <text class="text-default">信号强度</text>
-            </view>
+<!--            <view class="elc_power_container">-->
+<!--              <img-->
+<!--                src="https://img.shuimuai.com/web/dianchi_3.png"-->
+<!--                alt=""-->
+<!--                :style="{ width: device_power + '%' }"-->
+<!--                class="device_elc"-->
+<!--              />-->
+<!--            </view>-->
+            <text class="text-default">{{ device_voltage }}</text>
+            <text class="text-default">脑环电压</text>
+          </div>
+        </van-col>
+
+        <van-col span="4">
+          <div class="flex flex-direction align-center justify-center">
+<!--            <view class="elc_power_container">-->
+<!--              <img-->
+<!--                src="https://img.shuimuai.com/web/dianchi_3.png"-->
+<!--                alt=""-->
+<!--                :style="{ width: toy_power + '%' }"-->
+<!--                class="device_elc"-->
+<!--              />-->
+<!--            </view>-->
+            <text class="text-default">{{ toy_power }}</text>
+            <text class="text-default">教具电量</text>
+          </div>
+        </van-col>
+        <van-col span="4">
+          <div class="flex flex-direction align-center justify-center">
+<!--            <view class="elc_power_container">-->
+<!--              <img-->
+<!--                src="https://img.shuimuai.com/web/dianchi_3.png"-->
+<!--                alt=""-->
+<!--                :style="{ width: toy_power + '%' }"-->
+<!--                class="device_elc"-->
+<!--              />-->
+<!--            </view>-->
+            <text class="text-default">{{ toy_voltage }}</text>
+            <text class="text-default">教具电压</text>
           </div>
-        </van-col> -->
+        </van-col>
       </van-row>
     </div>
 
@@ -228,7 +264,6 @@
 
 <script>
 import util, {formatSeconds} from "../../utils/index";
-import bluetooth from "../../utils/bluetooth";
 import game_store from "@/store/game";
 import Toast from "../../../static/vant/toast/toast";
 import {gameAddLine, gameEnd} from "../../requests/game";
@@ -281,11 +316,10 @@ export default {
 
       timeData: {},
       mode_item: {},
-      device_power: 100,
 
       user_info: {},
       //设备值
-      _deviceId: "",
+      deviceId: "",
       _serviceId: "",
       _characteristicId: "",
 
@@ -344,49 +378,56 @@ export default {
       //  蓝牙信号强度
       rssi: 0,
       game_status: 0,
+
+      toy_power: 0,
+      toy_voltage:0,
+      device_power: 0,
+      device_voltage:0,
+
+
+      toy_UUID: "",
     };
   },
   methods: {
     //游戏结束方法
-    game_finished() {  
-        if (!$this.executed){
-          bluetooth.sendEnd();
-
-          $this.$emit("closePop", true);
-          //取消监听低功耗蓝牙设备
-          wx.offBLECharacteristicValueChange();
-          //设置游戏状态为 停止游戏
-          game_store.getters.getGameStatus() == 0
-            ? game_store.setters.setGameStatus(0)
-            : game_store.setters.setGameStatus(3);
-          //游戏结束重置游戏时间
-          wx.removeStorageSync("play_time");
-          //删除游戏专注数据
-          game_store.remover.rmGameAttMedDatas();
-          //删除隐藏时间
-          game_store.remover.rmHideTime();
-          //游戏结束重置游戏模式
-          // game_store.setters.setMode(0);
-          //删除游戏得id
-          game_store.setters.removeToyHex();
-
-          // 结束游戏在提交报告函数里
-          $this.post_data();
-
-          $this.game_over();
-
-          
-          Toast.loading({
-              forbidClick: true,
-              mask: true,
-              message: "正在生成报告...",
-              duration: 2000,
-              onClose() {
-                $this.to_report();
-              }
-          });
-        }
-        $this.executed = true;
+    game_finished() {
+      if (!$this.executed) {
+        $this.$bluetooth.sendControlClose();
+
+        $this.$emit("closePop", true);
+
+        //设置游戏状态为 停止游戏
+        game_store.getters.getGameStatus() == 0
+          ? game_store.setters.setGameStatus(0)
+          : game_store.setters.setGameStatus(3);
+        //游戏结束重置游戏时间
+        wx.removeStorageSync("play_time");
+        //删除游戏专注数据
+        game_store.remover.rmGameAttMedDatas();
+        //删除隐藏时间
+        game_store.remover.rmHideTime();
+        //游戏结束重置游戏模式
+        // game_store.setters.setMode(0);
+        //删除游戏得id
+        game_store.setters.removeToyHex();
+
+        // 结束游戏在提交报告函数里
+        $this.post_data();
+
+        $this.game_over();
+
+
+        Toast.loading({
+          forbidClick: true,
+          mask: true,
+          message: "正在生成报告...",
+          duration: 2000,
+          onClose() {
+            $this.to_report();
+          }
+        });
+      }
+      $this.executed = true;
     },
     to_report() {
       mpvue.redirectTo({
@@ -405,8 +446,13 @@ export default {
         keepScreenOn: true,
       });
 
-      bluetooth.watchingDevice($this);
-      bluetooth.sendControl();
+      $this.$bluetooth.watchingDevice($this);
+      $this.$bluetooth.SendOrder('8a')
+
+      // $this.$bluetooth.sendControl();
+      // setTimeout(() => {
+        $this.$bluetooth.sendToyPower()
+      // }, 2000)
     },
 
     // ArrayBuffer转16进度字符串示例
@@ -515,7 +561,7 @@ export default {
 
       $this.att_list.push($data["att"]);
       $this.med_list.push($data["med"]);
-      $this.amp_list.push(Math.abs($data["att"] - $data["med"]));
+      $this.amp_list.push(100 - Math.abs($data["att"] - $data["med"]));
       $this.delta_list.push($data['delta']);
       $this.theta_list.push($data['theta']);
       $this.low_alphas.push($data['low_alpha']);
@@ -609,9 +655,11 @@ export default {
     }
   },
   mounted() {
-    $this._deviceId = game_store.getters.getDeviceId();
-    $this._serviceId = game_store.getters.getServiceId();
-    $this._characteristicId = game_store.getters.getCharacterId();
+    console.log($this.$bluetooth.ToyPower)
+    $this.executed = false;
+    $this.deviceId = "";
+    $this.toy_UUID = "";
+    $this.deviceId = game_store.getters.getDeviceId();
     // setTimeout(() => {
     $this.game_status = game_store.getters.getGameStatus();
     // }, 1000)
@@ -623,8 +671,14 @@ export default {
       $this.start_game();
 
       //打开蓝牙监听
-      bluetooth.watch_bluetooth_status($this);
+      $this.$bluetooth.watch_bluetooth_status($this);
     }
+
+    // const $sendSmPack = setInterval(()=>{
+    //   if ($this.game_status == 1){
+    //     $this.$bluetooth.SendOrder("04")
+    //   }
+    // },1500)
   },
   created() {
     $this = this;
@@ -679,9 +733,6 @@ export default {
   onUnload() {
     console.log("小程序被销毁");
     if (!$this.is_end) {
-      //停止传输数据
-      bluetooth.sendEnd();
-      wx.offBLECharacteristicValueChange();
       //存储时间
       game_store.setters.setPlayedTime($this.played_time);
       //设置未结束游戏

+ 37 - 0
src/requests/game.js

@@ -43,3 +43,40 @@ export function gameList($params = {}) {
   $params["access_token"] = wx.getStorageSync("token");
   return fly.post("game/game-list", $params);
 }
+
+//2021年10月21日15:08:57
+//获取设备
+export function getDeviceBySn($sn) {
+  let $params = {
+    "access_token": wx.getStorageSync("token"),
+    "sn": $sn
+  }
+  return fly.post("equipment/equipment-search", $params)
+}
+
+//2021年10月22日11:11:03
+// 写入设备
+export function setDeviceInDb($this, $deviceId) {
+  let $params = $this.device_data;
+  $params["access_token"] = wx.getStorageSync("token")
+  wx.getSystemInfo({
+    success(res) {
+      switch (res.platform) {
+        case "android":
+        default:
+          $params['is_android'] = 0;
+          break;
+        case "ios":
+          $params['is_android'] = 2;
+          break;
+      }
+      if (res.platform == "ios") {
+        $params['ios_device_id'] = $deviceId
+      } else {
+        $params['device_id'] = $deviceId;
+      }
+    }
+  })
+  return fly.post("https://testadmin.shuimuai.com/equipment/factory", $params)
+}
+

+ 1 - 1
src/store/bluetooth.js

@@ -7,7 +7,7 @@ const getters = {
 const setters = {
   setBluetoothLinkStatus($bool) {
     wx.setStorageSync('ble_link_status', $bool)
-  }
+  },
 }
 
 export default {

+ 17 - 8
src/store/game.js

@@ -1,19 +1,21 @@
 const setters = {
   clearDeviceToy() {
     wx.removeStorageSync('deviceId')
+    wx.removeStorageSync('deviceSn')
     wx.removeStorageSync('serviceId')
-    wx.removeStorageSync('characteristicId')
+    wx.removeStorageSync('is_new')
+    // wx.removeStorageSync('characteristicId')
   },
   //setter模块
   setDeviceId(deviceId) {
     wx.setStorageSync('deviceId', deviceId)
   },
+  setDeviceSn(deviceSn) {
+    wx.setStorageSync('deviceSn', deviceSn)
+  },
   setServiceId(serviceId) {
     wx.setStorageSync('serviceId', serviceId)
   },
-  setCid(characteristicId) {
-    wx.setStorageSync('characteristicId', characteristicId)
-  },
   setGameStatus(status) {
     wx.setStorageSync('game_status', status)
   },
@@ -56,6 +58,9 @@ const setters = {
   //记录游戏数据
   setGameAttMedDatas($param) {
     wx.setStorageSync('game_data', $param)
+  },
+  setIsNew($param) {
+    wx.setStorageSync('is_new', $param)
   }
 }
 
@@ -63,19 +68,19 @@ const getters = {
   getDeviceId() {
     return wx.getStorageSync('deviceId')
   },
+  getDeviceSn() {
+    return wx.getStorageSync('deviceSn')
+  },
   getServiceId() {
     return wx.getStorageSync('serviceId')
   },
-  getCharacterId() {
-    return wx.getStorageSync('characteristicId')
-  },
   getGameStatus() {
     return wx.getStorageSync('game_status')
   },
   getGameCloseStatus() {
     return wx.getStorageSync('game_close_status')
   },
-  
+
   getToyList() {
     return wx.getStorageSync('toy_list')
   },
@@ -111,6 +116,10 @@ const getters = {
   //记录游戏数据
   getGameAttMedDatas() {
     return wx.getStorageSync('game_data')
+  },
+  //记录游戏数据
+  getIsNew() {
+    return wx.getStorageSync('is_new')
   }
 }
 

+ 594 - 122
src/utils/bluetooth.js

@@ -4,27 +4,147 @@ import Notify from "../../static/vant/notify/notify";
 
 var $ff = "ff";
 var $8f = "ffffffff"
-export default {
+var control_close = false
+var current_device_sn = ""
+//记录当前脑环的mac地址
+var current_device_mac = "";
+//记录教具连接状态
+var connect_toy = true;
+//记录教具连接的id
+var current_toy_id = "00";
+//记录教具的UUID
+var current_toy_UUID = "";
+
+//标记是否打开脑控
+var FlagOpenControl = false;
+
+var ToyPower = 0;
+
+//Math.round(new Date() / 1000)
+var logTime = "";
+
+var current_hex = "";
+
+var is_new = game_store.getters.getIsNew();
+
+//2021年11月10日14:59:38
+// 0为旧 1为新
+var services = [
+  "6e400001-b5a3-f393-e0a9-e50e24dcca9e".toUpperCase(),
+  "0000fff0-0000-1000-8000-00805f9b34fb".toUpperCase()
+]
+var charateristics = [
+  {
+    notify: "6e400003-b5a3-f393-e0a9-e50e24dcca9e".toUpperCase(),
+    write: "6e400002-b5a3-f393-e0a9-e50e24dcca9e".toUpperCase()
+  },
+  {
+    notify: "0000fff1-0000-1000-8000-00805f9b34fb".toUpperCase(),
+    write: "0000fff2-0000-1000-8000-00805f9b34fb".toUpperCase()
+  },
+]
+
+function getServicesAndCharateristc() {
+  //获取当前设备名称
+  // let $brainSn = game_store.getters.getDeviceSn();
+  let $deviceId = game_store.getters.getDeviceId();
+  let $serviceId = game_store.getters.getServiceId();
+  let $index = services.indexOf($serviceId.toUpperCase())
+  // let $index = $brainSn.toUpperCase().indexOf("JELLYFISH") != -1 ? 0 : 1;
+  return {
+    deviceId: $deviceId,
+    service: services[$index],
+    charateristic: charateristics[$index]
+  }
+}
 
-  // 发送开启脑电数据包指令
-  sendOpen() {
-    this.WriteBufferInBle("03 00 00 00 ff");
+export default {
+  //变量
+  connect_toy, control_close, current_toy_id, current_toy_UUID, ToyPower, current_device_sn, is_new,
+
+  /**
+   *  todo:打开大包数据
+   */
+  sendOpenBigData() {
+    this.SendOrder('ff')
   },
-  // 发送开启教具脑控指令
+  /**
+   *  todo:关闭大包数据
+   */
+  sendCloseBigData() {
+    this.SendOrder('00')
+  },
+  /**
+   *  todo:获取当前连接的教具类型
+   */
+  sendGetToyType() {
+    this.SendOrder('06')
+  },
+  /**
+   *  todo:开启脑控
+   */
   sendControl() {
-    this.WriteBufferInBle("03 00 00 00 07");
+    let that = this;
+    that.SendOrder('07')
   },
-  //发送断开玩具的指令
-  sendEnd() {
-    //AA CC 03 00 00 00 09 F3
-    this.WriteBufferInBle("03 00 00 00 09");
+  /**
+   *  todo:关闭脑控
+   */
+  sendControlClose() {
+    let that = this
+    control_close = false;
+    let $intv = setInterval(() => {
+      if (!control_close) {
+        that.SendOrder('09')
+        //如果是jellyfish则发送00教具
+        if(!is_new){
+          that.sendConnectOneToMore('00')
+        }
+
+      } else {
+        //设置打开脑控为false
+        FlagOpenControl = false;
+        clearInterval($intv)
+        //清空当前数据
+        that.clearLocalDatas()
+      }
+    }, 1000)
   },
-  // 发送停止发送脑电数据包指令
-  sendPause() {
-    this.WriteBufferInBle("03 00 00 00 08");
+  /**
+   *  todo:发送一对多连接
+   */
+  sendConnectOneToMore(id) {
+    this.WriteBufferInBle(`03 00 ${id} 00 0A`);
+  },
+  /**
+   *  todo:发送一对一连接
+   */
+  sendConnectOneToOne(id) {
+    current_toy_id = id;
+    this.WriteBufferInBle(`03 00 ${id} 01 0A`)
   },
 
-  //  获取大包数据 进行绘制图表
+  /**
+   *  todo:获取教具电量
+   */
+  sendToyPower() {
+    let that = this;
+    if (is_new) {
+      let $connect_false_count = 0;
+      let toy_intv = setInterval(() => {
+        let $game_status = game_store.getters.getGameStatus();
+        if ($game_status == 1) {
+          that.SendOrder('8a')
+        }
+      }, 3000)
+    }else{
+      console.log("旧脑环不支持获取教具电量")
+    }
+  },
+
+  /**
+   *  todo:获取大包数据进行绘制图表
+   */
   get_big_data(hex) {
     if (hex.substr(0, 6) != "555520") {
       return false;
@@ -76,16 +196,6 @@ export default {
     let $high_beta_2 = hex.substr(hex.indexOf("0418") + 36, 2);
     let $high_beta_3 = hex.substr(hex.indexOf("0418") + 38, 2);
     let $high_beta = parseInt($high_beta_1 + $high_beta_2 + $high_beta_3, 16);
-    console.log(
-      "att: " + $att,
-      "med: " + $med,
-      "delta: " + $delta,
-      "theta: " + $theta,
-      "low_alpha: " + $low_alpha,
-      "high_alpha: " + $high_alpha,
-      "low_beta: " + $low_beta,
-      "high_beta: " + $high_beta,
-    );
     let $max_num = 30000;
     return {
       att: $att,
@@ -98,7 +208,9 @@ export default {
       high_beta: $high_beta >= $max_num ? $max_num : $high_beta
     };
   },
-  //获取设备电量
+  /**
+   *  todo:获取设备电量
+   */
   get_device_elc(hex) {
     if (hex.substr(0, 8) != "55550203") {
       return false;
@@ -107,23 +219,16 @@ export default {
     return $power;
   },
 
-  //  监听蓝牙连接状态
-  watch_bluetooth_status($that) {
+  /**
+   *  todo:监听蓝牙连接状态
+   */
+  watch_bluetooth_status($this) {
     let that = this;
     // 微信自身监听低功耗蓝牙连接状态的改变事件
     wx.onBLEConnectionStateChange((res) => {
       // 该方法回调中可以用于处理连接意外断开等异常情况
       ble_store.setters.setBluetoothLinkStatus(res.connected);
       if (res.connected == false) {
-        //断开玩具连接
-        try {
-          $that.change_toy_connect_status(0);
-          //断开蓝牙连接
-          $that.change_device_status(0);
-        } catch (e) {
-          console.log("方法不存在");
-        }
-
         //判断游戏是否游戏中
         let $game_status = game_store.getters.getGameStatus();
         if ($game_status == 1) {
@@ -132,22 +237,84 @@ export default {
           Notify({
             type: 'danger',
             duration: 0,
-            message: '智脑环已断开连接,请重新扫码智脑环'
+            message: '智脑环已断开连接,正在尝试重新连接',
+            onOpened() {
+              that.reconnect(res.deviceId, $this)
+            }
           });
+          control_close = true
           // game_store.setters.setGameStatus(0);
           // 结束状态更改为1
-          game_store.setters.setGameCloseStatus(1);
+        } else {
+          //关闭脑控
+          // that.sendControlClose();
+          game_store.setters.setGameStatus(0);
+          // 清空链接得设备 三值
+          game_store.setters.clearDeviceToy();
+          $this.connect_toy = 0;
+          $this.connect_show = false;
+          $this.device_bg = false;
+          $this.change_toy_connect_status(0);
+          $this.device_status = 0;
+          $this.device = {}
+          $this.toy_UUID = "";
+          $this.$forceUpdate();
+          wx.closeBluetoothAdapter();
+        }
+      }
+    });
+  },
 
+  /**
+   * todo:重新连接蓝牙
+   */
+  reconnect($deviceId, $this) {
+    let that = this;
+    let $deviceInfo = getServicesAndCharateristc();
+    //重连的次数
+    let $connect_count = 0;
+    let $rec = setInterval(() => {
+      $connect_count += 1;
+      let $game_status = game_store.getters.getGameStatus();
+      if ($game_status == 1) {
+        wx.createBLEConnection({
+          deviceId: $deviceInfo.deviceId,
+          success(res) {
+            Notify({type: 'success', message: `第${$connect_count}次重新连接成功`});
+            let $system = wx.getSystemInfoSync()
+            if ($system.platform == 'ios') {
+              that.getBLEDeviceServices($deviceInfo.deviceId)
+              that.watchingDevice($this)
+            } else {
+              that.openNotify($this)
+              that.watch_bluetooth_status($this);
+            }
 
+            clearInterval($rec)
+          },
+          fail(res) {
+            Notify({type: 'danger', message: `第${$connect_count}次重新连接失败`});
+            game_store.setters.setGameCloseStatus(1);
+          }
+        })
+        if ($connect_count >= 3) {
+          $this.game_finished();
+          clearInterval($rec)
         }
+      } else {
+        clearInterval($rec)
       }
-    });
+    }, 5000)
+
   },
 
-  //获取蓝牙设备服务
+  /**
+   * todo 获取蓝牙设备服务
+   * @param deviceId
+   */
   getBLEDeviceServices(deviceId) {
-    const $this = this;
-
+    const that = this;
+    current_device_mac = deviceId
     wx.getBLEDeviceServices({
       deviceId,
       success: (res) => {
@@ -155,18 +322,22 @@ export default {
           console.log("serviceItem:" + res.services[i].uuid);
           if (res.services[i].uuid.indexOf('6E') != -1 || res.services[i].uuid.indexOf('0000FFF0') != -1) {
             console.log("SelectedServiceItem:" + res.services[i].uuid);
-            $this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid);
+            that.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid);
+            game_store.setters.setServiceId(res.services[i].uuid)
+            is_new = game_store.getters.getIsNew()
             return;
           }
         }
       },
       fail(res) {
-        console.log("连接蓝牙成功,获取服务失败");
+        console.log("连接蓝牙成功,获取服务失败", res);
       },
     });
   },
 
-  //获取蓝牙设备某个服务中所有特征值
+  /**
+   * todo 获取蓝牙设备某个服务中所有特征值
+   */
   getBLEDeviceCharacteristics(deviceId, serviceId) {
     console.log(deviceId, serviceId);
     const $this = this;
@@ -177,25 +348,12 @@ export default {
         console.log("getBLEDeviceCharacteristics success", res.characteristics);
         for (let i = 0; i < res.characteristics.length; i++) {
           let item = res.characteristics[i];
-          if (item.properties.read) {
-            wx.readBLECharacteristicValue({
-              deviceId,
-              serviceId,
-              characteristicId: item.uuid,
-            });
-          }
           if (item.properties.write) {
             $this.deviceId = deviceId;
             $this.serviceId = serviceId;
             $this.cid = item.uuid;
-            game_store.setters.setDeviceId(deviceId);
-            game_store.setters.setServiceId(serviceId);
-            game_store.setters.setCid(item.uuid);
             //打开数据帧
-            $this.sendOpen();
-            // $this.sendPause(deviceId, serviceId, item.uuid)
-            //获取玩具的值
-            // bluetooth.sendConnect($this.toy_hex, deviceId, serviceId, item.uuid)
+            $this.sendOpenBigData();
           }
 
           if (item.properties.notify || item.properties.indicate) {
@@ -214,17 +372,27 @@ export default {
     });
   },
 
-
-  // 发送连接玩具指令
-  sendConnect($hex) {
-    //获取最后两个字节
-    this.WriteBufferInBle("03 00 " + $hex + " 00 0a");
-  },
-  //  获取当前连接得玩具
-  getConnectedToy() {
-    this.WriteBufferInBle("03 00 00 00 06");
+  openNotify($this) {
+    let that = this;
+    let $deviceInfo = getServicesAndCharateristc();
+    console.log($deviceInfo)
+    wx.notifyBLECharacteristicValueChange({
+      deviceId: $deviceInfo.deviceId,
+      serviceId: $deviceInfo.service,
+      characteristicId: $deviceInfo.charateristic.notify,
+      state: true,
+      success() {
+        that.watchingDevice($this)
+        that.sendOpenBigData();
+      }
+    });
   },
-  // ArrayBuffer转16进度字符串示例
+
+  /**
+   * todo ArrayBuffer转16进度字符串示例
+   * @param buffer
+   * @returns {string}
+   */
   ab2hex(buffer) {
     var hexArr = Array.prototype.map.call(
       new Uint8Array(buffer),
@@ -234,45 +402,140 @@ export default {
     );
     return hexArr.join("");
   },
-  //断开发送数据
-  shutdownSendControl() {
-    this.WriteBufferInBle("03 00 00 00 0a");
-  },
 
-  // 监听脑环是否带正
+
+  /**
+   * todo 监听脑环数据
+   * @param $this
+   */
   watchingDevice($this) {
+    console.log("监听数据", "is_new:" + is_new)
     const that = this;
+    let DeviceId = game_store.getters.getDeviceId();
     wx.onBLECharacteristicValueChange((characteristic) => {
       let hexStr = that.ab2hex(characteristic.value);
-      console.log(hexStr);
+
+      // 教具断链
+      if (hexStr.toUpperCase().indexOf("AAEE70") != -1) {
+        wx.showToast({
+          title: "教具已断开",
+          icon: "error"
+        })
+        //重连机制
+        that.SendOrder("09")
+        setTimeout(() => {
+          that.ReconnectToy()
+        }, 1500)
+      }
+      if (hexStr.toUpperCase().indexOf("AAEE07") != -1) {
+        that.sendControl();
+      }
+
+      if (hexStr.toUpperCase().indexOf("AADD") != -1 || hexStr.toUpperCase().indexOf("AAEE") != -1) {
+        let nowTime = Math.round(new Date() / 1000);
+        console.log(`应答耗时:${(nowTime - logTime)}秒`)
+        console.log(hexStr);
+      }
       let $data = that.get_big_data(hexStr);
-      // wx.getBLEDeviceRSSI({
-      //   deviceId: characteristic.deviceId,
-      //   success(res) {
-      //     $this.rssi = Math.abs(res["RSSI"]);
-      //   },
-      // });
-
-      //监听连接教具
-      if (hexStr.substr(0, 8).toLowerCase() == "aadd0a00") {
-        if ($this.toy_item["hex"]) {
-          let $hex = $this.toy_item["hex"].substr($this.toy_item["hex"].length - 2, 2);
-          if (hexStr.substr(8, 2) == $hex) {
+      let $game_status = game_store.getters.getGameStatus();
+
+      // 2021年10月20日17:18:13 判断教具 连接
+      if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
+        //没连接上教具
+        if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
+          $this.change_toy_connect_status(3);
+          return false;
+        }
+        let $mHexStrIndex = hexStr.toUpperCase().indexOf("AADD0A");
+        let $hex_index = hexStr.substr($mHexStrIndex + 28, 2)
+        let $toy_id = hexStr.substr($mHexStrIndex + 8, 2)
+        console.log("连接", $hex_index)
+        console.log("玩具", $toy_id)
+        // 连接上教具
+        if (new RegExp("00").test($hex_index) == true) {
+          if (is_new) {
+            that.sendConnectOneToOne($toy_id)
+            $this.current_hex = `03 00 ${$toy_id} 01 0A`
+            console.log("一对多")
+          } else {
+            $this.current_hex = "";
             wx.showToast({
               title: "已连接到" + $this.toy_item.name
             });
+            $this.toy_connected = true;
             $this.change_toy_connect_status(2);
-          } else if (hexStr.substr(8, 2) == "00") {
-            $this.change_toy_connect_status(3);
           }
         }
+        if (new RegExp("01").test($hex_index) == true) {
+          console.log("一对一")
+          $this.current_hex = "";
+          wx.showToast({
+            title: "已连接到" + $this.toy_item.name
+          });
+          $this.toy_connected = true;
+          $this.change_toy_connect_status(2);
+          //连接成功后 获取一次教具名称
+          that.SendOrder('87')
+        }
+
+        if (new RegExp("02").test($hex_index) == true) {
+          //发送教具连接
+          connect_toy = true
+          wx.hideLoading()
+          wx.showToast({
+            title: "教具重连成功"
+          })
+          that.sendControl()
+          that.sendToyPower();
+        }
       }
 
-      //暂停脑控,切断教具连接
-      if (hexStr.substr(0, 8).toLowerCase() == "aadd0900") {
-        this.shutdownSendControl();
+      //2021年11月23日10:39:49
+      // 获取教具名称
+      if (hexStr.toUpperCase().indexOf("AADD87") != -1) {
+        let $mHexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD87"))
+        let $datas = that.DoAnalysis($mHexStr, 10)
+        let $number = $datas.match(/\d+/)
+        let toy_list_pre = {'01': "SW", '02': "KL", '04': "SC", '05': "PP", '06': "SU", '09': "UF"}
+        let $sn = toy_list_pre[current_toy_id] + $number;
+        $this.toy_sn = $sn;
+        //获取教具电量
+        that.SendOrder('8a')
       }
+      if (hexStr.toUpperCase().indexOf("AAEE87") != -1) {
+        //获取教具电量
+        that.SendOrder('87')
+      }
+
+      //2021年10月21日16:30:07
+      // 获取教具电量
+      if (hexStr.toUpperCase().indexOf("AADD8A") != -1) {//接收教具电量状态
+        let $_hexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD8A") + 6);
+        let $power = parseInt($_hexStr.substr(0, 2), 16)
+        let $voltage = parseInt($_hexStr.substr(2, 2), 16)
+
+        // $this.toy_power = Math.round(that.CalBLEPower($voltage));
+        if ($power > 0) {
+          $this.toy_power = $power
+          $this.toy_voltage = $voltage
+          ToyPower = $power;
+        }
 
+        //连接上教具的标识
+        //FF为无效
+        if ($power != 0) {
+          connect_toy = true;
+        }
+        if (hexStr.toUpperCase().indexOf("FF") != -1) {
+          connect_toy = false;
+        }
+
+
+        if (current_toy_UUID == "") {
+          //获取教具UUID
+          that.SendOrder('84')
+        }
+      }
 
       //监听佩戴正确
       if (hexStr.substr(0, 6) == "555520") {
@@ -283,25 +546,74 @@ export default {
         $this.device_bg = $s1 == "00";
       }
 
-      //  监听脑环电量
-      let $power = that.get_device_elc(hexStr);
-      if ($power) {
-        // console.log("当前脑环电量:", $power)
-        $this.device_power = $power;
+      // 2021年10月25日09:15:50
+      // 收到一次UUID就发送一次获取教具的电量
+      // 读取教具UUID
+      if (hexStr.toUpperCase().indexOf("AADD84") != -1) {//接收UUID 5个字节
+        let $hex_index = hexStr.toUpperCase().indexOf("AADD84") + 6;
+        let $datas = hexStr.substr($hex_index, 10);
+        if ($datas != "0000000000") {
+          console.log("以获取UUID:" + $datas)
+          current_toy_UUID = $datas;
+          $this.toy_UUID = $datas;
+        }
       }
-      if ($power < 10 && $power > 0) {
-        wx.showToast({
-          title: "脑环电量不足",
-          icon: "none",
-          duration: 2000,
-          success() {
-            // $this.change_device_status(0);
-          },
-        });
+
+
+      if (hexStr.toUpperCase().indexOf("AADD09") != -1) {
+        control_close = true;
+      }
+
+      //收到发送UUID的应答立马发送连接教具的指令
+      if (hexStr.toUpperCase().indexOf("AADD8E") != -1) {
+        //发送教具连接
+        that.WriteBufferInBle(`03 00 ${current_toy_id} 02 0A`)
       }
 
+
+      // 2021年11月10日14:34:26
+      // 处理打开脑控的应答
+      if (hexStr.toUpperCase().indexOf("AADD07") != -1) {
+        FlagOpenControl = true;
+        console.log($game_status)
+        if ($game_status != 1) {
+          setTimeout(() => {
+            mpvue.navigateTo({
+              url: "/pages/start/main",
+              success() {
+                // 设置游戏状态为游戏中
+                game_store.setters.setGameStatus(1);
+                $this.gameStart();
+              },
+            });
+          }, 800);
+        }
+      }
+
+
+      if (hexStr.substr(0, 8) == "55550203") {
+        let $power = parseInt(hexStr.substr(8, 2), 16);
+        let $voltage = parseInt(hexStr.substr(10, 2), 16);
+        //  监听脑环电量
+        if ($power) {
+          // console.log("当前脑环电量:", $power)
+          $this.device_power = $power;
+          $this.device_voltage = $voltage;
+        }
+        if ($power < 10 && $power > 0) {
+          wx.showToast({
+            title: "脑环电量不足",
+            icon: "none",
+            duration: 2000,
+            success() {
+              // $this.change_device_status(0);
+            },
+          });
+        }
+      }
+
+
       //游戏中模块
-      let $game_status = game_store.getters.getGameStatus();
       if ($game_status == 1 && $data) {
         try {
           if ($this.played_time > 0) {
@@ -310,14 +622,15 @@ export default {
             game_store.setters.setPlayedTime($this.played_time)
             $this.played_time_text = that.formatPlaySeconds($this.played_time);
             $this.do_datas($data);
-            // if ($this.played_time_text.indexOf(":00") != -1 || $this.played_time_text.indexOf(":30") != -1) {
-            //   $this.post_data();
+            // if ($this.played_time % 10 == 0) {
+            //   //读取教具电量
+            //   that.sendToyPower_CheckReconected()
             // }
           }
           if ($this.played_time == 0) {
             $this.post_data();
             //判断是否隐藏 隐藏则不绘画
-            that.shutdownSendControl();
+            that.sendControlClose();
             let $hide_status = game_store.getters.getHideStatus();
             if (!$hide_status) {
               $this.game_finished();
@@ -329,7 +642,12 @@ export default {
       }
     });
   },
-  // 游玩时间倒计时
+
+  /**
+   * todo 游玩时间倒计时
+   * @param value
+   * @returns {string}
+   */
   formatPlaySeconds(value) {
     // 字符串转数字
     var secondTime = parseInt(value); // 秒
@@ -358,7 +676,12 @@ export default {
     return result;
   },
 
-  //根据错误代码返回字符串信息
+  /**
+   * todo 根据错误代码返回字符串信息
+   * @param errCode
+   * @returns {string}
+   * @constructor
+   */
   GetopenBluetoothAdapterError(errCode) {
 
     let $errmsg = "";
@@ -384,11 +707,16 @@ export default {
 
     return $errmsg;
   },
-  //写入buffer
-  WriteBufferInBle($hex) {
-    let $device_id = game_store.getters.getDeviceId();
-    let $service_id = game_store.getters.getServiceId()
-    let $charateristic = game_store.getters.getCharacterId();
+
+  /**
+   * todo 写入buffer
+   * @param $hex
+   * @param $buffer_len
+   * @constructor
+   */
+  WriteBufferInBle($hex, $buffer_len = 8) {
+    let that = this;
+    let $deviceInfo = getServicesAndCharateristc();
     let $hex_header = "aa cc ";
     // let $hex = "03 00 01 00 0a";
 
@@ -401,7 +729,7 @@ export default {
     let $checksum = ($hex_sum ^ parseInt($8f, 16)) & parseInt($ff, 16);
 
     $hex = $hex_header + $hex + " " + $checksum.toString(16);
-    let buffer = new ArrayBuffer(8);
+    let buffer = new ArrayBuffer($buffer_len);
     let dataView = new DataView(buffer);
     $hex_ary = $hex.split(" ");
     $hex_ary.forEach(($val, $index) => {
@@ -409,17 +737,161 @@ export default {
     })
 
     wx.writeBLECharacteristicValue({
-      deviceId: $device_id,
-      serviceId: $service_id,
-      characteristicId: $charateristic,
+      deviceId: $deviceInfo.deviceId,
+      serviceId: $deviceInfo.service,
+      characteristicId: $deviceInfo.charateristic.write,
       value: buffer,
       success: function (res) {
         console.log($hex + ',写入成功')
+        logTime = Math.round(new Date() / 1000);
       },
       fail: function (err) {
         console.log($hex + "写入失败");
-        console.log(err);
+        console.log(err, $deviceInfo);
       },
     });
+  },
+
+  /**
+   * todo写入8位指令
+   * @param id 末尾id
+   * @constructor
+   */
+  SendOrder(id) {
+    let $hexStr = `03 00 00 00 ${id}`;
+    this.WriteBufferInBle($hexStr)
+  },
+
+  /**
+   * todo 写入16个字节的指令
+   * @param val
+   * @param id
+   * @constructor
+   */
+  Send16Order(val, id) {
+    let $str = val;
+    let $str_ary = $str.split('');
+    $str = "";
+    $str_ary.forEach(($val, $index) => {
+      $str += $val.charCodeAt().toString(16) + " "
+    });
+    $str = $str.substr(0, $str.length - 1)
+    let $hexStr = "03 ff " + $str + ` ${id}`;
+
+    this.WriteBufferInBle($hexStr, 16)
+  },
+
+
+  /**
+   * todo 解析hex
+   * @param hexStr
+   * @param byte_count
+   * @param sublen
+   * @returns {string}
+   * @constructor
+   */
+  DoAnalysis(hexStr, byte_count, sublen = 6) {
+    //byte_count
+    let $_str5 = hexStr.substr(sublen);
+    let $datas = $_str5.substr(0, byte_count * 2);
+    let $_data = "";
+    for (let $i = 0; $i < $datas.length; $i += 2) {
+      let $code = parseInt($datas.substr($i, 2), 16)
+      $_data += String.fromCharCode($code)
+    }
+    return $_data;
+  },
+
+  /**
+   * todo 重连教具
+   * @constructor
+   */
+  ReconnectToy() {
+    current_device_mac = game_store.getters.getDeviceId();
+    let $game_status = game_store.getters.getGameStatus();
+
+    let that = this;
+    try {
+      //发送UUID
+      let $uuid_str = "";
+      for (let $i = 0; $i < current_toy_UUID.length; $i += 2) {
+        $uuid_str += current_toy_UUID.substr($i, 2) + " ";
+      }
+
+      let _deviceId = "";
+      let deviceIds = current_device_mac.split(':');
+      for (let i = 0; i < deviceIds.length; i++) {
+        if (i != 2) {
+          _deviceId += deviceIds[i] + " ";
+        }
+      }
+
+      let sum = $uuid_str + _deviceId;
+      sum = sum.substr(0, sum.length - 1);
+      let $hexStr = `03 ff ${sum} 8e`;
+      let loop_count = "";
+      if ($game_status == 1) {
+        wx.showLoading({
+          title: "重新连接教具中"
+        })
+      }
+      let connect_toy_intv = setInterval(() => {
+        $game_status = game_store.getters.getGameStatus();
+        if ($game_status == 1) {
+
+          if (connect_toy == false) {
+            if (loop_count == 3) {
+              wx.hideLoading()
+              wx.showToast("教具已无法连接")
+              clearInterval(connect_toy_intv)
+            }
+            loop_count += 1;
+            that.WriteBufferInBle($hexStr, 16)
+          } else {
+            wx.hideLoading()
+            loop_count = 0;
+            clearInterval(connect_toy_intv)
+          }
+        } else {
+          wx.hideLoading()
+          clearInterval(connect_toy_intv)
+        }
+      }, 3000)
+
+
+    } catch (e) {
+      console.log("ReconnectToy:", e)
+    }
+
+  },
+
+  /**
+   * todo 清空当前脚本的变量值
+   */
+  clearLocalDatas() {
+    control_close = false
+    connect_toy = false;
+    current_toy_id = "00";
+    current_toy_UUID = "";
+  },
+
+  /**
+   * todo 计算电量
+   * @param $voltage
+   * @returns {number}
+   * @constructor
+   */
+  CalBLEPower($voltage) {
+    let $max = 4100;
+    let $min = 3500;
+
+    //(当前电压值(mV)-最低电压值(mV)) / (最大电压值(mV)-最低电压值(mV)) *100%
+    //当前电压
+    let $_voltage = $voltage * 100;
+    // console.log(`计算的当前电压:${$_voltage}`)
+
+    let $percent = (($_voltage - $min) / ($max - $min)) * 100;
+    // console.log(`计算的电量:${$percent}`);
+    return $percent;
   }
 };

+ 9 - 0
src/utils/index.js

@@ -2,7 +2,16 @@ function formatNumber(n) {
   const str = n.toString();
   return str[1] ? str : `0${str}`;
 }
+export function getNowDate() {
 
+  var date = new Date();
+  const year = date.getFullYear();
+  const month = date.getMonth() + 1;
+  const day = date.getDate();
+
+
+  return `${year}${month}${day}`;
+}
 export function formatTime(date) {
   if (date.length <= 11) {
     date = date * 1000;