MarkDrawTrack.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. top: topInsideSliceRatio * 100 + "%",
  60. left: leftInsideSliceRatio * 100 + "%",
  61. "font-size":
  62. (store.setting.uiSetting["score.fontSize.scale"] || 1) *
  63. store.setting.uiSetting["answer.paper.scale"] *
  64. 2.2 +
  65. "em",
  66. };
  67. };
  68. const focusedTrack = (track: Track) => {
  69. return store.focusTracks.includes(track);
  70. };
  71. watch(
  72. () => store.focusTracks.length,
  73. () => {
  74. if (store.focusTracks.length === 0) return;
  75. const minImageIndex = Math.min(
  76. ...store.focusTracks.map((t) => t.offsetIndex)
  77. );
  78. const minImageOffsetY = Math.min(
  79. ...store.focusTracks
  80. .filter((t) => t.offsetIndex === minImageIndex)
  81. .map((t) => t.offsetY)
  82. );
  83. const topTrack = store.focusTracks.find(
  84. (t) => t.offsetIndex === minImageIndex && t.offsetY === minImageOffsetY
  85. );
  86. if (topTrack) {
  87. document
  88. .querySelector(
  89. `#a-${topTrack.mainNumber}-${topTrack.subNumber}-${topTrack.offsetY}-${topTrack.offsetX}`
  90. )
  91. ?.scrollIntoView({ behavior: "smooth" });
  92. }
  93. }
  94. );
  95. </script>
  96. <style scoped>
  97. .score-container {
  98. position: absolute;
  99. display: flex;
  100. place-content: center;
  101. color: red;
  102. /* to center score */
  103. width: 200px;
  104. height: 200px;
  105. margin-top: -100px;
  106. margin-left: -100px;
  107. /* to click through div */
  108. pointer-events: none;
  109. }
  110. .score-animation {
  111. animation: 2s ease-in-out 0s infinite alternate change_size;
  112. }
  113. @keyframes change_size {
  114. from {
  115. font-size: 2em;
  116. margin-top: -100px;
  117. margin-left: -100px;
  118. }
  119. to {
  120. font-size: 4em;
  121. margin-top: -80px;
  122. margin-left: -80px;
  123. }
  124. }
  125. .track-score-enter-active {
  126. transition: opacity 0.3s ease;
  127. }
  128. .track-score-leave-active {
  129. transition: opacity 0.6s ease;
  130. }
  131. .track-score-enter-from,
  132. .track-score-leave-to {
  133. opacity: 0;
  134. }
  135. </style>