ReedawFoodApp/pageTwo/devices/PCT01.vue

380 lines
11 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("jumpFree"):info.active==2?$t("Countdown"):$t("backwardCount")}}</view>
<view class="skiptop">
<view class="item">
<view class="item-ite">{{info.active==1?$t("jumpFreeDegree"):info.active==2?$t("jumpFreeNumber"):$t("jumpTargetDegree")}}<text>{{weight}}</text>
</view>
<view class="item-ite">
{{info.active==2?$t("jumpTargetTime"):$t("MinuteSecond")}}<text>{{time_m?time_m:'00'}}:{{time_s?time_s:'00'}}</text>
</view>
<view class="item-ite">{{$t("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("LongpressEnd")}}</view>
<!-- 报告 -->
<view class="wrapper" v-if="iswrapper">
<view class="bg">
<view class="edit">
<view class="editem">
<view>{{$t("AverageSpeed")}}<text class="cyello Blue size20 mr-5">{{bpm.toFixed(1)}}</text>bpm</view>
<view class="size12 c999 ">(bpm= {{$t("Unit")}})</view>
</view>
<view class="center">
<view class="left">
<image src="/pageTwo/static/duan.png"></image>
<view class="name">
<view>
{{$t("Numberofinterrupts")}}
</view>
<view>
<text class="cyello Blue size20 mr-5">{{Bcount}}</text>{{$t("Times")}}
</view>
</view>
</view>
<!-- -->
<view class="left">
<image src="/pageTwo/static/xu.png"></image>
<view class="name">
<view>
{{$t("LongestConsecutive")}}
</view>
<view>
<text class="cyello Blue size20 mr-5">{{continuous}}</text>{{$t("Number")}}
</view>
</view>
</view>
</view>
<view class="item">
<view class="item-ite"><text>{{weight}}</text>{{$t("trainingsNumber")}}</view>
<view class="item-ite"><text>{{time_m?time_m:'00'}}:{{time_s?time_s:'00'}}</text>{{$t("MinuteSecond")}}</view>
<view class="item-ite"><text>{{Math.floor(kcal)}}</text>{{$t("Consumed")}}/kcal</view>
</view>
<view class="btn" @click="handleTarget">{{$t("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
}
},
computed: {
...mapState(["bleValue", "user", "isBluetoothTyle"]),
},
onLoad(options) {
let that = this
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)
}
},
onUnload: function() {
let that = this
that.handleEnd()
},
watch: {
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
uni.showModal({
title:that.$t("linkBluetoothFail"),
content: that.$t("deviceDisconnection"),
showCancel: false,
confirmText: that.$t("btnConfirm"),
success: function(res) {
if (res.confirm) {
that.handleTarget()
}
}
})
console.log("蓝牙是否连接", that.isBluetoothTyle)
}
},
// 切换模式
isToggle: function() {
let that = this
if (that.isToggle) {
uni.showModal({
title: that.$t("msgTitle"),
content: that.$t("ToggleTrainingsTips"),
showCancel: false,
confirmText: that.$t("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)
}
},
},
methods: {
// 接收蓝牙数据
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("msgTitle"),
content: that.$t("NOComplete"),
confirmText: that.$t("btnContinue"),
cancelText: that.$t("btnBack"),
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.user.aud_id, Math.floor(that.kcal), that.weight, Number(that.time_m), that
.time_s, that.info.active)
that.$model.getSkipResult({
aud_id: that.user.aud_id,
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("getSkipResult", {
aud_id: that.user.aud_id
})
} 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>