|
@@ -1,11 +1,13 @@
|
|
|
<template>
|
|
|
- <div class="mark-body-container" ref="container">
|
|
|
+ <div class="mark-body-container flex-auto" ref="container">
|
|
|
<div :style="{ width: answerPaperScale }">
|
|
|
<template v-for="(item, index) in imageWithStyles" :key="index">
|
|
|
<img :src="item.url" />
|
|
|
+ <hr style="border: 2px solid grey" />
|
|
|
</template>
|
|
|
<!-- style="border: 1px solid black; background: black" -->
|
|
|
</div>
|
|
|
+ <div v-if="!store.currentTask" class="text-center">暂无评卷任务</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -21,37 +23,40 @@ export default defineComponent({
|
|
|
name: "MarkBody",
|
|
|
setup() {
|
|
|
const container = ref(null);
|
|
|
- const imageWithStyles: Array<any> = reactive([]);
|
|
|
+ let imageWithStyles: Array<any> = reactive([]);
|
|
|
watchEffect(async () => {
|
|
|
- if (store.currentTask?.sliceConfig) {
|
|
|
- async function loadImage(url: string): Promise<HTMLImageElement> {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- const image = new Image();
|
|
|
- image.setAttribute("crossorigin", "anonymous");
|
|
|
- image.src = url;
|
|
|
- image.onload = () => resolve(image);
|
|
|
- image.onerror = reject;
|
|
|
- });
|
|
|
- }
|
|
|
+ async function loadImage(url: string): Promise<HTMLImageElement> {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const image = new Image();
|
|
|
+ image.setAttribute("crossorigin", "anonymous");
|
|
|
+ image.src = url;
|
|
|
+ image.onload = () => resolve(image);
|
|
|
+ image.onerror = reject;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!store.currentTask?.libraryId) return;
|
|
|
+ imageWithStyles.splice(0);
|
|
|
+ if (store.currentTask.sliceConfig?.length) {
|
|
|
for (const url of store.currentTask.sliceUrls) {
|
|
|
await loadImage(filters.toCompleteUrl(url));
|
|
|
}
|
|
|
- let zIndex = 500;
|
|
|
for (const sliceConfig of store.currentTask.sliceConfig) {
|
|
|
const url = filters.toCompleteUrl(
|
|
|
store.currentTask.sliceUrls[sliceConfig.i - 1]
|
|
|
);
|
|
|
const image = await loadImage(url);
|
|
|
|
|
|
- const div: HTMLDivElement = container.value;
|
|
|
+ const div = (container.value as unknown) as HTMLDivElement;
|
|
|
const maxSliceWidth = Math.max(
|
|
|
...store.currentTask.sliceConfig.map((v) => v.w)
|
|
|
);
|
|
|
|
|
|
const canvas = document.createElement("canvas");
|
|
|
+ // canvas.width = sliceConfig.w;
|
|
|
canvas.width = Math.max(sliceConfig.w, maxSliceWidth);
|
|
|
canvas.height = sliceConfig.h;
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
+ // drawImage 画图软件透明色
|
|
|
ctx?.drawImage(
|
|
|
image,
|
|
|
sliceConfig.x,
|
|
@@ -69,6 +74,55 @@ export default defineComponent({
|
|
|
url: canvas.toDataURL(),
|
|
|
});
|
|
|
}
|
|
|
+ } else {
|
|
|
+ const images = [];
|
|
|
+ for (const url of store.currentTask.sheetUrls) {
|
|
|
+ const image = await loadImage(filters.toCompleteUrl(url));
|
|
|
+ images.push(image);
|
|
|
+ }
|
|
|
+
|
|
|
+ const newConfig = (store.setting.splitConfig
|
|
|
+ .map((v, index, ary) =>
|
|
|
+ index % 2 === 0 ? [v, ary[index + 1]] : false
|
|
|
+ )
|
|
|
+ .filter((v) => v) as unknown) as Array<[number, number]>;
|
|
|
+
|
|
|
+ const maxSplitConfig = Math.max(...store.setting.splitConfig);
|
|
|
+ const maxSliceWidth =
|
|
|
+ Math.max(...images.map((v) => v.naturalWidth)) * maxSplitConfig;
|
|
|
+
|
|
|
+ for (const url of store.currentTask.sheetUrls) {
|
|
|
+ const completeUrl = filters.toCompleteUrl(url);
|
|
|
+
|
|
|
+ for (const config of newConfig) {
|
|
|
+ const image = await loadImage(completeUrl);
|
|
|
+
|
|
|
+ const div = (container.value as unknown) as HTMLDivElement;
|
|
|
+
|
|
|
+ const width = image.naturalWidth * (config[1] - config[0]);
|
|
|
+ const canvas = document.createElement("canvas");
|
|
|
+ canvas.width = Math.max(width, maxSliceWidth);
|
|
|
+ canvas.height = image.naturalHeight;
|
|
|
+ const ctx = canvas.getContext("2d");
|
|
|
+ // drawImage 画图软件透明色
|
|
|
+ ctx?.drawImage(
|
|
|
+ image,
|
|
|
+ image.naturalWidth * config[0],
|
|
|
+ 0,
|
|
|
+ image.naturalWidth * config[1],
|
|
|
+ image.naturalHeight,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ image.naturalWidth * config[1],
|
|
|
+ image.naturalHeight
|
|
|
+ );
|
|
|
+ // console.log(image, canvas.height, sliceConfig, ctx);
|
|
|
+ // console.log(canvas.toDataURL());
|
|
|
+ imageWithStyles.push({
|
|
|
+ url: canvas.toDataURL(),
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|