MinimapModal.vue 2.1 KB

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