middleBox.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="left-top-box">
  3. <ul class="flex justify-end gap-15px mb-15px absolute right-15px z-10">
  4. <li
  5. :class="[
  6. 'w-50px cursor-pointer text-center b-solid b-1px b-color-#389bff hover:b-color-#FAC858',
  7. i === selectedI ? 'b-color-#FAC858' : ''
  8. ]"
  9. v-for="(item, i) in options"
  10. :key="item.code"
  11. @click="dayClick(i)"
  12. >
  13. <span class="text-12px">{{ item.name }}</span>
  14. </li>
  15. </ul>
  16. <ECharts
  17. id="xwjc-echarts"
  18. ref="echartsRef"
  19. width="100%"
  20. height="276px"
  21. :loading="loading"
  22. :fullOptions="fullOptions"
  23. />
  24. </div>
  25. </template>
  26. <script setup>
  27. import { chartOptions } from '@/components/ECharts/optionsConfig'
  28. const loading = ref(true)
  29. const echartsRef = ref(null)
  30. let timer = null
  31. let xData = [],
  32. yData1 = [],
  33. yData2 = [],
  34. yData3 = [],
  35. yData4 = []
  36. const fullOptions = ref({ options: {} })
  37. const selectedI = ref(0)
  38. const options = ref([
  39. { name: '当日', code: 0 },
  40. { name: '近一周', code: 1 },
  41. { name: '近一月', code: 2 }
  42. ])
  43. const dayClick = (v) => {
  44. selectedI.value = v
  45. switch (v) {
  46. case 0: {
  47. const xPoint = []
  48. for (let i = 0; i < 10; i++) {
  49. let currentTime = new Date().getTime() - 3600 * 1000 * i
  50. let time = new Date(currentTime).toLocaleTimeString()
  51. xPoint.push(time)
  52. }
  53. xData = xPoint
  54. for (let i = 0; i < xData.length; i++) {
  55. const curData1 = [],
  56. curData2 = [],
  57. curData3 = [],
  58. curData4 = []
  59. for (let j = 0; j < 10; j++) {
  60. curData1.push(Math.floor(Math.random() * 100))
  61. curData2.push(Math.floor(Math.random() * 100))
  62. curData3.push(Math.floor(Math.random() * 100))
  63. curData4.push(Math.floor(Math.random() * 100))
  64. }
  65. ;[yData1, yData2, yData3, yData4] = [curData1, curData2, curData3, curData4]
  66. }
  67. break
  68. }
  69. case 1: {
  70. const xPoint = []
  71. for (let i = 0; i < 7; i++) {
  72. // 修改循环次数为7
  73. let currentTime = new Date().getTime() - 24 * 3600 * 1000 * i // 修改为每天减少一天的时间
  74. let time = new Date(currentTime).toLocaleDateString() // 使用 toLocaleDateString 获取日期部分
  75. xPoint.push(time)
  76. }
  77. xData = xPoint
  78. for (let i = 0; i < xData.length; i++) {
  79. const curData1 = [],
  80. curData2 = [],
  81. curData3 = [],
  82. curData4 = []
  83. for (let j = 0; j < 7; j++) {
  84. curData1.push(Math.floor(Math.random() * 100))
  85. curData2.push(Math.floor(Math.random() * 100))
  86. curData3.push(Math.floor(Math.random() * 100))
  87. curData4.push(Math.floor(Math.random() * 100))
  88. }
  89. ;[yData1, yData2, yData3, yData4] = [curData1, curData2, curData3, curData4]
  90. }
  91. break
  92. }
  93. case 2: {
  94. const xPoint = []
  95. for (let i = 0; i < 30; i++) {
  96. // 修改循环次数为30
  97. let currentTime = new Date().getTime() - 24 * 3600 * 1000 * i // 修改为每天减少一天的时间
  98. let time = new Date(currentTime).toLocaleDateString() // 使用 toLocaleDateString 获取日期部分
  99. xPoint.push(time)
  100. }
  101. xData = xPoint
  102. for (let i = 0; i < xData.length; i++) {
  103. const curData1 = [],
  104. curData2 = [],
  105. curData3 = [],
  106. curData4 = []
  107. for (let j = 0; j < 30; j++) {
  108. curData1.push(Math.floor(Math.random() * 100))
  109. curData2.push(Math.floor(Math.random() * 100))
  110. curData3.push(Math.floor(Math.random() * 100))
  111. curData4.push(Math.floor(Math.random() * 100))
  112. }
  113. ;[yData1, yData2, yData3, yData4] = [curData1, curData2, curData3, curData4]
  114. }
  115. break
  116. }
  117. }
  118. const options = chartOptions.setXwjcOption(xData, yData1, yData2, yData3, yData4)
  119. if (v === 2) {
  120. options.xAxis[0].axisLabel.rotate = 0
  121. fullOptions.value.options = Object.assign(options, {
  122. dataZoom: [
  123. {
  124. type: 'slider',
  125. start: 0,
  126. end: 10,
  127. showDataShadow: false,
  128. height: 20,
  129. width: '80%',
  130. top: '14%'
  131. }
  132. ]
  133. })
  134. } else {
  135. fullOptions.value.options = options
  136. }
  137. }
  138. const moveShow = () => {
  139. let count = 0
  140. let dataLength = yData4.length
  141. timer && clearInterval(timer)
  142. timer = setInterval(() => {
  143. echartsRef.value.myChart.dispatchAction({
  144. type: 'downplay',
  145. seriesIndex: 1
  146. })
  147. echartsRef.value.myChart.dispatchAction({
  148. type: 'highlight',
  149. seriesIndex: 1,
  150. dataIndex: count % dataLength
  151. })
  152. echartsRef.value.myChart.dispatchAction({
  153. type: 'showTip',
  154. seriesIndex: 1,
  155. dataIndex: count % dataLength
  156. })
  157. count++
  158. }, 2000)
  159. }
  160. onMounted(() => {
  161. setTimeout(() => {
  162. loading.value = false
  163. dayClick(selectedI.value)
  164. moveShow()
  165. }, 1000)
  166. })
  167. onBeforeUnmount(() => {
  168. clearInterval(timer)
  169. })
  170. </script>
  171. <style scoped lang="scss">
  172. .box-style {
  173. background: url('@/assets/images/box-bg.png') no-repeat center;
  174. background-size: 100% 100%;
  175. }
  176. .left-top-box {
  177. :deep(.swiper) {
  178. width: 100%;
  179. height: 300px;
  180. .swiper-slide {
  181. height: 100%;
  182. }
  183. .swiper-pagination {
  184. --swiper-pagination-bottom: -5px;
  185. }
  186. .swiper-pagination-bullet {
  187. --swiper-pagination-bullet-width: 20px;
  188. --swiper-pagination-bullet-height: 4px;
  189. border-radius: 0;
  190. }
  191. }
  192. }
  193. </style>