examTeamApp/pageTwo/devices/PCT01.vue

493 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="content skipping">
<!--自由训练 -->
<view class="title">
{{info.active==1?$t("skip.jumpFree"):info.active==2?$t("skip.Countdown"):$t("skip.backwardCount")}}</view>
<view class="skiptop">
<view class="item">
<view class="item-ite">
{{info.active==1?$t("skip.jumpFreeDegree"):info.active==2?$t("skip.jumpFreeNumber"):$t("skip.jumpTargetDegree")}}<text>{{weight}}</text>
</view>
<view class="item-ite">
{{info.active==2?$t("skip.jumpTargetTime"):$t("skip.MinuteSecond")}}<text>{{time_m?time_m:'00'}}:{{time_s?time_s:'00'}}</text>
</view>
<view class="item-ite">{{$t("skip.Consumed")}}/kcal<text>{{Math.floor(kcal)}}</text></view>
</view>
</view>
<view class="image">
<image src="/pageTwo/static/t01.gif"></image>
</view>
<view class="end" @longpress="onlongpress">{{$t("skip.LongpressEnd")}}</view>
<!-- 报告 -->
<view class="wrapper" v-if="iswrapper">
<view class="bg">
<view class="edit">
<view class="editem">
<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>
</view>
<view class="center" :class="[language== 'zh-Hans'?'':'center2']">
<view class="left">
<image src="/pageTwo/static/duan.png"></image>
<view class="name">
<view>
{{$t("skip.Numberofinterrupts")}}
</view>
<view>
<text class="cyello Blue size20 mr-5">{{Bcount}}</text>{{$t("skip.Times")}}
</view>
</view>
</view>
<!-- -->
<view class="left">
<image src="/pageTwo/static/xu.png"></image>
<view class="name">
<view>
{{$t("skip.LongestConsecutive")}}
</view>
<view>
<text class="cyello Blue size20 mr-5">{{continuous}}</text>{{$t("skip.Number")}}
</view>
</view>
</view>
</view>
<view class="item">
<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>
</view>
<view class="btn" @click="handleTarget">{{$t("skip.complete")}}</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,
language: "",
}
},
computed: {
...mapState(["isConnected", "isBluetoothTyle"]),
},
onLoad(options) {
let that = this
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);
// })
},
onUnload: function() {
let that = this
// if (innerAudioContext) {
// innerAudioContext.destroy(); // 销毁实例
// }
// that.handleEnd()
// console.log("PCT01返回onUnload")
},
watch: {
isConnected: function() {
let that = this
// 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)
// }
},
isBluetoothTyle: function() {
let that = this
// if (!that.isBluetoothTyle) {
// console.log("蓝牙是否打开", that.isBluetoothTyle)
// }
},
// 开始跳绳
isStart: function() {
let that = this
// if (that.isStart) {
// that.handleAudio()
// }
},
// 切换模式
isToggle: function() {
let that = this
// 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)
// }
// }
// })
// }
},
// 模式被结束
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: that.$t("tips.msgTitle"),
content: that.$t("skip.NOComplete"),
cancelText: that.$t('tips.btnBack'),
confirmText: that.$t('tips.btnContinue'),
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
}
console.log("111111保存", that.weight, that.Ycount, that.time_m, that.time_s)
that.$model.getskipResult({
aud_id: uni.getStorageSync('userid'),
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
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
})
} 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>