index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view>
  3. <uni-section title="选择开始时间" type="line" style="width:80%;margin: auto;">
  4. <uni-data-select v-model="value" :localdata="range" @change="change"></uni-data-select>
  5. </uni-section>
  6. <view v-for="item in echartsData" :key="item.id">
  7. <view v-if="item.chartType==='pie'">
  8. <view class="title" v-if="echartsData.length">
  9. {{item.chartName}}
  10. </view>
  11. <pieEcharts :echartsData="item" @piePolling="piePolling" />
  12. </view>
  13. <view v-if="item.chartType==='bar'">
  14. <view class="title" v-if="echartsData.length">
  15. {{item.chartName}}
  16. </view>
  17. <barEcharts :echartsData="item" @barPolling="barPolling" />
  18. </view>
  19. <view v-if="item.chartType==='line'">
  20. <view class="title" v-if="echartsData.length">
  21. {{item.chartName}}
  22. </view>
  23. <lineEcharts :echartsData="item" @linePolling="linePolling" />
  24. </view>
  25. </view>
  26. <u-empty text="暂无数据" icon="../../static/data.png" v-if="!echartsData.length"></u-empty>
  27. </view>
  28. </template>
  29. <script>
  30. import lineEcharts from '../../components/ecahrts/line-echarts.vue'
  31. import pieEcharts from '../../components/ecahrts/pie-echarts.vue'
  32. import barEcharts from '../../components/ecahrts/bar-echarts.vue'
  33. import {
  34. nowDate,
  35. timeToDate
  36. } from '../../utils/date.js'
  37. export default {
  38. components: {
  39. lineEcharts,
  40. pieEcharts,
  41. barEcharts
  42. },
  43. data() {
  44. return {
  45. queryParams: {
  46. page: 1,
  47. limit: 999
  48. },
  49. //图表数据
  50. echartsData: [],
  51. value: null,
  52. startTime: null,
  53. range: [{
  54. value: 3600000,
  55. text: "近一小时"
  56. },
  57. {
  58. value: 10800000,
  59. text: "近三小时"
  60. },
  61. {
  62. value: 86400000,
  63. text: "近一天"
  64. },
  65. ],
  66. barTime: null,
  67. lineTime: null,
  68. pieTime: null
  69. }
  70. },
  71. onShow() {
  72. this.startTime = nowDate().split(' ')[0] + " 00:00:00"
  73. this.temperature()
  74. },
  75. methods: {
  76. //用户图表数据
  77. temperature() {
  78. this.echartsData = []
  79. uni.$http.get('/chart/getAllOkChart', this.queryParams).then(res => {
  80. const data = res.data
  81. if (data.code === 200) {
  82. const {
  83. reportTableList
  84. } = data.data
  85. reportTableList.map(item => {
  86. this.getChartData(item.id)
  87. })
  88. }
  89. })
  90. },
  91. getChartData(id) {
  92. let chartParams = {
  93. id: id,
  94. startTime: this.startTime,
  95. endTime: nowDate()
  96. }
  97. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  98. const data = res.data
  99. if (data.code === 200) {
  100. this.echartsData.push(data.data)
  101. }
  102. })
  103. },
  104. change(e) {
  105. if (e) {
  106. this.startTime = timeToDate(new Date().getTime() - e)
  107. } else {
  108. this.startTime = nowDate().split(' ')[0] + " 00:00:00"
  109. this.echartsData = []
  110. clearInterval(this.barTime)
  111. clearInterval(this.lineTime)
  112. clearInterval(this.pieTime)
  113. }
  114. this.temperature()
  115. },
  116. //轮询
  117. barPolling(time, id) {
  118. this.barTime = setInterval(() => {
  119. let chartParams = {
  120. id: id,
  121. startTime: this.startTime,
  122. endTime: nowDate()
  123. }
  124. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  125. })
  126. }, time)
  127. },
  128. linePolling(time, id) {
  129. this.lineTime = setInterval(() => {
  130. let chartParams = {
  131. id: id,
  132. startTime: this.startTime,
  133. endTime: nowDate()
  134. }
  135. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  136. })
  137. }, time)
  138. },
  139. piePolling(time, id) {
  140. this.pieTime = setInterval(() => {
  141. let chartParams = {
  142. id: id,
  143. startTime: this.startTime,
  144. endTime: nowDate()
  145. }
  146. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  147. })
  148. }, time)
  149. }
  150. }
  151. };
  152. </script>
  153. <style scoped>
  154. .title {
  155. margin-left: 24rpx;
  156. font-size: 36rpx;
  157. color: #666666;
  158. }
  159. </style>