unknown 4 سال پیش
والد
کامیت
343a3b41a8
5فایلهای تغییر یافته به همراه238 افزوده شده و 88 حذف شده
  1. 201 82
      src/components/device/toy/connecting.vue
  2. 5 1
      src/components/index/regist.vue
  3. 1 2
      src/pages/index/index.vue
  4. 22 3
      src/pages/start/index.vue
  5. 9 0
      src/store/game.js

+ 201 - 82
src/components/device/toy/connecting.vue

@@ -3,40 +3,92 @@
     <van-row class="padding">
       <van-col span="5">
         <div class="device_bg flex flex-direction align-center justify-center">
-          <img src="https://img.shuimuai.com/web/phone.png" alt="" class="device_phone">
+          <img
+            src="https://img.shuimuai.com/web/phone.png"
+            alt=""
+            class="device_phone"
+          >
           <text class="text-gray device_text"> 我的手机</text>
         </div>
       </van-col>
-      <van-col span="3" offset="1">
+      <van-col
+        span="3"
+        offset="1"
+      >
         <div class="dot_container flex align-center">
           <div class="dot_wait">
-            <img src="https://img.shuimuai.com/m_sign_gou%402x.png" alt="" class="moving_dot">
+            <img
+              src="https://img.shuimuai.com/m_sign_gou%402x.png"
+              alt=""
+              class="moving_dot"
+            >
           </div>
         </div>
       </van-col>
-      <van-col span="5" offset="0">
+      <van-col
+        span="5"
+        offset="0"
+      >
         <div class="device_bg flex flex-direction align-center justify-center">
-          <img src="https://img.shuimuai.com/web/sign_green.png" alt="" class="sign_green" v-if="device_bg == true">
-          <img src="https://img.shuimuai.com/web/sign_red.png" class="sign_green" alt="" v-else>
-          <img src="https://img.shuimuai.com/web/brain.png" alt="" class="device_brain">
+          <img
+            src="https://img.shuimuai.com/web/sign_green.png"
+            alt=""
+            class="sign_green"
+            v-if="device_bg == true"
+          >
+          <img
+            src="https://img.shuimuai.com/web/sign_red.png"
+            class="sign_green"
+            alt=""
+            v-else
+          >
+          <img
+            src="https://img.shuimuai.com/web/brain.png"
+            alt=""
+            class="device_brain"
+          >
           <text class="text-gray device_text second_device_text"> 已连接({{device_power}}%)</text>
         </div>
       </van-col>
-      <van-col span="3" offset="1">
+      <van-col
+        span="3"
+        offset="1"
+      >
         <div class="dot_container flex align-center">
           <div class="dot_wait">
-            <img v-if="connect_toy == 1" src="https://img.shuimuai.com/web/dot.png" alt="" class="moving_dot"
-                 :class="{moving:connect_toy==1}"
+            <img
+              v-if="connect_toy == 1"
+              src="https://img.shuimuai.com/web/dot.png"
+              alt=""
+              class="moving_dot"
+              :class="{moving:connect_toy==1}"
             />
-            <img v-if="connect_toy == 2" src="https://img.shuimuai.com/m_sign_gou%402x.png" alt="" class="moving_dot">
-            <img v-if="connect_toy == 3" src="https://img.shuimuai.com/fail.png" alt="" class="moving_dot">
+            <img
+              v-if="connect_toy == 2"
+              src="https://img.shuimuai.com/m_sign_gou%402x.png"
+              alt=""
+              class="moving_dot"
+            >
+            <img
+              v-if="connect_toy == 3"
+              src="https://img.shuimuai.com/fail.png"
+              alt=""
+              class="moving_dot"
+            >
 
           </div>
         </div>
       </van-col>
-      <van-col span="5" offset="0">
+      <van-col
+        span="5"
+        offset="0"
+      >
         <div class="device_bg flex flex-direction align-center justify-center">
-          <img :src="toy['img']" alt="" class="uav_toy">
+          <img
+            :src="toy['img']"
+            alt=""
+            class="uav_toy"
+          >
           <text class="text-gray device_text">
             <template v-if="connect_toy == 1 || connect_toy == 3">
               {{ toy['name'] }}
@@ -51,13 +103,24 @@
     <!--        按钮组合-->
     <van-row gutter="6">
       <van-col span="8">
-        <button class="cu-btn bg-red lg text-white" @click="change_status">
-          <img src="https://img.shuimuai.com/m_duankainaohuan.png" class="cut_brain_icon" alt="">
+        <button
+          class="cu-btn bg-red lg text-white"
+          @click="change_status"
+        >
+          <img
+            src="https://img.shuimuai.com/m_duankainaohuan.png"
+            class="cut_brain_icon"
+            alt=""
+          >
           <text class=" cut_text">断开脑环</text>
         </button>
       </van-col>
 
