index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. <div class="moreTime">
  8. <div v-for="(item,index) in range" :key="index" @click="change(1,index,item.value)"
  9. :class="choiceTime===index?'bod':''">
  10. {{item.text}}
  11. </div>
  12. </div>
  13. <div class="childTime" v-if="isShow">
  14. <div v-for="(item,index) in moreTimeList" @click="change(2,index,item.value)"
  15. :class="choiceMoreTime===index?'box':''">
  16. {{item.text}}
  17. </div>
  18. </div>
  19. <template v-if="clear">
  20. <view v-for="item in echartsData" :key="item.id" style="padding-right:20rpx">
  21. <view v-if="item.chartType==='pie'">
  22. <view class="title" v-if="echartsData.length">
  23. {{item.chartName}}
  24. </view>
  25. <pieEcharts :echartsData="item" />
  26. </view>
  27. <view v-if="item.chartType==='bar'">
  28. <view class="title" v-if="echartsData.length">
  29. {{item.chartName}}
  30. </view>
  31. <barEcharts :echartsData="item" />
  32. </view>
  33. <view v-if="item.chartType==='line'">
  34. <view class="title" v-if="echartsData.length">
  35. {{item.chartName}}
  36. </view>
  37. <!-- <lineEcharts :echartsData="item" /> -->
  38. <demo :echartsData="item" />
  39. </view>
  40. </view>
  41. </template>
  42. <!-- <demo1/> -->
  43. <u-empty text="暂无数据" icon="../../static/data.png" v-if="!echartsData.length"></u-empty>
  44. </view>
  45. </template>
  46. <script>
  47. import lineEcharts from '../../components/ecahrts/line-echarts.vue'
  48. import pieEcharts from '../../components/ecahrts/pie-echarts.vue'
  49. import barEcharts from '../../components/ecahrts/bar-echarts.vue'
  50. import demo from '../../components/ecahrts/demo.vue'
  51. import demo1 from '../../components/ecahrts/demo1.vue'
  52. import {
  53. nowDate,
  54. timeToDate,
  55. getLastWeek,
  56. getLastMonth,
  57. getLast3Month
  58. } from '../../utils/date.js'
  59. export default {
  60. components: {
  61. lineEcharts,
  62. pieEcharts,
  63. barEcharts,
  64. demo,
  65. demo1
  66. },
  67. data() {
  68. return {
  69. queryParams: {
  70. page: 1,
  71. limit: 999
  72. },
  73. //图表数据
  74. echartsData: [],
  75. value: 3600000,
  76. startTime: null,
  77. range: [{
  78. value: 3600000,
  79. text: "分时"
  80. },
  81. {
  82. value: 86400000,
  83. text: "日"
  84. },
  85. {
  86. value: 1,
  87. text: "周"
  88. },
  89. {
  90. value: 2,
  91. text: "月"
  92. }
  93. ],
  94. moreTimeList: [{
  95. value: 7200000,
  96. text: "120分"
  97. },
  98. {
  99. value: 3600000,
  100. text: "60分"
  101. },
  102. {
  103. value: 1800000,
  104. text: "30分"
  105. },
  106. {
  107. value: 900000,
  108. text: "15分"
  109. },
  110. {
  111. value: 300000,
  112. text: '5分'
  113. },
  114. {
  115. value: 60000,
  116. text: '1分'
  117. }
  118. ],
  119. clear: true,
  120. choiceTime: 0,
  121. choiceMoreTime: 0,
  122. isShow: false
  123. }
  124. },
  125. onShow() {
  126. uni.removeStorage('sTime')
  127. this.clear = true
  128. this.value = null
  129. this.choiceTime = 0
  130. this.startTime = timeToDate(new Date().getTime() - 3600000)
  131. this.temperature()
  132. },
  133. onHide() {
  134. this.clear = false
  135. },
  136. methods: {
  137. //用户图表数据
  138. temperature() {
  139. this.echartsData = []
  140. uni.$http.get('/chart/getAllOkChart', this.queryParams).then(res => {
  141. const data = res.data
  142. if (data.code === 200) {
  143. const {
  144. reportTableList
  145. } = data.data
  146. reportTableList.map(item => {
  147. this.getChartData(item.id)
  148. })
  149. }
  150. })
  151. },
  152. getChartData(id) {
  153. let chartParams = {
  154. id: id,
  155. startTime: this.startTime,
  156. endTime: nowDate()
  157. }
  158. uni.setStorage({
  159. key: 'sTime',
  160. data: chartParams.endTime
  161. })
  162. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  163. const data = res.data
  164. if (data.code === 200) {
  165. this.echartsData.push(data.data)
  166. }
  167. })
  168. },
  169. change(type, i, e) {
  170. if (type === 1) {
  171. this.choiceTime = i
  172. } else {
  173. this.choiceMoreTime = i
  174. }
  175. if (e === 'more') {
  176. this.isShow = !this.isShow
  177. } else {
  178. if (typeof(e) !== 'string' && e !== 1 && e !== 2 && e !== 3) {
  179. this.startTime = timeToDate(new Date().getTime() - e)
  180. } else if (typeof(e) !== 'string' && e !== null) {
  181. switch (e) {
  182. case 1:
  183. this.startTime = timeToDate(getLastWeek()[0])
  184. break;
  185. case 2:
  186. this.startTime = timeToDate(getLastMonth()[0])
  187. break;
  188. case 3:
  189. this.startTime = timeToDate(getLast3Month()[0])
  190. break;
  191. }
  192. } else if (typeof(e) === 'string') {
  193. this.startTime = timeToDate(new Date().getTime() - 3600000)
  194. this.echartsData = []
  195. }
  196. this.temperature()
  197. }
  198. }
  199. }
  200. };
  201. </script>
  202. <style scoped>
  203. .title {
  204. margin: 34rpx 0 10rpx 20rpx;
  205. font-size: 28rpx;
  206. color: #666666;
  207. }
  208. ::v-deep .uni-section-content {
  209. width: 50%;
  210. margin-bottom: 20rpx;
  211. }
  212. .moreTime {
  213. display: flex;
  214. justify-content: space-between;
  215. align-items: center;
  216. margin: 0 34rpx
  217. }
  218. .bod {
  219. border-bottom: 3px solid #007AFF;
  220. }
  221. .box {
  222. border: 1px solid #007AFF !important;
  223. }
  224. .childTime {
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. margin: 60rpx 34rpx 0 34rpx;
  229. }
  230. .childTime div {
  231. padding: 10rpx;
  232. border: 1px solid #e6e6e6;
  233. border-radius: 16rpx;
  234. color: #7e7e7e;
  235. font-size: 26rpx;
  236. width: 80rpx;
  237. text-align: center;
  238. }
  239. </style>