heartbeatDetails.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <view>
  3. <!-- 导航栏 -->
  4. <view @tap="closeFrame">
  5. <cu-custom bgColor="bg-gradual-sisBlack" :isBack="true">
  6. <block slot="backText">
  7. <view style="height: 80rpx;line-height: 80rpx;color: silver;">返回</view>
  8. </block>
  9. <block slot="content">
  10. <view style="color: silver;">{{name}}历史曲线</view>
  11. </block>
  12. </cu-custom>
  13. </view>
  14. <view class="bc">
  15. <!-- 心跳标签 -->
  16. <view class="heartbeatLabel">
  17. <div class="zhiti heartbeat">{{name}}</div>
  18. <div class="zhiti heartbeat">{{realValue}}</div>
  19. <div class="zhiti heartbeat">{{unit}}</div>
  20. </view>
  21. <!-- 日期时间选择器 -->
  22. <view class="chooseTime">
  23. <view class="timeSelector">
  24. <div class="zhiti">{{rangetime[0]}} - {{rangetime[1]}}</div>
  25. <button type="primary" @click="onShowDatePicker('rangetime')">选择日期时间范围</button>
  26. </view>
  27. <mx-date-picker :show="showPicker" :type="type" :value="value" :show-tips="false" :begin-text="'运动开始'" :end-text="'运动结束'" :show-seconds="true" @confirm="onSelected" @cancel="onSelected" />
  28. </view>
  29. <!-- 曲线图标题 -->
  30. <view titleC>
  31. <view class="curveTitle">{{name}}曲线图</view>
  32. <view class="garden" style="background-color:;"></view>
  33. <view class="curveTitle_1">{{unit}}</view>
  34. </view>
  35. <!-- 曲线图 -->
  36. <scroll-view scroll-x class="horizontalSlider">
  37. <view class="slide">
  38. <view class="graphHeartbeat">
  39. <view class="qiun-charts">
  40. <!-- 没用 <canvas canvas-id="canvasLineC" id="canvasLineC" class="charts" :width="cWidth*pixelRatio" :height="cHeight*pixelRatio" :style="{'width':cWidth+'px','height':cHeight+'px'}" disable-scroll=true @ontouchstart="touchLineC" @ontouchmove="moveLineC" @ontouchend="touchEndLineC"></canvas> -->
  41. <canvas canvas-id="canvasLineC" id="canvasLineC" class="charts" @touchstart="touchLineC" ></canvas>
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import uCharts from '../../tools/u-charts/u-charts.js';
  51. import MxDatePicker from "@/components/mx-datepicker/mx-datepicker.vue";
  52. var _self;
  53. var canvaLineC=null;
  54. export default {
  55. data:function() {
  56. return {
  57. showPicker: false,
  58. date: '2019/01/01',
  59. time: '15:00:12',
  60. datetime: '2019/01/01 15:00:12',
  61. range: ['2019/01/01','2019/01/06'],
  62. rangetime: ['2020/03/20 14:00','2020/03/21 13:59'],
  63. type: 'rangetime',
  64. value: '',
  65. XT_Num:[],
  66. braceletCurve_XTPL:{},
  67. beginTime:'',
  68. endTime:'',
  69. isFrameShow: false,
  70. count: 0,
  71. cWidth: '',
  72. cHeight: '',
  73. pixelRatio: 1,
  74. serverData: '',
  75. sanJiao: 'sanJiaoDown',
  76. unit:'',
  77. color:'',
  78. name:'',
  79. realValue:''
  80. }
  81. },
  82. onLoad(option){
  83. _self = this;
  84. this.braceletCurve_XTPL = JSON.parse(option.braceletCurve_XTPL_Details);
  85. this.realValue = option.dataInformation;
  86. this.unit = option.unit;
  87. this.color = option.color;
  88. this.name = option.name;
  89. this.cWidth = uni.upx2px(1850);
  90. this.cHeight = uni.upx2px(600);
  91. this.getServerData_C();
  92. },
  93. //整体背景颜色
  94. mounted() {
  95. document.querySelector('body').setAttribute('style', 'background-color:#242424');
  96. },
  97. /* beforeCreate () {
  98. document.querySelector('body').setAttribute('style', 'background-color:#242424')
  99. },
  100. beforeDestroy () {
  101. document.querySelector('body').removeAttribute('style')
  102. }, */
  103. onShow:function(){
  104. },
  105. methods: {
  106. closeFrame: function() {
  107. this.count = this.count + 1;
  108. if (this.isFrameShow) {
  109. this.isFrameShow = false;
  110. this.sanJiao = 'sanJiaoDown';
  111. }
  112. },
  113. onShowDatePicker(type){//显示
  114. this.type = type;
  115. this.showPicker = true;
  116. this.value = this[type];
  117. },
  118. onSelected(e) {//选择
  119. let LineC = {
  120. categories: [
  121. ' 17:26',
  122. '18:56',
  123. '19:56',
  124. '20:56',
  125. '21:56',
  126. '22:56',
  127. '23:56',
  128. '00:56',
  129. '01:56',
  130. '02:56',
  131. '03:56',
  132. '04:56',
  133. '05:56',
  134. '06:56',
  135. '07:56',
  136. '08:56',
  137. '09:56',
  138. '10:56',
  139. '11:56',
  140. '12:56',
  141. '13:56',
  142. '14:56',
  143. '15:56',
  144. '16:56',
  145. '17:56 '
  146. ],
  147. series: [{
  148. pointShape:'triangle',
  149. name: this.name,
  150. data: [
  151. ],
  152. color: this.color,
  153. textColor: '#ffffff',
  154. textSize: this.seriesTextSize,
  155. /* format: val => {
  156. return val + 'kwh';
  157. }, */
  158. index: 0,
  159. legendShape: 'circle'
  160. },
  161. ]
  162. };
  163. Date.prototype.Format = function(fmt) {
  164. var o = {
  165. 'M+': this.getMonth() + 1, //月份
  166. 'd+': this.getDate(), //日
  167. 'h+': this.getHours(), //小时
  168. 'm+': this.getMinutes(), //分
  169. 's+': this.getSeconds(), //秒
  170. 'q+': Math.floor((this.getMonth() + 3) / 3), //季度
  171. S: this.getMilliseconds() //毫秒
  172. };
  173. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  174. for (var k in o)
  175. if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[
  176. k]).substr(('' + o[k]).length));
  177. return fmt;
  178. };
  179. this.showPicker = false;
  180. if(e) {
  181. this[this.type] = e.value;
  182. //选择的值
  183. console.log('value => '+ e.value[0]);
  184. console.log('value => '+ e.value[1]);
  185. this.beginTime = new Date(e.value[0]).getTime();
  186. this.endTime = new Date(e.value[1]).getTime();
  187. console.log(this.endTime+"结束");
  188. console.log(this.beginTime+"开始");
  189. //原始的Date对象
  190. /* console.log('date => ' + e.date); */
  191. LineC.categories = [];
  192. LineC.series[0].data = [];
  193. var j=Math.ceil(this.braceletCurve_XTPL.length/10);
  194. for(var i=0;i<this.braceletCurve_XTPL.length;i+=j){
  195. if(this.braceletCurve_XTPL[i].ts<this.endTime&&this.braceletCurve_XTPL[i].ts>this.beginTime){
  196. LineC.series[0].data.push(this.braceletCurve_XTPL[i].value);
  197. LineC.categories.push(new Date(this.braceletCurve_XTPL[i].ts).Format('MM/dd hh:mm'));
  198. }
  199. };
  200. /* for(var j=0;j<(LineC.series[0].data).length;j++){
  201. LineC.categories.push(j);
  202. }; */
  203. /* for(var i=0;i<_this.braceletCurve_XTPL.length;i++){
  204. if(this.braceletCurve_XTPL[i].ts<this.endTime&&this.braceletCurve_XTPL[i].ts>this.beginTime){
  205. LineC.categories.push(new Date(_this.braceletCurve_XTPL[i].ts).Format('hh:mm'));
  206. }
  207. } */
  208. this.showLineC('canvasLineC', LineC);
  209. }
  210. },
  211. choiceRange(){
  212. /* for(var i=0;i<braceletCurve_XTPL.length;i++){
  213. if(braceletCurve_XTPL[i].ts>this.endTime&&this.beginTime>braceletCurve_XTPL[i]){
  214. .push(braceletCurve_XTPL[i].value);
  215. }
  216. } */
  217. },
  218. getServerData_C() {
  219. // 折线图
  220. let LineC = {
  221. categories: [
  222. ' 17:26',
  223. '18:56',
  224. '19:56',
  225. '20:56',
  226. '21:56',
  227. '22:56',
  228. '23:56',
  229. '00:56',
  230. '01:56',
  231. '02:56',
  232. '03:56',
  233. '04:56',
  234. '05:56',
  235. '06:56',
  236. '07:56',
  237. '08:56',
  238. '09:56',
  239. '10:56',
  240. '11:56',
  241. '12:56',
  242. '13:56',
  243. '14:56',
  244. '15:56',
  245. '16:56',
  246. '17:56 '
  247. ],
  248. series: [{
  249. pointShape:'triangle',
  250. name: this.name,
  251. data: [
  252. ],
  253. color: this.color,
  254. textColor: '#ffffff',
  255. textSize: this.seriesTextSize,
  256. /* format: val => {
  257. return val + 'kwh';
  258. }, */
  259. index: 0,
  260. /* legendShape: 'circle' */
  261. },
  262. ]
  263. };
  264. let _this = this;
  265. LineC.categories = [];
  266. LineC.series[0].data = [];
  267. /* */
  268. /*
  269. _this.lengthDate = */
  270. /* console.log("---");
  271. console.log((LineC.categories).length); */
  272. /* _this.braceletCurve_SSXY = _this.braceletCurve[_this.deviceNameSsxy]; */
  273. Date.prototype.Format = function(fmt) {
  274. var o = {
  275. 'M+': this.getMonth() + 1, //月份
  276. 'd+': this.getDate(), //日
  277. 'h+': this.getHours(), //小时
  278. 'm+': this.getMinutes(), //分
  279. 's+': this.getSeconds(), //秒
  280. 'q+': Math.floor((this.getMonth() + 3) / 3), //季度
  281. S: this.getMilliseconds() //毫秒
  282. };
  283. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  284. for (var k in o)
  285. if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[
  286. k]).substr(('' + o[k]).length));
  287. return fmt;
  288. };
  289. for(let i=_this.braceletCurve_XTPL.length-7;i<_this.braceletCurve_XTPL.length;i++){
  290. LineC.series[0].data.push(_this.braceletCurve_XTPL[i].value);
  291. }
  292. /* for(let j=0;j<(LineC.series[0].data).length;j++){
  293. LineC.categories.push(j);
  294. } */
  295. for(let i=_this.braceletCurve_XTPL.length-7;i<_this.braceletCurve_XTPL.length;i++){
  296. LineC.categories.push(new Date(_this.braceletCurve_XTPL[i].ts).Format('MM/dd hh:mm'));
  297. }
  298. this.showLineC('canvasLineC', LineC);
  299. },
  300. showLineC(canvasId, chartData) {
  301. var _self = this;
  302. canvaLineC = new uCharts({
  303. $this: _self,
  304. canvasId: canvasId,
  305. type: 'line',
  306. fontSize: 8,
  307. legend: {
  308. show: false,
  309. position: 'top',
  310. float: 'right',
  311. fontColor: '#242424',
  312. itemGap: '4',
  313. itemWidth: '3',
  314. fontSize:'13',
  315. },
  316. dataLabel: false,
  317. dataPointShape: false,/*
  318. dataLabel:true, */
  319. background: '#242424',
  320. pixelRatio: _self.pixelRatio,
  321. categories: chartData.categories,
  322. series: chartData.series,
  323. animation: true,
  324. gridColor: '#2E2E2E',
  325. splitNumber: 5,
  326. gridType: 'solid',
  327. dashLength: 8,
  328. enableScroll: false,
  329. /* enableMarkLine:true, */
  330. xAxis: {
  331. rotateLabel:true,
  332. gridEval:3,
  333. scrollShow:false,
  334. scrollAlign:'left',
  335. disableGrid:false,
  336. axisLine:true,
  337. type: 'grid',
  338. disabled: false,
  339. gridColor: '#2E2E2E',
  340. fontColor: 'silver',
  341. gridType: 'solid',
  342. axisLineColor: '#2E2E2E',
  343. labelCount: 13,
  344. itemCount:10,
  345. scrollBackgroundColor:'#2E2E2E',
  346. scrollColor:'#bdbdbd',
  347. },
  348. yAxis: {
  349. gridColor: '#2D2D2D',
  350. gridType:'solid',
  351. splitNumber:8,
  352. showTitle:false,
  353. data: [{
  354. type: 'value',
  355. fontColor: 'silver',
  356. disabled: false, //y轴轴线
  357. min: 10,
  358. max: 180,
  359. position: 'left',
  360. axisLineColor: '#2E2E2E',
  361. title: this.unit,
  362. titleFontColor: '#BDBDBD',
  363. format: val => {
  364. return val.toFixed(0);
  365. }
  366. }
  367. ],
  368. },
  369. width: _self.cWidth * _self.pixelRatio ,
  370. height: _self.cHeight * _self.pixelRatio ,
  371. extra: {
  372. line: {
  373. type: 'line',
  374. width: '1'
  375. }
  376. }
  377. });
  378. },
  379. touchLineC(e) {
  380. canvaLineC.showToolTip(e, {
  381. format: function(item, category) {
  382. return category + ' ' + item.name + ':' + item.data;
  383. }
  384. });
  385. },
  386. moveLineC(e) {
  387. canvaLineC.scroll(e);
  388. },
  389. },
  390. components: {
  391. MxDatePicker
  392. },
  393. }
  394. </script>
  395. <style>
  396. .horizontalSlider {
  397. white-space: nowrap;
  398. width: 100%;
  399. height: 400px;
  400. background-color: #242424;
  401. /* margin-top: 540px; */
  402. }
  403. .slide {
  404. margin-top: 6%;
  405. width: 900px;
  406. height: 350px;
  407. background-color: #242424;
  408. }
  409. /* .qiun-charts {
  410. width: 100%;
  411. height: 700upx;
  412. } */
  413. .charts {
  414. position: absolute;
  415. width: 100%;
  416. height: 600upx;
  417. top: 1%;
  418. }
  419. .timeSelector{
  420. position: absolute;
  421. text-align: center;
  422. width: 100%;
  423. height: 100px;
  424. }
  425. button{
  426. margin: 20upx;
  427. font-size: 28upx;
  428. }
  429. .bc{
  430. height: 673px;
  431. width: 100%;
  432. background-color: #242424;
  433. }
  434. .heartbeatLabel{
  435. height: 139px;
  436. width: 100%;
  437. background-color: 'silver';
  438. display: flex;
  439. align-items: center;
  440. justify-content:space-around ;
  441. /* display: flex;
  442. justify-content: space-between; */
  443. }
  444. .heartbeat{
  445. height: 50px;
  446. width: 30%;
  447. background: -webkit-linear-gradient(top, rgba(159, 131, 111, 0.1) 0%, rgba(193, 94, 21, 0.2) 100%) !important;
  448. /* width: 20%;
  449. position: absolute;
  450. top: 50%;
  451. margin-top: -25px;
  452. font-size: 18px;
  453. color: #bdbdbd; */
  454. display: flex;
  455. justify-content:space-around ;
  456. align-items: center;
  457. }
  458. .zhiti{
  459. text-align: center;
  460. /* margin-top: 12px; */
  461. color: #BDBDBD;
  462. }
  463. .chooseTime{
  464. position: relative;
  465. width: 100%;
  466. height: 100px;
  467. /* background-color: 'silver' ; */
  468. }
  469. .graphHeartbeat{
  470. position: relative;
  471. padding-bottom: 100px;
  472. width: 100%;
  473. height: 100%;
  474. }
  475. .titleC{
  476. margin-top: 3%;
  477. float: left;
  478. }
  479. .curveTitle{
  480. float: left;
  481. display: block;
  482. color: #BDBDBD;
  483. margin-left: 3%;
  484. }
  485. .curveTitle_1{
  486. float: right;
  487. display: block;
  488. color: #BDBDBD;
  489. margin-right: -9%;
  490. }
  491. .garden{
  492. width: 16px;
  493. height: 16px;
  494. border-radius: 50%;
  495. -moz-border-radius: 50%;
  496. -webkit-border-radius: 50%;
  497. float: right;
  498. margin-right: 8%;
  499. line-height: 16px;
  500. margin-top: 1%;
  501. }
  502. </style>