-      <van-col span="12" offset="1" v-if="connect_toy == 1">
+      <van-col
+        span="12"
+        offset="1"
+        v-if="connect_toy == 1"
+      >
         <van-row class="text-center">
           <text class="text-gray text-lg">
             连接中...
@@ -68,16 +131,33 @@
       <!--      已经连接玩具-->
       <div v-if="connect_toy == 2">
         <van-col span="8">
-          <button class="cu-btn bg-red lg cu-btn-primary" @click="open_choose_toy">
-            <img src="https://img.shuimuai.com/m_xuanzewanju.png" alt="" class="cut_brain_icon">
+          <button
+            class="cu-btn bg-red lg cu-btn-primary"
+            @click="open_choose_toy"
+          >
+            <img
+              src="https://img.shuimuai.com/m_xuanzewanju.png"
+              alt=""
+              class="cut_brain_icon"
+            >
             <text class=" cut_text">选择玩具</text>
           </button>
         </van-col>
 
         <van-col span="8">
-          <button class="cu-btn bg-red lg cu-btn-primary" @click="choose_pay_window">
-            <img src="https://img.shuimuai.com/web/start_game_icon.png" alt="" class="cut_start_game_icon">
-            <text class=" cut_text" style="padding: 0px;">开始游戏</text>
+          <button
+            class="cu-btn bg-red lg cu-btn-primary"
+            @click="choose_pay_window"
+          >
+            <img
+              src="https://img.shuimuai.com/web/start_game_icon.png"
+              alt=""
+              class="cut_start_game_icon"
+            >
+            <text
+              class=" cut_text"
+              style="padding: 0px;"
+            >开始游戏</text>
           </button>
         </van-col>
 
@@ -86,8 +166,15 @@
       <!--      玩具连接失败-->
       <div v-if="connect_toy == 3">
         <van-col span="8">
-          <button class="cu-btn bg-red lg cu-btn-primary" @click="open_choose_toy">
-            <img src="https://img.shuimuai.com/m_xuanzewanju.png" alt="" class="cut_brain_icon">
+          <button
+            class="cu-btn bg-red lg cu-btn-primary"
+            @click="open_choose_toy"
+          >
+            <img
+              src="https://img.shuimuai.com/m_xuanzewanju.png"
+              alt=""
+              class="cut_brain_icon"
+            >
             <text class=" cut_text">选择玩具</text>
           </button>
         </van-col>
@@ -104,17 +191,28 @@
 
       <!--      玩具连接中-->
       <div v-if="connect_toy == 4">
-<!--        <van-col span="8" style="visibility: hidden">-->
-<!--          <button class="cu-btn bg-red lg cu-btn-primary" @click="open_choose_toy">-->
-<!--            <img src="https://img.shuimuai.com/m_xuanzewanju.png" alt="" class="cut_brain_icon">-->
-<!--            <text class=" cut_text">选择玩具</text>-->
-<!--          </button>-->
-<!--        </van-col>-->
+        <!--        <van-col span="8" style="visibility: hidden">-->
+        <!--          <button class="cu-btn bg-red lg cu-btn-primary" @click="open_choose_toy">-->
+        <!--            <img src="https://img.shuimuai.com/m_xuanzewanju.png" alt="" class="cut_brain_icon">-->
+        <!--            <text class=" cut_text">选择玩具</text>-->
+        <!--          </button>-->
+        <!--        </van-col>-->
 
         <van-col span="16">
-          <button class="cu-btn bg-green lg " @click="to_playing" style="width: 100%">
-            <img src="https://img.shuimuai.com/web/start_game_icon.png" alt="" class="cut_start_game_icon">
-            <text class=" cut_text" style="padding: 0px;">游戏中</text>
+          <button
+            class="cu-btn bg-green lg "
+            @click="to_playing"
+            style="width: 100%"
+          >
+            <img
+              src="https://img.shuimuai.com/web/start_game_icon.png"
+              alt=""
+              class="cut_start_game_icon"
+            >
+            <text
+              class=" cut_text"
+              style="padding: 0px;"
+            >游戏中</text>
           </button>
         </van-col>
 
@@ -123,22 +221,35 @@
 
     <!--  选择消费方式的窗口  -->
 
