heartbeatDetails.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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="All">
  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. <!-- <view>日期选择 - 示例</view>
  25. {{date}}
  26. <button type="primary" @click="onShowDatePicker('date')">选择日期</button>
  27. {{time}}
  28. <button type="primary" @click="onShowDatePicker('time')">选择时间</button>
  29. {{datetime}}
  30. <button type="primary" @click="onShowDatePicker('datetime')">选择日期时间</button>
  31. {{range[0]}} - {{range[1]}}
  32. <button type="primary" @click="onShowDatePicker('range')">选择日期范围</button> -->
  33. <div class="zhiti">{{rangetime[0]}} - {{rangetime[1]}}</div>
  34. <button type="primary" @click="onShowDatePicker('rangetime')">选择日期时间范围</button>
  35. </view>
  36. <mx-date-picker :show="showPicker" :type="type" :value="value" :show-tips="false" :begin-text="'运动开始'" :end-text="'运动结束'" :show-seconds="true" @confirm="onSelected" @cancel="onSelected" />
  37. </view>
  38. <view titleC>
  39. <view class="curveTitle">{{name}}曲线图</view>
  40. <view class="garden" style="background-color:;"></view>
  41. <view class="curveTitle_1">{{unit}}</view>
  42. </view>
  43. <!-- 曲线图 -->
  44. <scroll-view scroll-x class="horizontalSlider">
  45. <view class="slide">
  46. <view class="graphHeartbeat">
  47. <view class="qiun-charts">
  48. <!-- <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> -->
  49. <canvas canvas-id="canvasLineC" id="canvasLineC" class="charts" @touchstart="touchLineC" ></canvas>
  50. </view>
  51. </view>
  52. </view>
  53. </scroll-view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import uCharts from '../../tools/u-charts/u-charts.js';
  59. import MxDatePicker from "@/components/mx-datepicker/mx-datepicker.vue";
  60. var _self;
  61. var canvaLineC=null;
  62. export default {
  63. data:function() {
  64. return {
  65. showPicker: false,
  66. date: '2019/01/01',
  67. time: '15:00:12',
  68. datetime: '2019/01/01 15:00:12',
  69. range: ['2019/01/01','2019/01/06'],
  70. rangetime: ['2020/03/20 14:00','2020/03/21 13:59'],
  71. type: 'rangetime',
  72. value: '',
  73. XT_Num:[],
  74. braceletCurve_XTPL:{},
  75. beginTime:'',
  76. endTime:'',
  77. isFrameShow: false,
  78. count: 0,
  79. cWidth: '',
  80. cHeight: '',
  81. pixelRatio: 1,
  82. serverData: '',
  83. sanJiao: 'sanJiaoDown',
  84. unit:'',
  85. color:'',
  86. name:'',
  87. realValue:''
  88. }
  89. },
  90. onLoad(option){
  91. _self = this;
  92. this.braceletCurve_XTPL = JSON.parse(option.braceletCurve_XTPL_Details);
  93. this.realValue = option.dataInformation;
  94. this.unit = option.unit;
  95. this.color = option.color;
  96. this.name = option.name;
  97. this.cWidth = uni.upx2px(1850);
  98. this.cHeight = uni.upx2px(600);
  99. this.getServerData_C();
  100. },
  101. mounted() {
  102. document.querySelector('body').setAttribute('style', 'background-color:#242424');
  103. },
  104. onShow:function(){
  105. },
  106. methods: {
  107. closeFrame: function() {
  108. this.count = this.count + 1;
  109. if (this.isFrameShow) {
  110. this.isFrameShow = false;
  111. this.sanJiao = 'sanJiaoDown';
  112. }
  113. },
  114. onShowDatePicker(type){//显示
  115. this.type = type;
  116. this.showPicker = true;
  117. this.value = this[type];
  118. },
  119. onSelected(e) {//选择
  120. let LineC = {
  121. categories: [
  122. ' 17:26',
  123. '18:56',
  124. '19:56',
  125. '20:56',
  126. '21:56',
  127. '22:56',
  128. '23:56',
  129. '00:56',
  130. '01:56',
  131. '02:56',
  132. '03:56',
  133. '04:56',
  134. '05:56',
  135. '06:56',
  136. '07:56',
  137. '08:56',
  138. '09:56',
  139. '10:56',
  140. '11:56',
  141. '12:56',
  142. '13:56',
  143. '14:56',
  144. '15:56',
  145. '16:56',
  146. '17:56 '
  147. ],
  148. series: [{
  149. pointShape:'triangle',
  150. name: this.name,
  151. data: [
  152. ],
  153. color: this.color,
  154. textColor: '#ffffff',
  155. textSize: this.seriesTextSize,
  156. /* format: val => {
  157. return val + 'kwh';
  158. }, */
  159. index: 0,
  160. legendShape: 'circle'
  161. },
  162. ]
  163. };
  164. Date.prototype.Format = function(fmt) {
  165. var o = {
  166. 'M+': this.getMonth() + 1, //月份
  167. 'd+': this.getDate(), //日
  168. 'h+': this.getHours(), //小时
  169. 'm+': this.getMinutes(), //分
  170. 's+': this.getSeconds(), //秒
  171. 'q+': Math.floor((this.getMonth() + 3) / 3), //季度
  172. S: this.getMilliseconds() //毫秒
  173. };
  174. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  175. for (var k in o)
  176. if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[
  177. k]).substr(('' + o[k]).length));
  178. return fmt;
  179. };
  180. this.showPicker = false;
  181. if(e) {
  182. this[this.type] = e.value;
  183. //选择的值
  184. console.log('value => '+ e.value[0]);
  185. console.log('value => '+ e.value[1]);
  186. this.beginTime = new Date(e.value[0]).getTime();
  187. this.endTime = new Date(e.value[1]).getTime();
  188. console.log(this.endTime+"结束");
  189. console.log(this.beginTime+"开始");
  190. //原始的Date对象
  191. /* console.log('date => ' + e.date); */
  192. LineC.categories = [];
  193. LineC.series[0].data = [];
  194. for(var i=0;i<this.braceletCurve_XTPL.length;i++){
  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 mm:ss'));
  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 mm:ss'));
  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: 11,
  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: 350px;
  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. }
  424. button{
  425. margin: 20upx;
  426. font-size: 28upx;
  427. }
  428. .All{
  429. width: 100%;
  430. height: 100%;
  431. background-color: #242424;
  432. }
  433. .heartbeatLabel{
  434. height: 139px;
  435. width: 100%;
  436. background-color: 'silver';
  437. display: flex;
  438. align-items: center;
  439. justify-content:space-around ;
  440. /* display: flex;
  441. justify-content: space-between; */
  442. }
  443. .heartbeat{
  444. height: 50px;
  445. width: 30%;
  446. background: -webkit-linear-gradient(top, rgba(159, 131, 111, 0.1) 0%, rgba(193, 94, 21, 0.2) 100%) !important;
  447. /* width: 20%;
  448. position: absolute;
  449. top: 50%;
  450. margin-top: -25px;
  451. font-size: 18px;
  452. color: #bdbdbd; */
  453. display: flex;
  454. justify-content:space-around ;
  455. align-items: center;
  456. }
  457. .zhiti{
  458. text-align: center;
  459. /* margin-top: 12px; */
  460. color: #BDBDBD;
  461. }
  462. .chooseTime{
  463. position: relative;
  464. width: 100%;
  465. height: 100px;
  466. /* background-color: 'silver' ; */
  467. }
  468. .graphHeartbeat{
  469. position: relative;
  470. width: 100%;
  471. height: 350px;
  472. }
  473. .titleC{
  474. margin-top: 3%;
  475. float: left;
  476. }
  477. .curveTitle{
  478. float: left;
  479. display: block;
  480. color: #BDBDBD;
  481. margin-left: 3%;
  482. }
  483. .curveTitle_1{
  484. float: right;
  485. display: block;
  486. color: #BDBDBD;
  487. margin-right: -9%;
  488. }
  489. .garden{
  490. width: 16px;
  491. height: 16px;
  492. border-radius: 50%;
  493. -moz-border-radius: 50%;
  494. -webkit-border-radius: 50%;
  495. float: right;
  496. margin-right: 8%;
  497. line-height: 16px;
  498. margin-top: 1%;
  499. }
  500. </style>