index.vue 3.2 KB

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