2
0

MinimapModal.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <qm-dialog
  3. v-if="store.setting.uiSetting['minimap.modal']"
  4. top="10%"
  5. width="200px"
  6. height="500px"
  7. title="缩略图"
  8. @close="close"
  9. >
  10. <div
  11. class="mini-map-container"
  12. v-html="imagesHtml"
  13. @click.stop="setScrollTo"
  14. ></div>
  15. </qm-dialog>
  16. </template>
  17. <script setup lang="ts">
  18. import { onBeforeUpdate, watch } from "vue";
  19. import { store } from "@/store/store";
  20. // 切换任务后,关闭缩略图
  21. watch(
  22. () => store.currentTask,
  23. () => {
  24. close();
  25. }
  26. );
  27. let imagesHtml = $ref("");
  28. onBeforeUpdate(() => {
  29. imagesHtml =
  30. document.querySelector(".mark-body-container div:first-of-type")
  31. ?.innerHTML ?? "请关闭或重新打开";
  32. });
  33. const setScrollTo = (e: MouseEvent) => {
  34. const target = e.target as HTMLElement;
  35. const container = target.parentElement?.parentElement as HTMLDivElement;
  36. const containerPos = container.getBoundingClientRect();
  37. const parent = target.parentElement as HTMLDivElement;
  38. const parentPos = parent.getBoundingClientRect();
  39. // console.log(containerPos, parentPos);
  40. // 试验出来的... 大概就是2个顶部距离相减,得到相对距离
  41. const scrollToX =
  42. (e.offsetX + parentPos.x - containerPos.x) /
  43. parseFloat(getComputedStyle(container).width);
  44. const scrollToY =
  45. (e.offsetY + parentPos.y - containerPos.y) /
  46. parseFloat(getComputedStyle(container).height);
  47. if (typeof scrollToX === "number" && typeof scrollToY === "number") {
  48. store.minimapScrollToX = scrollToX;
  49. store.minimapScrollToY = scrollToY;
  50. }
  51. };
  52. const close = () => {
  53. store.setting.uiSetting["minimap.modal"] = false;
  54. };
  55. </script>
  56. <style>
  57. .mini-map-container {
  58. background-image: linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
  59. linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
  60. linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
  61. linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  62. background-size: 20px 20px;
  63. background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  64. }
  65. .mini-map-container div div:not(.single-image-container) {
  66. display: none;
  67. }
  68. .mini-map-container .ant-spin-container > div {
  69. width: 100% !important;
  70. }
  71. .mini-map-container .score-container {
  72. display: none;
  73. }
  74. </style>