Browse Source

蓝牙设备连接检测玩具连接状态,优化蓝牙发送数据

yerong 4 years ago
parent
commit
ca5c910728

+ 2 - 1
config/dev.env.js

@@ -2,5 +2,6 @@ var merge = require('webpack-merge')
 var prodEnv = require('./prod.env')
 
 module.exports = merge(prodEnv, {
-  NODE_ENV: '"development"'
+  NODE_ENV: '"development"',
+  REQUEST_URI:"'https://testapi.shuimuai.com/'"
 })

+ 2 - 1
config/prod.env.js

@@ -1,3 +1,4 @@
 module.exports = {
-  NODE_ENV: '"production"'
+  NODE_ENV: '"production"',
+  REQUEST_URI: "'https://api.shuimuai.com/'"
 }

+ 1 - 1
dist/wx

@@ -1 +1 @@
-Subproject commit 797fab254203dfa4b8ce2658f12aa1ceb8686f0c
+Subproject commit 18ea23d3c5218154616bb925c8efe2f6ffd1845e

+ 20 - 4
src/components/device/device.vue

@@ -114,6 +114,7 @@ import Toast from "../../../static/vant/toast/toast";
 import {game_devices} from "../../requests/game";
 import game_store from "@/store/game";
 import bluetooth from "@/utils/bluetooth";
