|
@@ -57,7 +57,7 @@
|
|
|
<em>心率带未连接</em>
|
|
<em>心率带未连接</em>
|
|
|
<button>点击连接</button>
|
|
<button>点击连接</button>
|
|
|
</div>
|
|
</div>
|
|
|
- <div class="classInfo" v-if="InClass == 1">
|
|
|
|
|
|
|
+ <div class="classInfo" v-if="InClass == 1 && watchState">
|
|
|
<em><span>课程名称</span>:{{DpName}}</em>
|
|
<em><span>课程名称</span>:{{DpName}}</em>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -137,6 +137,9 @@
|
|
|
export default {
|
|
export default {
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
|
|
+ runMode: '',//'' 为正常模式 mock 为模拟操作模式
|
|
|
|
|
+ isClassTime: 5000,//上课状态检测频率
|
|
|
|
|
+ isAddHeartTime: 1000,//心率上报检测频率
|
|
|
dataLabels: [],
|
|
dataLabels: [],
|
|
|
dataDatasets: [],
|
|
dataDatasets: [],
|
|
|
watchText: '',
|
|
watchText: '',
|
|
@@ -169,24 +172,50 @@
|
|
|
watchs: [],
|
|
watchs: [],
|
|
|
begin: null,
|
|
begin: null,
|
|
|
heartLine: [],
|
|
heartLine: [],
|
|
|
- dataLabels: [],
|
|
|
|
|
InClass: 0,//是否上课
|
|
InClass: 0,//是否上课
|
|
|
DpName: '1234',//课程名称
|
|
DpName: '1234',//课程名称
|
|
|
HrId: '',//心率带
|
|
HrId: '',//心率带
|
|
|
- duId:'',
|
|
|
|
|
- sn:'',
|
|
|
|
|
|
|
+ duId: '',
|
|
|
|
|
+ sn: '',
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|
|
|
this.getBodyInfo();
|
|
this.getBodyInfo();
|
|
|
this.init();
|
|
this.init();
|
|
|
- clearInterval(this.timer);
|
|
|
|
|
- this.timer = setInterval(() => {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 获取上课状态
|
|
|
|
|
+ clearInterval(this.timerisClass);
|
|
|
|
|
+ this.timerisClass = setInterval(() => {
|
|
|
this.isClass();
|
|
this.isClass();
|
|
|
- }, 3000);
|
|
|
|
|
|
|
+ }, this.isClassTime);
|
|
|
|
|
+
|
|
|
|
|
+ // 上报心率信息
|
|
|
|
|
+ clearInterval(this.timerAutoAddAppHeartRate);
|
|
|
|
|
+ this.timerAutoAddAppHeartRate = setInterval(() => {
|
|
|
|
|
+ // 上课中,且已连接心率带
|
|
|
|
|
+ if (this.InClass == 1 && this.watchState) {
|
|
|
|
|
+ // 上课就自动上报
|
|
|
|
|
+ this.AutoAddAppHeartRate();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 不上课就不报
|
|
|
|
|
+ console.log('下课中,不汇报');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // if (this.runMode == 'mock') {
|
|
|
|
|
+ // this.InClass = 1;
|
|
|
|
|
+ // this.duId = 775;
|
|
|
|
|
+ // this.sn = '22735';
|
|
|
|
|
+ // this.HrId = 87;
|
|
|
|
|
+ // this.AutoAddAppHeartRate();
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // // 不上课就不报
|
|
|
|
|
+ // console.log('下课中,不汇报test');
|
|
|
|
|
+ // }
|
|
|
|
|
+ }, this.isAddHeartTime);
|
|
|
},
|
|
},
|
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
|
- clearInterval(this.timer);
|
|
|
|
|
|
|
+ clearInterval(this.timerisClass);
|
|
|
|
|
+ clearInterval(this.timerAutoAddAppHeartRate);
|
|
|
},
|
|
},
|
|
|
watch: {
|
|
watch: {
|
|
|
activeLevel(val) {
|
|
activeLevel(val) {
|
|
@@ -222,36 +251,66 @@
|
|
|
methods: {
|
|
methods: {
|
|
|
init() {
|
|
init() {
|
|
|
let that = this;
|
|
let that = this;
|
|
|
- // 页面初始化操作
|
|
|
|
|
- document.addEventListener('plusready', function (e) {
|
|
|
|
|
- plus.bluetooth.onBLECharacteristicValueChange(function (e) {
|
|
|
|
|
- if (e.characteristicId == '00002A19-0000-1000-8000-00805F9B34FB') {
|
|
|
|
|
- // 获取电量
|
|
|
|
|
- var value = that.buffer2hexPower(e.value);
|
|
|
|
|
- that.battery = value + '%';
|
|
|
|
|
- } else {
|
|
|
|
|
- // 成功获取心跳
|
|
|
|
|
- that.heartRate = parseInt(that.parseHeartRate(e.value).heartRate);
|
|
|
|
|
- that.watchText = '心率带已连接';
|
|
|
|
|
- that.activeState = true;
|
|
|
|
|
- // 运动强度计算
|
|
|
|
|
- that.calcActLevel(that.heartRate);
|
|
|
|
|
- that.openAlert = false;//关闭弹窗
|
|
|
|
|
- that.watchState = true;//关闭连接按钮
|
|
|
|
|
- // 卡路里计算
|
|
|
|
|
- that.calcCalorie(that.heartRate);
|
|
|
|
|
- if (that.heartLine.length > 30) {
|
|
|
|
|
- that.heartLine.unshift();
|
|
|
|
|
- that.dataLabels.unshift();
|
|
|
|
|
|
|
+ if (this.runMode == 'mock') {
|
|
|
|
|
+ that.mockCreateDate();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 页面初始化操作
|
|
|
|
|
+ document.addEventListener('plusready', function (e) {
|
|
|
|
|
+ plus.bluetooth.onBLECharacteristicValueChange(function (e) {
|
|
|
|
|
+ if (e.characteristicId == '00002A19-0000-1000-8000-00805F9B34FB') {
|
|
|
|
|
+ // 获取电量
|
|
|
|
|
+ var value = that.buffer2hexPower(e.value);
|
|
|
|
|
+ that.battery = value + '%';
|
|
|
} else {
|
|
} else {
|
|
|
- that.heartLine.push(that.heartRate);
|
|
|
|
|
- that.dataLabels.push('');
|
|
|
|
|
|
|
+ // 成功获取心跳
|
|
|
|
|
+ that.heartRate = parseInt(that.parseHeartRate(e.value).heartRate);
|
|
|
|
|
+ that.watchText = '心率带已连接';
|
|
|
|
|
+ that.activeState = true;
|
|
|
|
|
+ // 运动强度计算
|
|
|
|
|
+ that.calcActLevel(that.heartRate);
|
|
|
|
|
+ that.openAlert = false;//关闭弹窗
|
|
|
|
|
+ that.watchState = true;//关闭连接按钮并显示当前课程名
|
|
|
|
|
+ // 卡路里计算
|
|
|
|
|
+ that.calcCalorie(that.heartRate);
|
|
|
|
|
+ if (that.heartLine.length > 30) {
|
|
|
|
|
+ that.heartLine.unshift();
|
|
|
|
|
+ that.dataLabels.unshift();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ that.heartLine.push(that.heartRate);
|
|
|
|
|
+ that.dataLabels.push('');
|
|
|
|
|
+ }
|
|
|
|
|
+ that.DrawHeartLine(that.heartLine, that.dataLabels);
|
|
|
|
|
+ // that.AutoAddAppHeartRate();
|
|
|
}
|
|
}
|
|
|
- that.DrawHeartLine(that.heartLine, that.dataLabels);
|
|
|
|
|
- // that.AutoAddAppHeartRate();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ // 生成心率数据
|
|
|
|
|
+ mockCreateDate() {
|
|
|
|
|
+ let that = this;
|
|
|
|
|
+ clearInterval(this.timermockCreateDate);
|
|
|
|
|
+ this.timermockCreateDate = setInterval(() => {
|
|
|
|
|
+ that.battery = '85%';
|
|
|
|
|
+ // 成功获取心跳
|
|
|
|
|
+ that.heartRate = parseInt(Math.random() * 100 + 90);
|
|
|
|
|
+ that.watchText = '心率带已连接';
|
|
|
|
|
+ that.activeState = true;
|
|
|
|
|
+ // 运动强度计算
|
|
|
|
|
+ that.calcActLevel(that.heartRate);
|
|
|
|
|
+ that.openAlert = false;//关闭弹窗
|
|
|
|
|
+ that.watchState = true;//关闭连接按钮
|
|
|
|
|
+ // 卡路里计算
|
|
|
|
|
+ that.calcCalorie(that.heartRate);
|
|
|
|
|
+ if (that.heartLine.length > 30) {
|
|
|
|
|
+ that.heartLine.shift();
|
|
|
|
|
+ that.dataLabels.shift();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ that.heartLine.push(that.heartRate);
|
|
|
|
|
+ that.dataLabels.push('');
|
|
|
|
|
+ }
|
|
|
|
|
+ that.DrawHeartLine(that.heartLine, that.dataLabels);
|
|
|
|
|
+ }, 1000);
|
|
|
},
|
|
},
|
|
|
// 是否正在上课
|
|
// 是否正在上课
|
|
|
isClass() {
|
|
isClass() {
|
|
@@ -264,16 +323,8 @@
|
|
|
let json = res;
|
|
let json = res;
|
|
|
if (json.Code == 0) {
|
|
if (json.Code == 0) {
|
|
|
that.InClass = json.InClass;//0下课,1上课
|
|
that.InClass = json.InClass;//0下课,1上课
|
|
|
- if (that.InClass == 1) {
|
|
|
|
|
- // 记录duid
|
|
|
|
|
- that.duid = json.DuInfo.DuId;
|
|
|
|
|
- // 上课就上报
|
|
|
|
|
- that.AutoAddAppHeartRate();
|
|
|
|
|
- } else {
|
|
|
|
|
- // 不上课就不报
|
|
|
|
|
- console.log('下课中,不汇报');
|
|
|
|
|
- return false
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 记录duid
|
|
|
|
|
+ that.duid = json.DuInfo.DuId;
|
|
|
} else {
|
|
} else {
|
|
|
that.$message.error(json.Memo);
|
|
that.$message.error(json.Memo);
|
|
|
}
|
|
}
|
|
@@ -295,6 +346,10 @@
|
|
|
connectWatch() {
|
|
connectWatch() {
|
|
|
// 打开蓝牙适配器
|
|
// 打开蓝牙适配器
|
|
|
let that = this;
|
|
let that = this;
|
|
|
|
|
+ if(typeof plus == 'undefined'){
|
|
|
|
|
+ that.Toast('当前设备不支持蓝牙心率带', 'error');
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
plus.bluetooth.openBluetoothAdapter({
|
|
plus.bluetooth.openBluetoothAdapter({
|
|
|
success: function (e) {
|
|
success: function (e) {
|
|
|
that.Toast('蓝牙适配器打开成功!', 'success');
|
|
that.Toast('蓝牙适配器打开成功!', 'success');
|
|
@@ -356,7 +411,7 @@
|
|
|
}, 2000);
|
|
}, 2000);
|
|
|
},
|
|
},
|
|
|
fail: function (e) {
|
|
fail: function (e) {
|
|
|
- that.Toast('连接失败! ' + JSON.stringify(e));
|
|
|
|
|
|
|
+ that.Toast('连接失败! 请重新连接' + JSON.stringify(e));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
@@ -366,7 +421,7 @@
|
|
|
plus.bluetooth.getBLEDeviceServices({
|
|
plus.bluetooth.getBLEDeviceServices({
|
|
|
deviceId: w.deviceId,
|
|
deviceId: w.deviceId,
|
|
|
success: function (e) {
|
|
success: function (e) {
|
|
|
- that.Toast('获取服务成功!', 'success');
|
|
|
|
|
|
|
+ that.Toast('获取蓝牙服务成功!', 'success');
|
|
|
// 获取服务的特征值
|
|
// 获取服务的特征值
|
|
|
// console.log('服务的特征值' + w.advertisServiceUUIDs[0]);
|
|
// console.log('服务的特征值' + w.advertisServiceUUIDs[0]);
|
|
|
var HEARTuuid = "0000180D-0000-1000-8000-00805F9B34FB";//HEART RATE
|
|
var HEARTuuid = "0000180D-0000-1000-8000-00805F9B34FB";//HEART RATE
|
|
@@ -380,7 +435,7 @@
|
|
|
},
|
|
},
|
|
|
fail: function (e) {
|
|
fail: function (e) {
|
|
|
console.log('获取服务失败! ' + JSON.stringify(e));
|
|
console.log('获取服务失败! ' + JSON.stringify(e));
|
|
|
- that.Toast('获取服务失败! ' + JSON.stringify(e));
|
|
|
|
|
|
|
+ that.Toast('获取服务失败!请重试 ' + JSON.stringify(e));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
@@ -408,13 +463,13 @@
|
|
|
//that.onValuesChange();
|
|
//that.onValuesChange();
|
|
|
},
|
|
},
|
|
|
fail: function (e) {
|
|
fail: function (e) {
|
|
|
- that.Toast('notifyBLECharacteristicValueChange failed! ' + JSON.stringify(e));
|
|
|
|
|
|
|
+ that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
fail: function (e) {
|
|
fail: function (e) {
|
|
|
console.log('获取特征值失败! ' + JSON.stringify(e));
|
|
console.log('获取特征值失败! ' + JSON.stringify(e));
|
|
|
- that.Toast('获取特征值失败! ' + JSON.stringify(e));
|
|
|
|
|
|
|
+ that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
@@ -445,7 +500,7 @@
|
|
|
},
|
|
},
|
|
|
fail: function (e) {
|
|
fail: function (e) {
|
|
|
console.log('获取特征值失败! ' + JSON.stringify(e));
|
|
console.log('获取特征值失败! ' + JSON.stringify(e));
|
|
|
- that.Toast('获取特征值失败! ' + JSON.stringify(e));
|
|
|
|
|
|
|
+ that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
@@ -459,7 +514,7 @@
|
|
|
console.log("读取电量数据成功" + JSON.stringify(e));
|
|
console.log("读取电量数据成功" + JSON.stringify(e));
|
|
|
},
|
|
},
|
|
|
fail: function (e) {
|
|
fail: function (e) {
|
|
|
- that.Toast('读取电量数据失败! ' + JSON.stringify(e));
|
|
|
|
|
|
|
+ that.Toast('读取电量数据失败!重启APP后再次尝试 ' + JSON.stringify(e));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
@@ -536,19 +591,23 @@
|
|
|
// 活动强度计算公式
|
|
// 活动强度计算公式
|
|
|
calcActLevel(heartRate) {
|
|
calcActLevel(heartRate) {
|
|
|
let sum = 170 - this.age;
|
|
let sum = 170 - this.age;
|
|
|
- this.activeLevel = parseInt((heartRate / sum) * 100);
|
|
|
|
|
|
|
+ let actLevel = parseInt((heartRate / sum) * 100) > 100 ? 100 : parseInt((heartRate / sum) * 100);
|
|
|
|
|
+ this.activeLevel = actLevel;
|
|
|
},
|
|
},
|
|
|
// 持续时间
|
|
// 持续时间
|
|
|
calcHoldTime(curTime) {
|
|
calcHoldTime(curTime) {
|
|
|
- let res = parseInt(curTime.getTime() - this.begin.getTime()) / 1000;
|
|
|
|
|
- return parseInt(res)
|
|
|
|
|
|
|
+ if (this.runMode == 'mock') {
|
|
|
|
|
+ return 1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let res = parseInt(curTime.getTime() - this.begin.getTime()) / 1000;
|
|
|
|
|
+ return parseInt(res)
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
// 计算卡路里
|
|
// 计算卡路里
|
|
|
calcCalorie(heartRate) {
|
|
calcCalorie(heartRate) {
|
|
|
let that = this;
|
|
let that = this;
|
|
|
let calorieNoVo2 = 0;
|
|
let calorieNoVo2 = 0;
|
|
|
let curTime = that.calcHoldTime(new Date());
|
|
let curTime = that.calcHoldTime(new Date());
|
|
|
- console.log(curTime);
|
|
|
|
|
// 男
|
|
// 男
|
|
|
if (that.sex == 1) {
|
|
if (that.sex == 1) {
|
|
|
calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) / 60 * 1;
|
|
calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) / 60 * 1;
|
|
@@ -568,6 +627,7 @@
|
|
|
},
|
|
},
|
|
|
// 计算运动卡路里
|
|
// 计算运动卡路里
|
|
|
calcSportCal(calorieNoVo2) {
|
|
calcSportCal(calorieNoVo2) {
|
|
|
|
|
+ let that = this;
|
|
|
let bmrMSjDaily = (10.00 * this.weight) + (6.25 * this.height) - (5.00 * this.age) + 5.00;
|
|
let bmrMSjDaily = (10.00 * this.weight) + (6.25 * this.height) - (5.00 * this.age) + 5.00;
|
|
|
let BmrMSjRmrcb = parseFloat((bmrMSjDaily * 1.1) / 24);
|
|
let BmrMSjRmrcb = parseFloat((bmrMSjDaily * 1.1) / 24);
|
|
|
let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / 3600 * 1);
|
|
let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / 3600 * 1);
|
|
@@ -605,16 +665,17 @@
|
|
|
hrId: that.HrId,
|
|
hrId: that.HrId,
|
|
|
heartRate: that.heartRate,
|
|
heartRate: that.heartRate,
|
|
|
rcvTime: new Date().getTime(),
|
|
rcvTime: new Date().getTime(),
|
|
|
- calories: that.addCalories,
|
|
|
|
|
- pureCalories: that.addPureCalories,
|
|
|
|
|
|
|
+ calories: parseInt(that.addCalories * 1000), //卡
|
|
|
|
|
+ pureCalories: parseInt(that.addPureCalories * 1000), //卡
|
|
|
};
|
|
};
|
|
|
let postdata = qs.stringify(param);
|
|
let postdata = qs.stringify(param);
|
|
|
AddAppHeartRate(postdata).then(res => {
|
|
AddAppHeartRate(postdata).then(res => {
|
|
|
let json = res;
|
|
let json = res;
|
|
|
if (json.Code == 0) {
|
|
if (json.Code == 0) {
|
|
|
|
|
+ that.InClass = json.InClass;
|
|
|
console.log('心率数据上传成功!');
|
|
console.log('心率数据上传成功!');
|
|
|
} else {
|
|
} else {
|
|
|
- that.Toast(json.Memo);
|
|
|
|
|
|
|
+ that.Toast( '心率数据上传失败' + json.Memo);
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|