Fury vor 3 Jahren
Ursprung
Commit
583f228ad0
4 geänderte Dateien mit 165 neuen und 105 gelöschten Zeilen
  1. 26 7
      src/components/device/device.vue
  2. 133 81
      src/components/index/personal.vue
  3. 0 16
      src/pages/index/index.vue
  4. 6 1
      src/utils/bluetooth.js

+ 26 - 7
src/components/device/device.vue

@@ -219,8 +219,30 @@ export default {
     open_scan() {
       // 打开蓝牙扫描 重置游戏状态
       game_store.setters.setGameStatus(0);
-      //
-      $this.scan_to_bluetooth();
+
+      wx.getSystemInfoAsync({
+        success(res) {
+          if (res.bluetoothEnabled == false) {
+            wx.showToast({
+              icon: "none",
+              title: "请打开蓝牙",
+            });
+          } else if (res.locationEnabled == false) {
+            // 如果是苹果系统则直接打开扫描
+            if (res.system.indexOf("iOS") != -1) {
+              $this.scan_to_bluetooth();
+            } else {
+              //如果是安卓系统 则提示打开位置信息 后 打开扫描
+              wx.showToast({
+                icon: "none",
+                title: "请打开位置信息",
+              });
+            }
+          } else {
+            $this.scan_to_bluetooth();
+          }
+        },
+      });
     },
     //扫描连接蓝牙
     scan_to_bluetooth() {
@@ -470,14 +492,10 @@ export default {
       try {
         // 5秒后判断 这5秒在搜索设备,搜索到就赋值给_deviceId
         // setTimeout(() => {
-        //   if (!$this.device.deviceId) {
+        //   if ($this.device_data.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);
         // 小乌龟
@@ -493,6 +511,7 @@ export default {
               $this.stopBluetoothDevicesDiscovery();
               console.log("搜索设备", device);
               $this.createBLEConnection(device.deviceId);
+              $this.device_data.deviceId = device.deviceId;
             }
           });
         });

+ 133 - 81
src/components/index/personal.vue

@@ -1,10 +1,18 @@
 <template>
   <div id="personal">
     <!--    用户信息-->
-    <div :class="{userinfoYellow:userinfo.isActive, userinfoGrey:userinfo.isntActive}" >
+    <div
+      :class="{
+        userinfoYellow: userinfo.isActive,
+        userinfoGrey: userinfo.isntActive,
+      }"
+    >
       <van-row class="padding">
         <van-col span="3" offset="2">
-          <view class="cu-avatar radius lg" :style="'background-image:url('+userinfo.portrait+');'"></view>
+          <view
+            class="cu-avatar radius lg"
+            :style="'background-image:url(' + userinfo.portrait + ');'"
+          ></view>
         </van-col>
         <van-col span="12" offset="1">
           <div class="flex flex-direction align-start justify-start">
@@ -12,11 +20,18 @@
               <text class="text-black text-bold">{{ userinfo.user_name }}</text>
             </div>
             <div class="flex justify-between align-center">
-              <button class="cu-btn sm round" :class="{level_btn_yellow:userinfo.isActive, level_btn_grey:userinfo.isntActive}">
+              <button
+                class="cu-btn sm round"
+                :class="{
+                  level_btn_yellow: userinfo.isActive,
+                  level_btn_grey: userinfo.isntActive,
+                }"
+              >
                 {{ userinfo.level_name }}
-
               </button>
-              <view class="text-xs padding-left" v-if="userinfo.level == 11">有效期至 {{ userinfo['validity_time_formatted'] }}</view>
+              <view class="text-xs padding-left" v-if="userinfo.level == 11"
+                >有效期至 {{ userinfo["validity_time_formatted"] }}</view
+              >
             </div>
           </div>
         </van-col>
@@ -28,7 +43,7 @@
         </van-col>
       </van-row>
       <van-row class="padding">
-        <view style="opacity: 1;">
+        <view style="opacity: 1">
           <van-col span="4" class="lg" offset="2">
             <text class="cuIcon-selection"></text>
             卡号:
@@ -37,26 +52,22 @@
             <text class="text-white text-bold text-lg">{{ invite_code }}</text>
           </van-col>
         </view>
-
       </van-row>
       <van-row>
         <van-col span="6" offset="1">
           <div class="flex flex-direction align-center">
-
             <text class="text-xxl">{{ userinfo.play_time }}</text>
             <text class="font-sm">可用时长(分钟)</text>
           </div>
         </van-col>
         <van-col span="7" offset="2" @click="to_coupons">
           <div class="flex flex-direction align-center">
-
             <text class="text-xxl">{{ userinfo.coupon }}</text>
             <text class="font-sm">已领券数量</text>
           </div>
         </van-col>
         <van-col span="6" offset="2">
           <div class="flex flex-direction align-center">
