detailedView.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div>
  3. <div style="margin: 15px;text-align: right">
  4. <span class="bottom_01" :style="{backgroundColor:chooseColor==='30'? '#2b85e4':''}"
  5. @click="chooseDate('30')">实时</span>
  6. <span class="bottom_01" :style="{backgroundColor:chooseColor==='1'? '#2b85e4':''}"
  7. @click="chooseDate('1')">近1天</span>
  8. <span class="bottom_01" :style="{backgroundColor:chooseColor==='10'? '#2b85e4':''}"
  9. @click="chooseDate('10')">近10天</span>
  10. <span class="bottom_01" :style="{backgroundColor:chooseColor==='20'? '#2b85e4':''}"
  11. @click="chooseDate('20')">近20天</span>
  12. </div>
  13. <div id="transactionFlowView" style="height:180px;width: 100%;margin-bottom: 10px;"></div>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. name: "detailedView",
  19. data() {
  20. return {
  21. begin: this.formatDate(new Date()), //是 string 开始时间
  22. end: this.formatDate(new Date()), //是 string 截止日期
  23. timer: '',
  24. monitorId: '',
  25. chooseColor: '30',
  26. viewNum: [],
  27. viewData: [],
  28. type: 'second',
  29. days: ''
  30. }
  31. },
  32. destroyed() {
  33. clearInterval(this.timer);
  34. this.timer = null;
  35. },
  36. methods: {
  37. formatDate(value) {
  38. let date = new Date(value);
  39. let y = date.getFullYear();
  40. let MM = date.getMonth() + 1;
  41. MM = MM < 10 ? ('0' + MM) : MM;
  42. let d = date.getDate();
  43. d = d < 10 ? ('0' + d) : d;
  44. let h = date.getHours();
  45. h = h < 10 ? ('0' + h) : h;
  46. let m = date.getMinutes();
  47. m = m < 10 ? ('0' + m) : m;
  48. let s = date.getSeconds();
  49. s = s < 10 ? ('0' + s) : s;
  50. return d;
  51. },
  52. chooseDate(data) {
  53. // 选中先清除定时器
  54. clearInterval(this.timer);
  55. // startDate,endDate
  56. switch (data) {
  57. case '1':
  58. this.type = 'hour';
  59. this.end = this.formatDate(new Date());
  60. this.begin = this.formatDate(new Date());
  61. break
  62. case '10':
  63. this.end = this.formatDate(new Date());
  64. this.begin = this.formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24 * 11));
  65. this.days='10'
  66. this.type = 'day';
  67. break
  68. case '20':
  69. this.end = this.formatDate(new Date());
  70. this.begin = this.formatDate(new Date(new Date().getTime() - 3600 * 1000 * 24 * 21));
  71. this.days='20'
  72. this.type = 'day';
  73. break
  74. case '30':
  75. this.end = this.formatDate(new Date());
  76. this.begin = this.formatDate(new Date());
  77. this.type = 'second'
  78. break
  79. }
  80. this.chooseColor = data;
  81. if(this.type === 'second'){
  82. clearInterval(this.timer);
  83. // 如果选中的type是为实时的话,每1s执行一次
  84. this.timer = setInterval(() => {
  85. this.getTableData();
  86. }, 1000)
  87. }else {
  88. this.getTableData();
  89. }
  90. },
  91. getTableData() {
  92. let _data = {
  93. monitorId: this.monitorId, //是 string 区域测点ID
  94. begin: this.begin, //是 string 开始时间
  95. end: this.end, //是 string 截止日期
  96. type: this.type,
  97. days: this.days
  98. };
  99. this.$get("index/monitors/measuring/record/monitors", _data).then(res => {
  100. if (res.code === 200) {
  101. this.viewData = res.data.keys || [];
  102. this.viewNum = res.data.values || [];
  103. this.showIview()
  104. } else {
  105. console.error(res.msg);
  106. }
  107. });
  108. },
  109. parentHandleclick(e) {
  110. this.monitorId = e.monitorId
  111. clearInterval(this.timer);
  112. if(this.type === 'second'){
  113. clearInterval(this.timer);
  114. this.timer = setInterval(() => {
  115. // 选中second实时,定时调用getTableData()方法,显示数据
  116. this.getTableData();
  117. }, 1000)
  118. }else {
  119. // 选中其他,静态显示
  120. this.getTableData();
  121. }
  122. },
  123. showIview() {
  124. let myChart = this.$echarts.init(
  125. // echarts绑定到指定id元素上
  126. document.getElementById("transactionFlowView"), 'dark'
  127. );
  128. myChart.setOption(
  129. {
  130. darkMode: true,
  131. backgroundColor: '#100C2A',
  132. tooltip: {
  133. trigger: 'axis'
  134. },
  135. grid: {
  136. left: '3%',
  137. right: '4%',
  138. bottom: '5%',
  139. top:'15%',
  140. containLabel: true
  141. },
  142. toolbox: {
  143. feature: {
  144. saveAsImage: {
  145. show: false,
  146. }
  147. }
  148. },
  149. xAxis: {
  150. type: 'category',
  151. boundaryGap: false,
  152. data: this.viewData,
  153. },
  154. yAxis: {
  155. type: 'value'
  156. },
  157. series: [
  158. {
  159. name: '测点监测值',
  160. type: 'line',
  161. stack: 'Total',
  162. data: this.viewNum
  163. },
  164. ]
  165. },
  166. true
  167. );
  168. myChart.resize();
  169. }
  170. }
  171. }
  172. </script>
  173. <style scoped>
  174. .bottom_01 {
  175. padding: 5px 10px;
  176. border: #2d8cf0 1px solid;
  177. margin: 5px 10px;
  178. border-radius: 10px;
  179. }
  180. </style>