ReedawFoodApp/pageTwo/devices/PCT01.vue

478 lines
13 KiB
Vue
Raw Permalink Normal View History

2025-05-30 11:14:38 +08:00
<template>
<view class="content skipping">
<!--自由训练 -->
<view class="title">{{info.active==1?'自由跳':info.active==2?'倒计时':'倒计数'}}</view>
<view class="skiptop">
<view class="item">
<view class="item-ite">{{info.active==1?'自由次数':info.active==2?"个数":'目标次数'}}<text>{{weight}}</text>
</view>
<view class="item-ite">
{{info.active==2?'目标时长 分:秒':"分:秒"}}<text>{{time_m?time_m:'00'}}:{{time_s?time_s:'00'}}</text>
</view>
<view class="item-ite">消耗/kcal<text>{{Math.floor(kcal)}}</text></view>
</view>
</view>
<view class="image">
2026-03-27 10:04:26 +08:00
<image src="/pageTwo/static/t01.gif"></image>
2025-05-30 11:14:38 +08:00
</view>
<view class="end" @longpress="onlongpress">长按结束</view>
<!-- 报告 -->
<view class="wrapper" v-if="iswrapper">
<view class="bg">
<view class="edit">
<view class="editem">
<view>平均速度<text class="cyello Blue size20 mr-5">{{bpm.toFixed(1)}}</text>bpm</view>
<view class="size12 c999 ">(bpm=/分钟)</view>
</view>
<view class="center">
<view class="left">
<image src="/pageTwo/static/duan.png"></image>
<view class="name">
<view>
中断次数
</view>
<view>
<text class="cyello Blue size20 mr-5">{{Bcount}}</text>
</view>
</view>
</view>
<!-- -->
<view class="left">
<image src="/pageTwo/static/xu.png"></image>
<view class="name">
<view>
最长连续
</view>
<view>
<text class="cyello Blue size20 mr-5">{{continuous}}</text>
</view>
</view>
</view>
</view>
<view class="item">
<view class="item-ite"><text>{{weight}}</text>训练个数</view>
<view class="item-ite"><text>{{time_m?time_m:'00'}}:{{time_s?time_s:'00'}}</text>:</view>
<view class="item-ite"><text>{{Math.floor(kcal)}}</text>消耗/kcal</view>
</view>
<view class="btn" @click="handleTarget">完成</view>
</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
let innerAudioContext = null;
export default {
data() {
return {
bpm: 0,
isend: false,
weight: 0,
Ycount: 0,
time_m: "",
time_s: "",
time: 0,
kcal: 0,
Bcount: 0,
continuous: 0,
info: {},
isToggle: false,
isEnd: false,
iswrapper: false,
isStart: false
}
},
computed: {
2026-03-27 10:04:26 +08:00
...mapState(["bleValue", "user", "isBluetoothTyle"]),
},
onHide() {
console.log("PCT01返回onHide", innerAudioContext)
2025-05-30 11:14:38 +08:00
},
onLoad(options) {
let that = this
innerAudioContext = uni.createInnerAudioContext()
if (options && options.info) {
let info = options.info
that.info = JSON.parse(info)
that.notifyBLECharacteristicValue()
setTimeout(function() {
that.handleStart('开始')
}, 900)
setTimeout(function() {
that.handleStart('连续')
}, 1200)
}
that.handleAudioStart()
},
onUnload: function() {
let that = this
2026-03-27 10:04:26 +08:00
innerAudioContext.destroy();
2025-05-30 11:14:38 +08:00
that.handleEnd()
2026-03-27 10:04:26 +08:00
console.log("PCT01返回onUnload", innerAudioContext)
2025-05-30 11:14:38 +08:00
},
watch: {
2026-03-27 10:04:26 +08:00
isBluetoothTyle: function() {
2025-05-30 11:14:38 +08:00
let that = this
2026-03-27 10:04:26 +08:00
if (!that.isBluetoothTyle) {
2025-05-30 11:14:38 +08:00
uni.showModal({
title: '连接已断开',
content: '训练过程中已与设备连接中断,请重新连接设备再开始训练',
showCancel: false,
success: function(res) {
if (res.confirm) {
that.handleTarget()
}
}
})
2026-03-27 10:04:26 +08:00
console.log("蓝牙是否连接", that.isBluetoothTyle)
2025-05-30 11:14:38 +08:00
}
},
2026-03-27 10:04:26 +08:00
2025-05-30 11:14:38 +08:00
// 开始跳绳
isStart: function() {
let that = this
if (that.isStart) {
that.handleAudio()
}
},
// 切换模式
isToggle: function() {
let that = this
if (that.isToggle) {
uni.showModal({
title: '友情提示',
content: '训练过程中请勿切换训练,返回训练',
showCancel: false,
success: function(res) {
if (res.confirm) {
setTimeout(function() {
that.handleStart('结束')
}, 400)
setTimeout(function() {
that.handleTarget()
}, 600)
}
}
})
}
},
// 模式被结束
isEnd: function() {
let that = this
if (that.isEnd) {
setTimeout(function() {
that.handleStart('停止')
}, 200)
setTimeout(function() {
that.handleGetMeasure()
}, 400)
}
},
//
weight: function() {
let that = this
if (that.info.active == 1) {
that.$video.video.forEach(ite => {
if (Number(ite.name) == that.weight) {
innerAudioContext.autoplay = true;
innerAudioContext.loop = false;
innerAudioContext.src = ite.video;
innerAudioContext.play()
setTimeout(function() {
innerAudioContext.stop();
that.handleAudio()
}, 3000)
}
})
}
if (that.info.active == 2) {
let time = that.time_m * 60 + that.time_s
that.$video.video.forEach(ite => {
if ((Number(ite.name) == that.weight) && (Number(time) > 10)) {
innerAudioContext.autoplay = true;
innerAudioContext.loop = false;
innerAudioContext.src = ite.video;
innerAudioContext.play()
setTimeout(function() {
innerAudioContext.stop();
that.handleAudio()
}, 3000)
}
})
if (that.time_m == "00" && that.time_s == "10") {
innerAudioContext.autoplay = true;
innerAudioContext.loop = false;
innerAudioContext.src = '/pageTwo/static/time.mp3';
innerAudioContext.play()
setTimeout(function() {
innerAudioContext.stop();
that.handleAudio()
}, 3000)
}
}
if (that.info.active == 3) {
that.$video.video.forEach(ite => {
if ((Number(ite.name) == (Number(that.Ycount) - Number(that.weight))) && Number(that
.weight) != 0) {
innerAudioContext.autoplay = true;
innerAudioContext.loop = false;
innerAudioContext.src = ite.video;
innerAudioContext.play()
setTimeout(function() {
innerAudioContext.stop();
that.handleAudio()
}, 3000)
}
})
if (Number(that.weight) == 10) {
innerAudioContext.autoplay = true;
innerAudioContext.loop = false;
innerAudioContext.src = '/pageTwo/static/number.mp3';
innerAudioContext.play()
setTimeout(function() {
innerAudioContext.stop();
that.handleAudio()
}, 3000)
}
}
},
},
methods: {
handleAudioStart() {
let that = this
innerAudioContext.autoplay = true;
innerAudioContext.loop = false;
innerAudioContext.src = '/pageTwo/static/Start.mp3';
innerAudioContext.play()
setTimeout(function() {
innerAudioContext.stop();
that.handleAudio()
}, 5000)
},
handleAudio() {
innerAudioContext.autoplay = true;
innerAudioContext.loop = true;
innerAudioContext.src = '/pageTwo/static/flight.mp3';
innerAudioContext.play()
},
// 接收蓝牙数据
notifyBLECharacteristicValue() {
let that = this;
uni.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId: that.info.deviceId,
serviceId: that.info.serviceId,
characteristicId: that.info.notify,
success(res) {
uni.onBLECharacteristicValueChange(function(res) {
let value = that.$tools.ab2hex(res.value, "");
let count = parseInt(value.substring(8, 12), 16)
let Ycount = parseInt(value.substring(12, 16), 16) //设置次数
let time = parseInt(value.substring(16, 20), 16) //运行时间/秒
let timeDown = parseInt(value.substring(20, 24), 16) //倒计时时间
let type = parseInt(value.substring(30, 32), 16) //当前状态
let weight = parseInt(value.substring(32, 34), 16) //重量
let kcal = parseInt(value.substring(34, 38), 16) //卡路里
let minutes = null
let seconds = null
if (type == 0 || type == 4) {
that.weight = count //个数
that.Ycount = Ycount
that.time = time
that.kcal = kcal / 10
if (that.info.active != 2 && count != 0) { //自由模式 + 计数
minutes = Math.floor((time % 3600) / 60)
seconds = time % 60
that.time_m = minutes > 9 ? minutes : '0' + minutes
that.time_s = seconds > 9 ? seconds : '0' + seconds
}
if (that.info.active == 2) { //计时
let T = Number(timeDown) - Number(time)
minutes = Math.floor((T % 3600) / 60)
seconds = T % 60
that.time_m = minutes > 9 ? minutes : '0' + minutes
that.time_s = seconds > 9 ? seconds : '0' + seconds
}
that.Bcount = parseInt(value.substring(24, 26), 16) //绊绳个数
that.continuous = parseInt(value.substring(26, 30), 16) //连续个数
console.log("自由模式", count, kcal, time, that.time_m, that.time_s, weight)
}
if ((type == 2 || type == 3) && !that.isToggle) {
setTimeout(function() {
that.isToggle = true
that.handleStart('停止')
}, 200)
console.log("当前状态被切换")
}
if (type == 4 && !that.isEnd) {
that.isEnd = true
console.log("当前状态被结束")
}
})
},
fail(res) {
console.log("测量失败", res.value);
}
})
},
SendData(str) {
let that = this
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
return parseInt(h, 16)
}))
uni.writeBLECharacteristicValue({
deviceId: that.info.deviceId,
serviceId: that.info.serviceId,
characteristicId: that.info.write,
value: buf.buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
},
fail: res => {
console.log("下发指令失败", res);
},
})
},
onlongpress() {
let that = this
uni.vibrateLong({
success: function() {
console.log('短震动');
if (Number(that.time) < 10) {
uni.showModal({
title: '友情提示',
content: '本次跳绳时间低于10秒记录将不会被保存',
confirmText: "继续",
cancelText: "返回",
success: function(res) {
if (res.cancel) {
that.isStart = false
innerAudioContext.stop();
uni.navigateBack({ //返回
delta: 1
})
}
},
})
} else {
that.handleStart('停止')
setTimeout(function() {
that.handleStart('结束')
}, 400)
setTimeout(function() {
that.handleGetMeasure()
}, 800)
}
},
fail: function(err) {
console.error('震动失败:', err);
},
})
},
// 保存测量结果
handleGetMeasure() {
let that = this
if (that.info.active == 3 && that.weight == 0 && that.Ycount != 0) {
console.log("1", that.weight, that.Ycount)
that.weight = that.Ycount
} else if (that.info.active == 3 && that.weight != 0 && that.Ycount != 0) {
console.log("2", that.weight, that.Ycount)
that.weight = Number(that.Ycount) - Number(that.weight)
}
if (that.info.active == 2) {
that.time_m = Math.floor((that.time % 3600) / 60)
that.time_s = that.time % 60
}
2026-03-27 10:04:26 +08:00
console.log("111111保存", that.user.aud_id, Math.floor(that.kcal), that.weight, Number(that.time_m), that
.time_s, that.info.active)
2026-03-25 17:27:29 +08:00
that.$model.getSkipResult({
aud_id: that.user.aud_id,
2025-05-30 11:14:38 +08:00
kcal: Math.floor(that.kcal),
num: that.weight,
time_m: Number(that.time_m),
time_s: that.time_s,
type: that.info.active == 1 ? 'free' : that.info.active == 2 ? 'time' : 'num'
}).then(res => {
console.log("保存", that.time, res)
that.isStart = false
innerAudioContext.stop()
if (res.code == 0) {
that.bpm = that.weight / (that.time / 60)
that.iswrapper = true
that.info.isSuccessful = true
2026-03-25 17:27:29 +08:00
that.$store.dispatch("getSkipResult", {
aud_id: that.user.aud_id
2025-05-30 11:14:38 +08:00
})
} else {
that.$tools.msg(res.msg)
}
})
},
// 开始指令
handleStart(text) {
let that = this
let j = null
let str = null
if (text == '连续') {
j = Number(165 + 5 + 3).toString(16)
str = "A5050300" + j.substr(j.length - 2, 2)
console.log("连续连续", str)
}
if (text == '停止') {
j = Number(165 + 5 + 3 + 5).toString(16)
str = "A5050305" + j.substr(j.length - 2, 2)
console.log("停止连续", str)
}
if (text == '开始') {
j = Number(165 + 5 + 5).toString(16)
str = "A5050500" + j.substr(j.length - 2, 2)
}
if (text == '结束') {
j = Number(165 + 5 + 5 + 1).toString(16)
str = "A5050501" + j.substr(j.length - 2, 2)
console.log("结束指令", str)
}
if (text == '继续') {
j = Number(165 + 5 + 4).toString(16)
str = "A5050400" + j.substr(j.length - 2, 2)
console.log("继续指令", str)
}
if (text == '暂停') {
j = Number(165 + 5 + 4 + 1).toString(16)
str = "A5050401" + j.substr(j.length - 2, 2)
console.log("暂停指令", str)
}
that.SendData(str)
},
handleTarget() {
let that = this
innerAudioContext.stop();
uni.navigateBack({ //返回
delta: 1
})
},
//
handleEnd() {
let that = this
that.handleStart('停止')
setTimeout(function() {
that.handleStart('结束')
}, 400)
setTimeout(function() {
uni.$emit('updateData', JSON.stringify(that.info))
}, 600)
}
}
}
</script>
<style lang="scss" scoped>
@import "./scss/PCT01.scss";
</style>