+import ext from "../../utils/ext";
 
 let $this;
 export default {
@@ -259,12 +260,20 @@ export default {
         wx.closeBLEConnection({
           deviceId: $this._deviceId,
           success(res) {
-            Toast.success("已成功断开");
+            Toast.success({
+              message: "已成功断开",
+              onClose() {
+                let $game_status = game_store.getters.getGameStatus;
+                if ($game_status == 1) {
+                  mpvue.navigateTo({
+                    url: "/pages/start/main?end=1"
+                  })
+                }
+              }
+            });
           },
+
         });
-        bluetooth.sendPause($this._deviceId, bluetooth.serviceId, bluetooth.cid)
-        bluetooth.sendEnd($this._deviceId, bluetooth.serviceId, bluetooth.cid)
-        bluetooth.shutdownSendControl($this._deviceId, bluetooth.serviceId, bluetooth.cid)
 
 
       }
@@ -365,6 +374,7 @@ export default {
     },
   },
   mounted() {
+
     $this.get_toy_list();
   },
   created() {
@@ -372,6 +382,12 @@ export default {
   },
   onShow() {
     //判断是否游戏中
+    let $game_status = game_store.getters.getGameStatus;
+    console.log("游戏状态", $game_status)
+    if ($game_status == 0) {
+      $this.connect_show = true;
+      $this.connect_toy = 0;
+    }
   },
   onLoad(options) {
     // 原有的code

+ 5 - 21
src/components/index/login.vue

@@ -23,7 +23,6 @@
 </template>
 <script>
 import Toast from '../../../static/vant/toast/toast';
-import {userCheckCode, userCheckInvite} from "../../requests/user";
 
 export default {
   name: "login_container",
@@ -33,7 +32,7 @@ export default {
       this.$emit('changeTitle', $status)
     },
     to_scan() {
-      this.$emit('to_scan', 'scan')
+      this.to_regist(1)
     }
   },
   onLoad(options) {
@@ -44,6 +43,7 @@ export default {
     if (options.q) {
       let url = decodeURIComponent(options.q)
       let $code = url.match(/\?code=(.*)/)[1];
+      wx.setStorageSync('is_scan', true)
 
       this.$store.commit('set_invite_code', $code)
       console.log('1---' + $_code, '2---' + $code)
@@ -51,31 +51,15 @@ export default {
       if ($_code && $_code != $code) {
         Toast.fail('该用户已绑定邀请码')
       }
-      //本地存储没有邀请码
-      // if (!$_code) {
-      //   //校验邀请码
-      //   userCheckInvite($code).then((res) => {
-      //     let $res = res.data;
-      //     if ($res.code != 0) {
-      //       Toast.fail({
-      //         message: $res.errmsg,
-      //         duration: 0
-      //         // onClose() {
-      //         //   $this.$emit('changeStatus', 'scan')
-      //         // }
-      //       })
-      //     }
-      //   })
-      // }
 
 
     }
     // 测试注释
     else {
       // 跳转到关于水母页面
-      mpvue.reLaunch({
-        url: "/pages/none/main"
-      })
+      //设置是否扫码
+      wx.setStorageSync('is_scan', false)
+      this.to_scan()
     }
   }
 }

+ 7 - 1
src/components/index/personal.vue

@@ -94,7 +94,13 @@
     </div>
 
     <!--    领券弹窗-->
-    <van-popup :show="first" :close-on-click-overlay="false" custom-class="pop">
+    <van-popup
+      :show="first"
+      :close-on-click-overlay="false"
+      custom-class="pop"
+      overlay
+      z-index="99"
+    >
       <div class="quan_container">
         <van-row gutter="10">
           <van-col span="14" offset="1">

+ 5 - 3
src/components/index/regist.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="index_login_container" class="animation-slide-right">
     <view class="text-xl padding text-center">
-      <img class="back regist_back_btn" @click="goIndex" src="https://img.shuimuai.com/fanhui.png"/>
+      <img class="back regist_back_btn" @click="goIndex" src="https://img.shuimuai.com/fanhui.png" v-if="is_scan"/>
       <text class=" text-bold title_color">会员{{ title }}</text>
     </view>
     <view class="text-df text-center slogen">请输入手机号码,以便更好的享受我们的服务</view>
@@ -70,7 +70,9 @@ export default {
       btn_disabled: true,
       time_show: false,
       time_start: false,
-      time_count: 60
+      time_count: 60,
+      //判断是否扫码进来的
+      is_scan: false
     }
   },
   watch: {
@@ -207,7 +209,7 @@ export default {
         $this.js_code = $res.code
       }
     })
-
+    $this.is_scan = wx.getStorageSync('is_scan')
   },
   created() {
     $this = this

+ 1 - 1
src/main.js

@@ -7,7 +7,7 @@ import store from '@/store/index'
 
 var fly = new Fly()
 // fly.config.baseURL = "https://testapi.shuimuai.com/"
-fly.config.baseURL = "https://api.shuimuai.com/"
+fly.config.baseURL = process.env.REQUEST_URI
 fly.config.headers = {
   access_token:11,
   // 'Content-Type':'multipart/form-data; boundary=AaB03x'

+ 6 - 3
src/pages/game_record/index.vue

@@ -5,7 +5,7 @@
       <div class="header text-center">
         <view class="padding">
           <text class="title">
-            {{ total }}
+            {{ total }}
           </text>
         </view>
         <view>
@@ -46,6 +46,7 @@
 
 
 import {gameList} from "../../requests/game";
+import {formatSeconds} from "../../utils";
 
 var $this
 export default {
@@ -97,8 +98,10 @@ export default {
       gameList($params).then((res) => {
           let $res = res.data;
           $this.items = $res.data.list
-          let $total_second = $res.data.total
-          $this.total = $res.data.total
+          $this.items.forEach(($val, $index) => {
+            $val['play_time'] = formatSeconds($val['play_time'])
+          })
+          $this.total = formatSeconds($res.data.total)
         },
         (err) => {
           console.log(err)

+ 7 - 4
src/pages/index/index.css

@@ -45,18 +45,17 @@
   position: relative;
   width: 100%;
   padding: 5px 7px 35px;
-  margin-top: 20px;
+  /*margin-top: 20px;*/
   /* top: 520px; */
-  top: 10px;
+  /*top: 10px;*/
 }
 
 .service .content {
   width: 100%;
-  float: left;
 }
 
 .service .content image {
-  width: 50%;
+  width: 186px;
   height: 89px;
 }
 
@@ -77,5 +76,9 @@
   background-color: rgba(255, 255, 255, 0);
 }
 
+
+.personal_card{
+  height: 300px;
+}
 /* 测试 元素标签名*/
 /* service */

+ 18 - 5
src/pages/index/index.vue

@@ -31,10 +31,23 @@
         </div>
       </div>
       <div class="content">
-        <img src="https://img.shuimuai.com/web/index_btn_chongzhizhongxin.png" @click="to_recharge"></img>
-        <img src="https://img.shuimuai.com/web/index_btn_gerenzhongxin.png" @click="to_page('user_center')"></img>
-        <img src="https://img.shuimuai.com/web/index_btn_chengjijilu.png" @click="to_page('game_record')"></img>
-        <img src="https://img.shuimuai.com/web/index_btn_dailishang.png" @click="to_page('agent/index')"></img>
+        <van-row>
+          <van-col span="12">
+            <img src="https://img.shuimuai.com/web/index_btn_chongzhizhongxin.png" @click="to_recharge"></img>
+          </van-col>
+          <van-col span="12">
+            <img src="https://img.shuimuai.com/web/index_btn_gerenzhongxin.png" @click="to_page('user_center')"></img>
+          </van-col>
+        </van-row>
+
+        <van-row>
+          <van-col span="12">
+            <img src="https://img.shuimuai.com/web/index_btn_chengjijilu.png" @click="to_page('game_record')"></img>
+          </van-col>
+          <van-col span="12">
+            <img src="https://img.shuimuai.com/web/index_btn_dailishang.png" @click="to_page('agent/index')"></img>
+          </van-col>
+        </van-row>
       </div>
     </div>
     <van-toast id="van-toast"/>
@@ -121,7 +134,7 @@ export default {
       this.is_login = this.$store.getters.get_login_status
     }
   },
-  created(){
+  created() {
     $this = this
   }
 }

+ 4 - 3
src/pages/report/index.vue

@@ -64,10 +64,10 @@
           <text v-if="record.consumption_type==1">次卡</text>
           <text v-if="record.consumption_type==2">时间卡</text>
         </view>
-        <view>会员游玩时间: {{ record.play_time }}</view>
+        <view>会员游玩时间: {{ record.play_time }}</view>
       </view>
       <view class="right">
-        <view>专注力训练时长: {{ record.play_time }}</view>
+        <view>专注力训练时长: {{ record.play_time }}</view>
       </view>
     </view>
 
@@ -77,7 +77,7 @@
 <script>
 import mpvueEcharts from 'mpvue-echarts'
 import echarts from '../../../static/echarts.min';
-import util from '../../utils/index'
+import util, {formatSeconds} from '../../utils/index'
 import {gameDetail, gameLineChart} from "../../requests/game";
 import game_store from "../../store/game";
 
@@ -121,6 +121,7 @@ export default {
       gameDetail($record_id).then((res) => {
         let $res = res.data;
         $this.record = $res.data
+        $this.record.play_time = formatSeconds($this.record.play_time)
       })
     },
     get_game_line($record_id) {

+ 13 - 11
src/pages/start/index.vue

@@ -104,7 +104,9 @@
     </div>
 
     <!--    窗口弹出-->
-    <van-popup :show="pop_show" @close="close_pop" round :close-on-click-overlay="false">
+    <van-popup :show="pop_show" @close="close_pop" round :close-on-click-overlay="false"
+               overlay
+               z-index="99">
       <div class="err_container flex flex-direction align-center justify-around">
         <view>
           <text class="title">
@@ -133,6 +135,7 @@ import bluetooth from "../../utils/bluetooth";
 import game_store from "@/store/game";
 import Toast from '../../../static/vant/toast/toast';
 import {game_devices, gameAddLine, gameEnd} from "../../requests/game";
+import ext from "../../utils/ext";
 
 var att_charts,
   med_charts,
@@ -342,12 +345,6 @@ export default {
         //连接玩具
         console.log('玩具hexStr', hexStr)
         bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
-
-        //连接不上设备
-        if ($flag == false) {
-          // $this.game_finished()
-          console.log('info', $this._deviceId, $this._serviceId, $this._characteristicId)
-        }
       })
     },
 
@@ -401,10 +398,8 @@ export default {
       let $play_time = $this.play_time - $current_time
       if ($this.mode == 2) {
         let $userinfo = wx.getStorageSync('userinfo')
-        $play_time = $userinfo['play_time'] - $current_time
+        $play_time = $userinfo['play_time'] * 60 - $current_time
       }
-      console.log('当前结束时间', $current_time)
-      console.log('游玩时间:', $this.play_time)
       let $params = {
         game_record_id: game_store.getters.getGameRecordId,
         type: $this.mode,
@@ -447,7 +442,14 @@ export default {
     bluetooth.watch_bluetooth_status($this)
 
   },
-  onLoad() {
+  onLoad(options) {
+    let $game_status = game_store.getters.getGameStatus;
+    if ($game_status == 1) {
+      console.log("结束游戏跳转", options)
+      if (options.end) {
+        $this.game_finished()
+      }
+    }
   },
   onUnload() {
     // 返回 的时候 暂停

+ 34 - 3
src/pages/user_center/edit/confirm_phone_finally/index.vue

@@ -26,6 +26,8 @@
         error-message="手机号格式错误"
         :custom-style="custom_style"
         type="number"
+        clearable
+        @change="inputNewPhone"
       />
 
       <van-field
@@ -36,11 +38,20 @@
         placeholder="请输入短信验证码"
         use-button-slot
         :custom-style='custom_style'
+        @change="inputSms"
+        :maxlength="6"
       >
         <van-button slot="button" size="small" type="primary" @click="sand_sms"
-        >发送验证码
-        </van-button
+                    class="flex"
+                    v-if="time_show==false"
         >
+          <text>发送验证码</text>
+        </van-button>
+        <view v-else slot="button" class="flex align-center">
+          <van-count-down v-if="time_show" :auto-start="time_start" class="control-count-down" @finish="time_finished"
+                          :time="time_count * 1000" format="ss"/>
+          <text>后发送验证码</text>
+        </view>
       </van-field>
       <div class="padding bottom_button">
         <button class="cu-btn lg cu-btn-primary text-white text-center " @click="confirm_modify">确定修改</button>
@@ -70,7 +81,11 @@ export default {
             border-radius: 10px;
             margin: 20px auto;
       `,
-      new_phone: ""
+      new_phone: "",
+
+      time_show: false,
+      time_start: false,
+      time_count: 60
     }
   },
   methods: {
@@ -81,6 +96,12 @@ export default {
       let end = $val.slice(-2);
       return start + '******' + end;
     },
+    inputNewPhone($val) {
+      $this.new_phone = $val.mp.detail
+    },
+    inputSms($val) {
+      $this.sms = $val.mp.detail
+    },
     //  发送验证码
     sand_sms() {
       if (!$this.new_phone) {
@@ -92,6 +113,7 @@ export default {
       userGetCode($param).then((res) => {
         let $data = res.data
         if ($data.code != 200) {
+          $this.start_count_down()
           Toast.fail($data.errmsg)
         }
       })
@@ -111,8 +133,17 @@ export default {
           mpvue.navigateBack({
             delta: 2
           })
+        } else {
+          Toast.fail($data.errmsg)
         }
       })
+    },
+    start_count_down() {
+      $this.time_count = 60
+      $this.time_start = $this.time_show = true
+    },
+    time_finished() {
+      $this.time_start = $this.time_show = false
     }
   }
   ,

+ 2 - 1
src/pages/user_center/edit/confirm_phone_finally/main.json

@@ -6,6 +6,7 @@
     "van-cell-group": "../../../../static/vant/cell-group/index",
     "van-field": "../../../../static/vant/field/index",
     "van-button": "../../../../static/vant/button/index",
-    "van-toast": "../../../../static/vant/toast/index"
+    "van-toast": "../../../../static/vant/toast/index",
+    "van-count-down": "../../../../static/vant/count-down/index"
   }
 }

+ 6 - 1
src/pages/user_center/edit/confirm_phone_first/index.vue

@@ -10,13 +10,15 @@
       </view>
 
       <van-field
-        v-model="sms"
+        :value="sms"
         center
         clearable
         label="短信验证码"
         placeholder="请输入短信验证码"
         use-button-slot
         :custom-style=custom_style
+        @change="inputSms"
+        :maxlength="6"
       >
         <van-button slot="button" size="small" type="primary" @click="sand_sms"
                     class="flex"
@@ -72,6 +74,9 @@ export default {
       let end = $val.slice(-2);
       return start + '******' + end;
     },
+    inputSms($val) {
+      $this.sms = $val.mp.detail
+    },
     //  发送验证码
     sand_sms() {
       Toast.loading({

+ 6 - 1
src/pages/user_center/recharge/index.css

@@ -114,6 +114,11 @@
   width: 167px;
   height: 184px;
 }
-.ext_container{
+
+.ext_container {
   height: 320px;
+  /*background-image: url("https://img.shuimuai.com/web/boyya_bg.png");*/
+  /*background-size: 100% 100%;*/
+  /*background-position: center;*/
+  background-color: rgba(255, 255, 255, 0)
 }

+ 13 - 4
src/pages/user_center/recharge/index.vue

@@ -92,7 +92,7 @@
             <div class="card_body">
               <view>
                 <text class="mine_min  text-white">{{ item.play_time }}</text>
-                <text class="text-white">分钟</text>
+                <text class="text-white"></text>
               </view>
               <view>
                 <text class="text-white text-sm">{{ item.title1 }}</text>
@@ -187,7 +187,7 @@
     </van-popup>
 
     <!--    充值成功-->
-    <van-popup :show="success_show" @close="close_success_pop" round :close-on-click-overlay="false">
+    <van-popup :show="success_show" @close="close_success_pop" round :close-on-click-overlay="false" >
       <div class="err_container flex flex-direction align-center justify-around ext_container">
         <img src="https://img.shuimuai.com/web/boyya.png" class="boy_logo" alt="">
         <view>
@@ -213,7 +213,7 @@
 <script>
 
 import {goodsCardList} from "../../../requests/goods";
-import {createOrder} from "../../../requests/orders";
+import {createOrder, deleteOrder} from "../../../requests/orders";
 
 var $this
 export default {
@@ -235,7 +235,9 @@ export default {
       //  选中的充值卡
       selection_card: {},
       //支付信息
-      payment_info: {}
+      payment_info: {},
+      //订单编号
+      order_sn: ""
     }
   },
   watch: {},
@@ -256,6 +258,12 @@ export default {
     //取消充值
     cancel_recharge() {
       $this.close_err_pop()
+
+      deleteOrder($this.order_sn).then((res) => {
+        let $res = res.data
+      }, (err) => {
+        console.log("删除订单错误", err)
+      })
     },
     // 打开充值成功窗口
     open_success_window() {
@@ -305,6 +313,7 @@ export default {
       createOrder($params).then((res) => {
           let $data = res.data
           let $payment = $data.data
+          $this.order_sn = $payment['sn']
           $this.payment_info = $payment
           wx.requestPayment({
             timeStamp: $payment.timeStamp,

+ 7 - 1
src/pages/user_center/vip_code/index.vue

@@ -15,6 +15,9 @@
         </view>
       </view>
       <img src="https://img.shuimuai.com/web/demo_code.png" class="qrcode margin-xl" alt="">
+<!--      <view class="text-center">-->
+<!--        <text class="text-normal ">{{ invite_code }}</text>-->
+<!--      </view>-->
     </div>
   </div>
 </template>
@@ -28,7 +31,8 @@ export default {
   components: {},
   data() {
     return {
-      userinfo: {}
+      userinfo: {},
+      invite_code: ""
     }
   },
   methods: {}
@@ -40,6 +44,8 @@ export default {
   },
   onLoad() {
     $this.userinfo = wx.getStorageSync('userinfo')
+    $this.invite_code = wx.getStorageSync('code')
+
   }
 }
 </script>

+ 2 - 1
src/requests/main.js

@@ -1,7 +1,8 @@
 import Fly from 'flyio/dist/npm/wx'
 
 var fly = new Fly()
-fly.config.baseURL = "https://api.shuimuai.com/"
+fly.config.baseURL = process.env.REQUEST_URI
+// fly.config.baseURL = "https://testapi.shuimuai.com/"
 fly.config.headers = {
   access_token: 11,
   // 'Content-Type':'multipart/form-data; boundary=AaB03x'

+ 9 - 0
src/requests/orders.js

@@ -21,3 +21,12 @@ export function payOrder($params) {
   $params['access_token'] = wx.getStorageSync('token')
   return fly.post('order/pay', $params)
 }
+
+
+//删除订单
+export function deleteOrder($sn) {
+  let $params = {}
+  $params['sn'] = $sn
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('order/order-delete', $params)
+}

+ 6 - 3
src/store/game.js

@@ -23,12 +23,15 @@ export default new Vuex.Store({
   mutations: {
     setDeviceId(state, deviceId) {
       state.deviceId = deviceId
+      wx.setStorageSync('deviceId', deviceId)
     },
     setServiceId(state, serviceId) {
       state.serviceId = serviceId
+      wx.setStorageSync('serviceId', serviceId)
     },
     setCid(state, characteristicId) {
       state.characteristicId = characteristicId
+      wx.setStorageSync('characteristicId', characteristicId)
     },
     setGameStatus(state, status) {
       state.game_status = status
@@ -51,13 +54,13 @@ export default new Vuex.Store({
   },
   getters: {
     getDeviceId(state, getters) {
-      return state.deviceId
+      return wx.getStorageSync('deviceId')
     },
     getServiceId(state, getters) {
-      return state.serviceId
+      return wx.getStorageSync('serviceId')
     },
     getCharacterId(state, getters) {
-      return state.characteristicId
+      return wx.getStorageSync('characteristicId')
     },
     getGameStatus(state) {
       return state.game_status

+ 7 - 6
src/utils/bluetooth.js

@@ -461,7 +461,8 @@ export default {
     })
   },
   //监听玩具得状态
-  watching_toy($this, deviceId, serviceId, Cid, Toast) {
+  watching_toy($this, deviceId, serviceId, Cid, Toast)
+  {
     Toast.clear()
     Toast.loading({
       duration: 0,
@@ -585,11 +586,11 @@ export default {
       },
       fail: function (err) {
         console.log('发送连接玩具指令失败')
-        wx.showModal({
-          showCancel: false,
-          title: '提示',
-          content: '指令发送失败',
-        })
+        // wx.showModal({
+        //   showCancel: false,
+        //   title: '提示',
+        //   content: '指令发送失败',
+        // })
         console.log(err)
       }
     })

+ 2 - 0
src/utils/ext.js

@@ -0,0 +1,2 @@
+import Vue from 'vue'
+export default new Vue

+ 29 - 0
src/utils/index.js

@@ -244,6 +244,35 @@ function getBaseOption(delta, theta, alpha, beta) {
   return option
 }
 
+export function formatSeconds(value) {
+  var secondTime = parseInt(value);// 秒
+  var minuteTime = 0;// 分
+  var hourTime = 0;// 小时
+  if (secondTime > 60) {//如果秒数大于60,将秒数转换成整数
+    //获取分钟,除以60取整数,得到整数分钟
+    minuteTime = parseInt(secondTime / 60);
+    //获取秒数,秒数取佘,得到整数秒数
+    secondTime = parseInt(secondTime % 60);
+    //如果分钟大于60,将分钟转换成小时
+    if (minuteTime > 60) {
+      //获取小时,获取分钟除以60,得到整数小时
+      hourTime = parseInt(minuteTime / 60);
+      //获取小时后取佘的分,获取分钟除以60取佘的分
+      minuteTime = parseInt(minuteTime % 60);
+    }
+  }
+  var result = "" + parseInt(secondTime) + "秒";
+
+  if (minuteTime > 0) {
+    result = "" + parseInt(minuteTime) + "分" + result;
+  }
+  if (hourTime > 0) {
+    result = "" + parseInt(hourTime) + "小时" + result;
+  }
+  return result;
+}
+
+
 //获取等级名称
 function get_level_name($level_id) {
   let $level = ['普通用户', '体验会员', '黄金会员', '白金会员', '钻石会员', '创客代理', '合伙人', '店员', '店长']