|
@@ -8,11 +8,7 @@
|
|
|
<text class="title">已游玩时间</text>
|
|
|
</view>
|
|
|
<view class="text-lg padding-top">
|
|
|
- <van-count-down :time="mode_item.time" format="mm:ss" use-slot auto-start @finish="time_out"
|
|
|
- @change="watch_time" class="control-count-down"
|
|
|
- >
|
|
|
- <text>{{ timeData.minutes }}:{{ timeData.seconds }}</text>
|
|
|
- </van-count-down>
|
|
|
+ <text class="count_down_text">{{ played_time_text }}</text>
|
|
|
</view>
|
|
|
</van-col>
|
|
|
<van-col span="10" offset="4">
|
|
@@ -32,7 +28,7 @@
|
|
|
<div class="game_status padding-tb">
|
|
|
<van-row>
|
|
|
<van-col span="10" offset="2">
|
|
|
- <div class="flex flex-direction align-center justify-center" v-if="device_ok == true">
|
|
|
+ <div class="flex flex-direction align-center justify-center" v-if="device_bg">
|
|
|
<img src="https://img.shuimuai.com/web/touhuanzhuangtai_2.png" alt="" class="device_img">
|
|
|
<text class="text-default">已经正确佩戴</text>
|
|
|
</div>
|
|
@@ -51,14 +47,14 @@
|
|
|
<text class="text-default">设备电量</text>
|
|
|
</div>
|
|
|
</van-col>
|
|
|
-<!-- <van-col span="2">-->
|
|
|
-<!-- <view>-->
|
|
|
-<!-- <text>{{ rssi }}</text>-->
|
|
|
-<!-- </view>-->
|
|
|
-<!-- <view>-->
|
|
|
-<!-- <text>信号强度</text>-->
|
|
|
-<!-- </view>-->
|
|
|
-<!-- </van-col>-->
|
|
|
+ <!-- <van-col span="2">-->
|
|
|
+ <!-- <view>-->
|
|
|
+ <!-- <text>{{ rssi }}</text>-->
|
|
|
+ <!-- </view>-->
|
|
|
+ <!-- <view>-->
|
|
|
+ <!-- <text>信号强度</text>-->
|
|
|
+ <!-- </view>-->
|
|
|
+ <!-- </van-col>-->
|
|
|
</van-row>
|
|
|
</div>
|
|
|
|
|
@@ -215,11 +211,11 @@ export default {
|
|
|
//判断是否结束游戏
|
|
|
is_end: false,
|
|
|
// 消耗的时间
|
|
|
- played_time: 0,
|
|
|
- played_time_text: "",
|
|
|
+ played_time: null,
|
|
|
+ played_time_text: "--:--",
|
|
|
|
|
|
// 检测佩戴是否正确
|
|
|
- device_ok: true,
|
|
|
+ device_bg: true,
|
|
|
|
|
|
// 蓝牙信号强度
|
|
|
rssi: 0
|
|
@@ -228,55 +224,48 @@ export default {
|
|
|
methods: {
|
|
|
//游戏结束方法
|
|
|
game_finished() {
|
|
|
- try {
|
|
|
- bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- //停止控制游戏
|
|
|
- const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
- countDown.pause();
|
|
|
- //取消监听低功耗蓝牙设备
|
|
|
- wx.offBLECharacteristicValueChange()
|
|
|
- Toast.success('已成功断开')
|
|
|
- //设置游戏状态为 停止游戏
|
|
|
- game_store.setters.setGameStatus(3)
|
|
|
- //游戏结束重置游戏时间
|
|
|
- wx.removeStorageSync('play_time')
|
|
|
- wx.removeStorageSync('hide_time')
|
|
|
- //游戏结束重置游戏模式
|
|
|
- game_store.setters.setMode(0)
|
|
|
- //删除游戏得id
|
|
|
- game_store.setters.removeToyHex()
|
|
|
- //关闭游戏常亮
|
|
|
- wx.setKeepScreenOn({
|
|
|
- keepScreenOn: false
|
|
|
- })
|
|
|
- //游戏结束传送一下数据
|
|
|
- $this.post_data()
|
|
|
-
|
|
|
+ bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+ //取消监听低功耗蓝牙设备
|
|
|
+ wx.offBLECharacteristicValueChange()
|
|
|
+ //设置游戏状态为 停止游戏
|
|
|
+ game_store.setters.setGameStatus(3)
|
|
|
+ //游戏结束重置游戏时间
|
|
|
+ wx.removeStorageSync('play_time')
|
|
|
+ wx.removeStorageSync('hide_time')
|
|
|
+ //游戏结束重置游戏模式
|
|
|
+ game_store.setters.setMode(0)
|
|
|
+ //删除游戏得id
|
|
|
+ game_store.setters.removeToyHex()
|
|
|
+ const $proce = new Promise((resolve, reject) => {
|
|
|
+ let cost_time = $this.post_data()
|
|
|
+ console.log('提交数据使用了:', cost_time)
|
|
|
+ resolve(cost_time)
|
|
|
+ }).then((value) => {
|
|
|
Toast.loading({
|
|
|
forbidClick: true,
|
|
|
+ mask: true,
|
|
|
message: "正在生成报告...",
|
|
|
- duration: 800,
|
|
|
+ duration: value,
|
|
|
onClose() {
|
|
|
$this.game_over()
|
|
|
$this.to_report()
|
|
|
}
|
|
|
})
|
|
|
- } catch (e) {
|
|
|
- console.log('error', e)
|
|
|
- }
|
|
|
+ })
|
|
|
},
|
|
|
// 时间到
|
|
|
time_out() {
|
|
|
console.log('游戏结束')
|
|
|
- $this.played_time = $this.play_time
|
|
|
//游戏结束
|
|
|
$this.game_finished()
|
|
|
},
|
|
|
to_report() {
|
|
|
- mpvue.reLaunch({
|
|
|
+ mpvue.redirectTo({
|
|
|
url: "/pages/report/main",
|
|
|
success() {
|
|
|
$this.timeData = {}
|
|
|
+ $this.attList = []
|
|
|
+ $this.medList = []
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -295,73 +284,71 @@ export default {
|
|
|
)
|
|
|
return hexArr.join('');
|
|
|
},
|
|
|
-
|
|
|
- // 监听时间发生变动
|
|
|
- watch_time(e) {
|
|
|
- let $datetime = e.mp.detail
|
|
|
- for (let $key in $datetime) {
|
|
|
- if ($datetime[$key].toString().length == 1) {
|
|
|
- $datetime[$key] = "0" + $datetime[$key]
|
|
|
- }
|
|
|
- }
|
|
|
- $this.timeData = $datetime
|
|
|
- $this.played_time += 1
|
|
|
- if ($this.played_time % 60 == 0) {
|
|
|
- $this.post_data()
|
|
|
- }
|
|
|
- },
|
|
|
// 往后端推送一次定时数据
|
|
|
post_data() {
|
|
|
- let $params = {
|
|
|
- game_record_id: game_store.getters.getGameRecordId(),
|
|
|
- line: $this.attList,
|
|
|
- line_med: $this.medList
|
|
|
- }
|
|
|
- if (!$params.line && !$params.line_med) {
|
|
|
- return false
|
|
|
- }
|
|
|
- gameAddLine($params).then((res) => {
|
|
|
- let $data = res.data
|
|
|
- if ($data.code == 0) {
|
|
|
- $this.attList = []
|
|
|
- $this.medList = []
|
|
|
- } else {
|
|
|
- bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
- //停止控制游戏
|
|
|
- const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
- countDown.pause();
|
|
|
- //取消监听低功耗蓝牙设备
|
|
|
- wx.offBLECharacteristicValueChange()
|
|
|
- Toast.success('已成功断开')
|
|
|
- //设置游戏状态为 停止游戏
|
|
|
- game_store.setters.setGameStatus(3)
|
|
|
- //游戏结束重置游戏时间
|
|
|
- wx.removeStorageSync('play_time')
|
|
|
- wx.removeStorageSync('hide_time')
|
|
|
- //游戏结束重置游戏模式
|
|
|
- game_store.setters.setMode(0)
|
|
|
- //删除游戏得id
|
|
|
- game_store.setters.removeToyHex()
|
|
|
- //关闭游戏常亮
|
|
|
- wx.setKeepScreenOn({
|
|
|
- keepScreenOn: false
|
|
|
- })
|
|
|
- userjs.do_logout($this)
|
|
|
+ //判断数据长度大于理想状态 需要对数组进行切割 逐个提交数据
|
|
|
+ let $len = 60
|
|
|
+ if ($this.attList.length > 65) {
|
|
|
+ let $count = Math.ceil($this.attList.length / 60)
|
|
|
+
|
|
|
+ let index = 0
|
|
|
+ let inter = setInterval(() => {
|
|
|
+ if (index < $count) {
|
|
|
+ let $params = {
|
|
|
+ game_record_id: game_store.getters.getGameRecordId(),
|
|
|
+ //数据段长度大于65 多个提交
|
|
|
+ line: $this.attList.slice(index * $len, (index + 1) * $len),
|
|
|
+ line_med: $this.medList.slice(index * $len, (index + 1) * $len)
|
|
|
+ }
|
|
|
+ console.log($this.attList)
|
|
|
+ console.log(index * $len, (index + 1) * $len)
|
|
|
+ console.log($this.attList.slice(index * $len, (index + 1) * $len))
|
|
|
+ gameAddLine($params).then((res) => {
|
|
|
+ let $data = res.data
|
|
|
+ if ($data.code == 0) {
|
|
|
+ console.log('ok', $params['line'])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ index++
|
|
|
+ if (index == $count) {
|
|
|
+ clearInterval(inter)
|
|
|
+ }
|
|
|
+ }, 800)
|
|
|
+ return $count * 800
|
|
|
+ } else {
|
|
|
+ let $params = {
|
|
|
+ game_record_id: game_store.getters.getGameRecordId(),
|
|
|
+ //数据段长度小于65 单个提交
|
|
|
+ line: $this.attList,
|
|
|
+ line_med: $this.medList
|
|
|
}
|
|
|
- })
|
|
|
+
|
|
|
+ if (!$params.line) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ gameAddLine($params).then((res) => {
|
|
|
+ let $data = res.data
|
|
|
+ if ($data.code == 0) {
|
|
|
+ $this.attList = []
|
|
|
+ $this.medList = []
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return 800
|
|
|
+ }
|
|
|
},
|
|
|
// 结束游戏
|
|
|
game_over() {
|
|
|
let $params = {
|
|
|
game_record_id: game_store.getters.getGameRecordId(),
|
|
|
type: $this.mode,
|
|
|
- play_time: Math.abs($this.played_time)
|
|
|
+ play_time: $this.play_time - Math.abs($this.played_time)
|
|
|
}
|
|
|
console.log("结束游戏参数", $params)
|
|
|
//
|
|
|
gameEnd($params).then((res) => {
|
|
|
let $data = res.data
|
|
|
- $this.played_time = 0
|
|
|
+ $this.played_time = null
|
|
|
//设置未结束游戏
|
|
|
$this.is_end = false
|
|
|
$this.att_list = []
|
|
@@ -410,14 +397,10 @@ export default {
|
|
|
{
|
|
|
id: 1,
|
|
|
name: "次卡(10分钟)",
|
|
|
- time: 10 * 60 * 1000,
|
|
|
- err_title: "您的会员消费时间已用完",
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
|
name: "会员时间消费",
|
|
|
- time: 30 * 60 * 1000,
|
|
|
- err_title: "本次游玩时间已用完"
|
|
|
}
|
|
|
|
|
|
]
|
|
@@ -426,17 +409,19 @@ export default {
|
|
|
let $play_time = $this.play_time = game_store.getters.getPlayTime()
|
|
|
|
|
|
//已经完了多长时间
|
|
|
- let $played_time = $this.played_time = game_store.getters.getPlayedTime() ? game_store.getters.getPlayedTime() : 0
|
|
|
+ // $this.played_time = game_store.getters.getPlayedTime() ? game_store.getters.getPlayedTime() : 0
|
|
|
+ $this.played_time = game_store.getters.getPlayTime()
|
|
|
|
|
|
//判断可玩时长超出了时间 就直接结束游戏
|
|
|
- if ($played_time >= ($play_time * 1000)) {
|
|
|
- $this.game_finished()
|
|
|
- }
|
|
|
+ // if ($played_time >= ($play_time * 1000)) {
|
|
|
+ // $this.game_finished()
|
|
|
+ // }
|
|
|
|
|
|
$this.mode_item = {}
|
|
|
$this.mode_item = mode_list[$this.mode - 1]
|
|
|
- let $origin_time = $play_time * 1000
|
|
|
- $this.mode_item['time'] = $origin_time - ($played_time * 1000)
|
|
|
+ // let $origin_time = $play_time * 1000
|
|
|
+ // $this.mode_item['time'] = $origin_time - ($played_time * 1000)
|
|
|
+ $this.mode_item['time'] = $play_time * 1000
|
|
|
}
|
|
|
}
|
|
|
,
|
|
@@ -463,47 +448,14 @@ export default {
|
|
|
$this = this;
|
|
|
},
|
|
|
onShow() {
|
|
|
- if ($this.timeData.minutes == '00' && $this.timeData.seconds == '00') {
|
|
|
+ if ($this.played_time == 0) {
|
|
|
$this.time_out()
|
|
|
- } else {
|
|
|
- //获取 拉到后台得时间
|
|
|
- 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()
|
|
|
- }
|
|
|
}
|
|
|
},
|
|
|
- onHide() {
|
|
|
- game_store.setters.setHideTime(Math.round(new Date() / 1000))
|
|
|
- },
|
|
|
onLoad(options) {
|
|
|
if (options.end == 1) {
|
|
|
$this.is_end = true
|
|
|
}
|
|
|
- },
|
|
|
- onUnload() {
|
|
|
- if (!$this.is_end) {
|
|
|
- // 返回 的时候 暂停
|
|
|
- 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)
|
|
|
- wx.offBLECharacteristicValueChange()
|
|
|
- //存储时间
|
|
|
- game_store.setters.setPlayedTime($this.played_time)
|
|
|
- //设置未结束游戏
|
|
|
- $this.is_end = false
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
@@ -700,4 +652,13 @@ export default {
|
|
|
position: relative;
|
|
|
bottom: 5px;
|
|
|
}
|
|
|
+
|
|
|
+/*倒计时样式*/
|
|
|
+.count_down_text {
|
|
|
+ font-size: 35px;
|
|
|
+ font-family: PingFang SC;
|
|
|
+ font-weight: 400;
|
|
|
+ color: #fff;
|
|
|
+ line-height: 28px;
|
|
|
+}
|
|
|
</style>
|