-    <van-overlay :show="pay_window" @click="onClickHide" z-index="5">
+    <van-overlay
+      :show="pay_window"
+      @click="onClickHide"
+      z-index="5"
+    >
       <div class="pay_type_window">
         <div class="pay_type_title padding">
           <text class="text-bold pay_type_title_text">选择消费方式</text>
         </div>
 
         <van-row gutter="11">
-          <van-col span="11" offset="1">
-            <div class="pay_type_item flex flex-direction justify-center align-center" @click.prevent="choose_pay(2)">
+          <van-col
+            span="11"
+            offset="1"
+          >
+            <div
+              class="pay_type_item flex flex-direction justify-center align-center"
+              @click.prevent="choose_pay(2)"
+            >
               <view class="text-xl padding">
                 <text class="text-white text-bold">消费时间</text>
               </view>
             </div>
           </van-col>
           <van-col span="11">
-            <div class="pay_type_item  flex flex-direction justify-center align-center" @click.prevent="choose_pay(1)">
+            <div
+              class="pay_type_item  flex flex-direction justify-center align-center"
+              @click.prevent="choose_pay(1)"
+            >
               <view class="text-xl padding">
                 <text class="text-white text-bold">消费次卡</text>
               </view>
@@ -149,9 +260,13 @@
           </van-col>
         </van-row>
       </div>
-      <img src="https://img.shuimuai.com/web/boy2.png" alt="" class="connected_boy2">
+      <img
+        src="https://img.shuimuai.com/web/boy2.png"
+        alt=""
+        class="connected_boy2"
+      >
     </van-overlay>
-    <van-toast id="van-toast"/>
+    <van-toast id="van-toast" />
 
     <van-popup
       :show="start_show"
@@ -167,108 +282,113 @@
 </template>
 
 <script>
-import {gameStart} from "@/requests/game";
+import { gameStart } from "@/requests/game";
 import Toast from "../../../../static/vant/toast/toast";
-import game_store from '../../../store/game'
+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'],
+  props: [
+    "connect_toy",
+    "deviceId",
+    "toy_id",
+    "toy",
+    "device_bg",
+    "device_power",
+  ],
   data() {
     return {
       pay_window: false,
       //  使用类型 1次数 2时间 0未选择
       pay_type: 0,
 
-      start_show: false
-    }
+      start_show: false,
+    };
   },
   methods: {
     open_choose_toy() {
-      $this.$emit('open_choose_toy', true)
+      $this.$emit("open_choose_toy", true);
     },
     //打开选择消费的选项框
     choose_pay_window() {
       if (!$this.device_bg) {
-        Toast.fail("请佩戴好脑环开始游戏")
+        Toast.fail("请佩戴好脑环开始游戏");
         return false;
       }
-      $this.pay_window = true
+      $this.pay_window = true;
     },
     //选择消费的时间或者次数
     choose_pay($event) {
       if (!$this.device_bg) {
-        Toast.fail("请佩戴好脑环开始游戏")
+        Toast.fail("请佩戴好脑环开始游戏");
         return false;
       }
-      $this.pay_type = $event
+      $this.pay_type = $event;
       let $params = {
         type: $event,
         device_id: $this.toy_id,
-        access_token: wx.getStorageSync('token')
-      }
+        access_token: wx.getStorageSync("token"),
+      };
       gameStart($params).then(
         (res) => {
-          let $data = res.data
-          let $res = $data.data
+          let $data = res.data;
+          let $res = $data.data;
           if ($data.code == 0) {
             // 设置游戏中
             // 设置游戏模式
-            game_store.setters.setMode($event)
+            game_store.setters.setMode($event);
             // 设置游戏状态为游戏中
-            game_store.setters.setGameStatus(1)
+            game_store.setters.setGameStatus(1);
             // 设置游戏记录id
-            game_store.setters.setGameRecordId($res['game_record_id'])
-
+            game_store.setters.setGameRecordId($res["game_record_id"]);
 
-            Toast.success($data.errmsg)
+            Toast.success($data.errmsg);
             setTimeout(() => {
               mpvue.navigateTo({
                 url: "/pages/start/main",
                 success() {
-                  wx.offBLECharacteristicValueChange()
-                  game_store.setters.setPlayTime($res['play_time'])
-                  $this.$emit('gameStart', true)
-                }
-              })
-            }, 800)
-
+                  wx.offBLECharacteristicValueChange();
+                  // 记录消费方式 选择时间卡还是次卡
+                  game_store.setters.setPlayTime($res["play_time"]);
+                  game_store.setters.setOverPlayTime($res["play_time"]);
+                  $this.$emit("gameStart", true);
+                },
+              });
+            }, 800);
           } else {
-            Toast.fail($data.errmsg)
+            Toast.fail($data.errmsg);
           }
