|
@@ -1,19 +1,87 @@
|
|
<template>
|
|
<template>
|
|
- <div>
|
|
|
|
- <div>
|
|
|
|
- <a href="/mark/subject-select">{{ store.setting.subject?.name }}</a>
|
|
|
|
- </div>
|
|
|
|
|
|
+ <div class="mark-body-container" ref="container">
|
|
|
|
+ <template v-for="(item, index) in imageWithStyles" :key="index">
|
|
|
|
+ <img :src="item.url" />
|
|
|
|
+ <!-- style="border: 1px solid black; background: black" -->
|
|
|
|
+ </template>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
-import { defineComponent } from "vue";
|
|
|
|
|
|
+import { defineComponent, onMounted, reactive, ref, watchEffect } from "vue";
|
|
import { store } from "./store";
|
|
import { store } from "./store";
|
|
|
|
+import filters from "@/filters";
|
|
|
|
|
|
|
|
+interface ImageStyle {
|
|
|
|
+ width: number; // or string?
|
|
|
|
+}
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
name: "MarkBody",
|
|
name: "MarkBody",
|
|
setup() {
|
|
setup() {
|
|
- return { store };
|
|
|
|
|
|
+ const container = ref(null);
|
|
|
|
+ const 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;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ 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 containerWidth = +getComputedStyle(div).width.replace("px", "");
|
|
|
|
+ // console.log(div, containerWidth, sliceConfig);
|
|
|
|
+ // console.log(container);
|
|
|
|
+ // const originalWidth = image.naturalWidth;
|
|
|
|
+ // const originalHeight = image.naturalHeight;
|
|
|
|
+ // console.log({ originalWidth, originalHeight });
|
|
|
|
+ // const ratio = containerWidth / originalWidth;
|
|
|
|
+ // getNaturalWidth
|
|
|
|
+ const canvas = document.createElement("canvas");
|
|
|
|
+ canvas.width = sliceConfig.w;
|
|
|
|
+ canvas.height = sliceConfig.h;
|
|
|
|
+ const ctx = canvas.getContext("2d");
|
|
|
|
+ ctx?.drawImage(
|
|
|
|
+ image,
|
|
|
|
+ sliceConfig.x,
|
|
|
|
+ sliceConfig.y,
|
|
|
|
+ sliceConfig.w,
|
|
|
|
+ sliceConfig.h,
|
|
|
|
+ 0,
|
|
|
|
+ 0,
|
|
|
|
+ sliceConfig.w,
|
|
|
|
+ sliceConfig.h
|
|
|
|
+ );
|
|
|
|
+ console.log(image, canvas.height, sliceConfig, ctx);
|
|
|
|
+ // console.log(canvas.toDataURL());
|
|
|
|
+ imageWithStyles.push({
|
|
|
|
+ url: canvas.toDataURL(),
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ console.log("watch effect", imageWithStyles);
|
|
|
|
+ });
|
|
|
|
+ return { container, store, imageWithStyles };
|
|
},
|
|
},
|
|
});
|
|
});
|
|
</script>
|
|
</script>
|
|
|
|
+
|
|
|
|
+<style scoped>
|
|
|
|
+.mark-body-container {
|
|
|
|
+ height: calc(100vh - 21px);
|
|
|
|
+ /* overflow: scroll; */
|
|
|
|
+}
|
|
|
|
+</style>
|