-
             <text class="text-xxl">{{ userinfo.experience }}</text>
             <text class="font-sm">次卡</text>
           </div>
@@ -64,8 +75,12 @@
       </van-row>
     </div>
 
-    <view class="text-center font-sm" v-if="userinfo.level >= 3 && userinfo.level <= 7">
-      <text class="text-gray">今日专注力免费训练时长还有:
+    <view
+      class="text-center font-sm"
+      v-if="userinfo.level >= 3 && userinfo.level <= 7"
+    >
+      <text class="text-gray"
+        >今日专注力免费训练时长还有:
         <text class="text-yellow">{{ userinfo.free_time }}</text>
       </text>
     </view>
@@ -109,83 +124,120 @@
       z-index="99"
     >
       <div class="quan_container padding-tb-xl">
-          <view class="margin-top-xl flex justify-center">
-              <text class="title">{{outCouponData.name}}</text>
-          </view>
-          <view class="flex justify-center margin-top">
-              <text class="text-xs" v-if="outCouponData.validity_time.type==1">{{outCouponData.validity_time.time_format}}&nbsp;之前领取有效</text>
-              <text class="text-xs" v-else>{{outCouponData.validity_time.start_time_format}}&nbsp;至&nbsp;{{outCouponData.validity_time.end_time_format}}&nbsp;之前领取有效</text>
-          </view>
-            <!-- 核销 -->
-            <view class="flex justify-center margin-top" v-if="outCouponData.type==1">
-              <div class="flex justify-center quan_container_lil">
-                <div style="display: flex;align-items: baseline">
-                 <text class="hexiao time margin-right-xs">{{ outCouponData.discount.time }}</text>
-                 <text class="time_text" v-if="outCouponData.discount.type==0">分钟</text>
-                 <text class="time_text" v-else>次</text>
-                </div> 
-              </div>
-            </view>
-           <!-- 满减 -->
-            <view class="flex justify-center margin-top" v-if="outCouponData.type==2">
-              <div class="flex justify-center quan_container_lil">
-                <div style="display: flex;align-items: baseline">
-                  <text class="time_text">满</text>
-                  <text class="manjian time margin-lr-xs">{{ outCouponData.discount.full }}</text>
-                  <text class="time_text">减</text>
-                  <text class="manjian time margin-left-xs">{{ outCouponData.discount.reduce }}</text>
-                </div>  
-              </div>   
-            </view>
-            <!-- 折扣 -->
-            <view class="flex justify-center margin-top" v-if="outCouponData.type==3">
-              <div class="flex justify-center quan_container_lil">
-                <div style="display: flex;align-items: baseline">
-                  <text class="time_text">打</text>
-                  <text class="discount time margin-lr-sm">{{ outCouponData.discount.discount*10 }}</text>
-                  <text class="time_text">折</text>
-                </div>
-              </div>  
-            </view>
-            <!-- 随机 -->
-            <view class="flex justify-center margin-top" v-if="outCouponData.type==4">
-              <div class="flex justify-center quan_container_lil">
-                <div style="display: flex;align-items: baseline">
-                  <text class="time_text">随机</text>
-                  <text class="random time margin-lr-xs">{{ outCouponData.discount.start }}</text>
-                  <text class="time_text">至</text>
-                  <text class="random time margin-lr-xs">{{ outCouponData.discount.end }}</text>
-                  <text class="time_text">元</text>
-                </div> 
-              </div>  
-            </view>
-       </div>
-       <view class="flex justify-center margin-top-xl">
-          <button class="cu-btn get_btn text-white" @click="get_coupon">领取</button>
-       </view>
-
-      
+        <view class="margin-top-xl flex justify-center">
+          <text class="title">{{ outCouponData.name }}</text>
+        </view>
+        <view class="flex justify-center margin-top">
+          <text class="text-xs" v-if="outCouponData.validity_time.type == 1"
+            >{{
+              outCouponData.validity_time.time_format
+            }}&nbsp;之前领取有效</text
+          >
+          <text class="text-xs" v-else
+            >{{ outCouponData.validity_time.start_time_format }}&nbsp;至&nbsp;{{
+              outCouponData.validity_time.end_time_format
+            }}&nbsp;之前领取有效</text
+          >
+        </view>
+        <!-- 核销 -->
+        <view
+          class="flex justify-center margin-top"
+          v-if="outCouponData.type == 1"
+        >
+          <div class="flex justify-center quan_container_lil">
+            <div style="display: flex; align-items: baseline">
+              <text class="hexiao time margin-right-xs">{{
+                outCouponData.discount.time
+              }}</text>
+              <text class="time_text" v-if="outCouponData.discount.type == 0"
+                >分钟</text
+              >
+              <text class="time_text" v-else>次</text>
+            </div>
+          </div>
+        </view>
+        <!-- 满减 -->
+        <view
+          class="flex justify-center margin-top"
+          v-if="outCouponData.type == 2"
+        >
+          <div class="flex justify-center quan_container_lil">
+            <div style="display: flex; align-items: baseline">
+              <text class="time_text">满</text>
+              <text class="manjian time margin-lr-xs">{{
+                outCouponData.discount.full
+              }}</text>
+              <text class="time_text">减</text>
+              <text class="manjian time margin-left-xs">{{
+                outCouponData.discount.reduce
+              }}</text>
+            </div>
+          </div>
+        </view>
+        <!-- 折扣 -->
+        <view
+          class="flex justify-center margin-top"
+          v-if="outCouponData.type == 3"
+        >
+          <div class="flex justify-center quan_container_lil">
+            <div style="display: flex; align-items: baseline">
+              <text class="time_text">打</text>
+              <text class="discount time margin-lr-sm">{{
+                outCouponData.discount.discount * 10
+              }}</text>
+              <text class="time_text">折</text>
+            </div>
+          </div>
+        </view>
+        <!-- 随机 -->
+        <view
+          class="flex justify-center margin-top"
+          v-if="outCouponData.type == 4"
+        >
+          <div class="flex justify-center quan_container_lil">
+            <div style="display: flex; align-items: baseline">
+              <text class="time_text">随机</text>
+              <text class="random time margin-lr-xs">{{
+                outCouponData.discount.start
+              }}</text>
+              <text class="time_text">至</text>
+              <text class="random time margin-lr-xs">{{
+                outCouponData.discount.end
+              }}</text>
+              <text class="time_text">元</text>
+            </div>
+          </div>
+        </view>
+      </div>
+      <view class="flex justify-center margin-top-xl">
+        <button class="cu-btn get_btn text-white" @click="get_coupon">
+          领取
+        </button>
+      </view>
     </van-popup>
 
     <!--    窗口弹出-->
     <van-popup :show="pop_show" @close="close_pop" round>
