index.vue 6.4 KB

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