-        }
-        ,
+        },
         (err) => {
-          console.log(err)
+          console.log(err);
         }
-      )
-
+      );
     },
     //点击隐藏
     onClickHide() {
-      $this.pay_window = false
+      $this.pay_window = false;
     },
     // 前往正在玩的波动时间界面
     to_playing() {
-      $this.$emit('gameStart', true)
+      $this.$emit("gameStart", true);
       mpvue.navigateTo({
         url: "/pages/start/main",
-      })
+      });
     },
     //修改连接状态
     change_toy_connect_status($status) {
-      $this.$emit('change_toy_connect_status', $status)
+      $this.$emit("change_toy_connect_status", $status);
     },
     change_status() {
-      $this.$emit('change_status', 0)
-    }
+      $this.$emit("change_status", 0);
+    },
   },
   created() {
-    $this = this
-  }
-}
+    $this = this;
+  },
+};
 </script>
 
 <style scoped>
@@ -300,7 +420,7 @@ export default {
 }
 
 .pay_type_title_text {
-  color: #6B6B6B;
+  color: #6b6b6b;
   font-size: 12px;
 }
 
@@ -319,5 +439,4 @@ export default {
   right: 0px;
   bottom: 160px;
 }
-
 </style>

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 5 - 1
src/components/index/regist.vue


+ 1 - 2
src/pages/index/index.vue

@@ -29,7 +29,7 @@
     >
       <personal_container @change_login_status="change_login_status"></personal_container>
 
-      <device_container></device_container> 
+      <device_container></device_container>
     </div>
     <div
       class="service"
@@ -146,7 +146,6 @@ export default {
       if (!this.is_login) {
         Toast.fail("请先登录");
         return false;
-        
       }
       mpvue.navigateTo({
         url: "/pages/" + $page + "/main",

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

@@ -252,6 +252,8 @@ export default {
       played_time: null,
       played_time_text: "--:--",
 
+      //结束游戏时选择类型的时间
+      over_play_time: 0,
       //  检测佩戴是否正确
       device_bg: true,
 
@@ -413,10 +415,23 @@ export default {
     },
     //  结束游戏
     game_over() {
+      $this.over_play_time = game_store.getters.getOverPlayTime();
+      $this.played_time = $this.played_time >= 0 ? $this.played_time : 0;
+      console.log(
+        "结束游戏时游玩的时间倒计时~~played_time~~",
+        $this.played_time,
+        "~~play_time~~",
+        $this.play_time,
+        // "所选类型的时间",
+        "~~$this.over_play_time~~",
+        $this.over_play_time
+      );
       let $params = {
         game_record_id: game_store.getters.getGameRecordId(),
         type: $this.mode,
-        play_time: $this.play_time - Math.abs($this.played_time),
+        // play_time: $this.play_time - Math.abs($this.played_time),
+        // play_time: $this.play_time - $this.played_time,
+        play_time: $this.over_play_time - $this.played_time,
       };
       //
       gameEnd($params).then((res) => {
@@ -430,6 +445,8 @@ export default {
         $this.alpha_list = [];
         $this.theta_list = [];
         $this.beta_list = [];
+        //游戏结束重置游戏时间
+        wx.removeStorageSync("over_play_time");
       });
     },
     //  处理游戏中数据的方法
@@ -551,8 +568,10 @@ export default {
                   "后台退出时间大于游玩剩余的时间~~",
                   "后台返回前台的时间差",
                   $residue,
-                  "游玩的剩余时间played_time",
-                  $this.played_time
+                  "游玩的剩余时间played_time~~",
+                  $this.played_time,
+                  "所选类型的时间  $this.play_time~~",
+                  $this.play_time
                 );
                 $this.game_finished();
               }

+ 9 - 0
src/store/game.js

@@ -32,6 +32,10 @@ const setters = {
   setGameRecordId(param) {
     wx.setStorageSync('game_record_id', param)
   },
+  // 游玩类型的时间30分钟或10分钟
+  setOverPlayTime(param) {
+    wx.setStorageSync('over_play_time', param)
+  },
   setPlayTime(param) {
     wx.setStorageSync('play_time', param)
   },
@@ -77,6 +81,11 @@ const getters = {
   getGameRecordId() {
     return wx.getStorageSync('game_record_id')
   },
+  // 游玩类型的时间30分钟或10分钟
+  getOverPlayTime() {
+    return wx.getStorageSync('over_play_time')
+  },
+  //该局游戏剩余可以游玩的时间
   getPlayTime() {
     return wx.getStorageSync('play_time')
   },

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است