MinimapModal.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, ref, watch } from "vue";
  19. import { store } from "./store";
  20. // 切换任务后,关闭缩略图
  21. watch(
  22. () => store.currentTask,
  23. () => {
  24. close();
  25. }
  26. );
  27. const imagesHtml = ref("");
  28. onBeforeUpdate(() => {
  29. imagesHtml.value =
  30. document.querySelector(".mark-body-container div:first-of-type")
  31. ?.innerHTML ?? "请关闭或重新打开";
  32. // 没取到图片,提示
  33. // if (imagesHtml.value.length <= 500) {
  34. // imagesHtml.value = "请关闭或重新打开";
  35. // }
  36. // console.log(imagesHtml);
  37. });
  38. const setScrollTo = (e: MouseEvent) => {
  39. const target = e.target as HTMLElement;
  40. const container = target.parentElement?.parentElement as HTMLDivElement;
  41. const containerPos = container.getBoundingClientRect();
  42. const parent = target.parentElement as HTMLDivElement;
  43. const parentPos = parent.getBoundingClientRect();
  44. // console.log(containerPos, parentPos);
  45. // 试验出来的... 大概就是2个顶部距离相减,得到相对距离
  46. const scrollToX =
  47. (e.offsetX + parentPos.x - containerPos.x) /
  48. parseFloat(getComputedStyle(container).width);
  49. const scrollToY =
  50. (e.offsetY + parentPos.y - containerPos.y) /
  51. parseFloat(getComputedStyle(container).height);
  52. if (typeof scrollToX === "number" && typeof scrollToY === "number") {
  53. store.minimapScrollToX = scrollToX;
  54. store.minimapScrollToY = scrollToY;
  55. }
  56. };
  57. const close = () => {
  58. store.setting.uiSetting["minimap.modal"] = false;
  59. };
  60. </script>
  61. <style>
  62. .mini-map-container {
  63. background-image: linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
  64. linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
  65. linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
  66. linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  67. background-size: 20px 20px;
  68. background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  69. }
  70. .mini-map-container div div:not(.single-image-container) {
  71. display: none;
  72. }
  73. .mini-map-container .ant-spin-container > div {
  74. width: 100% !important;
  75. }
  76. .mini-map-container .score-container {
  77. display: none;
  78. }
  79. </style>