|
@@ -134,8 +134,7 @@ import util from '../../utils/index'
|
|
|
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";
|
|
|
+import {gameAddLine, gameEnd} from "../../requests/game";
|
|
|
|
|
|
var att_charts,
|
|
|
med_charts,
|
|
@@ -221,7 +220,11 @@ export default {
|
|
|
delta_list: [],
|
|
|
alpha_list: [],
|
|
|
beta_list: [],
|
|
|
- theta_list: []
|
|
|
+ theta_list: [],
|
|
|
+ //判断是否结束游戏
|
|
|
+ is_end: false,
|
|
|
+ // 消耗的时间
|
|
|
+ played_time: 0
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
@@ -238,7 +241,9 @@ export default {
|
|
|
wx.offBLECharacteristicValueChange()
|
|
|
Toast.success('已成功断开')
|
|
|
//设置游戏状态为 停止游戏
|
|
|
- game_store.commit('setGameStatus', 0)
|
|
|
+ game_store.commit('setGameStatus', 3)
|
|
|
+ //游戏结束重置游戏时间
|
|
|
+ game_store.commit('setPlayTime', 0)
|
|
|
//游戏结束传送一下数据
|
|
|
$this.post_data()
|
|
|
$this.game_over()
|
|
@@ -251,7 +256,6 @@ export default {
|
|
|
// 时间到
|
|
|
time_out() {
|
|
|
$this.pop_show = true
|
|
|
- $this.game_finished()
|
|
|
},
|
|
|
to_report() {
|
|
|
mpvue.reLaunch({
|
|
@@ -317,7 +321,7 @@ export default {
|
|
|
})
|
|
|
// 操作之前先监听,保证第一时间获取数据
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
- console.log("收到" + $this.ab2hex(characteristic.value));
|
|
|
+ // console.log("收到" + $this.ab2hex(characteristic.value));
|
|
|
let hexStr = $this.ab2hex(characteristic.value)
|
|
|
let $data = bluetooth.get_big_data(hexStr)
|
|
|
if ($data) {
|
|
@@ -343,7 +347,6 @@ export default {
|
|
|
}
|
|
|
|
|
|
//连接玩具
|
|
|
- console.log('玩具hexStr', hexStr)
|
|
|
bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
})
|
|
|
},
|
|
@@ -363,6 +366,9 @@ export default {
|
|
|
watch_time(e) {
|
|
|
let $datetime = e.mp.detail
|
|
|
$this.timeData = $datetime
|
|
|
+ $this.played_time += 1
|
|
|
+ console.log("玩了:" + $this.played_time + "秒")
|
|
|
+
|
|
|
//时间倒数
|
|
|
if ($datetime.seconds == '00') {
|
|
|
// 时间满一分钟 则提交一次数据
|
|
@@ -394,78 +400,261 @@ export default {
|
|
|
},
|
|
|
// 结束游戏
|
|
|
game_over() {
|
|
|
- let $current_time = $this.timeData.minutes * 60 + $this.timeData.seconds
|
|
|
- let $play_time = $this.play_time - $current_time
|
|
|
- if ($this.mode == 2) {
|
|
|
- let $userinfo = wx.getStorageSync('userinfo')
|
|
|
- $play_time = $userinfo['play_time'] * 60 - $current_time
|
|
|
- }
|
|
|
+ // let $current_time = $this.timeData.minutes * 60 + $this.timeData.seconds
|
|
|
+ // let $play_time = $this.play_time - $current_time
|
|
|
+ // if ($this.mode == 2) {
|
|
|
+ // let $userinfo = wx.getStorageSync('userinfo')
|
|
|
+ // $play_time = $userinfo['play_time'] * 60 - $current_time
|
|
|
+ // }
|
|
|
let $params = {
|
|
|
game_record_id: game_store.getters.getGameRecordId,
|
|
|
type: $this.mode,
|
|
|
- play_time: $play_time
|
|
|
+ play_time: $this.played_time
|
|
|
}
|
|
|
console.log("结束游戏参数", $params)
|
|
|
//
|
|
|
gameEnd($params).then((res) => {
|
|
|
let $data = res.data
|
|
|
+ $this.played_time = 0
|
|
|
+ //设置未结束游戏
|
|
|
+ $this.is_end = false
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
,
|
|
|
mounted() {
|
|
|
+ //判断是否结束游戏
|
|
|
+ if ($this.is_end == true) {
|
|
|
+ $this.game_finished()
|
|
|
+ } else {
|
|
|
+ $this._deviceId = game_store.getters.getDeviceId
|
|
|
+ $this.getBLEDeviceServices($this._deviceId)
|
|
|
+
|
|
|
+ // 筛选 玩具id
|
|
|
+ $this.toy_hex = game_store.getters.getToyHex
|
|
|
+ // bluetooth.sendConnect($this.toy_hex, $this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+
|
|
|
+ //筛选模式
|
|
|
+ $this.mode = game_store.getters.getMode
|
|
|
+
|
|
|
+ //获取用户游玩时间
|
|
|
+ let $play_time = $this.play_time = game_store.getters.getPlayTime
|
|
|
+ $this.mode_list.forEach(($val, $index) => {
|
|
|
+ $val['time'] = $play_time * 1000
|
|
|
+ if ($val['id'] == $this.mode) {
|
|
|
+ $this.mode_item = $val
|
|
|
+ }
|
|
|
+ })
|
|
|
+ bluetooth.watch_bluetooth_status($this)
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
created() {
|
|
|
$this = this;
|
|
|
},
|
|
|
onShow() {
|
|
|
- $this._deviceId = game_store.getters.getDeviceId
|
|
|
- $this.getBLEDeviceServices($this._deviceId)
|
|
|
-
|
|
|
- // 筛选 玩具id
|
|
|
- $this.toy_hex = game_store.getters.getToyHex
|
|
|
- // bluetooth.sendConnect($this.toy_hex, $this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
-
|
|
|
-
|
|
|
- //筛选模式
|
|
|
- $this.mode = game_store.getters.getMode
|
|
|
-
|
|
|
- //获取用户游玩时间
|
|
|
- let $play_time = $this.play_time = game_store.getters.getPlayTime
|
|
|
- $this.mode_list.forEach(($val, $index) => {
|
|
|
- $val['time'] = $play_time * 1000
|
|
|
- if ($val['id'] == $this.mode) {
|
|
|
- $this.mode_item = $val
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- bluetooth.watch_bluetooth_status($this)
|
|
|
-
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
- let $game_status = game_store.getters.getGameStatus;
|
|
|
- if ($game_status == 1) {
|
|
|
- console.log("结束游戏跳转", options)
|
|
|
- if (options.end) {
|
|
|
- $this.game_finished()
|
|
|
- }
|
|
|
+ if (options.end == 1) {
|
|
|
+ $this.is_end = true
|
|
|
}
|
|
|
},
|
|
|
onUnload() {
|
|
|
// 返回 的时候 暂停
|
|
|
const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
countDown.pause();
|
|
|
- // bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- // bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
-
|
|
|
+ //停止传输数据
|
|
|
+ bluetooth.sendPause($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+ bluetooth.sendEnd($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+ wx.offBLECharacteristicValueChange()
|
|
|
+ //存储时间
|
|
|
let $play_time = $this.timeData.minutes * 60 + $this.timeData.seconds
|
|
|
- console.log($play_time)
|
|
|
game_store.commit('setPlayTime', $play_time)
|
|
|
this.pop_show = false
|
|
|
+ //设置未结束游戏
|
|
|
+ $this.is_end = false
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
-@import "index.css";
|
|
|
+#playing_container {
|
|
|
+ width: 100%;
|
|
|
+ background: linear-gradient(0deg, rgba(40, 157, 206, 0.51), rgba(135, 145, 226, 0.26));
|
|
|
+ background-color: #46425E;
|
|
|
+ padding: 5px;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+.game_panel {
|
|
|
+ width: 100%;
|
|
|
+ height: 76px;
|
|
|
+ background: #46425E;
|
|
|
+ box-shadow: 0px 3px 4px 0px #302D43;
|
|
|
+ border-radius: 11px;
|
|
|
+ margin: 0px auto;
|
|
|
+}
|
|
|
+
|
|
|
+.game_panel .title {
|
|
|
+ color: #9A96B7;
|
|
|
+}
|
|
|
+
|
|
|
+.game_panel .type {
|
|
|
+ color: #FFFFFF;
|
|
|
+}
|
|
|
+
|
|
|
+.van-count-down {
|
|
|
+ font-weight: bold;
|
|
|
+ font-size: 30px !important;
|
|
|
+ color: white !important;
|
|
|
+}
|
|
|
+
|
|
|
+.cut_brain_icon {
|
|
|
+ width: 11px;
|
|
|
+ height: 11px;
|
|
|
+}
|
|
|
+
|
|
|
+.device_img {
|
|
|
+ width: 36px;
|
|
|
+ height: 36px;
|
|
|
+}
|
|
|
+
|
|
|
+.text-default {
|
|
|
+ color: #9A95B7;
|
|
|
+ font-size: 10px;
|
|
|
+}
|
|
|
+
|
|
|
+/*电量显示*/
|
|
|
+.elc_power_container {
|
|
|
+ width: 28px;
|
|
|
+ border: #9A95B7 3px solid;
|
|
|
+ border-radius: 5px;
|
|
|
+ height: 22px;
|
|
|
+}
|
|
|
+
|
|
|
+.device_elc {
|
|
|
+ height: 22px;
|
|
|
+ width: 4px;
|
|
|
+}
|
|
|
+
|
|
|
+/* 节标题 */
|
|
|
+.bar {
|
|
|
+ width: 100%;
|
|
|
+ height: 15px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ padding: 0 7px;
|
|
|
+ box-sizing: border-box;
|
|
|
+ margin: 11px 0;
|
|
|
+}
|
|
|
+
|
|
|
+.bar view {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: start;
|
|
|
+}
|
|
|
+
|
|
|
+.bar .line {
|
|
|
+ width: 4px;
|
|
|
+ height: 15px;
|
|
|
+ background-color: #FFB400;
|
|
|
+ margin-right: 7px;
|
|
|
+}
|
|
|
+
|
|
|
+.bar .title {
|
|
|
+ color: #fff;
|
|
|
+ font-size: 15px;
|
|
|
+}
|
|
|
+
|
|
|
+.label {
|
|
|
+ color: #9A95B7;
|
|
|
+ font-size: 10px;
|
|
|
+}
|
|
|
+
|
|
|
+/*点图*/
|
|
|
+.dot {
|
|
|
+ width: 8px;
|
|
|
+ height: 8px;
|
|
|
+ border-radius: 50%;
|
|
|
+ margin-right: 4px;
|
|
|
+ margin-left: 15px;
|
|
|
+}
|
|
|
+
|
|
|
+.dot-orange {
|
|
|
+ background: #FFB400;
|
|
|
+}
|
|
|
+
|
|
|
+.dot-pink {
|
|
|
+
|
|
|
+ background: #D4327A;
|
|
|
+}
|
|
|
+
|
|
|
+.dot-blue {
|
|
|
+
|
|
|
+ background: #00CCFF;
|
|
|
+}
|
|
|
+
|
|
|
+.dot-green {
|
|
|
+
|
|
|
+ background: #0CDA2E;
|
|
|
+}
|
|
|
+
|
|
|
+.dot-yellow {
|
|
|
+
|
|
|
+ background: #D1D310;
|
|
|
+}
|
|
|
+
|
|
|
+.dot-orange-yellow {
|
|
|
+
|
|
|
+ background: #F8A117;
|
|
|
+}
|
|
|
+
|
|
|
+/* 图表 */
|
|
|
+#mychart-dom-multi-line {
|
|
|
+ width: 100%;
|
|
|
+ height: 175px;
|
|
|
+}
|
|
|
+
|
|
|
+#mychart-dom-multi-line-med {
|
|
|
+ width: 100%;
|
|
|
+ height: 100px;
|
|
|
+}
|
|
|
+
|
|
|
+.chart {
|
|
|
+ width: 360px;
|
|
|
+ height: 193px;
|
|
|
+ background: #302D43;
|
|
|
+ opacity: 0.6;
|
|
|
+ border-radius: 10px;
|
|
|
+}
|
|
|
+
|
|
|
+/*弹窗模块*/
|
|
|
+.err_container {
|
|
|
+ width: 260px;
|
|
|
+ height: 300px;
|
|
|
+ border-radius: 5px;
|
|
|
+}
|
|
|
+
|
|
|
+/*标题*/
|
|
|
+.err_container .title {
|
|
|
+ font-size: 20px;
|
|
|
+ font-weight: bold;
|
|
|
+ color: #4C4C4C;
|
|
|
+ line-height: 24px;
|
|
|
+}
|
|
|
+
|
|
|
+/*子标题*/
|
|
|
+.err_container .sub-title {
|
|
|
+ font-size: 12px;
|
|
|
+ font-family: Microsoft YaHei;
|
|
|
+ font-weight: 400;
|
|
|
+ color: #4B4B4B;
|
|
|
+ line-height: 24px;
|
|
|
+}
|
|
|
+
|
|
|
+.err_img{
|
|
|
+ width: 73px;
|
|
|
+ height: 83px;
|
|
|
+}
|
|
|
</style>
|