examTeamApp/pageTwo/devices/PCT01.vue

493 lines
14 KiB
Vue
Raw Normal View History

2024-07-08 10:50:07 +08:00
<template>
2024-07-22 14:13:19 +08:00
<view class="content skipping">
<!--自由训练 -->
2025-04-26 13:35:30 +08:00
<view class="title">
{{info.active==1?$t("skip.jumpFree"):info.active==2?$t("skip.Countdown"):$t("skip.backwardCount")}}</view>
2024-07-22 14:13:19 +08:00
<view class="skiptop">
<view class="item">
2025-04-26 13:35:30 +08:00
<view class="item-ite">
{{info.active==1?$t("skip.jumpFreeDegree"):info.active==2?$t("skip.jumpFreeNumber"):$t("skip.jumpTargetDegree")}}<text>{{weight}}</text>
2024-07-22 14:13:19 +08:00
</view>
<view class="item-ite">
2025-04-26 13:35:30 +08:00
{{info.active==2?$t("skip.jumpTargetTime"):$t("skip.MinuteSecond")}}<text>{{time_m?time_m:'00'}}:{{time_s?time_s:'00'}}</text>
2024-07-22 14:13:19 +08:00
</view>
2025-04-26 13:35:30 +08:00
<view class="item-ite">{{$t("skip.Consumed")}}/kcal<text>{{Math.floor(kcal)}}</text></view>
2024-07-22 14:13:19 +08:00
</view>
</view>
<view class="image">
2025-04-26 13:35:30 +08:00
<image src="/pageTwo/static/t01.gif"></image>
2024-07-22 14:13:19 +08:00
</view>
2025-04-26 13:35:30 +08:00
<view class="end" @longpress="onlongpress">{{$t("skip.LongpressEnd")}}</view>
2024-07-22 14:13:19 +08:00
<!-- 报告 -->
<view class="wrapper" v-if="iswrapper">
<view class="bg">
<view class="edit">
<view class="editem">
2025-04-26 13:35:30 +08:00
<view>{{$t("skip.AverageSpeed")}}<text
class="cyello Blue size20 mr-5">{{bpm.toFixed(1)}}</text>bpm</view>
<view class="size12 c999 ">(bpm={{$t("skip.Unit")}})</view>
2024-07-22 14:13:19 +08:00
</view>
2025-04-26 13:35:30 +08:00
<view class="center" :class="[language== 'zh-Hans'?'':'center2']">
2024-07-22 14:13:19 +08:00
<view class="left">
2024-12-14 09:42:21 +08:00
<image src="/pageTwo/static/duan.png"></image>
2024-07-22 14:13:19 +08:00
<view class="name">
<view>
2025-04-26 13:35:30 +08:00
{{$t("skip.Numberofinterrupts")}}
2024-07-22 14:13:19 +08:00
</view>
<view>
2025-04-26 13:35:30 +08:00
<text class="cyello Blue size20 mr-5">{{Bcount}}</text>{{$t("skip.Times")}}
2024-07-22 14:13:19 +08:00
</view>
</view>
</view>
<!-- -->
<view class="left">
2024-12-14 09:42:21 +08:00
<image src="/pageTwo/static/xu.png"></image>
2024-07-22 14:13:19 +08:00
<view class="name">
<view>
2025-04-26 13:35:30 +08:00
{{$t("skip.LongestConsecutive")}}
2024-07-22 14:13:19 +08:00
</view>
<view>
2025-04-26 13:35:30 +08:00
<text class="cyello Blue size20 mr-5">{{continuous}}</text>{{$t("skip.Number")}}
2024-07-22 14:13:19 +08:00
</view>
</view>
</view>
</view>
<view class="item">
2025-04-26 13:35:30 +08:00
<view class="item-ite"><text>{{weight}}</text>{{$t("skip.trainingsNumber")}}</view>
<view class="item-ite">
<text>{{time_m?time_m:'00'}}:{{time_s?time_s:'00'}}</text>{{$t("skip.MinuteSecond")}}</view>
<view class="item-ite"><text>{{Math.floor(kcal)}}</text>{{$t("skip.Consumed")}}/kcal</view>
2024-07-22 14:13:19 +08:00
</view>
2025-04-26 13:35:30 +08:00
<view class="btn" @click="handleTarget">{{$t("skip.complete")}}</view>
2024-07-22 14:13:19 +08:00
</view>
</view>
</view>
2024-07-08 10:50:07 +08:00
</view>
</template>
<script>
2024-07-22 14:13:19 +08:00
import {
mapState
} from "vuex";
2024-12-10 14:14:28 +08:00
let innerAudioContext = null;
2024-07-08 10:50:07 +08:00
export default {
data() {
return {
2024-07-22 14:13:19 +08:00
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,
2025-04-26 13:35:30 +08:00
isStart: false,
language: "",
2024-07-22 14:13:19 +08:00
}
},
computed: {
...mapState(["isConnected", "isBluetoothTyle"]),
},
onLoad(options) {
let that = this
2025-04-26 13:35:30 +08:00
that.language = uni.getStorageSync('language')
// 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()
// that.$Bluetooth.onBLEConnectionStateChange()
// uni.onBluetoothAdapterStateChange(function(res) {
// that.$store.commit("changeBluetooth", res.available);
// })
2024-07-22 14:13:19 +08:00
},
2024-10-11 10:04:19 +08:00
onUnload: function() {
let that = this
2025-04-26 13:35:30 +08:00
// if (innerAudioContext) {
// innerAudioContext.destroy(); // 销毁实例
// }
// that.handleEnd()
// console.log("PCT01返回onUnload")
2024-10-11 10:04:19 +08:00
},
2024-07-22 14:13:19 +08:00
watch: {
isConnected: function() {
let that = this
2025-04-26 13:35:30 +08:00
// if (!that.isConnected) {
// uni.showModal({
// title: that.$t("tips.linkBluetoothFail"),
// content: that.$t("skip.deviceDisconnection"),
// showCancel: false,
// confirmText: that.$t('tips.btnConfirm'),
// success: function(res) {
// if (res.confirm) {
// that.handleTarget()
// }
// }
// })
// console.log("蓝牙是否连接", that.isConnected)
// }
2024-07-22 14:13:19 +08:00
},
isBluetoothTyle: function() {
let that = this
2025-04-26 13:35:30 +08:00
// if (!that.isBluetoothTyle) {
// console.log("蓝牙是否打开", that.isBluetoothTyle)
// }
2024-07-22 14:13:19 +08:00
},
// 开始跳绳
isStart: function() {
let that = this
2025-04-26 13:35:30 +08:00
// if (that.isStart) {
// that.handleAudio()
// }
},
2024-07-22 14:13:19 +08:00
// 切换模式
isToggle: function() {
let that = this
2025-04-26 13:35:30 +08:00
// if (that.isToggle) {
// uni.showModal({
// title: that.$t("tips.msgTitle"),
// content: that.$t("skip.ToggleTrainingsTips"),
// showCancel: false,
// confirmText: that.$t('tips.btnConfirm'),
// success: function(res) {
// if (res.confirm) {
// setTimeout(function() {
// that.handleStart('结束')
// }, 400)
// setTimeout(function() {
// that.handleTarget()
// }, 600)
// }
// }
// })
// }
2024-07-22 14:13:19 +08:00
},
// 模式被结束
isEnd: function() {
let that = this
2025-04-26 13:35:30 +08:00
// if (that.isEnd) {
// setTimeout(function() {
// that.handleStart('停止')
// }, 200)
// setTimeout(function() {
// that.handleGetMeasure()
// }, 400)
// }
2024-07-25 16:55:39 +08:00
},
//
weight: function() {
2024-07-25 16:55:39 +08:00
let that = this
2025-04-26 13:35:30 +08:00
// 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)
// }
// }
},
2024-07-08 10:50:07 +08:00
},
methods: {
handleAudioStart() {
let that = this
innerAudioContext.autoplay = true;
innerAudioContext.loop = false;
2024-12-14 09:42:21 +08:00
innerAudioContext.src = '/pageTwo/static/Start.mp3';
innerAudioContext.play()
setTimeout(function() {
innerAudioContext.stop();
that.handleAudio()
}, 5000)
2024-07-25 16:55:39 +08:00
},
2024-12-09 09:57:51 +08:00
handleAudio() {
innerAudioContext.autoplay = true;
innerAudioContext.loop = true;
2024-12-14 09:42:21 +08:00
innerAudioContext.src = '/pageTwo/static/flight.mp3';
2024-12-09 09:57:51 +08:00
innerAudioContext.play()
},
2024-07-22 14:13:19 +08:00
// 接收蓝牙数据
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({
2025-04-26 13:35:30 +08:00
title: that.$t("tips.msgTitle"),
content: that.$t("skip.NOComplete"),
cancelText: that.$t('tips.btnBack'),
confirmText: that.$t('tips.btnContinue'),
2024-07-22 14:13:19 +08:00
success: function(res) {
if (res.cancel) {
that.isStart = false
2024-08-16 14:37:37 +08:00
innerAudioContext.stop();
2024-10-11 17:23:56 +08:00
uni.navigateBack({ //返回
delta: 1
})
2024-07-22 14:13:19 +08:00
}
},
})
} 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) {
2024-07-25 16:55:39 +08:00
console.log("1", that.weight, that.Ycount)
2024-07-22 14:13:19 +08:00
that.weight = that.Ycount
2024-07-25 16:55:39 +08:00
} else if (that.info.active == 3 && that.weight != 0 && that.Ycount != 0) {
console.log("2", that.weight, that.Ycount)
2024-07-22 14:13:19 +08:00
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
}
2024-07-25 16:55:39 +08:00
console.log("111111保存", that.weight, that.Ycount, that.time_m, that.time_s)
2024-07-22 14:13:19 +08:00
that.$model.getskipResult({
aud_id: uni.getStorageSync('userid'),
kcal: Math.floor(that.kcal),
num: that.weight,
2024-07-25 16:55:39 +08:00
time_m: Number(that.time_m),
2024-07-22 14:13:19 +08:00
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()
2024-07-22 14:13:19 +08:00
if (res.code == 0) {
that.bpm = that.weight / (that.time / 60)
that.iswrapper = true
2024-10-11 17:23:56 +08:00
that.info.isSuccessful = true
2024-07-25 16:55:39 +08:00
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
})
} else {
2024-07-22 14:13:19 +08:00
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();
2024-07-22 14:13:19 +08:00
uni.navigateBack({ //返回
delta: 1
})
},
//
handleEnd() {
let that = this
that.handleStart('停止')
setTimeout(function() {
that.handleStart('结束')
}, 400)
setTimeout(function() {
2024-10-11 17:23:56 +08:00
uni.$emit('updateData', JSON.stringify(that.info))
2024-07-22 14:13:19 +08:00
}, 600)
}
2024-07-08 10:50:07 +08:00
}
}
</script>
2024-07-22 14:13:19 +08:00
<style lang="scss" scoped>
@import "./scss/PCT01.scss";
2024-07-22 14:13:19 +08:00
</style>