index-old.vue 6.6 KB

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