|
@@ -167,12 +167,15 @@ export async function getDataUrlForSplitConfig(
|
|
|
return dataurl;
|
|
|
}
|
|
|
|
|
|
-export async function preDrawImage(_currentTask: Task) {
|
|
|
+export async function preDrawImage(_currentTask: Task | undefined) {
|
|
|
+ console.log('preDrawImage=>curTask:',store.currentTask);
|
|
|
+
|
|
|
if (!_currentTask?.libraryId) return;
|
|
|
|
|
|
let maxSliceWidth = 0; // 最大的裁切块宽度,图片容器以此为准
|
|
|
|
|
|
- const hasSliceConfig = store.currentTask?.sliceConfig?.length;
|
|
|
+ // const hasSliceConfig = store.currentTask?.sliceConfig?.length;
|
|
|
+ const hasSliceConfig = _currentTask?.sliceConfig?.length;
|
|
|
|
|
|
const images = [];
|
|
|
|
|
@@ -241,6 +244,84 @@ export async function preDrawImage(_currentTask: Task) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+export async function preDrawImageHistory(_currentTask: Task | undefined) {
|
|
|
+ console.log('preDrawImageHistory=>curTask:',store.currentTask);
|
|
|
+
|
|
|
+ if (!_currentTask?.libraryId) return;
|
|
|
+
|
|
|
+ let maxSliceWidth = 0; // 最大的裁切块宽度,图片容器以此为准
|
|
|
+
|
|
|
+ // const hasSliceConfig = store.currentTask?.sliceConfig?.length;
|
|
|
+ const hasSliceConfig = _currentTask?.sliceConfig?.length;
|
|
|
+
|
|
|
+ const images = [];
|
|
|
+
|
|
|
+ if (hasSliceConfig) {
|
|
|
+ // 必须要先加载一遍,把“选择整图”的宽高重置后,再算总高度
|
|
|
+ const sliceNum = _currentTask.sliceUrls.length;
|
|
|
+ if (_currentTask.sliceConfig.some((v) => v.i > sliceNum)) {
|
|
|
+ console.warn("裁切图设置的数量小于该学生的总图片数量");
|
|
|
+ }
|
|
|
+ _currentTask.sliceConfig = _currentTask.sliceConfig.filter(
|
|
|
+ (v) => v.i <= sliceNum
|
|
|
+ );
|
|
|
+ for (const sliceConfig of _currentTask.sliceConfig) {
|
|
|
+ const url = _currentTask.sliceUrls[sliceConfig.i - 1];
|
|
|
+ const image = await loadImage(url);
|
|
|
+ images[sliceConfig.i] = image;
|
|
|
+ if (sliceConfig.w === 0 && sliceConfig.h === 0) {
|
|
|
+ // 选择整图时,w/h 为0
|
|
|
+ sliceConfig.w = image.naturalWidth;
|
|
|
+ sliceConfig.h = image.naturalHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ maxSliceWidth = Math.max(..._currentTask.sliceConfig.map((v) => v.w));
|
|
|
+
|
|
|
+ // 用来保存sliceImage在整个图片容器中(不包括image-seperator)的高度范围
|
|
|
+ for (const sliceConfig of _currentTask.sliceConfig) {
|
|
|
+ const url = _currentTask.sliceUrls[sliceConfig.i - 1];
|
|
|
+ const image = images[sliceConfig.i];
|
|
|
+
|
|
|
+ try {
|
|
|
+ await getDataUrlForSliceConfig(image, sliceConfig, maxSliceWidth, url);
|
|
|
+ } catch (error) {
|
|
|
+ console.log("preDrawImage failed: ", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (const url of _currentTask.sliceUrls) {
|
|
|
+ const image = await loadImage(url);
|
|
|
+ images.push(image);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const maxSplitConfig = Math.max(...store.setting.splitConfig);
|
|
|
+ maxSliceWidth =
|
|
|
+ Math.max(...images.map((v) => v.naturalWidth)) * maxSplitConfig;
|
|
|
+
|
|
|
+ for (const url of _currentTask.sliceUrls) {
|
|
|
+ for (const config of splitConfigPairs) {
|
|
|
+ const indexInSliceUrls = _currentTask.sliceUrls.indexOf(url) + 1;
|
|
|
+ const image = images[indexInSliceUrls - 1];
|
|
|
+
|
|
|
+ try {
|
|
|
+ await getDataUrlForSplitConfig(image, config, maxSliceWidth, url);
|
|
|
+ } catch (error) {
|
|
|
+ console.log("preDrawImage failed: ", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
export function addFileServerPrefixToTask(rawTask: Task): Task {
|
|
|
const newTask = JSON.parse(JSON.stringify(rawTask)) as Task;
|
|
|
|