mainpage.vue 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. <template>
  2. <div class="content">
  3. <div class="top" :style="{backgroundColor:bgColor}">
  4. <span class="watchState">{{watchText}} {{battery}}</span>
  5. <div class="toprow">
  6. <div class="lt">
  7. <div class="activeLevel">
  8. <div v-if="activeState">
  9. <s>%</s>
  10. <em>{{activeLevel}}</em>
  11. </div>
  12. <div v-else>
  13. <s class="noValue">--</s>
  14. </div>
  15. </div>
  16. <span>{{activeLevelText}}</span>
  17. </div>
  18. <div class="md">
  19. <div class="headContainer">
  20. <img :src="userHead"/>
  21. </div>
  22. <span class="username">
  23. <em>{{username}}</em>
  24. <img src="../static/images/main/male.png" height="60" width="60" v-if="sex == 1"/>
  25. <img src="../static/images/main/female.png" height="60" width="60" v-if="sex == 2"/>
  26. </span>
  27. </div>
  28. <div class="rt">
  29. <div class="heartJump">
  30. <div v-if="activeState">
  31. <img src="../static/images/main/heart.png" height="74" width="86"/>
  32. <em :class="[
  33. {'normalJump':activeLevel > 30 && activeLevel <= 90},
  34. {'fastJump':activeLevel > 90},
  35. {'slowJump':activeLevel < 30},
  36. ]">{{heartRate}}</em>
  37. </div>
  38. <div v-else>
  39. <s class="noValue">--</s>
  40. </div>
  41. </div>
  42. <span @click="showConsole()">瞬时心率</span>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="info">
  47. <ul>
  48. <li><em>{{height}}</em><span>身高cm</span></li>
  49. <li><em>{{age}}</em><span>年龄</span></li>
  50. <li><em>{{weight}}</em><span>体重kg</span></li>
  51. <li><em>{{peaceHeart}}</em><span>静息心率</span></li>
  52. </ul>
  53. </div>
  54. <div class="row">
  55. <div class="rowCenter" v-if="!watchState" @click="connectWatch">
  56. <img src="../static/images/main/chain.png"/>
  57. <em>心率带未连接</em>
  58. <button>点击连接</button>
  59. </div>
  60. <div class="classInfo" v-if="InClass == 1 && watchState">
  61. <em><span>课程名称:</span>{{DpName}}</em>
  62. </div>
  63. </div>
  64. <div class="middle">
  65. <ul>
  66. <li>
  67. <div class="center">
  68. <em>{{cal |parseToInt}}</em>
  69. <img src="../static/images/main/normal.png"/>
  70. <span>卡路里</span>
  71. </div>
  72. </li>
  73. <li>
  74. <div class="center">
  75. <em>{{sportCal |parseToInt}}</em>
  76. <img src="../static/images/main/redfire.png"/>
  77. <span>运动卡路里</span>
  78. </div>
  79. </li>
  80. <li>
  81. <div class="center">
  82. <em>{{ck |parseToFix2}}</em>
  83. <img src="../static/images/main/ck.png" class="ck"/>
  84. <span>CK</span>
  85. </div>
  86. </li>
  87. </ul>
  88. </div>
  89. <div class="bottom">
  90. <h5>心率趋势图</h5>
  91. <span>最大心率 : {{heartMax}} 平均心率 : {{heartAverage}}</span>
  92. <Line-example
  93. :width="screenWidth"
  94. :height="screenHeight"
  95. :dataLabels="dataLabels"
  96. :datadatasets="dataDatasets"
  97. />
  98. <em v-if="activeState" :class="[
  99. {'normalJump':activeLevel > 30 && activeLevel <= 90},
  100. {'fastJump':activeLevel > 90},
  101. {'slowJump':activeLevel < 30},
  102. ]"
  103. :style="{bottom:parseInt(screenHeight - 30) +'px'}"
  104. >{{heartRate}}</em>
  105. </div>
  106. <mu-dialog title="" width="600" max-width="80%" :esc-press-close="true"
  107. :overlay-close="true" :open.sync="openAlert">
  108. <p v-if="!watchListState">
  109. 没有任何设备
  110. </p>
  111. <div class="watchList" v-else>
  112. <p>请选择设备</p>
  113. <ul>
  114. <li v-for="w in watchs" @click="choiceWatch(w)">{{w.localName}} <em>信号:{{w.RSSI |parseLevel}}</em>
  115. </li>
  116. </ul>
  117. </div>
  118. <br>
  119. <mu-button slot="actions" flat color="primary" @click="closeAlertDialog" v-if="watchListState">取消
  120. </mu-button>
  121. <mu-button slot="actions" flat color="primary" @click="searchWatch" v-else>搜索</mu-button>
  122. </mu-dialog>
  123. </div>
  124. </template>
  125. <script>
  126. import LineExample from '../components/LineExample'
  127. import {
  128. UserSelfQuery,
  129. GetDuInfoAndUserInfoByUserMd5,
  130. HrSensorsUpdate,
  131. AddAppHeartRate,
  132. } from '../api/getApiRes.js'
  133. let qs = require('qs');
  134. export default {
  135. data() {
  136. return {
  137. runMode: '',//'' 为正常模式 mock 为模拟操作模式
  138. isClassTime: 5000,//上课状态检测频率
  139. isAddHeartTime: 1000,//心率上报检测频率
  140. dataLabels: [],
  141. dataDatasets: [],
  142. watchText: '',
  143. battery: '',
  144. userHead: 'http://xhead.beswell.com/flyhead.png',
  145. watchState: false,//false
  146. bgColor: '#028FE1',
  147. activeLevel: 0,
  148. activeLevelText: '激活放松',
  149. heartRate: 0,
  150. activeState: false,//false
  151. openAlert: false,//false
  152. alertState: false,//false
  153. watchListState: false,//false
  154. username: 'XXX',
  155. sex: 1,
  156. height: 148,
  157. age: 8,
  158. weight: 38,
  159. peaceHeart: 70,
  160. heartMax: 0,
  161. heartAverage: 0,
  162. cal: 0,
  163. sportCal: 0,
  164. ck: 0,
  165. addCalories: 0,//增量卡路里
  166. addPureCalories: 0,//增量运动卡路里
  167. screenWidth: parseInt(document.body.clientWidth - 10),
  168. screenHeight: parseInt(document.documentElement.clientHeight / 3),
  169. watchs: [],
  170. begin: null,
  171. heartLine: [],
  172. InClass: 0,//是否上课
  173. DpName: '1234',//课程名称
  174. HrId: '',//心率带
  175. duId: 0,
  176. sn: '',
  177. }
  178. },
  179. mounted() {
  180. this.getBodyInfo();
  181. this.init();
  182. // 获取上课状态
  183. clearInterval(this.timerisClass);
  184. this.timerisClass = setInterval(() => {
  185. this.isClass();
  186. }, this.isClassTime);
  187. // 上报心率信息
  188. clearInterval(this.timerAutoAddAppHeartRate);
  189. this.timerAutoAddAppHeartRate = setInterval(() => {
  190. // 上课中,且已连接心率带
  191. if (this.InClass == 1 && this.watchState && this.runMode != 'mock') {
  192. // 上课就自动上报
  193. this.AutoAddAppHeartRate();
  194. } else {
  195. // 不上课就不报
  196. console.log('下课中,不汇报');
  197. }
  198. //
  199. // if (this.runMode == 'mock') {
  200. // this.InClass = 1;
  201. // this.duId = 775;
  202. // this.sn = '22735';
  203. // this.HrId = 87;
  204. // this.AutoAddAppHeartRate();
  205. // } else {
  206. // // 不上课就不报
  207. // console.log('下课中,不汇报test');
  208. // }
  209. }, this.isAddHeartTime);
  210. },
  211. beforeDestroy() {
  212. clearInterval(this.timerisClass);
  213. clearInterval(this.timerAutoAddAppHeartRate);
  214. },
  215. watch: {
  216. activeLevel(val) {
  217. let that = this;
  218. switch (true) {
  219. case parseInt(val) < 39 :
  220. that.bgColor = '#028FE1';
  221. that.activeLevelText = '激活放松';
  222. break;
  223. case parseInt(val) < 54 && parseInt(val) >= 39 :
  224. that.bgColor = '#6D29FA';
  225. that.activeLevelText = '动态热身';
  226. break;
  227. case parseInt(val) < 69 && parseInt(val) >= 54 :
  228. that.bgColor = '#0AB105';
  229. that.activeLevelText = '脂肪燃烧';
  230. break;
  231. case parseInt(val) < 79 && parseInt(val) >= 69 :
  232. that.bgColor = '#B9CB01';
  233. that.activeLevelText = '糖分消耗';
  234. break;
  235. case parseInt(val) < 89 && parseInt(val) >= 79 :
  236. that.bgColor = '#EA8813';
  237. that.activeLevelText = '心肺训练';
  238. break;
  239. case parseInt(val) >= 90 :
  240. that.bgColor = '#D11122';
  241. that.activeLevelText = '峰值锻炼';
  242. break;
  243. }
  244. },
  245. },
  246. methods: {
  247. init() {
  248. let that = this;
  249. if (this.runMode == 'mock') {
  250. that.mockCreateDate();
  251. } else {
  252. // 页面初始化操作
  253. document.addEventListener('plusready', function (e) {
  254. plus.bluetooth.onBLECharacteristicValueChange(function (e) {
  255. if (e.characteristicId == '00002A19-0000-1000-8000-00805F9B34FB') {
  256. // 获取电量
  257. var value = that.buffer2hexPower(e.value);
  258. that.battery = value + '%';
  259. } else {
  260. // 成功获取心跳
  261. that.heartRate = parseInt(that.parseHeartRate(e.value).heartRate);
  262. that.watchText = '心率带已连接';
  263. that.activeState = true;
  264. // 运动强度计算
  265. that.calcActLevel(that.heartRate);
  266. that.openAlert = false;//关闭弹窗
  267. that.watchState = true;//关闭连接按钮并显示当前课程名
  268. // 卡路里计算
  269. that.calcCalorie(that.heartRate);
  270. if (that.heartLine.length > 30) {
  271. that.heartLine = that.heartLine.concat();
  272. that.dataLabels = that.dataLabels.concat();
  273. } else {
  274. that.heartLine.push(that.heartRate);
  275. that.dataLabels.push('');
  276. }
  277. that.DrawHeartLine(that.heartLine, that.dataLabels);
  278. }
  279. });
  280. });
  281. }
  282. },
  283. showConsole() {
  284. let vconDom = document.getElementById('__vconsole');
  285. this.toggleClass(vconDom, 'show')
  286. },
  287. toggleClass(obj, cls) {
  288. if (this.hasClass(obj, cls)) {
  289. this.removeClass(obj, cls);
  290. } else {
  291. this.addClass(obj, cls);
  292. }
  293. },
  294. hasClass(obj, cls) {
  295. return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
  296. },
  297. addClass(obj, cls) {
  298. if (!this.hasClass(obj, cls)) obj.className += " " + cls;
  299. },
  300. removeClass(obj, cls) {
  301. if (this.hasClass(obj, cls)) {
  302. var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
  303. obj.className = obj.className.replace(reg, ' ');
  304. }
  305. },
  306. // 生成心率数据
  307. mockCreateDate() {
  308. let that = this;
  309. clearInterval(this.timermockCreateDate);
  310. this.timermockCreateDate = setInterval(() => {
  311. that.battery = '85%';
  312. // 成功获取心跳
  313. that.heartRate = parseInt(Math.random() * 100 + 90);
  314. that.watchText = '心率带已连接';
  315. that.activeState = true;
  316. // 运动强度计算
  317. that.calcActLevel(that.heartRate);
  318. that.openAlert = false;//关闭弹窗
  319. that.watchState = true;//关闭连接按钮
  320. // 卡路里计算
  321. that.calcCalorie(that.heartRate);
  322. if (that.heartLine.length > 30) {
  323. that.heartLine.shift();
  324. that.dataLabels.shift();
  325. } else {
  326. that.heartLine.push(that.heartRate);
  327. that.dataLabels.push('');
  328. }
  329. that.DrawHeartLine(that.heartLine, that.dataLabels);
  330. }, 1000);
  331. },
  332. // 是否正在上课
  333. isClass() {
  334. let that = this;
  335. let param = {
  336. token: localStorage.token,
  337. };
  338. let postdata = qs.stringify(param);
  339. GetDuInfoAndUserInfoByUserMd5(postdata).then(res => {
  340. let json = res;
  341. if (json.Code == 0) {
  342. that.InClass = json.InClass;//0下课,1上课
  343. // 记录duid
  344. that.duId = parseInt(json.DuInfo.DuId);
  345. that.DpName = json.DuInfo.DpName;
  346. console.log('that.duId:' + that.duId);
  347. } else {
  348. that.$message.error(json.Memo);
  349. }
  350. })
  351. },
  352. buffer2hexPower(value) {
  353. var t = '';
  354. if (value) {
  355. var v = new Uint8Array(value);
  356. for (var i in v) {
  357. // t += '0x' + v[i].toString(16) + ' ';
  358. t += v[i].toString(10) + ' ';
  359. }
  360. } else {
  361. t = '无效值';
  362. }
  363. return t;
  364. },
  365. connectWatch() {
  366. // 打开蓝牙适配器
  367. let that = this;
  368. if (typeof plus == 'undefined') {
  369. that.Toast('当前设备不支持蓝牙心率带', 'error');
  370. return false
  371. }
  372. plus.bluetooth.openBluetoothAdapter({
  373. success: function (e) {
  374. that.Toast('蓝牙适配器打开成功!', 'success');
  375. that.openAlert = true;
  376. that.searchWatch();
  377. return e
  378. },
  379. fail: function (e) {
  380. that.Toast('打开失败! 请确认蓝牙开关已开启', 'error');
  381. }
  382. });
  383. },
  384. closeAlertDialog() {
  385. this.openAlert = false;
  386. },
  387. // 监听搜索到新设备
  388. searchWatch() {
  389. let that = this;
  390. that.watchs = [];
  391. plus.bluetooth.startBluetoothDevicesDiscovery({
  392. // services: ['heart_rate'],//ios不支持
  393. success: function (e) {
  394. that.Toast('开始搜索成功!', 'success');
  395. plus.bluetooth.onBluetoothDeviceFound(function (e) {
  396. let devices = e.devices;
  397. for (let i in devices) {
  398. let device = devices[i];
  399. // localName CL831
  400. if (device.localName.indexOf('CL831') != -1) {
  401. console.log(JSON.stringify(device));
  402. that.watchs.push(device)
  403. }
  404. }
  405. that.watchListState = true;
  406. });
  407. },
  408. fail: function (e) {
  409. that.Toast('开始搜索失败! ' + JSON.stringify(e));
  410. }
  411. });
  412. },
  413. choiceWatch(w) {
  414. let that = this;
  415. that.Toast('连接心率带' + w.localName + '中...', 'success');
  416. // 建立连接
  417. plus.bluetooth.createBLEConnection({
  418. deviceId: w.deviceId,
  419. success: function (e) {
  420. // 记录心率带sn
  421. that.sn = w.localName;
  422. that.AddHrSensorsUpdate(w.localName);
  423. that.Toast('连接成功!', 'success');
  424. // 渲染完毕再执行这个,所以才能没有延时的更改
  425. // 需要一个回调等待5S
  426. clearTimeout(that.timer); //清除延迟执行
  427. that.timer = setTimeout(() => { //设置延迟执行
  428. // 获取服务
  429. that.getServices(w);
  430. }, 2000);
  431. },
  432. fail: function (e) {
  433. that.Toast('连接失败! 请重新连接' + JSON.stringify(e));
  434. }
  435. });
  436. },
  437. getServices(w) {
  438. let that = this;
  439. that.Toast('获取蓝牙设备服务:', 'success');
  440. plus.bluetooth.getBLEDeviceServices({
  441. deviceId: w.deviceId,
  442. success: function (e) {
  443. that.Toast('获取蓝牙服务成功!', 'success');
  444. // 获取服务的特征值
  445. // console.log('服务的特征值' + w.advertisServiceUUIDs[0]);
  446. var HEARTuuid = "0000180D-0000-1000-8000-00805F9B34FB";//HEART RATE
  447. var Batteryuuid = "0000180F-0000-1000-8000-00805F9B34FB";//Battery
  448. that.getBatteryCharacteristics(w.deviceId, Batteryuuid);
  449. clearTimeout(that.timer); //清除延迟执行
  450. that.timer = setTimeout(() => { //设置延迟执行
  451. // 获取心跳服务
  452. that.getCharacteristics(w.deviceId, HEARTuuid);
  453. }, 3000);
  454. },
  455. fail: function (e) {
  456. console.log('获取服务失败! ' + JSON.stringify(e));
  457. that.Toast('获取服务失败!请重试 ' + JSON.stringify(e));
  458. }
  459. });
  460. },
  461. // 获取服务的特征值
  462. getCharacteristics(deviceId, serviceId) {
  463. let that = this;
  464. let chaaracterUuid = '00002A37-0000-1000-8000-00805F9B34FB';
  465. let characteristicId = null;
  466. that.begin = new Date();
  467. plus.bluetooth.getBLEDeviceCharacteristics({
  468. deviceId: deviceId,
  469. serviceId: serviceId,
  470. success: function (e) {
  471. let characteristics = e.characteristics;
  472. that.Toast('获取特征值成功! ' + characteristics.length, 'success');
  473. console.log('获取特征值成功! ' + characteristics.length, 'success');
  474. console.log('特征值列表: ' + JSON.stringify(characteristics));
  475. plus.bluetooth.notifyBLECharacteristicValueChange({ //监听数据变化
  476. deviceId: deviceId,
  477. serviceId: serviceId,
  478. characteristicId: chaaracterUuid,
  479. success: function (e) {
  480. console.log('---> 获取心跳服务' + JSON.stringify(e));
  481. console.log('---> notifyBLECharacteristicValueChange ' + chaaracterUuid + ' success.');
  482. //that.onValuesChange();
  483. },
  484. fail: function (e) {
  485. that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
  486. }
  487. });
  488. },
  489. fail: function (e) {
  490. console.log('获取特征值失败! ' + JSON.stringify(e));
  491. that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
  492. }
  493. })
  494. },
  495. // 获取服务的特征值
  496. getBatteryCharacteristics(deviceId, serviceId) {
  497. let that = this;
  498. let chaaracterUuid = '00002A19-0000-1000-8000-00805F9B34FB';
  499. let characteristicId = null;
  500. that.begin = new Date();
  501. that.readValue(deviceId, serviceId, chaaracterUuid);
  502. plus.bluetooth.getBLEDeviceCharacteristics({
  503. deviceId: deviceId,
  504. serviceId: serviceId,
  505. success: function (e) {
  506. var characteristics = e.characteristics;
  507. that.Toast('获取心率带服务成功! ' + characteristics.length, 'success');
  508. plus.bluetooth.notifyBLECharacteristicValueChange({ //监听数据变化
  509. deviceId: deviceId,
  510. serviceId: serviceId,
  511. characteristicId: chaaracterUuid,
  512. success: function (e) {
  513. console.log('notifyBLECharacteristicValueChange' + JSON.stringify(e));
  514. },
  515. fail: function (e) {
  516. that.Toast('notifyBLECharacteristicValueChange失败! ' + JSON.stringify(e));
  517. }
  518. });
  519. },
  520. fail: function (e) {
  521. console.log('获取特征值失败! ' + JSON.stringify(e));
  522. that.Toast('获取特征值失败!重启APP后再次尝试 ' + JSON.stringify(e));
  523. }
  524. })
  525. },
  526. readValue(deviceId, serviceId, characteristicId) {
  527. let that = this;
  528. plus.bluetooth.readBLECharacteristicValue({
  529. deviceId: deviceId,
  530. serviceId: serviceId,
  531. characteristicId: characteristicId,
  532. success: function (e) {
  533. console.log("读取电量数据成功" + JSON.stringify(e));
  534. },
  535. fail: function (e) {
  536. that.Toast('读取电量数据失败!重启APP后再次尝试 ' + JSON.stringify(e));
  537. }
  538. });
  539. },
  540. // 获取基础身体数据
  541. getBodyInfo() {
  542. let that = this;
  543. let param = {
  544. token: localStorage.token,
  545. };
  546. let postdata = qs.stringify(param);
  547. UserSelfQuery(postdata).then(res => {
  548. let json = res;
  549. if (json.Code == 0) {
  550. that.username = json.Rs.UserName;
  551. that.sex = json.Rs.Sex;
  552. that.height = json.Rs.Height;
  553. // Birthday
  554. let age = parseInt((new Date().getTime() - new Date(json.Rs.Birthday).getTime()) / (365 * 24 * 60 * 60 * 1000));
  555. that.age = age;
  556. that.weight = parseInt(json.Rs.Weight) / 10;
  557. that.peaceHeart = json.Rs.StaticHr;
  558. // 有无默认头像
  559. if (json.Rs.Head) {
  560. that.userHead = json.Rs.Head;
  561. } else {
  562. that.userHead = 'http://xhead.beswell.com/flyhead.png';
  563. }
  564. } else {
  565. if (json.Code == 9999999999) {
  566. that.Toast('登陆已失效,请重新登陆');
  567. localStorage.token = '';
  568. this.$router.push({path: '/login'});
  569. } else {
  570. that.Toast(json.Memo, 'error');
  571. }
  572. }
  573. })
  574. }
  575. ,
  576. parseHeartRate(data) {
  577. var data = new DataView(data);
  578. const flags = data.getUint8(0);
  579. const rate16Bits = flags & 0x1;
  580. const result = {};
  581. let index = 1;
  582. if (rate16Bits) {
  583. result.heartRate = data.getUint16(index, /*littleEndian=*/ true);
  584. index += 2;
  585. } else {
  586. result.heartRate = data.getUint8(index);
  587. index += 1;
  588. }
  589. const contactDetected = flags & 0x2;
  590. const contactSensorPresent = flags & 0x4;
  591. if (contactSensorPresent) {
  592. result.contactDetected = !!contactDetected;
  593. }
  594. const energyPresent = flags & 0x8;
  595. if (energyPresent) {
  596. result.energyExpended = data.getUint16(index, /*littleEndian=*/ true);
  597. index += 2;
  598. }
  599. const rrIntervalPresent = flags & 0x10;
  600. if (rrIntervalPresent) {
  601. const rrIntervals = [];
  602. for (; index + 1 < data.byteLength; index += 2) {
  603. rrIntervals.push(data.getUint16(index, /*littleEndian=*/ true));
  604. }
  605. result.rrIntervals = rrIntervals;
  606. }
  607. return result;
  608. }
  609. ,
  610. // 活动强度计算公式
  611. calcActLevel(heartRate) {
  612. let sum = 170 - this.age;
  613. let actLevel = parseInt((heartRate / sum) * 100) > 100 ? 100 : parseInt((heartRate / sum) * 100);
  614. this.activeLevel = actLevel;
  615. },
  616. // 持续时间
  617. calcHoldTime(curTime) {
  618. if (this.runMode == 'mock') {
  619. return 1
  620. } else {
  621. let res = parseInt(curTime.getTime() - this.begin.getTime()) / 1000;
  622. return parseInt(res)
  623. }
  624. },
  625. // 计算卡路里
  626. calcCalorie(heartRate) {
  627. let that = this;
  628. let calorieNoVo2 = 0;
  629. let curTime = that.calcHoldTime(new Date());
  630. // 男
  631. if (that.sex == 1) {
  632. calorieNoVo2 = ((-55.0969 + (0.6309 * heartRate) + (0.1988 * that.weight) + (0.2017 * that.age)) / 4.184) / 60 * 1;
  633. } else {
  634. calorieNoVo2 = ((-20.4022 + (0.4472 * heartRate) + (0.1263 * that.weight) + (0.074 * that.age)) / 4.184) / 60 * 1;
  635. }
  636. // 记录增量卡路里
  637. that.addCalories = calorieNoVo2;
  638. that.cal = that.cal + calorieNoVo2;
  639. // 计算CK
  640. that.calcCk(that.cal);
  641. that.calcSportCal(calorieNoVo2, curTime)
  642. },
  643. // 计算CK
  644. calcCk(cal) {
  645. this.ck = parseFloat(cal / this.weight).toFixed(2);
  646. },
  647. // 计算运动卡路里
  648. calcSportCal(calorieNoVo2) {
  649. let that = this;
  650. let bmrMSjDaily = (10.00 * this.weight) + (6.25 * this.height) - (5.00 * this.age) + 5.00;
  651. let BmrMSjRmrcb = parseFloat((bmrMSjDaily * 1.1) / 24);
  652. let calorieNoVo2Pure = (calorieNoVo2 - BmrMSjRmrcb / 3600 * 1);
  653. // 记录增量运动卡路里
  654. that.addPureCalories = calorieNoVo2Pure;
  655. this.sportCal = this.sportCal + calorieNoVo2Pure;
  656. },
  657. // 绘制心电图
  658. DrawHeartLine(heartLine, dataLabels) {
  659. this.dataLabels = dataLabels;
  660. this.dataDatasets = heartLine;
  661. this.calcMaxHr(heartLine);
  662. this.calcAveHr(heartLine);
  663. },
  664. // 最大心率
  665. calcMaxHr(heartLine) {
  666. this.heartMax = Math.max(...heartLine);
  667. },
  668. // 平均心率
  669. calcAveHr(heartLine) {
  670. var sum = 0;
  671. for (var i = 0; i < heartLine.length; i++) {
  672. sum += heartLine[i];
  673. }
  674. this.heartAverage = parseInt(sum / heartLine.length);
  675. },
  676. // 上报信息
  677. AutoAddAppHeartRate() {
  678. let that = this;
  679. console.log('duId:' + that.duId);
  680. let param = {
  681. token: localStorage.token,
  682. duId: that.duId,
  683. sn: that.sn,
  684. hrId: that.HrId,
  685. heartRate: that.heartRate,
  686. rcvTime: new Date().getTime(),
  687. calories: parseInt(that.addCalories * 1000000), //卡
  688. pureCalories: parseInt(that.addPureCalories * 1000000), //卡
  689. };
  690. let postdata = qs.stringify(param);
  691. AddAppHeartRate(postdata).then(res => {
  692. let json = res;
  693. if (json.Code == 0) {
  694. that.InClass = json.InClass;
  695. console.log('心率数据上传成功!');
  696. } else {
  697. // that.Toast( '心率数据上传失败' + json.Memo);
  698. console.log('心率数据上传失败' + json.Memo);
  699. }
  700. })
  701. },
  702. AddHrSensorsUpdate(sn) {
  703. let that = this;
  704. let param = {
  705. token: localStorage.token,
  706. sn: sn,
  707. };
  708. let postdata = qs.stringify(param);
  709. HrSensorsUpdate(postdata).then(res => {
  710. let json = res;
  711. if (json.Code == 0) {
  712. that.HrId = json.HrId;
  713. that.Toast('心率带已连接在线课程', 'success');
  714. } else {
  715. that.HrId = '';
  716. that.Toast(json.Memo);
  717. }
  718. })
  719. },
  720. },
  721. filters: {
  722. parseLevel: function (value) {
  723. if (!value) {
  724. return '无'
  725. } else {
  726. if (value < -90) {
  727. return '强'
  728. } else {
  729. return '弱'
  730. }
  731. }
  732. }
  733. ,
  734. parseToInt: function (val) {
  735. return parseInt(val)
  736. }
  737. ,
  738. parseToFix2: function (val) {
  739. return parseFloat(val).toFixed(2)
  740. }
  741. }
  742. ,
  743. components: {
  744. LineExample
  745. }
  746. }
  747. </script>
  748. <style scoped>
  749. .top {
  750. width: 100%;
  751. overflow: hidden;
  752. display: block;
  753. margin: 0 auto;
  754. padding-top: 10px;
  755. padding-bottom: 10px;
  756. }
  757. .top .watchState {
  758. width: 100%;
  759. overflow: hidden;
  760. display: block;
  761. margin: 0 auto;
  762. height: 20px;
  763. line-height: 20px;
  764. color: #fff;
  765. text-align: center;
  766. margin-top: 20px;
  767. margin-bottom: 10px;
  768. }
  769. .toprow {
  770. width: 100%;
  771. overflow: hidden;
  772. display: block;
  773. margin: 0 auto;
  774. }
  775. .toprow .lt {
  776. width: 30%;
  777. float: left;
  778. overflow: hidden;
  779. }
  780. .toprow .md {
  781. width: 40%;
  782. float: left;
  783. overflow: hidden;
  784. }
  785. .toprow .rt {
  786. width: 30%;
  787. float: right;
  788. overflow: hidden;
  789. }
  790. .toprow .lt .activeLevel {
  791. width: 100%;
  792. overflow: hidden;
  793. display: block;
  794. margin: 0 auto;
  795. margin-top: 10px;
  796. color: #fff;
  797. }
  798. .activeLevel div {
  799. width: 86px;
  800. overflow: hidden;
  801. display: block;
  802. margin: 0 auto;
  803. }
  804. .activeLevel s {
  805. float: right;
  806. font-size: 20px;
  807. }
  808. .activeLevel em {
  809. font-size: 40px;
  810. text-align: right;
  811. font-weight: bold;
  812. float: right;
  813. }
  814. .toprow .lt span {
  815. width: 80px;
  816. height: 20px;
  817. overflow: hidden;
  818. display: block;
  819. margin: 0 auto;
  820. color: #fff;
  821. border: 1px solid #fff;
  822. border-radius: 250px;
  823. text-align: center;
  824. line-height: 20px;
  825. font-size: 12px;
  826. }
  827. .toprow .md .headContainer {
  828. width: 70%;
  829. height: 70%;
  830. border: 3px solid rgba(255, 255, 255, 0.71);
  831. border-radius: 250px;
  832. overflow: hidden;
  833. display: block;
  834. margin: 0 auto;
  835. }
  836. .headContainer img {
  837. width: 100%;
  838. height: 100%;
  839. overflow: hidden;
  840. display: block;
  841. margin: 0 auto;
  842. }
  843. .activeLevel .noValue {
  844. width: 100%;
  845. overflow: hidden;
  846. display: block;
  847. margin: 0 auto;
  848. font-weight: bold;
  849. font-size: 40px;
  850. text-align: center;
  851. float: none;
  852. }
  853. .username {
  854. width: 100%;
  855. height: 30px;
  856. overflow: hidden;
  857. display: block;
  858. margin: 0 auto;
  859. font-size: 14px;
  860. color: #fff;
  861. margin-top: 10px;
  862. }
  863. .username em {
  864. width: 100%;
  865. overflow: hidden;
  866. display: block;
  867. margin: 0 auto;
  868. text-align: center;
  869. }
  870. .username img {
  871. position: relative;
  872. bottom: 20px;
  873. float: right;
  874. width: 15px;
  875. height: 15px;
  876. right: 15%;
  877. }
  878. .heartJump {
  879. width: 90%;
  880. overflow: hidden;
  881. float: left;
  882. margin: 0 auto;
  883. margin-top: 10px;
  884. color: #fff;
  885. }
  886. .heartJump div {
  887. width: 86px;
  888. overflow: hidden;
  889. display: block;
  890. margin: 0 auto;
  891. }
  892. .heartJump img {
  893. width: 16px;
  894. height: 14px;
  895. float: right;
  896. }
  897. .heartJump em {
  898. font-size: 40px;
  899. text-align: right;
  900. font-weight: bold;
  901. float: right;
  902. }
  903. .heartJump .noValue {
  904. width: 100%;
  905. overflow: hidden;
  906. display: block;
  907. margin: 0 auto;
  908. font-weight: bold;
  909. font-size: 40px;
  910. text-align: center;
  911. float: none;
  912. }
  913. .toprow .rt span {
  914. width: 80px;
  915. height: 20px;
  916. overflow: hidden;
  917. display: block;
  918. margin: 0 auto;
  919. /*float: left;*/
  920. color: #fff;
  921. border: 1px solid #fff;
  922. border-radius: 250px;
  923. text-align: center;
  924. line-height: 20px;
  925. font-size: 12px;
  926. }
  927. .info {
  928. width: 100%;
  929. overflow: hidden;
  930. display: block;
  931. margin: 0 auto;
  932. }
  933. .info ul {
  934. width: 100%;
  935. overflow: hidden;
  936. display: block;
  937. margin: 0 auto;
  938. margin-top: 10px;
  939. margin-bottom: 10px;
  940. }
  941. .info li {
  942. width: 25%;
  943. border-left: 1px solid #fff;
  944. border-right: 1px solid #fff;
  945. float: left;
  946. text-align: center;
  947. }
  948. .info li:nth-child(2) {
  949. border-color: #E2E2E2;
  950. }
  951. .info li:nth-child(3) {
  952. border-color: #E2E2E2;
  953. border-left: 0;
  954. }
  955. .info li em {
  956. width: 100%;
  957. overflow: hidden;
  958. display: block;
  959. margin: 0 auto;
  960. color: #363636;
  961. font-size: 20px;
  962. text-align: center;
  963. }
  964. .info li span {
  965. width: 100%;
  966. overflow: hidden;
  967. display: block;
  968. margin: 0 auto;
  969. color: #C4C4C4;
  970. font-size: 12px;
  971. text-align: center;
  972. }
  973. .row {
  974. width: 100%;
  975. overflow: hidden;
  976. display: block;
  977. margin: 0 auto;
  978. background: #EFEFEF;
  979. padding-top: 5px;
  980. padding-bottom: 5px;
  981. }
  982. .row .rowCenter {
  983. width: 208px;
  984. overflow: hidden;
  985. display: block;
  986. margin: 0 auto;
  987. line-height: 30px;
  988. }
  989. .rowCenter img {
  990. width: 11px;
  991. height: 11px;
  992. float: left;
  993. margin-top: 10px;
  994. margin-right: 5px;
  995. }
  996. .rowCenter em {
  997. font-size: 14px;
  998. color: #FF4040;
  999. margin-right: 15px;
  1000. }
  1001. .rowCenter button {
  1002. width: 92px;
  1003. height: 27px;
  1004. text-align: center;
  1005. line-height: 27px;
  1006. color: black;
  1007. background: #FFDE93;
  1008. border-radius: 6px;
  1009. border: none;
  1010. outline: none;
  1011. }
  1012. .middle {
  1013. width: 100%;
  1014. overflow: hidden;
  1015. display: block;
  1016. margin: 0 auto;
  1017. border-bottom: 10px solid #EFEFEF;
  1018. }
  1019. .middle ul {
  1020. width: 100%;
  1021. overflow: hidden;
  1022. display: block;
  1023. margin: 0 auto;
  1024. padding-top: 10px;
  1025. padding-bottom: 10px;
  1026. }
  1027. .middle li {
  1028. width: 33%;
  1029. float: left;
  1030. border-left: 1px solid #fff;
  1031. border-right: 1px solid #fff;
  1032. }
  1033. .middle li .center {
  1034. width: 72px;
  1035. overflow: hidden;
  1036. display: block;
  1037. margin: 0 auto;
  1038. }
  1039. .middle li:nth-child(2) {
  1040. border-color: #E2E2E2;
  1041. }
  1042. .middle li img {
  1043. width: 15px;
  1044. float: right;
  1045. margin-top: 4px;
  1046. margin-right: 5px;
  1047. }
  1048. .middle li em {
  1049. float: right;
  1050. text-align: right;
  1051. color: #000;
  1052. font-weight: bold;
  1053. font-size: 22px;
  1054. }
  1055. .middle li span {
  1056. width: 100%;
  1057. overflow: hidden;
  1058. display: block;
  1059. margin: 0 auto;
  1060. text-align: right;
  1061. color: #9A9A9A;
  1062. font-size: 12px;
  1063. }
  1064. .middle .ck {
  1065. width: 19px;
  1066. height: 19px;
  1067. margin-top: 6px;
  1068. }
  1069. .bottom {
  1070. width: 100%;
  1071. overflow: hidden;
  1072. display: block;
  1073. margin: 0 auto;
  1074. }
  1075. .bottom h5 {
  1076. width: 100%;
  1077. overflow: hidden;
  1078. display: block;
  1079. margin: 0 auto;
  1080. color: #363636;
  1081. font-size: 16px;
  1082. text-align: center;
  1083. font-weight: normal;
  1084. margin-top: 14px;
  1085. }
  1086. .bottom span {
  1087. width: 100%;
  1088. overflow: hidden;
  1089. display: block;
  1090. margin: 0 auto;
  1091. text-align: center;
  1092. font-size: 12px;
  1093. color: #9A9A9A;
  1094. }
  1095. .bottom em {
  1096. position: relative;
  1097. bottom: 160px;
  1098. right: 20px;
  1099. float: right;
  1100. color: #FF4040;
  1101. background: #fff;
  1102. }
  1103. .slowJump {
  1104. animation: mymove 3s infinite;
  1105. -webkit-animation: mymove 3s infinite; /*Safari and Chrome*/
  1106. animation-direction: alternate; /*轮流反向播放动画。*/
  1107. animation-timing-function: ease-in-out; /*动画的速度曲线*/
  1108. /* Safari 和 Chrome */
  1109. -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
  1110. -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
  1111. }
  1112. .normalJump {
  1113. animation: mymove 2s infinite;
  1114. -webkit-animation: mymove 2s infinite; /*Safari and Chrome*/
  1115. animation-direction: alternate; /*轮流反向播放动画。*/
  1116. animation-timing-function: ease-in-out; /*动画的速度曲线*/
  1117. /* Safari 和 Chrome */
  1118. -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
  1119. -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
  1120. }
  1121. .fastJump {
  1122. animation: mymove 1s infinite;
  1123. -webkit-animation: mymove 1s infinite; /*Safari and Chrome*/
  1124. animation-direction: alternate; /*轮流反向播放动画。*/
  1125. animation-timing-function: ease-in-out; /*动画的速度曲线*/
  1126. /* Safari 和 Chrome */
  1127. -webkit-animation-direction: alternate; /*轮流反向播放动画。*/
  1128. -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
  1129. }
  1130. @keyframes mymove {
  1131. 0% {
  1132. transform: scale(1); /*开始为原始大小*/
  1133. }
  1134. 25% {
  1135. transform: scale(1.1); /*放大1.1倍*/
  1136. }
  1137. 50% {
  1138. transform: scale(1);
  1139. }
  1140. 75% {
  1141. transform: scale(1.1);
  1142. }
  1143. }
  1144. @-webkit-keyframes mymove /*Safari and Chrome*/
  1145. {
  1146. 0% {
  1147. transform: scale(1); /*开始为原始大小*/
  1148. }
  1149. 25% {
  1150. transform: scale(1.1); /*放大1.1倍*/
  1151. }
  1152. 50% {
  1153. transform: scale(1);
  1154. }
  1155. 75% {
  1156. transform: scale(1.1);
  1157. }
  1158. }
  1159. /deep/ .mu-dialog {
  1160. background-color: rgba(0, 0, 0, 0.85);
  1161. color: #fff;
  1162. border-radius: 20px;
  1163. background-size: 100%;
  1164. background-origin: content-box;
  1165. }
  1166. /deep/ .mu-dialog p {
  1167. color: #fff;
  1168. text-align: center;
  1169. }
  1170. /deep/ .mu-dialog .mu-primary-text-color {
  1171. margin: 0 auto;
  1172. border-radius: 9px;
  1173. background-color: rgba(255, 255, 255, 0.1);
  1174. color: #fff;
  1175. }
  1176. .watchList {
  1177. width: 100%;
  1178. overflow: hidden;
  1179. display: block;
  1180. margin: 0 auto;
  1181. min-height: 100px;
  1182. overflow-y: scroll;
  1183. }
  1184. .watchList li {
  1185. width: 100%;
  1186. padding-left: 5%;
  1187. padding-right: 5%;
  1188. padding-top: 5px;
  1189. padding-bottom: 5px;
  1190. overflow: hidden;
  1191. display: block;
  1192. margin: 0 auto;
  1193. background-color: rgba(255, 255, 255, 0.29);
  1194. color: #fff;
  1195. border-radius: 9px;
  1196. font-size: 12px;
  1197. margin-bottom: 5px;
  1198. }
  1199. .watchList li em {
  1200. float: right;
  1201. text-align: right;
  1202. }
  1203. .classInfo {
  1204. width: 100%;
  1205. overflow: hidden;
  1206. display: block;
  1207. margin: 0 auto;
  1208. font-size: 16px;
  1209. text-align: center;
  1210. }
  1211. .classInfo span {
  1212. font-size: 12px;
  1213. }
  1214. </style>