index.vue 5.7 KB

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