index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div>
  3. <div class="time-axis-container" :style="{ bottom: `${dragState.bottom}px`, left: `${dragState.left}px` }">
  4. <div class="expand-btn" @click="changeExpand">{{ timeAxisState.expand ? '收起' : '展开' }}</div>
  5. <div v-show="timeAxisState.expand" class="time-box">
  6. <div class="time-picker-box">
  7. <el-date-picker
  8. v-model="timeAxisState.startTime"
  9. type="datetime"
  10. :editable="false"
  11. :format="timeAxisState.format"
  12. :value-format="timeAxisState.format"
  13. :clearable="false"
  14. />
  15. <el-date-picker
  16. v-model="timeAxisState.endTime"
  17. type="datetime"
  18. :editable="false"
  19. :format="timeAxisState.format"
  20. :value-format="timeAxisState.format"
  21. :clearable="false"
  22. />
  23. </div>
  24. <div class="time-list-box">
  25. <el-timeline>
  26. <el-timeline-item
  27. v-for="(activity, index) in timeAxisState.data"
  28. :key="index"
  29. :class="timeAxisState.activeIndex === index ? 'active' : ''"
  30. :timestamp="activity.time"
  31. />
  32. </el-timeline>
  33. </div>
  34. <div class="time-tool">
  35. <div class="prevIcon" @click="toPrevTime" />
  36. <div class="playIcon" @click="toPlayTime" />
  37. <div class="nextIcon" @click="toNextTime(true)" />
  38. <div class="speed-btn" @click="changeSpeed">{{ timeAxisState.speed === 1 ? 'x1' : 'x2' }}</div>
  39. <div class="rankIcon" @mousedown="startDrag" @mousemove="onDrag" @mouseup="stopDrag" @click="dragMove" />
  40. </div>
  41. </div>
  42. </div>
  43. <Dialog v-model="timeAxisState.showDialog" title="气象图" hide-footer @close="dialogClose">
  44. <img v-show="timeAxisState.activeIndex > -1" :src="timeAxisState.data[timeAxisState.activeIndex]?.img" style="width: 100%" />
  45. </Dialog>
  46. </div>
  47. </template>
  48. <script lang="ts" setup name="TimeAxis">
  49. import { parseTime } from '@/utils/ruoyi';
  50. import Dialog from '@/components/Dialog/index.vue';
  51. import img1 from './tempImg/img1.jfif';
  52. import img2 from './tempImg/img2.jfif';
  53. import img3 from './tempImg/img3.jfif';
  54. import img4 from './tempImg/img4.jfif';
  55. import img5 from './tempImg/img5.jfif';
  56. import img6 from './tempImg/img6.jfif';
  57. import img7 from './tempImg/img7.jfif';
  58. import img8 from './tempImg/img8.jfif';
  59. import img9 from './tempImg/img9.jfif';
  60. import img10 from './tempImg/img10.jfif';
  61. const containerScale = inject('containerScale');
  62. const timeAxisState = reactive({
  63. expand: false,
  64. format: 'YYYY-MM-DD HH:mm',
  65. startTime: '',
  66. endTime: '',
  67. activeIndex: -1,
  68. playing: false,
  69. show: false,
  70. showDialog: false,
  71. speed: 1,
  72. data: [
  73. {
  74. time: '00:15',
  75. img: img1
  76. },
  77. {
  78. time: '01:15',
  79. img: img2
  80. },
  81. {
  82. time: '01:45',
  83. img: img3
  84. },
  85. {
  86. time: '02:15',
  87. img: img4
  88. },
  89. {
  90. time: '03:15',
  91. img: img5
  92. },
  93. {
  94. time: '04:15',
  95. img: img6
  96. },
  97. {
  98. time: '05:15',
  99. img: img7
  100. },
  101. {
  102. time: '06:15',
  103. img: img8
  104. },
  105. {
  106. time: '07:15',
  107. img: img9
  108. },
  109. {
  110. time: '07:45',
  111. img: img10
  112. }
  113. ]
  114. });
  115. let timer;
  116. // 展开收起
  117. const changeExpand = () => {
  118. timeAxisState.expand = !timeAxisState.expand;
  119. };
  120. // 设置初始时间
  121. const getInitTime = () => {
  122. // 获取当前时间
  123. const now = new Date();
  124. timeAxisState.endTime = parseTime(now.getTime(), '{y}-{m}-{d} {h}:{i}');
  125. // 计算12小时前的时间
  126. now.setHours(now.getHours() - 12);
  127. timeAxisState.startTime = parseTime(now.getTime(), '{y}-{m}-{d} {h}:{i}');
  128. };
  129. // 返回上一个时间点
  130. const toPrevTime = () => {
  131. timeAxisState.showDialog = true;
  132. timeAxisState.playing = false;
  133. if (timeAxisState.activeIndex === 0) {
  134. timeAxisState.playing = false;
  135. } else {
  136. timeAxisState.activeIndex -= 1;
  137. }
  138. };
  139. // 播放
  140. const toPlayTime = () => {
  141. timeAxisState.playing = true;
  142. if (timeAxisState.activeIndex === timeAxisState.data.length - 1) {
  143. timeAxisState.activeIndex = -1;
  144. }
  145. loopPlay();
  146. };
  147. // 循环播放
  148. const loopPlay = () => {
  149. if (timeAxisState.playing === false) return;
  150. toNextTime();
  151. // && timeAxisState.activeIndex < timeAxisState.data.length - 1
  152. if (timeAxisState.playing) {
  153. setTimeout(loopPlay, 1000 / timeAxisState.speed);
  154. }
  155. };
  156. // 前往下一个时间点
  157. const toNextTime = (flag?: boolean) => {
  158. timeAxisState.showDialog = true;
  159. if (flag) {
  160. timeAxisState.playing = false;
  161. } else if (!timeAxisState.playing) {
  162. return;
  163. }
  164. if (timeAxisState.activeIndex === timeAxisState.data?.length - 1) {
  165. timeAxisState.playing = false;
  166. } else {
  167. timeAxisState.activeIndex += 1;
  168. }
  169. };
  170. // 更换倍速
  171. const changeSpeed = () => {
  172. timeAxisState.speed = timeAxisState.speed === 1 ? 2 : 1;
  173. };
  174. // 拖拽移动位置
  175. const dragMove = () => {};
  176. // 弹窗关闭后
  177. const dialogClose = () => {
  178. timeAxisState.playing = false;
  179. };
  180. // 拖拽的参数
  181. const dragState = reactive({
  182. bottom: 180,
  183. left: 200,
  184. dragging: false,
  185. startX: 20,
  186. startY: 20,
  187. initialMouseX: 20,
  188. initialMouseY: 20
  189. });
  190. // 开始拖拽
  191. const startDrag = (event) => {
  192. dragState.dragging = true;
  193. dragState.startX = dragState.left;
  194. dragState.startY = dragState.bottom;
  195. dragState.initialMouseX = event.clientX;
  196. dragState.initialMouseY = event.clientY;
  197. document.addEventListener('mousemove', onDrag);
  198. document.addEventListener('mouseup', stopDrag2);
  199. };
  200. const onDrag = (event) => {
  201. if (!dragState.dragging) return;
  202. console.log(dragState.bottom + dragState.initialMouseY - event.clientY);
  203. console.log(dragState.bottom, dragState.initialMouseY, event.clientY);
  204. let left = (dragState.startX + event.clientX - dragState.initialMouseX) / containerScale().scaleX - 134;
  205. let bottom = (dragState.startY + dragState.initialMouseY - event.clientY) / containerScale().scaleY - 134;
  206. // // 检测是否溢出
  207. // if (left < 0) {
  208. // left = 0;
  209. // } else if (left > document.body.clientWidth - 1001) {
  210. // left = document.body.clientWidth - 1001;
  211. // }
  212. // if (bottom < 0) {
  213. // bottom = 0;
  214. // } else if (bottom > document.body.clientHeight - 70) {
  215. // bottom = document.body.clientHeight - 70;
  216. // }
  217. dragState.left = left;
  218. dragState.bottom = bottom;
  219. };
  220. const stopDrag = () => {
  221. dragState.dragging = false;
  222. };
  223. const stopDrag2 = () => {
  224. dragState.dragging = false;
  225. document.removeEventListener('mousemove', onDrag);
  226. document.removeEventListener('mouseup', stopDrag2);
  227. };
  228. onMounted(() => {
  229. getInitTime();
  230. });
  231. </script>
  232. <style lang="scss" scoped>
  233. .time-axis-container {
  234. position: absolute;
  235. z-index: 2;
  236. color: #fff;
  237. font-size: 16px;
  238. height: 131px;
  239. display: flex;
  240. &::before {
  241. content: '';
  242. position: absolute;
  243. top: 50%;
  244. left: -15px;
  245. transform: translateY(-50%);
  246. width: 9px;
  247. height: 142px;
  248. background: url('@/assets/images/timeAxis/timeLeft.png') no-repeat;
  249. background-size: 100% 100%;
  250. }
  251. &::after {
  252. content: '';
  253. position: absolute;
  254. top: 50%;
  255. right: -15px;
  256. transform: translateY(-50%);
  257. width: 9px;
  258. height: 142px;
  259. background: url('@/assets/images/timeAxis/timeRight.png') no-repeat;
  260. }
  261. .expand-btn {
  262. width: 61px;
  263. height: 131px;
  264. background: url('@/assets/images/timeAxis/timeBtn.png') no-repeat;
  265. display: flex;
  266. justify-content: center;
  267. align-items: center;
  268. padding: 0 16px;
  269. cursor: pointer;
  270. font-size: 30px;
  271. }
  272. .time-box {
  273. width: 2640px;
  274. height: 158px;
  275. background: url('@/assets/images/timeAxis/timeAxis.png') no-repeat;
  276. display: flex;
  277. }
  278. .time-picker-box {
  279. width: 257px;
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. flex-direction: column;
  284. padding: 10px;
  285. :deep(.el-date-editor.el-input) {
  286. width: 257px;
  287. height: 50px;
  288. font-size: 30px;
  289. }
  290. :deep(.el-input__wrapper) {
  291. background-color: transparent;
  292. border: unset;
  293. box-shadow: unset;
  294. }
  295. :deep(.el-input__inner) {
  296. color: #b5dbfc;
  297. cursor: pointer;
  298. }
  299. :deep(.el-input__prefix) {
  300. display: none;
  301. }
  302. }
  303. .time-list-box {
  304. flex: 1;
  305. display: flex;
  306. align-items: flex-end;
  307. overflow-x: auto;
  308. padding: 0 20px;
  309. .active {
  310. :deep(.el-timeline-item__node) {
  311. background-color: #ff0000;
  312. box-shadow: 0 0 8px 8px #f68686;
  313. }
  314. }
  315. :deep(.el-timeline) {
  316. display: flex;
  317. align-items: center;
  318. width: 100%;
  319. height: 100%;
  320. padding-top: 30px;
  321. }
  322. :deep(.el-timeline-item__tail) {
  323. height: 13px;
  324. //background-color: #1f54b6;
  325. background-image: linear-gradient(to bottom, #1064d6 10%, #1876be 50%, #1064d6 90%);
  326. width: 100%;
  327. position: absolute;
  328. top: 3px;
  329. }
  330. :deep(.el-timeline-item__wrapper) {
  331. top: 10px;
  332. left: -42px;
  333. padding-left: 0;
  334. }
  335. :deep(.el-timeline-item__timestamp) {
  336. font-size: 30px;
  337. color: #ffffff;
  338. font-family: 'PingFang SC', sans-serif;
  339. margin-top: 33px;
  340. }
  341. :deep(.el-timeline-item__node) {
  342. background-color: #ffffff;
  343. box-shadow: 0 0 8px 8px #569eff;
  344. width: 16px !important;
  345. height: 16px !important;
  346. }
  347. :deep(.el-timeline-item) {
  348. width: 120px;
  349. min-width: 120px;
  350. }
  351. }
  352. .time-tool {
  353. width: 457px;
  354. display: flex;
  355. align-items: center;
  356. padding: 0 5px;
  357. .tool-icon {
  358. margin-right: 5px;
  359. cursor: pointer;
  360. font-size: 20px;
  361. }
  362. .speed-btn {
  363. margin-right: 5px;
  364. color: #ffffff;
  365. cursor: pointer;
  366. font-size: 40px;
  367. padding-bottom: 10px;
  368. font-family: 'PingFang SC', sans-serif;
  369. }
  370. .prevIcon {
  371. width: 69px;
  372. height: 73px;
  373. background: url('@/assets/images/timeAxis/prev.png') no-repeat;
  374. cursor: pointer;
  375. }
  376. .playIcon {
  377. width: 93px;
  378. height: 93px;
  379. background: url('@/assets/images/timeAxis/play.png') no-repeat;
  380. cursor: pointer;
  381. }
  382. .nextIcon {
  383. width: 69px;
  384. height: 73px;
  385. background: url('@/assets/images/timeAxis/next.png') no-repeat;
  386. cursor: pointer;
  387. }
  388. .rankIcon {
  389. width: 104px;
  390. height: 104px;
  391. background: url('@/assets/images/timeAxis/rank.png') no-repeat;
  392. cursor: pointer;
  393. margin-left: 50px;
  394. }
  395. }
  396. }
  397. </style>