ソースを参照

修改了监测蓝牙,监测位置信息
在游戏中的界面,在重新显示的时候添加了操作平台的验证
验证是否安卓系统或者苹果系统
如果是苹果系统则添加减去隐藏后的时间

yerong 4 年 前
コミット
19846f5d04

+ 51 - 47
src/components/device/device.vue

@@ -123,15 +123,15 @@
     <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-popup-->
+    <!--      :show="start_show"-->
+    <!--      :closeable="false"-->
+    <!--      position="bottom"-->
+    <!--      custom-style="height: 100%"-->
+    <!--      @close="onStartGameShowClose"-->
+    <!--    >-->
+    <!--      <gameIng v-if="game_status" @closePop="onStartGameShowClose"></gameIng>-->
+    <!--    </van-popup>-->
 
   </div>
 </template>
@@ -210,42 +210,52 @@ export default {
     },
     //扫描连接蓝牙
     scan_to_bluetooth() {
-      wx.scanCode({
-        onlyFromCamera: true,
-        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=(.*)/);
-            // 判断新的标识值
-            $this.code = $code[1].toUpperCase();
-            console.log("头环码", $code);
-            //打开蓝牙设备
-            wx.openBluetoothAdapter({
-              success(res) {
-                //判断已经打开连接了
-                if (res["errMsg"] == "openBluetoothAdapter:ok") {
-                  $this.startBluetoothDevicesDiscovery();
-                }
-              },
-              fail(err) {
-                if (err["errCode"] == 10001) {
-                  Toast.fail({
-                    message: "请打开蓝牙和位置信息!",
-                  });
-                } else {
-                  Toast.fail({
-                    message: "蓝牙连接失败",
+      wx.getSystemInfoAsync({
+        success(res) {
+          console.log(res)
+          if (res.bluetoothEnabled == false || res.locationEnabled == false) {
+            Toast.fail('请打开蓝牙和位置信息')
+          } else {
+            wx.scanCode({
+              onlyFromCamera: true,
+              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=(.*)/);
+                  // 判断新的标识值
+                  $this.code = $code[1].toUpperCase();
+                  console.log("头环码", $code);
+                  //打开蓝牙设备
+                  wx.openBluetoothAdapter({
+                    success(res) {
+                      //判断已经打开连接了
+                      if (res["errMsg"] == "openBluetoothAdapter:ok") {
+                        $this.startBluetoothDevicesDiscovery();
+                      }
+                    },
+                    fail(err) {
+                      if (err["errCode"] == 10001) {
+                        Toast.fail({
+                          message: "请打开蓝牙和位置信息!",
+                        });
+                      } else {
+                        Toast.fail({
+                          message: "蓝牙连接失败",
+                        });
+                      }
+                    },
                   });
                 }
               },
             });
+
           }
         },
       });
@@ -430,12 +440,6 @@ export default {
   },
   mounted() {
     $this.get_toy_list();
-    wx.getSystemInfo({
-      success(res) {
-        console.log(res);
-        console.log(res.brand);
-      },
-    });
   },
   created() {
     $this = this;

+ 1 - 1
src/components/device/unconnect.vue

@@ -2,7 +2,7 @@
   <div>
     <van-row>
       <van-col span="11" class="text-gray text-sm left" offset="1">
-        <view>1.打开手机蓝牙</view>
+        <view>1.打开手机蓝牙和位置信息</view>
         <view>2.长按头环侧面按钮启动头环</view>
         <view>3.点击扫码开始连接</view>
       </van-col>

+ 20 - 0
src/pages/start/index.vue

@@ -405,6 +405,26 @@ export default {
     game_store.setters.setHideStatus(false)
     if ($this.played_time == 0) {
       $this.game_finished()
+    } else {
+      wx.getSystemInfoAsync({
+        success(res) {
+          if (res.platform != 'android') {
+            //获取 拉到后台得时间
+            let $hide_time = game_store.getters.getHideTime()
+            if ($hide_time) {
+              //获取当前时间
+              let $now = Math.round(new Date() / 1000)
+              //获得后台到当前时间差
+              let $residue = $now - $hide_time
+              //将原来的游玩时间+上 时间差
+              let $played_time = $this.played_time * 1 - $residue * 1
+              //重新设置游玩时间
+              game_store.setters.setPlayedTime($played_time)
+              $this.calThePlayedTime()
+            }
+          }
+        }
+      })
     }
   },
   onLoad(options) {