MarkDrawTrack.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. :id="`a-${track.mainNumber}-${track.subNumber}-${track.offsetY}-${track.offsetX}`"
  10. class="tw-m-auto"
  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 "@/store/store";
  27. import { toRefs, watch } from "vue";
  28. import { message } from "ant-design-vue";
  29. const props = defineProps<{
  30. trackList: Array<Track>;
  31. specialTagList: Array<SpecialTag>;
  32. originalImageWidth: number;
  33. originalImageHeight: number;
  34. }>();
  35. const { trackList } = toRefs(props);
  36. const focusedTrack = (track: Track) => {
  37. return store.focusTracks.includes(track);
  38. };
  39. const computeTopAndLeft = (track: Track | SpecialTag) => {
  40. const topInsideSlice = track.offsetY;
  41. const leftInsideSlice = track.offsetX;
  42. const topInsideSliceRatio = topInsideSlice / props.originalImageHeight;
  43. const leftInsideSliceRatio = leftInsideSlice / props.originalImageWidth;
  44. if (
  45. topInsideSliceRatio < 0 ||
  46. topInsideSliceRatio > 1 ||
  47. leftInsideSliceRatio < 0 ||
  48. leftInsideSliceRatio > 1
  49. ) {
  50. void message.error("轨迹坐标有误,可能是图片被修改过,请联系管理员!");
  51. }
  52. return {
  53. top: topInsideSliceRatio * 100 + "%",
  54. left: leftInsideSliceRatio * 100 + "%",
  55. "font-size":
  56. (store.setting.uiSetting["score.fontSize.scale"] || 1) *
  57. store.setting.uiSetting["answer.paper.scale"] *
  58. 2.2 +
  59. "em",
  60. };
  61. };
  62. watch(
  63. () => store.focusTracks.length,
  64. () => {
  65. if (store.focusTracks.length === 0) return;
  66. const minImageIndex = Math.min(
  67. ...store.focusTracks.map((t) => t.offsetIndex)
  68. );
  69. const minImageOffsetY = Math.min(
  70. ...store.focusTracks
  71. .filter((t) => t.offsetIndex === minImageIndex)
  72. .map((t) => t.offsetY)
  73. );
  74. const topTrack = store.focusTracks.find(
  75. (t) => t.offsetIndex === minImageIndex && t.offsetY === minImageOffsetY
  76. );
  77. if (topTrack) {
  78. document
  79. .querySelector(
  80. `#a-${topTrack.mainNumber}-${topTrack.subNumber}-${topTrack.offsetY}-${topTrack.offsetX}`
  81. )
  82. ?.scrollIntoView({ behavior: "smooth" });
  83. }
  84. }
  85. );
  86. </script>
  87. <style scoped>
  88. .score-container {
  89. position: absolute;
  90. display: flex;
  91. place-content: center;
  92. color: red;
  93. /* to center score */
  94. width: 200px;
  95. height: 200px;
  96. margin-top: -100px;
  97. margin-left: -100px;
  98. /* to click through div */
  99. pointer-events: none;
  100. }
  101. .score-animation {
  102. animation: 2s ease-in-out 0s infinite alternate change_size;
  103. }
  104. @keyframes change_size {
  105. from {
  106. font-size: 2em;
  107. margin-top: -100px;
  108. margin-left: -100px;
  109. }
  110. to {
  111. font-size: 4em;
  112. margin-top: -80px;
  113. margin-left: -80px;
  114. }
  115. }
  116. </style>