-      <div class="err_container flex flex-direction align-center justify-around">
+      <div
+        class="err_container flex flex-direction align-center justify-around"
+      >
         <view>
-          <text class="title">
-            您当前剩余时间不足
-          </text>
+          <text class="title"> 您当前剩余时间不足 </text>
         </view>
         <view>
-          <text class="sub-title">
-            请充值后进行游戏
-          </text>
+          <text class="sub-title"> 请充值后进行游戏 </text>
         </view>
-        <img src="https://img.shuimuai.com/web/sign_notimeJfish.png" class="err_img" alt="">
-        <button class="cu-btn lg bg-primary text-white" @click="to_recharge">立即充值</button>
+        <img
+          src="https://img.shuimuai.com/web/sign_notimeJfish.png"
+          class="err_img"
+          alt=""
+        />
+        <button class="cu-btn lg bg-primary text-white" @click="to_recharge">
+          立即充值
+        </button>
       </div>
     </van-popup>
-    <van-toast id="van-toast"/>
-
+    <van-toast id="van-toast" />
   </div>
 </template>
 
@@ -349,11 +401,11 @@ export default {
         // 判断外发哪种券
         if (wx.getStorageSync("is_other") == false) {
           outputCoupon().then((res) => {
-            handle_coupon_data(res)
+            handle_coupon_data(res);
           });
         } else {
           outCardCoupon().then((res) => {
-            handle_coupon_data(res)
+            handle_coupon_data(res);
           });
         }
       }

+ 0 - 16
src/pages/index/index.vue

@@ -180,22 +180,6 @@ export default {
       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));
-    //     });
-    //   },
-    // });
-    
-    // userDetail().then((res) => {
-    //   let $data = res.data;
-    //   //判断如果是第一次登录就 弹出领取体验卡
-    //   $this.userinfo = $data.data;
-    //   user_store.setters.set_userinfo($this.userinfo);
-    // });
   },
   onHide() {
   },

+ 6 - 1
src/utils/bluetooth.js

@@ -150,6 +150,8 @@ export default {
       return false;
     }
     //当s1为 00时 数据有效
+    // let hex_str = hex.substr(hex.indexOf("555520"))
+    // let $s1 = hex_str.substr(8, 2);
     let $s1 = hex.substr(8, 2);
     if ($s1 != "00") {
       return false;
@@ -414,7 +416,7 @@ export default {
     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({
@@ -738,6 +740,9 @@ export default {
       dataView.setUint8($index, parseInt($val, 16))
     })
 
+    if(!$deviceInfo.charateristic.write){
+      return false;
+    }
     wx.writeBLECharacteristicValue({
       deviceId: $deviceInfo.deviceId,
       serviceId: $deviceInfo.service,