MarkDrawTrack.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <transition-group name="track-score" tag="div">
  3. <template v-for="track in trackList">
  4. <div
  5. v-if="store.shouldShowTrack"
  6. :key="`key-${track.mainNumber}-${track.subNumber}-${track.offsetY}-${track.offsetX}`"
  7. class="score-container"
  8. :class="[focusedTrack(track) && 'score-animation']"
  9. :style="computeTopAndLeft(track)"
  10. >
  11. <span
  12. :id="`a-${track.mainNumber}-${track.subNumber}-${track.offsetY}-${track.offsetX}`"
  13. class="tw-m-auto"
  14. >
  15. {{ track.unanswered ? "空" : track.score }}
  16. </span>
  17. </div>
  18. </template>
  19. </transition-group>
  20. <template v-for="(tag, index) in specialTagList" :key="index">
  21. <div class="score-container" :style="computeTopAndLeft(tag)">
  22. <span class="tw-m-auto">
  23. {{ tag.tagName }}
  24. </span>
  25. </div>
  26. </template>
  27. </template>
  28. <script setup lang="ts">
  29. import type { SpecialTag, Track } from "@/types";
  30. import { toRefs, watch, nextTick } from "vue";
  31. import { store } from "@/store/store";
  32. import { message } from "ant-design-vue";
  33. const props = defineProps<{
  34. trackList: Array<Track>;
  35. specialTagList: Array<SpecialTag>;
  36. sliceImageWidth: number;
  37. sliceImageHeight: number;
  38. dx: number;
  39. dy: number;
  40. }>();
  41. const { trackList } = toRefs(props);
  42. const computeTopAndLeft = (track: Track | SpecialTag) => {
  43. const topInsideSlice = track.offsetY - props.dy;
  44. const leftInsideSlice = track.offsetX - props.dx;
  45. const topInsideSliceRatio = topInsideSlice / props.sliceImageHeight;
  46. const leftInsideSliceRatio = leftInsideSlice / props.sliceImageWidth;
  47. if (
  48. topInsideSliceRatio < 0 ||
  49. topInsideSliceRatio > 1 ||
  50. leftInsideSliceRatio < 0 ||
  51. leftInsideSliceRatio > 1
  52. ) {
  53. /** 解决message提示死循环的问题 */
  54. void nextTick(() => {
  55. void message.error("轨迹坐标有误,可能是图片被修改过,请联系管理员!");
  56. });
  57. }
  58. return {
  59. color: track.color || 'red',
  60. top: topInsideSliceRatio * 100 + "%",
  61. left: leftInsideSliceRatio * 100 + "%",
  62. "font-size":
  63. (store.setting.uiSetting["score.fontSize.scale"] || 1) *
  64. store.setting.uiSetting["answer.paper.scale"] *
  65. 2.2 +
  66. "em",
  67. };
  68. };
  69. const focusedTrack = (track: Track) => {
  70. return store.focusTracks.includes(track);
  71. };
  72. watch(
  73. () => store.focusTracks,
  74. () => {
  75. if (store.focusTracks.length === 0) return;
  76. const minImageIndex = Math.min(
  77. ...store.focusTracks.map((t) => t.offsetIndex)
  78. );
  79. const minImageOffsetY = Math.min(
  80. ...store.focusTracks
  81. .filter((t) => t.offsetIndex === minImageIndex)
  82. .map((t) => t.offsetY)
  83. );
  84. const topTrack = store.focusTracks.find(
  85. (t) => t.offsetIndex === minImageIndex && t.offsetY === minImageOffsetY
  86. );
  87. if (topTrack) {
  88. document
  89. .querySelector(
  90. `#a-${topTrack.mainNumber}-${topTrack.subNumber}-${topTrack.offsetY}-${topTrack.offsetX}`
  91. )
  92. ?.scrollIntoView({ behavior: "smooth" });
  93. }
  94. },
  95. {
  96. deep: true
  97. }
  98. );
  99. </script>
  100. <style scoped>
  101. .score-container {
  102. position: absolute;
  103. display: flex;
  104. place-content: center;
  105. /* color: red; */
  106. /* to center score */
  107. width: 200px;
  108. height: 200px;
  109. margin-top: -100px;
  110. margin-left: -100px;
  111. /* to click through div */
  112. pointer-events: none;
  113. }
  114. .score-animation {
  115. animation: 2s ease-in-out 0s infinite alternate change_size;
  116. }
  117. @keyframes change_size {
  118. from {
  119. font-size: 2em;
  120. margin-top: -100px;
  121. margin-left: -100px;
  122. }
  123. to {
  124. font-size: 4em;
  125. margin-top: -80px;
  126. margin-left: -80px;
  127. }
  128. }
  129. .track-score-enter-active {
  130. transition: opacity 0.3s ease;
  131. }
  132. .track-score-leave-active {
  133. transition: opacity 0.6s ease;
  134. }
  135. .track-score-enter-from,
  136. .track-score-leave-to {
  137. opacity: 0;
  138. }
  139. </style>