CommonMarkBody.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. <template>
  2. <div class="mark-body">
  3. <div v-if="markStatus" class="mark-body-status">
  4. {{ markStatus }}
  5. </div>
  6. <div ref="dragContainer" class="mark-body-container">
  7. <div v-if="!store.currentTask" class="mark-body-none">
  8. <div>
  9. <img src="@/assets/image-none-task.png" />
  10. <p>
  11. {{ store.message }}
  12. </p>
  13. </div>
  14. </div>
  15. <div
  16. v-else-if="store.isScanImage"
  17. :style="{ width: answerPaperScale }"
  18. :class="[`rotate-board-${rotateBoard}`]"
  19. >
  20. <template
  21. v-for="(item, index) in sliceImagesWithTrackList"
  22. :key="index"
  23. >
  24. <div class="single-image-container">
  25. <img
  26. :src="item.url"
  27. draggable="false"
  28. @click="(event) => innerMakeTrack(event, item)"
  29. @contextmenu="showBigImage"
  30. />
  31. <MarkDrawTrack
  32. :trackList="item.trackList"
  33. :specialTagList="item.tagList"
  34. :sliceImageWidth="item.sliceImageWidth"
  35. :sliceImageHeight="item.sliceImageHeight"
  36. :dx="item.dx"
  37. :dy="item.dy"
  38. @deleteSpecialtag="(tag) => deleteSpecialtag(item, tag)"
  39. @click-specialtag="(event) => clickSpecialtag(event, item)"
  40. />
  41. <div
  42. v-if="isCustomSpecialTag"
  43. class="image-canvas"
  44. v-ele-move-directive.stop.prevent="{
  45. moveStart: (event) => specialMouseStart(event, item),
  46. moveElement: specialMouseMove,
  47. moveStop: specialMouseStop,
  48. }"
  49. >
  50. <template v-if="curSliceImagesWithTrackItem?.url === item.url">
  51. <div
  52. v-if="store.currentSpecialTagType === 'LINE'"
  53. :style="specialLenStyle"
  54. ></div>
  55. <div
  56. v-if="store.currentSpecialTagType === 'CIRCLE'"
  57. :style="specialCircleStyle"
  58. ></div>
  59. </template>
  60. </div>
  61. </div>
  62. <hr class="image-seperator" />
  63. </template>
  64. </div>
  65. <div v-else-if="store.isMultiMedia">
  66. <MultiMediaMarkBody />
  67. </div>
  68. <div v-else>未知数据</div>
  69. </div>
  70. </div>
  71. </template>
  72. <script setup lang="ts">
  73. import { onMounted, onUnmounted, reactive, watch, watchEffect } from "vue";
  74. import { store } from "@/store/store";
  75. import MarkDrawTrack from "./MarkDrawTrack.vue";
  76. import type { SliceImage } from "@/types";
  77. import { useTimers } from "@/setups/useTimers";
  78. import {
  79. getDataUrlForSliceConfig,
  80. getDataUrlForSplitConfig,
  81. loadImage,
  82. } from "@/utils/utils";
  83. import { dragImage } from "./use/draggable";
  84. import MultiMediaMarkBody from "./MultiMediaMarkBody.vue";
  85. import "viewerjs/dist/viewer.css";
  86. import Viewer from "viewerjs";
  87. import { message } from "ant-design-vue";
  88. import EventBus from "@/plugins/eventBus";
  89. import { vEleMoveDirective } from "./use/eleMove";
  90. type MakeTrack = (
  91. event: MouseEvent,
  92. item: SliceImage,
  93. maxSliceWidth: number,
  94. theFinalHeight: number
  95. ) => void | (() => void);
  96. const {
  97. hasMarkResultToRender = false,
  98. makeTrack = () => console.debug("非评卷界面makeTrack没有意义"),
  99. } = defineProps<{
  100. hasMarkResultToRender?: boolean;
  101. makeTrack?: MakeTrack;
  102. }>();
  103. const emit = defineEmits(["error"]);
  104. //#region : 图片拖动。在轨迹模式下,仅当没有选择分数时可用。
  105. const { dragContainer } = dragImage();
  106. //#endregion : 图片拖动
  107. const { addTimeout } = useTimers();
  108. //#region : 缩略图定位
  109. watch(
  110. () => [store.minimapScrollToX, store.minimapScrollToY],
  111. () => {
  112. const container = document.querySelector<HTMLDivElement>(
  113. ".mark-body-container"
  114. );
  115. addTimeout(() => {
  116. if (
  117. container &&
  118. typeof store.minimapScrollToX === "number" &&
  119. typeof store.minimapScrollToY === "number"
  120. ) {
  121. const { scrollWidth, scrollHeight } = container;
  122. container.scrollTo({
  123. top: scrollHeight * store.minimapScrollToY,
  124. left: scrollWidth * store.minimapScrollToX,
  125. behavior: "smooth",
  126. });
  127. }
  128. }, 10);
  129. }
  130. );
  131. //#endregion : 缩略图定位
  132. //#region : 快捷键定位
  133. const scrollContainerByKey = (e: KeyboardEvent) => {
  134. const container = document.querySelector<HTMLDivElement>(
  135. ".mark-body-container"
  136. );
  137. if (!container) {
  138. return;
  139. }
  140. if (e.key === "w") {
  141. container.scrollBy({ top: -100, behavior: "smooth" });
  142. } else if (e.key === "s") {
  143. container.scrollBy({ top: 100, behavior: "smooth" });
  144. } else if (e.key === "a") {
  145. container.scrollBy({ left: -100, behavior: "smooth" });
  146. } else if (e.key === "d") {
  147. container.scrollBy({ left: 100, behavior: "smooth" });
  148. }
  149. };
  150. onMounted(() => {
  151. document.addEventListener("keypress", scrollContainerByKey);
  152. });
  153. onUnmounted(() => {
  154. document.removeEventListener("keypress", scrollContainerByKey);
  155. });
  156. //#endregion : 快捷键定位
  157. //#region : 计算裁切图和裁切图上的分数轨迹和特殊标记轨迹
  158. let rotateBoard = $ref(0);
  159. let sliceImagesWithTrackList: SliceImage[] = reactive([]);
  160. let maxSliceWidth = 0; // 最大的裁切块宽度,图片容器以此为准
  161. let theFinalHeight = 0; // 最终宽度,用来定位轨迹在第几张图片,不包括image-seperator高度
  162. watch(
  163. () => sliceImagesWithTrackList,
  164. () => {
  165. EventBus.emit("draw-change", sliceImagesWithTrackList);
  166. },
  167. { deep: true }
  168. );
  169. async function processSliceConfig() {
  170. if (!store.currentTask) return;
  171. let markResult = store.currentTask.markResult;
  172. if (hasMarkResultToRender) {
  173. // check if have MarkResult for currentTask
  174. if (!markResult) return;
  175. }
  176. const images = [];
  177. // 必须要先加载一遍,把“选择整图”的宽高重置后,再算总高度
  178. // 错误的搞法,张莹坚持要用
  179. const sliceNum = store.currentTask.sliceUrls.length;
  180. if (store.currentTask.sliceConfig.some((v) => v.i > sliceNum)) {
  181. console.warn("裁切图设置的数量小于该学生的总图片数量");
  182. }
  183. store.currentTask.sliceConfig = store.currentTask.sliceConfig.filter(
  184. (v) => v.i <= sliceNum
  185. );
  186. for (const sliceConfig of store.currentTask.sliceConfig) {
  187. const url = store.currentTask.sliceUrls[sliceConfig.i - 1];
  188. const image = await loadImage(url);
  189. images[sliceConfig.i] = image;
  190. const { x, y, w, h } = sliceConfig;
  191. x < 0 && (sliceConfig.x = 0);
  192. y < 0 && (sliceConfig.y = 0);
  193. if (sliceConfig.w === 0 && sliceConfig.h === 0) {
  194. // 选择整图时,w/h 为0
  195. sliceConfig.w = image.naturalWidth;
  196. sliceConfig.h = image.naturalHeight;
  197. }
  198. if (x <= 1 && y <= 1 && sliceConfig.w <= 1 && sliceConfig.h <= 1) {
  199. sliceConfig.x = image.naturalWidth * x;
  200. sliceConfig.y = image.naturalHeight * y;
  201. sliceConfig.w = image.naturalWidth * w;
  202. sliceConfig.h = image.naturalHeight * h;
  203. }
  204. }
  205. theFinalHeight = store.currentTask.sliceConfig
  206. .map((v) => v.h)
  207. .reduce((acc, v) => (acc += v));
  208. maxSliceWidth = Math.max(...store.currentTask.sliceConfig.map((v) => v.w));
  209. // 用来保存sliceImage在整个图片容器中(不包括image-seperator)的高度范围
  210. let accumTopHeight = 0;
  211. let accumBottomHeight = 0;
  212. const trackLists = hasMarkResultToRender
  213. ? markResult.trackList
  214. : store.currentTask.questionList.map((q) => q.trackList).flat();
  215. const tagLists = hasMarkResultToRender
  216. ? markResult.specialTagList ?? []
  217. : store.currentTask.specialTagList ?? [];
  218. const tempSliceImagesWithTrackList: Array<SliceImage> = [];
  219. for (const sliceConfig of store.currentTask.sliceConfig) {
  220. accumBottomHeight += sliceConfig.h;
  221. const url = store.currentTask.sliceUrls[sliceConfig.i - 1];
  222. const indexInSliceUrls = sliceConfig.i;
  223. const image = images[sliceConfig.i];
  224. const dataUrl = await getDataUrlForSliceConfig(
  225. image,
  226. sliceConfig,
  227. maxSliceWidth,
  228. url
  229. );
  230. const thisImageTrackList = trackLists.filter(
  231. (t) => t.offsetIndex === indexInSliceUrls
  232. );
  233. const thisImageTagList = tagLists.filter(
  234. (t) => t.offsetIndex === indexInSliceUrls
  235. );
  236. const sliceImageRendered = await loadImage(dataUrl);
  237. tempSliceImagesWithTrackList.push({
  238. url: dataUrl,
  239. indexInSliceUrls: sliceConfig.i,
  240. // 通过positionY来定位是第几张slice的还原,并过滤出相应的track
  241. trackList: thisImageTrackList.filter(
  242. (t) =>
  243. t.positionY >= accumTopHeight / theFinalHeight &&
  244. t.positionY < accumBottomHeight / theFinalHeight
  245. ),
  246. tagList: thisImageTagList.filter(
  247. (t) =>
  248. t.positionY >= accumTopHeight / theFinalHeight &&
  249. t.positionY < accumBottomHeight / theFinalHeight
  250. ),
  251. // originalImageWidth: image.naturalWidth,
  252. // originalImageHeight: image.naturalHeight,
  253. sliceImageWidth: sliceImageRendered.naturalWidth,
  254. sliceImageHeight: sliceImageRendered.naturalHeight,
  255. dx: sliceConfig.x,
  256. dy: sliceConfig.y,
  257. accumTopHeight,
  258. effectiveWidth: sliceConfig.w,
  259. });
  260. accumTopHeight = accumBottomHeight;
  261. }
  262. // 测试是否所有的track和tag都在待渲染的tempSliceImagesWithTrackList中
  263. const numOfTrackAndTagInData = trackLists.length + tagLists.length;
  264. const numOfTrackAndTagInTempSlice = tempSliceImagesWithTrackList
  265. .map((v) => v.trackList.length + v.tagList.length)
  266. .reduce((p, c) => p + c);
  267. if (numOfTrackAndTagInData !== numOfTrackAndTagInTempSlice) {
  268. console.warn({ tagLists, trackLists, tempSliceImagesWithTrackList });
  269. void message.warn("渲染轨迹数量与实际数量不一致");
  270. }
  271. // console.log("render: ", store.currentTask.secretNumber);
  272. if (sliceImagesWithTrackList.length === 0) {
  273. // 初次渲染,不做动画
  274. sliceImagesWithTrackList.push(...tempSliceImagesWithTrackList);
  275. // 没抽象好,这里不好做校验
  276. // const renderedTrackAndTagNumber = sliceImagesWithTrackList.map(s => s.trackList.length + s.tagList.length).reduce((p,c) => p+ c);
  277. // if(renderedTrackAndTagNumber === thisIma)
  278. } else {
  279. rotateBoard = 1;
  280. setTimeout(() => {
  281. sliceImagesWithTrackList.splice(0);
  282. sliceImagesWithTrackList.push(...tempSliceImagesWithTrackList);
  283. setTimeout(() => {
  284. rotateBoard = 0;
  285. }, 300);
  286. }, 300);
  287. }
  288. }
  289. async function processSplitConfig() {
  290. if (!store.currentTask) return;
  291. let markResult = store.currentTask.markResult;
  292. if (hasMarkResultToRender) {
  293. // check if have MarkResult for currentTask
  294. if (!markResult) return;
  295. }
  296. const images = [];
  297. for (const url of store.currentTask.sliceUrls) {
  298. const image = await loadImage(url);
  299. images.push(image);
  300. }
  301. // 如果拒绝裁切,则保持整卷
  302. if (!store.setting.enableSplit) {
  303. store.setting.splitConfig = [0, 1];
  304. }
  305. // 裁切块,可能是一块,两块,三块... [start, width ...] => [0, 0.3] | [0, 0.55, 0.45, 0.55] | [0, 0.35, 0.33, 0.35, 0.66, 0.35]
  306. // 要转变为 [[0, 0.3]] | [[0, 0.55], [0.45, 0.55]] | [[0, 0.35], [0.33, 0.35], [0.66, 0.35]]
  307. const splitConfigPairs = store.setting.splitConfig.reduce<[number, number][]>(
  308. (a, v, index) => {
  309. // 偶数位组成数组的第一位,奇数位组成数组的第二位
  310. index % 2 === 0 ? a.push([v, -1]) : (a.at(-1)![1] = v);
  311. return a;
  312. },
  313. []
  314. );
  315. // 最大的 splitConfig 的宽度
  316. const maxSplitConfig = Math.max(
  317. ...store.setting.splitConfig.filter((v, i) => i % 2)
  318. );
  319. maxSliceWidth =
  320. Math.max(...images.map((v) => v.naturalWidth)) * maxSplitConfig;
  321. theFinalHeight =
  322. splitConfigPairs.length *
  323. images.reduce((acc, v) => (acc += v.naturalHeight), 0);
  324. // 高度比宽度大的图片不裁切
  325. const imagesOfBiggerHeight = images.filter(
  326. (v) => v.naturalHeight > v.naturalWidth
  327. );
  328. if (imagesOfBiggerHeight.length > 0) {
  329. maxSliceWidth = Math.max(
  330. maxSliceWidth,
  331. ...imagesOfBiggerHeight.map((v) => v.naturalWidth)
  332. );
  333. // 不裁切的图剪切多加的高度
  334. theFinalHeight -=
  335. imagesOfBiggerHeight.map((v) => v.naturalHeight).reduce((p, c) => p + c) *
  336. (splitConfigPairs.length - 1);
  337. }
  338. let accumTopHeight = 0;
  339. let accumBottomHeight = 0;
  340. const tempSliceImagesWithTrackList: SliceImage[] = [];
  341. const trackLists = hasMarkResultToRender
  342. ? markResult.trackList
  343. : (store.currentTask.questionList || []).map((q) => q.trackList).flat();
  344. const tagLists = hasMarkResultToRender
  345. ? markResult.specialTagList ?? []
  346. : store.currentTask.specialTagList ?? [];
  347. for (const url of store.currentTask.sliceUrls) {
  348. for (const config of splitConfigPairs) {
  349. const indexInSliceUrls = store.currentTask.sliceUrls.indexOf(url) + 1;
  350. const image = images[indexInSliceUrls - 1];
  351. let shouldBreak = false;
  352. let [splitConfigStart, splitConfigEnd] = config;
  353. if (image.naturalHeight > image.naturalWidth) {
  354. splitConfigStart = 0;
  355. splitConfigEnd = 1;
  356. shouldBreak = true;
  357. }
  358. accumBottomHeight += image.naturalHeight;
  359. const dataUrl = await getDataUrlForSplitConfig(
  360. image,
  361. [splitConfigStart, splitConfigEnd],
  362. maxSliceWidth,
  363. url
  364. );
  365. const thisImageTrackList = trackLists.filter(
  366. (t) => t.offsetIndex === indexInSliceUrls
  367. );
  368. const thisImageTagList = tagLists.filter(
  369. (t) => t.offsetIndex === indexInSliceUrls
  370. );
  371. const sliceImageRendered = await loadImage(dataUrl);
  372. tempSliceImagesWithTrackList.push({
  373. url: dataUrl,
  374. indexInSliceUrls: store.currentTask.sliceUrls.indexOf(url) + 1,
  375. trackList: thisImageTrackList.filter(
  376. (t) =>
  377. t.positionY >= accumTopHeight / theFinalHeight &&
  378. t.positionY < accumBottomHeight / theFinalHeight
  379. ),
  380. tagList: thisImageTagList.filter(
  381. (t) =>
  382. t.positionY >= accumTopHeight / theFinalHeight &&
  383. t.positionY < accumBottomHeight / theFinalHeight
  384. ),
  385. // originalImageWidth: image.naturalWidth,
  386. // originalImageHeight: image.naturalHeight,
  387. sliceImageWidth: sliceImageRendered.naturalWidth,
  388. sliceImageHeight: sliceImageRendered.naturalHeight,
  389. dx: image.naturalWidth * splitConfigStart,
  390. dy: 0,
  391. accumTopHeight,
  392. effectiveWidth: image.naturalWidth * splitConfigEnd,
  393. });
  394. accumTopHeight = accumBottomHeight;
  395. // 如果本图高比宽大,不该裁切,则跳过多次裁切
  396. if (shouldBreak) {
  397. break;
  398. }
  399. }
  400. }
  401. // 测试是否所有的track和tag都在待渲染的tempSliceImagesWithTrackList中
  402. const numOfTrackAndTagInData = trackLists.length + tagLists.length;
  403. const numOfTrackAndTagInTempSlice = tempSliceImagesWithTrackList
  404. .map((v) => v.trackList.length + v.tagList.length)
  405. .reduce((p, c) => p + c);
  406. if (numOfTrackAndTagInData !== numOfTrackAndTagInTempSlice) {
  407. console.warn({ tagLists, trackLists, tempSliceImagesWithTrackList });
  408. void message.warn("渲染轨迹数量与实际数量不一致");
  409. }
  410. rotateBoard = 1;
  411. addTimeout(() => {
  412. sliceImagesWithTrackList.splice(0);
  413. sliceImagesWithTrackList.push(...tempSliceImagesWithTrackList);
  414. addTimeout(() => {
  415. rotateBoard = 0;
  416. }, 300);
  417. }, 300);
  418. }
  419. const deleteSpecialtag = (item, tag) => {
  420. const findInd = (tagList, curTag) => {
  421. return tagList.findIndex(
  422. (itemTag) =>
  423. itemTag.tagName === curTag.tagName &&
  424. itemTag.offsetX === curTag.offsetX &&
  425. itemTag.offsetY === curTag.offsetY
  426. );
  427. };
  428. const tagIndex = findInd(item.tagList, tag);
  429. if (tagIndex === -1) return;
  430. item.tagList.splice(tagIndex, 1);
  431. const stagIndex = findInd(
  432. store.currentTaskEnsured.markResult.specialTagList,
  433. tag
  434. );
  435. if (stagIndex === -1) return;
  436. store.currentTaskEnsured.markResult.specialTagList.splice(tagIndex, 1);
  437. };
  438. const clickSpecialtag = (event: MouseEvent, item: SliceImage) => {
  439. // console.log(event);
  440. const e = {
  441. target: event.target.offsetParent.childNodes[0],
  442. offsetX: event.offsetX + event.target.offsetLeft,
  443. offsetY: event.offsetY + event.target.offsetTop,
  444. };
  445. makeTrack(e as MouseEvent, item, maxSliceWidth, theFinalHeight);
  446. };
  447. const clearEmptySpecialTag = (item) => {
  448. item.tagList
  449. .filter((item) => !item.tagName.trim().replace("\n", ""))
  450. .forEach((tag) => {
  451. deleteSpecialtag(item, tag);
  452. });
  453. };
  454. // should not render twice at the same time
  455. let renderLock = false;
  456. const renderPaperAndMark = async () => {
  457. // console.log("renderPagerAndMark=>store.curTask:", store.currentTask);
  458. if (!store.currentTask) return;
  459. if (!store.isScanImage) return;
  460. if (renderLock) {
  461. console.log("上个任务还未渲染完毕,稍等一秒再尝试渲染");
  462. await new Promise((res) => setTimeout(res, 1000));
  463. await renderPaperAndMark();
  464. return;
  465. }
  466. // check if have MarkResult for currentTask
  467. let markResult = store.currentTask.markResult;
  468. if (hasMarkResultToRender && !markResult) {
  469. return;
  470. }
  471. renderLock = true;
  472. try {
  473. store.globalMask = true;
  474. const hasSliceConfig = store.currentTask.sliceConfig?.length;
  475. if (hasSliceConfig) {
  476. await processSliceConfig();
  477. } else {
  478. await processSplitConfig();
  479. }
  480. // 研究生考试需要停留在上次阅卷的位置,所以注释掉下面的代码
  481. // await new Promise((res) => setTimeout(res, 700));
  482. // const container = <HTMLDivElement>(
  483. // document.querySelector(".mark-body-container")
  484. // );
  485. // addTimeout(() => {
  486. // container?.scrollTo({
  487. // top: 0,
  488. // left: 0,
  489. // behavior: "smooth",
  490. // });
  491. // }, 10);
  492. } catch (error) {
  493. sliceImagesWithTrackList.splice(0);
  494. console.trace("render error ", error);
  495. // 图片加载出错,自动加载下一个任务
  496. emit("error");
  497. } finally {
  498. renderLock = false;
  499. store.globalMask = false;
  500. }
  501. };
  502. // watchEffect(renderPaperAndMark);
  503. // 在阻止渲染的情况下,watchEffect收集不到 store.currentTask 的依赖,会导致本组件不再更新
  504. watch(
  505. () => store.currentTask,
  506. () => {
  507. setTimeout(renderPaperAndMark, 50);
  508. }
  509. );
  510. //#endregion : 计算裁切图和裁切图上的分数轨迹和特殊标记轨迹
  511. //#region : 放大缩小和之后的滚动
  512. const answerPaperScale = $computed(() => {
  513. // 放大、缩小不影响页面之前的滚动条定位
  514. let percentWidth = 0;
  515. let percentTop = 0;
  516. const container = document.querySelector(".mark-body-container");
  517. if (container) {
  518. const { scrollLeft, scrollTop, scrollWidth, scrollHeight } = container;
  519. percentWidth = scrollLeft / scrollWidth;
  520. percentTop = scrollTop / scrollHeight;
  521. }
  522. addTimeout(() => {
  523. if (container) {
  524. const { scrollWidth, scrollHeight } = container;
  525. container.scrollTo({
  526. left: scrollWidth * percentWidth,
  527. top: scrollHeight * percentTop,
  528. });
  529. }
  530. }, 10);
  531. const scale = store.setting.uiSetting["answer.paper.scale"];
  532. return scale * 100 + "%";
  533. });
  534. //#endregion : 放大缩小和之后的滚动
  535. //#region : 显示评分状态和清除轨迹
  536. let markStatus = $ref("");
  537. if (hasMarkResultToRender) {
  538. watch(
  539. () => store.currentTask,
  540. () => {
  541. markStatus = store.getMarkStatus;
  542. }
  543. );
  544. // 清除分数轨迹
  545. watchEffect(() => {
  546. for (const track of store.removeScoreTracks) {
  547. for (const sliceImage of sliceImagesWithTrackList) {
  548. sliceImage.trackList = sliceImage.trackList.filter(
  549. (t) =>
  550. !(
  551. t.mainNumber === track.mainNumber &&
  552. t.subNumber === track.subNumber &&
  553. t.number === track.number
  554. )
  555. );
  556. }
  557. }
  558. // 清除后,删除,否则会影响下次切换
  559. store.removeScoreTracks.splice(0);
  560. });
  561. // 清除特殊标记轨迹
  562. watchEffect(() => {
  563. if (!store.currentTask) return;
  564. for (const sliceImage of sliceImagesWithTrackList) {
  565. sliceImage.tagList = sliceImage.tagList.filter((t) =>
  566. store.currentTaskEnsured.markResult?.specialTagList.find(
  567. (st) =>
  568. st.offsetIndex === t.offsetIndex &&
  569. st.offsetX === t.offsetX &&
  570. st.offsetY === t.offsetY
  571. )
  572. );
  573. }
  574. if (store.currentTaskEnsured.markResult?.specialTagList.length === 0) {
  575. for (const sliceImage of sliceImagesWithTrackList) {
  576. sliceImage.tagList = [];
  577. }
  578. }
  579. });
  580. }
  581. //#endregion : 显示评分状态和清除轨迹
  582. //#region : 评分
  583. const checkTrackValid = (event: MouseEvent) => {
  584. const { clientWidth, clientHeight, naturalWidth, naturalHeight } =
  585. event.target;
  586. const { offsetX, offsetY } = event;
  587. const xLimitRate = 10 / naturalWidth;
  588. const yLimitRate = 10 / naturalHeight;
  589. const xRange = [xLimitRate * clientWidth, (1 - xLimitRate) * clientWidth];
  590. const yRange = [yLimitRate * clientHeight, (1 - yLimitRate) * clientHeight];
  591. return (
  592. offsetX >= xRange[0] &&
  593. offsetX <= xRange[1] &&
  594. offsetY >= yRange[0] &&
  595. offsetY <= yRange[1]
  596. );
  597. };
  598. const innerMakeTrack = (event: MouseEvent, item: SliceImage) => {
  599. if (!checkTrackValid(event)) {
  600. void message.destroy();
  601. void message.warn("轨迹位置距离边界太近");
  602. return;
  603. }
  604. clearEmptySpecialTag(item);
  605. makeTrack(event, item, maxSliceWidth, theFinalHeight);
  606. };
  607. //#endregion : 评分
  608. //#region : 特殊标记:画线、框
  609. const isCustomSpecialTag = $computed(() => {
  610. return ["CIRCLE", "LINE"].includes(store.currentSpecialTagType);
  611. });
  612. let specialPoint = $ref({ x: 0, y: 0, ex: 0, ey: 0 });
  613. let curImageTarget: HTMLElement = null;
  614. let curSliceImagesWithTrackItem: SliceImage = $ref(null);
  615. const specialLenStyle = $computed(() => {
  616. if (specialPoint.ex <= specialPoint.x) return { display: "none" };
  617. const width =
  618. specialPoint.ex > specialPoint.x ? specialPoint.ex - specialPoint.x : 0;
  619. return {
  620. top: specialPoint.y + "px",
  621. left: specialPoint.x + "px",
  622. width: width + "px",
  623. position: "absolute",
  624. borderTop: "1px solid red",
  625. zIndex: 9,
  626. };
  627. });
  628. const specialCircleStyle = $computed(() => {
  629. if (specialPoint.ex <= specialPoint.x || specialPoint.ey <= specialPoint.y)
  630. return { display: "none" };
  631. const width =
  632. specialPoint.ex > specialPoint.x ? specialPoint.ex - specialPoint.x : 0;
  633. const height =
  634. specialPoint.ey > specialPoint.y ? specialPoint.ey - specialPoint.y : 0;
  635. return {
  636. top: specialPoint.y + "px",
  637. left: specialPoint.x + "px",
  638. width: width + "px",
  639. height: height + "px",
  640. position: "absolute",
  641. border: "1px solid red",
  642. borderRadius: "50%",
  643. zIndex: 9,
  644. };
  645. });
  646. function specialMouseStart(e: MouseEvent, item: SliceImage) {
  647. curImageTarget = e.target.parentElement.childNodes[0];
  648. curSliceImagesWithTrackItem = item;
  649. specialPoint.x = e.offsetX;
  650. specialPoint.y = e.offsetY;
  651. }
  652. function specialMouseMove({ left, top }) {
  653. specialPoint.ex = left + specialPoint.x;
  654. specialPoint.ey = top + specialPoint.y;
  655. }
  656. function specialMouseStop(e: MouseEvent) {
  657. if (
  658. store.currentSpecialTagType === "LINE" &&
  659. specialPoint.ex <= specialPoint.x
  660. ) {
  661. return;
  662. }
  663. if (
  664. store.currentSpecialTagType === "CIRCLE" &&
  665. (specialPoint.ex <= specialPoint.x || specialPoint.ey <= specialPoint.y)
  666. ) {
  667. return;
  668. }
  669. const track: SpecialTag = {
  670. tagName: "",
  671. tagType: store.currentSpecialTagType,
  672. offsetIndex: curSliceImagesWithTrackItem.indexInSliceUrls,
  673. offsetX:
  674. specialPoint.x * (curImageTarget.naturalWidth / curImageTarget.width) +
  675. curSliceImagesWithTrackItem.dx,
  676. offsetY:
  677. specialPoint.y * (curImageTarget.naturalHeight / curImageTarget.height) +
  678. curSliceImagesWithTrackItem.dy,
  679. positionX: -1,
  680. positionY: -1,
  681. };
  682. track.positionX =
  683. (specialPoint.x - curSliceImagesWithTrackItem.dx) / maxSliceWidth;
  684. track.positionY =
  685. (specialPoint.y -
  686. curSliceImagesWithTrackItem.dy +
  687. curSliceImagesWithTrackItem.accumTopHeight) /
  688. theFinalHeight;
  689. if (store.currentSpecialTagType === "LINE") {
  690. track.tagName = JSON.stringify({
  691. len:
  692. (specialPoint.ex - specialPoint.x) *
  693. (curImageTarget.naturalWidth / curImageTarget.width),
  694. });
  695. }
  696. if (store.currentSpecialTagType === "CIRCLE") {
  697. track.tagName = JSON.stringify({
  698. width:
  699. (specialPoint.ex - specialPoint.x) *
  700. (curImageTarget.naturalWidth / curImageTarget.width),
  701. height:
  702. (specialPoint.ey - specialPoint.y) *
  703. (curImageTarget.naturalHeight / curImageTarget.height),
  704. });
  705. }
  706. store.currentTaskEnsured.markResult.specialTagList.push(track);
  707. curSliceImagesWithTrackItem.tagList.push(track);
  708. specialPoint = { x: 0, y: 0, ex: 0, ey: 0 };
  709. }
  710. //#endregion
  711. //#region : 显示大图,供查看和翻转
  712. const showBigImage = (event: MouseEvent) => {
  713. event.preventDefault();
  714. // console.log(event);
  715. let viewer: Viewer = null as unknown as Viewer;
  716. viewer && viewer.destroy();
  717. viewer = new Viewer(event.target as HTMLElement, {
  718. // inline: true,
  719. viewed() {
  720. viewer.zoomTo(1);
  721. },
  722. hidden() {
  723. viewer.destroy();
  724. },
  725. zIndex: 1000000,
  726. });
  727. viewer.show();
  728. };
  729. //#endregion : 显示大图,供查看和翻转
  730. // onRenderTriggered(({ key, target, type }) => {
  731. // console.log({ key, target, type });
  732. // });
  733. let topKB = $ref(10);
  734. const topKBStyle = $computed(() => topKB + "%");
  735. let leftKB = $ref(10);
  736. const leftKBStyle = $computed(() => leftKB + "%");
  737. function moveCicle(event: KeyboardEvent) {
  738. // query mark-body-container and body to calc max/min topKB and max leftKB
  739. if (event.key === "k") {
  740. if (topKB > 1) topKB--;
  741. }
  742. if (event.key === "j") {
  743. if (topKB < 99) topKB++;
  744. }
  745. if (event.key === "h") {
  746. if (leftKB > 1) leftKB--;
  747. }
  748. if (event.key === "l") {
  749. if (leftKB < 99) leftKB++;
  750. }
  751. if (event.key === "c") {
  752. topKB = 50;
  753. leftKB = 50;
  754. }
  755. }
  756. function giveScoreCicle(event: KeyboardEvent) {
  757. // console.log(event.key);
  758. event.preventDefault();
  759. // console.log(store.currentScore);
  760. // 接收currentScore间隔时间外才会进入此事件
  761. if (event.key === " " && typeof store.currentScore === "number") {
  762. // topKB--;
  763. const circleElement = document.querySelector(".kb-circle");
  764. let { top, left } = circleElement.getBoundingClientRect();
  765. top = top + 45;
  766. left = left + 45;
  767. // console.log(top, left);
  768. // getBoundingClientRect().top left
  769. // capture => to the specific image
  770. const me = new MouseEvent("click", {
  771. bubbles: true,
  772. cancelable: true,
  773. view: window,
  774. clientY: top,
  775. clientX: left,
  776. });
  777. const eles = document.elementsFromPoint(left, top);
  778. // console.log(eles);
  779. let ele: Element;
  780. // if (eles[0].className === "kb-circle") {
  781. // if (eles[1].tagName == "IMG") {
  782. // ele = eles[1];
  783. // }
  784. // } else
  785. if (eles[0].tagName == "IMG") {
  786. ele = eles[0];
  787. }
  788. if (ele) {
  789. ele.dispatchEvent(me);
  790. }
  791. }
  792. }
  793. onMounted(() => {
  794. document.addEventListener("keypress", moveCicle);
  795. document.addEventListener("keypress", giveScoreCicle);
  796. });
  797. onUnmounted(() => {
  798. document.removeEventListener("keypress", moveCicle);
  799. document.removeEventListener("keypress", giveScoreCicle);
  800. });
  801. // setInterval(() => {
  802. // _topKB++;
  803. // console.log(topKB);
  804. // }, 1000);
  805. //#region autoScroll自动跳转
  806. let oldFirstScoreContainer: HTMLDivElement | null;
  807. watch(
  808. () => store.currentTask,
  809. () => {
  810. if (store.setting.autoScroll) {
  811. // 给任务清理和动画留一点时间
  812. oldFirstScoreContainer =
  813. document.querySelector<HTMLDivElement>(".score-container");
  814. oldFirstScoreContainer?.scrollIntoView({ behavior: "smooth" });
  815. addTimeout(scrollToFirstScore, 1000);
  816. } else {
  817. const container = document.querySelector<HTMLDivElement>(
  818. ".mark-body-container"
  819. );
  820. container?.scrollTo({ top: 0, left: 0, behavior: "smooth" });
  821. }
  822. }
  823. );
  824. function scrollToFirstScore() {
  825. if (renderLock) {
  826. window.requestAnimationFrame(scrollToFirstScore);
  827. }
  828. addTimeout(() => {
  829. const firstScore =
  830. document.querySelector<HTMLDivElement>(".score-container");
  831. firstScore?.scrollIntoView({ behavior: "smooth" });
  832. }, 1000);
  833. }
  834. //#endregion
  835. </script>
  836. <style scoped>
  837. .image-canvas {
  838. position: absolute;
  839. top: 0;
  840. left: 0;
  841. right: 0;
  842. bottom: 0;
  843. z-index: 9;
  844. }
  845. .double-triangle {
  846. background-color: #ef7c78;
  847. width: 30px;
  848. height: 6px;
  849. clip-path: polygon(0 0, 0 6px, 50% 0, 100% 0, 100% 6px, 50% 0);
  850. position: absolute;
  851. bottom: -5px;
  852. }
  853. @keyframes rotate {
  854. 0% {
  855. transform: rotateY(0deg);
  856. opacity: 1;
  857. }
  858. 50% {
  859. transform: rotateY(90deg);
  860. }
  861. 100% {
  862. transform: rotateY(0deg);
  863. opacity: 0;
  864. }
  865. }
  866. .kb-circle {
  867. position: fixed;
  868. width: 90px;
  869. height: 90px;
  870. border: 1px solid #ff5050;
  871. border-radius: 50%;
  872. /* margin-left: -45px;
  873. margin-top: -45px; */
  874. /* transform: translate(-50%, -50%); */
  875. /* margin-left: 50%;
  876. margin-top: 10%; */
  877. top: v-bind(topKBStyle);
  878. left: v-bind(leftKBStyle);
  879. /* c to center circle
  880. jikl
  881. 斜线移动
  882. space上分,方便连续给分
  883. shift加速?
  884. */
  885. /*
  886. getBoundingClientRect().top left
  887. capture => to the specific image
  888. new MouseEvent("click", {
  889. bubbles: true,
  890. cancelable: true,
  891. view: window,
  892. clientX
  893. clientY
  894. });
  895. */
  896. /* to click through div */
  897. pointer-events: none;
  898. /* display: grid; */
  899. }
  900. .kb-circle .text {
  901. font-size: 2rem;
  902. color: #ff5050;
  903. margin-top: 10px;
  904. display: block;
  905. text-align: center;
  906. width: 100%;
  907. line-height: 90px;
  908. }
  909. </style>