heartbeatDetails.vue 14 KB

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