|
@@ -11,7 +11,8 @@
|
|
|
<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>
|
|
|
+ <text v-if="mode == 1">{{ timeData.minutes }}:{{ timeData.seconds }}</text>
|
|
|
+ <text v-if="mode == 2">{{ played_time_text }}</text>
|
|
|
</van-count-down>
|
|
|
</view>
|
|
|
</van-col>
|
|
@@ -130,7 +131,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 bluetooth from "../../utils/bluetooth";
|
|
|
import game_store from "@/store/game";
|
|
|
import Toast from '../../../static/vant/toast/toast';
|
|
@@ -215,8 +216,8 @@ export default {
|
|
|
play_time: 0,
|
|
|
|
|
|
//图标数据集合
|
|
|
- att_list: [],
|
|
|
- med_list: [],
|
|
|
+ att_list: [0],
|
|
|
+ med_list: [0],
|
|
|
delta_list: [],
|
|
|
alpha_list: [],
|
|
|
beta_list: [],
|
|
@@ -224,17 +225,19 @@ export default {
|
|
|
//判断是否结束游戏
|
|
|
is_end: false,
|
|
|
// 消耗的时间
|
|
|
- played_time: 0
|
|
|
+ played_time: 0,
|
|
|
+ played_time_text: ""
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
//游戏结束方法
|
|
|
game_finished() {
|
|
|
+
|
|
|
+ //停止传输数据
|
|
|
+ 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)
|
|
|
bluetooth.shutdownSendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
-
|
|
|
const countDown = $this.$mp.page.selectComponent('.control-count-down');
|
|
|
countDown.pause();
|
|
|
//取消监听低功耗蓝牙设备
|
|
@@ -255,7 +258,8 @@ export default {
|
|
|
},
|
|
|
// 时间到
|
|
|
time_out() {
|
|
|
- $this.pop_show = true
|
|
|
+ // $this.pop_show = true
|
|
|
+ $this.game_finished()
|
|
|
},
|
|
|
to_report() {
|
|
|
mpvue.reLaunch({
|
|
@@ -264,20 +268,27 @@ export default {
|
|
|
},
|
|
|
//获取蓝牙设备服务
|
|
|
getBLEDeviceServices(deviceId) {
|
|
|
+ console.log('获取蓝牙设备服务', deviceId)
|
|
|
wx.getBLEDeviceServices({
|
|
|
deviceId,
|
|
|
success: (res) => {
|
|
|
+ console.log('获取蓝牙设备服务成功')
|
|
|
for (let i = 0; i < res.services.length; i++) {
|
|
|
if (res.services[i].isPrimary) {
|
|
|
this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+
|
|
|
+ console.log('获取蓝牙设备失败', res)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//获取蓝牙设备某个服务中所有特征值
|
|
|
getBLEDeviceCharacteristics(deviceId, serviceId) {
|
|
|
+ console.log('获取蓝牙设备某个服务中所有特征值')
|
|
|
wx.getBLEDeviceCharacteristics({
|
|
|
deviceId,
|
|
|
serviceId,
|
|
@@ -293,7 +304,6 @@ export default {
|
|
|
})
|
|
|
}
|
|
|
if (item.properties.write) {
|
|
|
- $this.canWrite = true
|
|
|
$this._deviceId = deviceId
|
|
|
$this._serviceId = serviceId
|
|
|
$this._characteristicId = item.uuid
|
|
@@ -320,10 +330,16 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
// 操作之前先监听,保证第一时间获取数据
|
|
|
+ $this.start_game()
|
|
|
+ },
|
|
|
+
|
|
|
+ start_game() {
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
+ console.log('监听蓝牙时间获取数据')
|
|
|
// console.log("收到" + $this.ab2hex(characteristic.value));
|
|
|
let hexStr = $this.ab2hex(characteristic.value)
|
|
|
let $data = bluetooth.get_big_data(hexStr)
|
|
|
+ //连接玩具
|
|
|
if ($data) {
|
|
|
$this.att_list.push($data['att'])
|
|
|
$this.med_list.push($data['med'])
|
|
@@ -345,10 +361,10 @@ export default {
|
|
|
if ($power) {
|
|
|
$this.elc_power = $power
|
|
|
}
|
|
|
-
|
|
|
- //连接玩具
|
|
|
bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
|
|
|
+
|
|
|
})
|
|
|
+
|
|
|
},
|
|
|
|
|
|
// ArrayBuffer转16进度字符串示例
|
|
@@ -368,7 +384,7 @@ export default {
|
|
|
$this.timeData = $datetime
|
|
|
$this.played_time += 1
|
|
|
console.log("玩了:" + $this.played_time + "秒")
|
|
|
-
|
|
|
+ $this.played_time_text = formatSeconds($this.played_time)
|
|
|
//时间倒数
|
|
|
if ($datetime.seconds == '00') {
|
|
|
// 时间满一分钟 则提交一次数据
|
|
@@ -383,6 +399,9 @@ export default {
|
|
|
line: $this.att_list,
|
|
|
line_med: $this.med_list
|
|
|
}
|
|
|
+ if (!$params.line && !$params.line_med) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
gameAddLine($params).then((res) => {
|
|
|
let $data = res.data
|
|
|
if ($data.code == 0) {
|
|
@@ -428,6 +447,7 @@ export default {
|
|
|
$this.game_finished()
|
|
|
} else {
|
|
|
$this._deviceId = game_store.getters.getDeviceId
|
|
|
+ console.log("游戏开始:当前device_id", $this._deviceId)
|
|
|
$this.getBLEDeviceServices($this._deviceId)
|
|
|
|
|
|
// 筛选 玩具id
|
|
@@ -655,7 +675,7 @@ export default {
|
|
|
line-height: 24px;
|
|
|
}
|
|
|
|
|
|
-.err_img{
|
|
|
+.err_img {
|
|
|
width: 73px;
|
|
|
height: 83px;
|
|
|
}
|