MarkDrawTrack.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <template v-for="(track, index) in trackList" :key="index">
  3. <div
  4. class="score-container"
  5. :class="[focusedTrack(track) && 'score-animation']"
  6. :style="computeTopAndLeft(track)"
  7. >
  8. <span
  9. class="tw-m-auto"
  10. :id="'a' + track.mainNumber + track.subNumber + track.offsetY"
  11. >
  12. {{ track.score }}
  13. </span>
  14. </div>
  15. </template>
  16. <template v-for="(tag, index) in specialTagList" :key="index">
  17. <div class="score-container" :style="computeTopAndLeft(tag)">
  18. <span class="tw-m-auto">
  19. {{ tag.tagName }}
  20. </span>
  21. </div>
  22. </template>
  23. </template>
  24. <script setup lang="ts">
  25. import type { SpecialTag, Track } from "@/types";
  26. import { store } from "@/features/mark/store";
  27. import { toRefs, watch } from "vue";
  28. const props = defineProps<{
  29. trackList: Array<Track>;
  30. specialTagList: Array<SpecialTag>;
  31. originalImage: HTMLImageElement;
  32. }>();
  33. const { trackList, originalImage } = toRefs(props);
  34. const focusedTrack = (track: Track) => {
  35. return store.focusTracks.includes(track);
  36. };
  37. const computeTopAndLeft = (track: Track | SpecialTag) => {
  38. const topInsideSlice = track.offsetY;
  39. const leftInsideSlice = track.offsetX;
  40. return {
  41. top: (topInsideSlice / originalImage.value.naturalHeight) * 100 + "%",
  42. left: (leftInsideSlice / originalImage.value.naturalWidth) * 100 + "%",
  43. "font-size": store.setting.uiSetting["answer.paper.scale"] * 2.2 + "em",
  44. };
  45. };
  46. watch(
  47. () => store.focusTracks.length,
  48. () => {
  49. if (store.focusTracks.length === 0) return;
  50. const minImageIndex = Math.min(
  51. ...store.focusTracks.map((t) => t.offsetIndex)
  52. );
  53. const minImageOffsetY = Math.min(
  54. ...store.focusTracks
  55. .filter((t) => t.offsetIndex === minImageIndex)
  56. .map((t) => t.offsetY)
  57. );
  58. const topTrack = store.focusTracks.find(
  59. (t) => t.offsetIndex === minImageIndex && t.offsetY === minImageOffsetY
  60. );
  61. if (topTrack) {
  62. document
  63. .querySelector(
  64. `#a${topTrack.mainNumber + topTrack.subNumber + topTrack.offsetY}`
  65. )
  66. ?.scrollIntoView({ behavior: "smooth" });
  67. }
  68. }
  69. );
  70. </script>
  71. <style scoped>
  72. .score-container {
  73. position: absolute;
  74. display: flex;
  75. place-content: center;
  76. color: red;
  77. /* to center score */
  78. width: 200px;
  79. height: 200px;
  80. margin-top: -100px;
  81. margin-left: -100px;
  82. /* to click through div */
  83. pointer-events: none;
  84. }
  85. .score-animation {
  86. animation: 2s ease-in-out 0s infinite alternate change_size;
  87. }
  88. @keyframes change_size {
  89. from {
  90. font-size: 2em;
  91. margin-top: -100px;
  92. margin-left: -100px;
  93. }
  94. to {
  95. font-size: 4em;
  96. margin-top: -80px;
  97. margin-left: -80px;
  98. }
  99. }
  100. </style>