123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984 |
- <template>
- <div class="mark-body">
- <div v-if="markStatus" class="mark-body-status">
- {{ markStatus }}
- </div>
- <div ref="dragContainer" class="mark-body-container">
- <div v-if="!store.currentTask" class="mark-body-none">
- <div>
- <img src="@/assets/image-none-task.png" />
- <p>
- {{ store.message }}
- </p>
- </div>
- </div>
- <div
- v-else-if="store.isScanImage"
- :style="{ width: answerPaperScale }"
- :class="[`rotate-board-${rotateBoard}`]"
- >
- <template
- v-for="(item, index) in sliceImagesWithTrackList"
- :key="index"
- >
- <div class="single-image-container">
- <img
- :src="item.url"
- draggable="false"
- @click="(event) => innerMakeTrack(event, item)"
- @contextmenu="showBigImage"
- />
- <MarkDrawTrack
- :trackList="item.trackList"
- :specialTagList="item.tagList"
- :sliceImageWidth="item.sliceImageWidth"
- :sliceImageHeight="item.sliceImageHeight"
- :dx="item.dx"
- :dy="item.dy"
- @deleteSpecialtag="(tag) => deleteSpecialtag(item, tag)"
- @click-specialtag="(event) => clickSpecialtag(event, item)"
- />
- <div
- v-if="isCustomSpecialTag"
- class="image-canvas"
- v-ele-move-directive.stop.prevent="{
- moveStart: (event) => specialMouseStart(event, item),
- moveElement: specialMouseMove,
- moveStop: specialMouseStop,
- }"
- >
- <template v-if="curSliceImagesWithTrackItem?.url === item.url">
- <div
- v-if="store.currentSpecialTagType === 'LINE'"
- :style="specialLenStyle"
- ></div>
- <div
- v-if="store.currentSpecialTagType === 'CIRCLE'"
- :style="specialCircleStyle"
- ></div>
- </template>
- </div>
- </div>
- <hr class="image-seperator" />
- </template>
- </div>
- <div v-else-if="store.isMultiMedia">
- <MultiMediaMarkBody />
- </div>
- <div v-else>未知数据</div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { onMounted, onUnmounted, reactive, watch, watchEffect } from "vue";
- import { store } from "@/store/store";
- import MarkDrawTrack from "./MarkDrawTrack.vue";
- import type { SliceImage } from "@/types";
- import { useTimers } from "@/setups/useTimers";
- import {
- getDataUrlForSliceConfig,
- getDataUrlForSplitConfig,
- loadImage,
- } from "@/utils/utils";
- import { dragImage } from "./use/draggable";
- import MultiMediaMarkBody from "./MultiMediaMarkBody.vue";
- import "viewerjs/dist/viewer.css";
- import Viewer from "viewerjs";
- import { message } from "ant-design-vue";
- import EventBus from "@/plugins/eventBus";
- import { vEleMoveDirective } from "./use/eleMove";
- type MakeTrack = (
- event: MouseEvent,
- item: SliceImage,
- maxSliceWidth: number,
- theFinalHeight: number
- ) => void | (() => void);
- const {
- hasMarkResultToRender = false,
- makeTrack = () => console.debug("非评卷界面makeTrack没有意义"),
- } = defineProps<{
- hasMarkResultToRender?: boolean;
- makeTrack?: MakeTrack;
- }>();
- const emit = defineEmits(["error"]);
- //#region : 图片拖动。在轨迹模式下,仅当没有选择分数时可用。
- const { dragContainer } = dragImage();
- //#endregion : 图片拖动
- const { addTimeout } = useTimers();
- //#region : 缩略图定位
- watch(
- () => [store.minimapScrollToX, store.minimapScrollToY],
- () => {
- const container = document.querySelector<HTMLDivElement>(
- ".mark-body-container"
- );
- addTimeout(() => {
- if (
- container &&
- typeof store.minimapScrollToX === "number" &&
- typeof store.minimapScrollToY === "number"
- ) {
- const { scrollWidth, scrollHeight } = container;
- container.scrollTo({
- top: scrollHeight * store.minimapScrollToY,
- left: scrollWidth * store.minimapScrollToX,
- behavior: "smooth",
- });
- }
- }, 10);
- }
- );
- //#endregion : 缩略图定位
- //#region : 快捷键定位
- const scrollContainerByKey = (e: KeyboardEvent) => {
- const container = document.querySelector<HTMLDivElement>(
- ".mark-body-container"
- );
- if (!container) {
- return;
- }
- if (e.key === "w") {
- container.scrollBy({ top: -100, behavior: "smooth" });
- } else if (e.key === "s") {
- container.scrollBy({ top: 100, behavior: "smooth" });
- } else if (e.key === "a") {
- container.scrollBy({ left: -100, behavior: "smooth" });
- } else if (e.key === "d") {
- container.scrollBy({ left: 100, behavior: "smooth" });
- }
- };
- onMounted(() => {
- document.addEventListener("keypress", scrollContainerByKey);
- });
- onUnmounted(() => {
- document.removeEventListener("keypress", scrollContainerByKey);
- });
- //#endregion : 快捷键定位
- //#region : 计算裁切图和裁切图上的分数轨迹和特殊标记轨迹
- let rotateBoard = $ref(0);
- let sliceImagesWithTrackList: SliceImage[] = reactive([]);
- let maxSliceWidth = 0; // 最大的裁切块宽度,图片容器以此为准
- let theFinalHeight = 0; // 最终宽度,用来定位轨迹在第几张图片,不包括image-seperator高度
- watch(
- () => sliceImagesWithTrackList,
- () => {
- EventBus.emit("draw-change", sliceImagesWithTrackList);
- },
- { deep: true }
- );
- async function processSliceConfig() {
- if (!store.currentTask) return;
- let markResult = store.currentTask.markResult;
- if (hasMarkResultToRender) {
- // check if have MarkResult for currentTask
- if (!markResult) return;
- }
- const images = [];
- // 必须要先加载一遍,把“选择整图”的宽高重置后,再算总高度
- // 错误的搞法,张莹坚持要用
- const sliceNum = store.currentTask.sliceUrls.length;
- if (store.currentTask.sliceConfig.some((v) => v.i > sliceNum)) {
- console.warn("裁切图设置的数量小于该学生的总图片数量");
- }
- store.currentTask.sliceConfig = store.currentTask.sliceConfig.filter(
- (v) => v.i <= sliceNum
- );
- for (const sliceConfig of store.currentTask.sliceConfig) {
- const url = store.currentTask.sliceUrls[sliceConfig.i - 1];
- const image = await loadImage(url);
- images[sliceConfig.i] = image;
- const { x, y, w, h } = sliceConfig;
- x < 0 && (sliceConfig.x = 0);
- y < 0 && (sliceConfig.y = 0);
- if (sliceConfig.w === 0 && sliceConfig.h === 0) {
- // 选择整图时,w/h 为0
- sliceConfig.w = image.naturalWidth;
- sliceConfig.h = image.naturalHeight;
- }
- if (x <= 1 && y <= 1 && sliceConfig.w <= 1 && sliceConfig.h <= 1) {
- sliceConfig.x = image.naturalWidth * x;
- sliceConfig.y = image.naturalHeight * y;
- sliceConfig.w = image.naturalWidth * w;
- sliceConfig.h = image.naturalHeight * h;
- }
- }
- theFinalHeight = store.currentTask.sliceConfig
- .map((v) => v.h)
- .reduce((acc, v) => (acc += v));
- maxSliceWidth = Math.max(...store.currentTask.sliceConfig.map((v) => v.w));
- // 用来保存sliceImage在整个图片容器中(不包括image-seperator)的高度范围
- let accumTopHeight = 0;
- let accumBottomHeight = 0;
- const trackLists = hasMarkResultToRender
- ? markResult.trackList
- : store.currentTask.questionList.map((q) => q.trackList).flat();
- const tagLists = hasMarkResultToRender
- ? markResult.specialTagList ?? []
- : store.currentTask.specialTagList ?? [];
- const tempSliceImagesWithTrackList: Array<SliceImage> = [];
- for (const sliceConfig of store.currentTask.sliceConfig) {
- accumBottomHeight += sliceConfig.h;
- const url = store.currentTask.sliceUrls[sliceConfig.i - 1];
- const indexInSliceUrls = sliceConfig.i;
- const image = images[sliceConfig.i];
- const dataUrl = await getDataUrlForSliceConfig(
- image,
- sliceConfig,
- maxSliceWidth,
- url
- );
- const thisImageTrackList = trackLists.filter(
- (t) => t.offsetIndex === indexInSliceUrls
- );
- const thisImageTagList = tagLists.filter(
- (t) => t.offsetIndex === indexInSliceUrls
- );
- const sliceImageRendered = await loadImage(dataUrl);
- tempSliceImagesWithTrackList.push({
- url: dataUrl,
- indexInSliceUrls: sliceConfig.i,
- // 通过positionY来定位是第几张slice的还原,并过滤出相应的track
- trackList: thisImageTrackList.filter(
- (t) =>
- t.positionY >= accumTopHeight / theFinalHeight &&
- t.positionY < accumBottomHeight / theFinalHeight
- ),
- tagList: thisImageTagList.filter(
- (t) =>
- t.positionY >= accumTopHeight / theFinalHeight &&
- t.positionY < accumBottomHeight / theFinalHeight
- ),
- // originalImageWidth: image.naturalWidth,
- // originalImageHeight: image.naturalHeight,
- sliceImageWidth: sliceImageRendered.naturalWidth,
- sliceImageHeight: sliceImageRendered.naturalHeight,
- dx: sliceConfig.x,
- dy: sliceConfig.y,
- accumTopHeight,
- effectiveWidth: sliceConfig.w,
- });
- accumTopHeight = accumBottomHeight;
- }
- // 测试是否所有的track和tag都在待渲染的tempSliceImagesWithTrackList中
- const numOfTrackAndTagInData = trackLists.length + tagLists.length;
- const numOfTrackAndTagInTempSlice = tempSliceImagesWithTrackList
- .map((v) => v.trackList.length + v.tagList.length)
- .reduce((p, c) => p + c);
- if (numOfTrackAndTagInData !== numOfTrackAndTagInTempSlice) {
- console.warn({ tagLists, trackLists, tempSliceImagesWithTrackList });
- void message.warn("渲染轨迹数量与实际数量不一致");
- }
- // console.log("render: ", store.currentTask.secretNumber);
- if (sliceImagesWithTrackList.length === 0) {
- // 初次渲染,不做动画
- sliceImagesWithTrackList.push(...tempSliceImagesWithTrackList);
- // 没抽象好,这里不好做校验
- // const renderedTrackAndTagNumber = sliceImagesWithTrackList.map(s => s.trackList.length + s.tagList.length).reduce((p,c) => p+ c);
- // if(renderedTrackAndTagNumber === thisIma)
- } else {
- rotateBoard = 1;
- setTimeout(() => {
- sliceImagesWithTrackList.splice(0);
- sliceImagesWithTrackList.push(...tempSliceImagesWithTrackList);
- setTimeout(() => {
- rotateBoard = 0;
- }, 300);
- }, 300);
- }
- }
- async function processSplitConfig() {
- if (!store.currentTask) return;
- let markResult = store.currentTask.markResult;
- if (hasMarkResultToRender) {
- // check if have MarkResult for currentTask
- if (!markResult) return;
- }
- const images = [];
- for (const url of store.currentTask.sliceUrls) {
- const image = await loadImage(url);
- images.push(image);
- }
- // 如果拒绝裁切,则保持整卷
- if (!store.setting.enableSplit) {
- store.setting.splitConfig = [0, 1];
- }
- // 裁切块,可能是一块,两块,三块... [start, width ...] => [0, 0.3] | [0, 0.55, 0.45, 0.55] | [0, 0.35, 0.33, 0.35, 0.66, 0.35]
- // 要转变为 [[0, 0.3]] | [[0, 0.55], [0.45, 0.55]] | [[0, 0.35], [0.33, 0.35], [0.66, 0.35]]
- const splitConfigPairs = store.setting.splitConfig.reduce<[number, number][]>(
- (a, v, index) => {
- // 偶数位组成数组的第一位,奇数位组成数组的第二位
- index % 2 === 0 ? a.push([v, -1]) : (a.at(-1)![1] = v);
- return a;
- },
- []
- );
- // 最大的 splitConfig 的宽度
- const maxSplitConfig = Math.max(
- ...store.setting.splitConfig.filter((v, i) => i % 2)
- );
- maxSliceWidth =
- Math.max(...images.map((v) => v.naturalWidth)) * maxSplitConfig;
- theFinalHeight =
- splitConfigPairs.length *
- images.reduce((acc, v) => (acc += v.naturalHeight), 0);
- // 高度比宽度大的图片不裁切
- const imagesOfBiggerHeight = images.filter(
- (v) => v.naturalHeight > v.naturalWidth
- );
- if (imagesOfBiggerHeight.length > 0) {
- maxSliceWidth = Math.max(
- maxSliceWidth,
- ...imagesOfBiggerHeight.map((v) => v.naturalWidth)
- );
- // 不裁切的图剪切多加的高度
- theFinalHeight -=
- imagesOfBiggerHeight.map((v) => v.naturalHeight).reduce((p, c) => p + c) *
- (splitConfigPairs.length - 1);
- }
- let accumTopHeight = 0;
- let accumBottomHeight = 0;
- const tempSliceImagesWithTrackList: SliceImage[] = [];
- const trackLists = hasMarkResultToRender
- ? markResult.trackList
- : (store.currentTask.questionList || []).map((q) => q.trackList).flat();
- const tagLists = hasMarkResultToRender
- ? markResult.specialTagList ?? []
- : store.currentTask.specialTagList ?? [];
- for (const url of store.currentTask.sliceUrls) {
- for (const config of splitConfigPairs) {
- const indexInSliceUrls = store.currentTask.sliceUrls.indexOf(url) + 1;
- const image = images[indexInSliceUrls - 1];
- let shouldBreak = false;
- let [splitConfigStart, splitConfigEnd] = config;
- if (image.naturalHeight > image.naturalWidth) {
- splitConfigStart = 0;
- splitConfigEnd = 1;
- shouldBreak = true;
- }
- accumBottomHeight += image.naturalHeight;
- const dataUrl = await getDataUrlForSplitConfig(
- image,
- [splitConfigStart, splitConfigEnd],
- maxSliceWidth,
- url
- );
- const thisImageTrackList = trackLists.filter(
- (t) => t.offsetIndex === indexInSliceUrls
- );
- const thisImageTagList = tagLists.filter(
- (t) => t.offsetIndex === indexInSliceUrls
- );
- const sliceImageRendered = await loadImage(dataUrl);
- tempSliceImagesWithTrackList.push({
- url: dataUrl,
- indexInSliceUrls: store.currentTask.sliceUrls.indexOf(url) + 1,
- trackList: thisImageTrackList.filter(
- (t) =>
- t.positionY >= accumTopHeight / theFinalHeight &&
- t.positionY < accumBottomHeight / theFinalHeight
- ),
- tagList: thisImageTagList.filter(
- (t) =>
- t.positionY >= accumTopHeight / theFinalHeight &&
- t.positionY < accumBottomHeight / theFinalHeight
- ),
- // originalImageWidth: image.naturalWidth,
- // originalImageHeight: image.naturalHeight,
- sliceImageWidth: sliceImageRendered.naturalWidth,
- sliceImageHeight: sliceImageRendered.naturalHeight,
- dx: image.naturalWidth * splitConfigStart,
- dy: 0,
- accumTopHeight,
- effectiveWidth: image.naturalWidth * splitConfigEnd,
- });
- accumTopHeight = accumBottomHeight;
- // 如果本图高比宽大,不该裁切,则跳过多次裁切
- if (shouldBreak) {
- break;
- }
- }
- }
- // 测试是否所有的track和tag都在待渲染的tempSliceImagesWithTrackList中
- const numOfTrackAndTagInData = trackLists.length + tagLists.length;
- const numOfTrackAndTagInTempSlice = tempSliceImagesWithTrackList
- .map((v) => v.trackList.length + v.tagList.length)
- .reduce((p, c) => p + c);
- if (numOfTrackAndTagInData !== numOfTrackAndTagInTempSlice) {
- console.warn({ tagLists, trackLists, tempSliceImagesWithTrackList });
- void message.warn("渲染轨迹数量与实际数量不一致");
- }
- rotateBoard = 1;
- addTimeout(() => {
- sliceImagesWithTrackList.splice(0);
- sliceImagesWithTrackList.push(...tempSliceImagesWithTrackList);
- addTimeout(() => {
- rotateBoard = 0;
- }, 300);
- }, 300);
- }
- const deleteSpecialtag = (item, tag) => {
- const findInd = (tagList, curTag) => {
- return tagList.findIndex(
- (itemTag) =>
- itemTag.tagName === curTag.tagName &&
- itemTag.offsetX === curTag.offsetX &&
- itemTag.offsetY === curTag.offsetY
- );
- };
- const tagIndex = findInd(item.tagList, tag);
- if (tagIndex === -1) return;
- item.tagList.splice(tagIndex, 1);
- const stagIndex = findInd(
- store.currentTaskEnsured.markResult.specialTagList,
- tag
- );
- if (stagIndex === -1) return;
- store.currentTaskEnsured.markResult.specialTagList.splice(tagIndex, 1);
- };
- const clickSpecialtag = (event: MouseEvent, item: SliceImage) => {
- // console.log(event);
- const e = {
- target: event.target.offsetParent.childNodes[0],
- offsetX: event.offsetX + event.target.offsetLeft,
- offsetY: event.offsetY + event.target.offsetTop,
- };
- makeTrack(e as MouseEvent, item, maxSliceWidth, theFinalHeight);
- };
- const clearEmptySpecialTag = (item) => {
- item.tagList
- .filter((item) => !item.tagName.trim().replace("\n", ""))
- .forEach((tag) => {
- deleteSpecialtag(item, tag);
- });
- };
- // should not render twice at the same time
- let renderLock = false;
- const renderPaperAndMark = async () => {
- // console.log("renderPagerAndMark=>store.curTask:", store.currentTask);
- if (!store.currentTask) return;
- if (!store.isScanImage) return;
- if (renderLock) {
- console.log("上个任务还未渲染完毕,稍等一秒再尝试渲染");
- await new Promise((res) => setTimeout(res, 1000));
- await renderPaperAndMark();
- return;
- }
- // check if have MarkResult for currentTask
- let markResult = store.currentTask.markResult;
- if (hasMarkResultToRender && !markResult) {
- return;
- }
- renderLock = true;
- try {
- store.globalMask = true;
- const hasSliceConfig = store.currentTask.sliceConfig?.length;
- if (hasSliceConfig) {
- await processSliceConfig();
- } else {
- await processSplitConfig();
- }
- // 研究生考试需要停留在上次阅卷的位置,所以注释掉下面的代码
- // await new Promise((res) => setTimeout(res, 700));
- // const container = <HTMLDivElement>(
- // document.querySelector(".mark-body-container")
- // );
- // addTimeout(() => {
- // container?.scrollTo({
- // top: 0,
- // left: 0,
- // behavior: "smooth",
- // });
- // }, 10);
- } catch (error) {
- sliceImagesWithTrackList.splice(0);
- console.trace("render error ", error);
- // 图片加载出错,自动加载下一个任务
- emit("error");
- } finally {
- renderLock = false;
- store.globalMask = false;
- }
- };
- // watchEffect(renderPaperAndMark);
- // 在阻止渲染的情况下,watchEffect收集不到 store.currentTask 的依赖,会导致本组件不再更新
- watch(
- () => store.currentTask,
- () => {
- setTimeout(renderPaperAndMark, 50);
- }
- );
- //#endregion : 计算裁切图和裁切图上的分数轨迹和特殊标记轨迹
- //#region : 放大缩小和之后的滚动
- const answerPaperScale = $computed(() => {
- // 放大、缩小不影响页面之前的滚动条定位
- let percentWidth = 0;
- let percentTop = 0;
- const container = document.querySelector(".mark-body-container");
- if (container) {
- const { scrollLeft, scrollTop, scrollWidth, scrollHeight } = container;
- percentWidth = scrollLeft / scrollWidth;
- percentTop = scrollTop / scrollHeight;
- }
- addTimeout(() => {
- if (container) {
- const { scrollWidth, scrollHeight } = container;
- container.scrollTo({
- left: scrollWidth * percentWidth,
- top: scrollHeight * percentTop,
- });
- }
- }, 10);
- const scale = store.setting.uiSetting["answer.paper.scale"];
- return scale * 100 + "%";
- });
- //#endregion : 放大缩小和之后的滚动
- //#region : 显示评分状态和清除轨迹
- let markStatus = $ref("");
- if (hasMarkResultToRender) {
- watch(
- () => store.currentTask,
- () => {
- markStatus = store.getMarkStatus;
- }
- );
- // 清除分数轨迹
- watchEffect(() => {
- for (const track of store.removeScoreTracks) {
- for (const sliceImage of sliceImagesWithTrackList) {
- sliceImage.trackList = sliceImage.trackList.filter(
- (t) =>
- !(
- t.mainNumber === track.mainNumber &&
- t.subNumber === track.subNumber &&
- t.number === track.number
- )
- );
- }
- }
- // 清除后,删除,否则会影响下次切换
- store.removeScoreTracks.splice(0);
- });
- // 清除特殊标记轨迹
- watchEffect(() => {
- if (!store.currentTask) return;
- for (const sliceImage of sliceImagesWithTrackList) {
- sliceImage.tagList = sliceImage.tagList.filter((t) =>
- store.currentTaskEnsured.markResult?.specialTagList.find(
- (st) =>
- st.offsetIndex === t.offsetIndex &&
- st.offsetX === t.offsetX &&
- st.offsetY === t.offsetY
- )
- );
- }
- if (store.currentTaskEnsured.markResult?.specialTagList.length === 0) {
- for (const sliceImage of sliceImagesWithTrackList) {
- sliceImage.tagList = [];
- }
- }
- });
- }
- //#endregion : 显示评分状态和清除轨迹
- //#region : 评分
- const checkTrackValid = (event: MouseEvent) => {
- const { clientWidth, clientHeight, naturalWidth, naturalHeight } =
- event.target;
- const { offsetX, offsetY } = event;
- const xLimitRate = 10 / naturalWidth;
- const yLimitRate = 10 / naturalHeight;
- const xRange = [xLimitRate * clientWidth, (1 - xLimitRate) * clientWidth];
- const yRange = [yLimitRate * clientHeight, (1 - yLimitRate) * clientHeight];
- return (
- offsetX >= xRange[0] &&
- offsetX <= xRange[1] &&
- offsetY >= yRange[0] &&
- offsetY <= yRange[1]
- );
- };
- const innerMakeTrack = (event: MouseEvent, item: SliceImage) => {
- if (!checkTrackValid(event)) {
- void message.destroy();
- void message.warn("轨迹位置距离边界太近");
- return;
- }
- clearEmptySpecialTag(item);
- makeTrack(event, item, maxSliceWidth, theFinalHeight);
- };
- //#endregion : 评分
- //#region : 特殊标记:画线、框
- const isCustomSpecialTag = $computed(() => {
- return ["CIRCLE", "LINE"].includes(store.currentSpecialTagType);
- });
- let specialPoint = $ref({ x: 0, y: 0, ex: 0, ey: 0 });
- let curImageTarget: HTMLElement = null;
- let curSliceImagesWithTrackItem: SliceImage = $ref(null);
- const specialLenStyle = $computed(() => {
- if (specialPoint.ex <= specialPoint.x) return { display: "none" };
- const width =
- specialPoint.ex > specialPoint.x ? specialPoint.ex - specialPoint.x : 0;
- return {
- top: specialPoint.y + "px",
- left: specialPoint.x + "px",
- width: width + "px",
- position: "absolute",
- borderTop: "1px solid red",
- zIndex: 9,
- };
- });
- const specialCircleStyle = $computed(() => {
- if (specialPoint.ex <= specialPoint.x || specialPoint.ey <= specialPoint.y)
- return { display: "none" };
- const width =
- specialPoint.ex > specialPoint.x ? specialPoint.ex - specialPoint.x : 0;
- const height =
- specialPoint.ey > specialPoint.y ? specialPoint.ey - specialPoint.y : 0;
- return {
- top: specialPoint.y + "px",
- left: specialPoint.x + "px",
- width: width + "px",
- height: height + "px",
- position: "absolute",
- border: "1px solid red",
- borderRadius: "50%",
- zIndex: 9,
- };
- });
- function specialMouseStart(e: MouseEvent, item: SliceImage) {
- curImageTarget = e.target.parentElement.childNodes[0];
- curSliceImagesWithTrackItem = item;
- specialPoint.x = e.offsetX;
- specialPoint.y = e.offsetY;
- }
- function specialMouseMove({ left, top }) {
- specialPoint.ex = left + specialPoint.x;
- specialPoint.ey = top + specialPoint.y;
- }
- function specialMouseStop(e: MouseEvent) {
- if (
- store.currentSpecialTagType === "LINE" &&
- specialPoint.ex <= specialPoint.x
- ) {
- return;
- }
- if (
- store.currentSpecialTagType === "CIRCLE" &&
- (specialPoint.ex <= specialPoint.x || specialPoint.ey <= specialPoint.y)
- ) {
- return;
- }
- const track: SpecialTag = {
- tagName: "",
- tagType: store.currentSpecialTagType,
- offsetIndex: curSliceImagesWithTrackItem.indexInSliceUrls,
- offsetX:
- specialPoint.x * (curImageTarget.naturalWidth / curImageTarget.width) +
- curSliceImagesWithTrackItem.dx,
- offsetY:
- specialPoint.y * (curImageTarget.naturalHeight / curImageTarget.height) +
- curSliceImagesWithTrackItem.dy,
- positionX: -1,
- positionY: -1,
- };
- track.positionX =
- (specialPoint.x - curSliceImagesWithTrackItem.dx) / maxSliceWidth;
- track.positionY =
- (specialPoint.y -
- curSliceImagesWithTrackItem.dy +
- curSliceImagesWithTrackItem.accumTopHeight) /
- theFinalHeight;
- if (store.currentSpecialTagType === "LINE") {
- track.tagName = JSON.stringify({
- len:
- (specialPoint.ex - specialPoint.x) *
- (curImageTarget.naturalWidth / curImageTarget.width),
- });
- }
- if (store.currentSpecialTagType === "CIRCLE") {
- track.tagName = JSON.stringify({
- width:
- (specialPoint.ex - specialPoint.x) *
- (curImageTarget.naturalWidth / curImageTarget.width),
- height:
- (specialPoint.ey - specialPoint.y) *
- (curImageTarget.naturalHeight / curImageTarget.height),
- });
- }
- store.currentTaskEnsured.markResult.specialTagList.push(track);
- curSliceImagesWithTrackItem.tagList.push(track);
- specialPoint = { x: 0, y: 0, ex: 0, ey: 0 };
- }
- //#endregion
- //#region : 显示大图,供查看和翻转
- const showBigImage = (event: MouseEvent) => {
- event.preventDefault();
- // console.log(event);
- let viewer: Viewer = null as unknown as Viewer;
- viewer && viewer.destroy();
- viewer = new Viewer(event.target as HTMLElement, {
- // inline: true,
- viewed() {
- viewer.zoomTo(1);
- },
- hidden() {
- viewer.destroy();
- },
- zIndex: 1000000,
- });
- viewer.show();
- };
- //#endregion : 显示大图,供查看和翻转
- // onRenderTriggered(({ key, target, type }) => {
- // console.log({ key, target, type });
- // });
- let topKB = $ref(10);
- const topKBStyle = $computed(() => topKB + "%");
- let leftKB = $ref(10);
- const leftKBStyle = $computed(() => leftKB + "%");
- function moveCicle(event: KeyboardEvent) {
- // query mark-body-container and body to calc max/min topKB and max leftKB
- if (event.key === "k") {
- if (topKB > 1) topKB--;
- }
- if (event.key === "j") {
- if (topKB < 99) topKB++;
- }
- if (event.key === "h") {
- if (leftKB > 1) leftKB--;
- }
- if (event.key === "l") {
- if (leftKB < 99) leftKB++;
- }
- if (event.key === "c") {
- topKB = 50;
- leftKB = 50;
- }
- }
- function giveScoreCicle(event: KeyboardEvent) {
- // console.log(event.key);
- event.preventDefault();
- // console.log(store.currentScore);
- // 接收currentScore间隔时间外才会进入此事件
- if (event.key === " " && typeof store.currentScore === "number") {
- // topKB--;
- const circleElement = document.querySelector(".kb-circle");
- let { top, left } = circleElement.getBoundingClientRect();
- top = top + 45;
- left = left + 45;
- // console.log(top, left);
- // getBoundingClientRect().top left
- // capture => to the specific image
- const me = new MouseEvent("click", {
- bubbles: true,
- cancelable: true,
- view: window,
- clientY: top,
- clientX: left,
- });
- const eles = document.elementsFromPoint(left, top);
- // console.log(eles);
- let ele: Element;
- // if (eles[0].className === "kb-circle") {
- // if (eles[1].tagName == "IMG") {
- // ele = eles[1];
- // }
- // } else
- if (eles[0].tagName == "IMG") {
- ele = eles[0];
- }
- if (ele) {
- ele.dispatchEvent(me);
- }
- }
- }
- onMounted(() => {
- document.addEventListener("keypress", moveCicle);
- document.addEventListener("keypress", giveScoreCicle);
- });
- onUnmounted(() => {
- document.removeEventListener("keypress", moveCicle);
- document.removeEventListener("keypress", giveScoreCicle);
- });
- // setInterval(() => {
- // _topKB++;
- // console.log(topKB);
- // }, 1000);
- //#region autoScroll自动跳转
- let oldFirstScoreContainer: HTMLDivElement | null;
- watch(
- () => store.currentTask,
- () => {
- if (store.setting.autoScroll) {
- // 给任务清理和动画留一点时间
- oldFirstScoreContainer =
- document.querySelector<HTMLDivElement>(".score-container");
- oldFirstScoreContainer?.scrollIntoView({ behavior: "smooth" });
- addTimeout(scrollToFirstScore, 1000);
- } else {
- const container = document.querySelector<HTMLDivElement>(
- ".mark-body-container"
- );
- container?.scrollTo({ top: 0, left: 0, behavior: "smooth" });
- }
- }
- );
- function scrollToFirstScore() {
- if (renderLock) {
- window.requestAnimationFrame(scrollToFirstScore);
- }
- addTimeout(() => {
- const firstScore =
- document.querySelector<HTMLDivElement>(".score-container");
- firstScore?.scrollIntoView({ behavior: "smooth" });
- }, 1000);
- }
- //#endregion
- </script>
- <style scoped>
- .image-canvas {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 9;
- }
- .double-triangle {
- background-color: #ef7c78;
- width: 30px;
- height: 6px;
- clip-path: polygon(0 0, 0 6px, 50% 0, 100% 0, 100% 6px, 50% 0);
- position: absolute;
- bottom: -5px;
- }
- @keyframes rotate {
- 0% {
- transform: rotateY(0deg);
- opacity: 1;
- }
- 50% {
- transform: rotateY(90deg);
- }
- 100% {
- transform: rotateY(0deg);
- opacity: 0;
- }
- }
- .kb-circle {
- position: fixed;
- width: 90px;
- height: 90px;
- border: 1px solid #ff5050;
- border-radius: 50%;
- /* margin-left: -45px;
- margin-top: -45px; */
- /* transform: translate(-50%, -50%); */
- /* margin-left: 50%;
- margin-top: 10%; */
- top: v-bind(topKBStyle);
- left: v-bind(leftKBStyle);
- /* c to center circle
- jikl
- 斜线移动
- space上分,方便连续给分
- shift加速?
- */
- /*
- getBoundingClientRect().top left
- capture => to the specific image
- new MouseEvent("click", {
- bubbles: true,
- cancelable: true,
- view: window,
- clientX
- clientY
- });
- */
- /* to click through div */
- pointer-events: none;
- /* display: grid; */
- }
- .kb-circle .text {
- font-size: 2rem;
- color: #ff5050;
- margin-top: 10px;
- display: block;
- text-align: center;
- width: 100%;
- line-height: 90px;
- }
- </style>
|