CommonMarkBody.vue 25 KB

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