|
@@ -4,11 +4,12 @@ import { getEmptyStoreData, StoreData } from "@/core/store/store";
|
|
import { getFixPosition } from "@/utils/bound";
|
|
import { getFixPosition } from "@/utils/bound";
|
|
import { Size } from "@/utils/math";
|
|
import { Size } from "@/utils/math";
|
|
import { getImage } from "@/utils/resource";
|
|
import { getImage } from "@/utils/resource";
|
|
-import { tableCoverKey, tableTableKey, tableTitleKey } from "../../store";
|
|
|
|
|
|
+import { tableCoverHeight, tableCoverKey, tableCoverScaleKey, tableCoverWidth, tableTableKey, tableTitleKey } from "../../store";
|
|
import { matResponse, TableData } from "@/core/components/table";
|
|
import { matResponse, TableData } from "@/core/components/table";
|
|
import { TextData } from "@/core/components/text";
|
|
import { TextData } from "@/core/components/text";
|
|
import { ImageData } from "@/core/components/image";
|
|
import { ImageData } from "@/core/components/image";
|
|
import { Transform } from "konva/lib/Util";
|
|
import { Transform } from "konva/lib/Util";
|
|
|
|
+import { TabCover } from "../../req";
|
|
|
|
|
|
const setCoverPosition = (
|
|
const setCoverPosition = (
|
|
size: Size,
|
|
size: Size,
|
|
@@ -63,12 +64,16 @@ const setTitlePosition = (
|
|
title.mat[4] = titlePos.x;
|
|
title.mat[4] = titlePos.x;
|
|
title.mat[5] = titlePos.y;
|
|
title.mat[5] = titlePos.y;
|
|
};
|
|
};
|
|
|
|
+const setCoverScaleTextPosition = (cover: ImageData, title: TextData) => {
|
|
|
|
+ const x = cover.mat[4] - (title.width || 0) / 2;
|
|
|
|
+ const y = cover.mat[5] + cover.height / 2 + 10;
|
|
|
|
+ title.mat[4] = x;
|
|
|
|
+ title.mat[5] = y;
|
|
|
|
+};
|
|
|
|
|
|
|
|
|
|
-const genDefaultCover = async (cover: string) => {
|
|
|
|
- const image = await getImage(cover);
|
|
|
|
- const tableCoverWidth = 514
|
|
|
|
- const tableCoverHeight = 425
|
|
|
|
|
|
+const genDefaultCover = async (cover: TabCover) => {
|
|
|
|
+ const image = await getImage(cover.url);
|
|
const rectScale = image.width / image.height
|
|
const rectScale = image.width / image.height
|
|
const tableCoverScale = tableCoverWidth / tableCoverHeight
|
|
const tableCoverScale = tableCoverWidth / tableCoverHeight
|
|
|
|
|
|
@@ -81,13 +86,24 @@ const genDefaultCover = async (cover: string) => {
|
|
width = rectScale * height;
|
|
width = rectScale * height;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 缩放比例默认给10的倍数
|
|
|
|
+ let wScale = cover.width / width
|
|
|
|
+ let scale = Math.round((wScale * cover.proportion.scale) / 10) * 10
|
|
|
|
+ width = cover.width / (scale / cover.proportion.scale)
|
|
|
|
+ height = width / rectScale;
|
|
|
|
+
|
|
const coverData = {
|
|
const coverData = {
|
|
...getBaseItem(),
|
|
...getBaseItem(),
|
|
cornerRadius: 0,
|
|
cornerRadius: 0,
|
|
strokeWidth: 0,
|
|
strokeWidth: 0,
|
|
- url: cover,
|
|
|
|
- lock: true,
|
|
|
|
|
|
+ url: cover.url,
|
|
|
|
+ // lock: true,
|
|
key: tableCoverKey,
|
|
key: tableCoverKey,
|
|
|
|
+ proportion: cover.proportion,
|
|
|
|
+ disableTransformer: true,
|
|
|
|
+ widthRaw: cover.width,
|
|
|
|
+ showScale: true,
|
|
|
|
+ heightRaw: cover.height,
|
|
zIndex: -1,
|
|
zIndex: -1,
|
|
width,
|
|
width,
|
|
height,
|
|
height,
|
|
@@ -96,6 +112,22 @@ const genDefaultCover = async (cover: string) => {
|
|
return coverData;
|
|
return coverData;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+const genDefaultCoverScaleText = (cover: ImageData) => {
|
|
|
|
+ const scale = (cover.widthRaw! / cover.width) * cover.proportion!.scale;
|
|
|
|
+ return {
|
|
|
|
+ ...getBaseItem(),
|
|
|
|
+ content: `1:${scale}`,
|
|
|
|
+ width: 100,
|
|
|
|
+ heihgt: 16,
|
|
|
|
+ fontSize: 12,
|
|
|
|
+ disableEditText: true,
|
|
|
|
+ key: tableCoverScaleKey,
|
|
|
|
+ disableDelete: true,
|
|
|
|
+ align: "center",
|
|
|
|
+ mat: [1, 0, 0, 1, 0, 0],
|
|
|
|
+ };
|
|
|
|
+}
|
|
|
|
+
|
|
const genDefaultTable = () => {
|
|
const genDefaultTable = () => {
|
|
const nameColl = {
|
|
const nameColl = {
|
|
width: 140,
|
|
width: 140,
|
|
@@ -123,7 +155,6 @@ const genDefaultTable = () => {
|
|
height: nameColl.height * 5,
|
|
height: nameColl.height * 5,
|
|
mat: [1, 0, 0, 1, 0, 0],
|
|
mat: [1, 0, 0, 1, 0, 0],
|
|
};
|
|
};
|
|
- console.log({...data})
|
|
|
|
return matResponse({ data, mat: new Transform() })
|
|
return matResponse({ data, mat: new Transform() })
|
|
};
|
|
};
|
|
|
|
|
|
@@ -145,7 +176,7 @@ export const getRepTabulationStore = async (
|
|
store: StoreData,
|
|
store: StoreData,
|
|
size: Size,
|
|
size: Size,
|
|
margin: number | number[],
|
|
margin: number | number[],
|
|
- coverUrl?: string | null,
|
|
|
|
|
|
+ cover?: TabCover | null,
|
|
place = true
|
|
place = true
|
|
) => {
|
|
) => {
|
|
const layers = store?.layers;
|
|
const layers = store?.layers;
|
|
@@ -158,19 +189,25 @@ export const getRepTabulationStore = async (
|
|
setTablePosition(size, margin, tableData);
|
|
setTablePosition(size, margin, tableData);
|
|
layer = { text: [titleData], table: [tableData] };
|
|
layer = { text: [titleData], table: [tableData] };
|
|
|
|
|
|
- if (coverUrl) {
|
|
|
|
- const imageData = await genDefaultCover(coverUrl);
|
|
|
|
|
|
+ if (cover) {
|
|
|
|
+ const imageData = await genDefaultCover(cover);
|
|
setCoverPosition(size, margin, imageData);
|
|
setCoverPosition(size, margin, imageData);
|
|
layer.image = [imageData];
|
|
layer.image = [imageData];
|
|
|
|
+ layer.text!.push(genDefaultCoverScaleText(imageData))
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
layer.image = layer.image || [];
|
|
layer.image = layer.image || [];
|
|
const coverNdx = layer.image.findIndex(
|
|
const coverNdx = layer.image.findIndex(
|
|
(item) => item.key === tableCoverKey
|
|
(item) => item.key === tableCoverKey
|
|
);
|
|
);
|
|
|
|
+ layer.text = layer.text || []
|
|
|
|
+ const coverScaleNdx = layer.text.findIndex(
|
|
|
|
+ (item) => item.key === tableCoverScaleKey
|
|
|
|
+ );
|
|
|
|
|
|
- if (coverUrl) {
|
|
|
|
- const imageData = await genDefaultCover(coverUrl);
|
|
|
|
|
|
+ if (cover) {
|
|
|
|
+ const imageData = await genDefaultCover(cover);
|
|
|
|
+ const imageScaleData = genDefaultCoverScaleText(imageData)
|
|
if (!~coverNdx) {
|
|
if (!~coverNdx) {
|
|
setCoverPosition(size, margin, imageData);
|
|
setCoverPosition(size, margin, imageData);
|
|
layer.image.push(imageData);
|
|
layer.image.push(imageData);
|
|
@@ -178,22 +215,35 @@ export const getRepTabulationStore = async (
|
|
layer.image[coverNdx].url = imageData.url
|
|
layer.image[coverNdx].url = imageData.url
|
|
layer.image[coverNdx].width = imageData.width
|
|
layer.image[coverNdx].width = imageData.width
|
|
layer.image[coverNdx].height = imageData.height
|
|
layer.image[coverNdx].height = imageData.height
|
|
|
|
+ layer.image[coverNdx].widthRaw = imageData.widthRaw
|
|
|
|
+ layer.image[coverNdx].heightRaw = imageData.heightRaw
|
|
|
|
+ layer.image[coverNdx].proportion = imageData.proportion
|
|
}
|
|
}
|
|
- } else if (~coverNdx) {
|
|
|
|
- layer.image.splice(coverNdx, 1);
|
|
|
|
|
|
+
|
|
|
|
+ if (!~coverScaleNdx) {
|
|
|
|
+ setCoverScaleTextPosition(imageData, imageScaleData)
|
|
|
|
+ } else {
|
|
|
|
+ console.log(imageScaleData)
|
|
|
|
+ layer.text[coverScaleNdx].content = imageScaleData.content
|
|
|
|
+ setCoverScaleTextPosition(imageData, layer.text[coverScaleNdx])
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ~coverNdx && layer.image.splice(coverNdx, 1);
|
|
|
|
+ ~coverScaleNdx && layer.image.splice(coverScaleNdx, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (place) {
|
|
if (place) {
|
|
const imageData = layer.image?.find(item => item.key === tableCoverKey)
|
|
const imageData = layer.image?.find(item => item.key === tableCoverKey)
|
|
imageData && setCoverPosition(size, margin, imageData)
|
|
imageData && setCoverPosition(size, margin, imageData)
|
|
|
|
+ const imageScaleData = layer.text?.find(item => item.key === tableCoverScaleKey)
|
|
|
|
+ imageScaleData && imageData && setCoverScaleTextPosition(imageData, imageScaleData)
|
|
const titleData = layer.text?.find(item => item.key === tableTitleKey)
|
|
const titleData = layer.text?.find(item => item.key === tableTitleKey)
|
|
titleData && setTitlePosition(size, margin, titleData)
|
|
titleData && setTitlePosition(size, margin, titleData)
|
|
const tableData = layer.table?.find(item => item.key === tableTableKey)
|
|
const tableData = layer.table?.find(item => item.key === tableTableKey)
|
|
tableData && setTablePosition(size, margin, tableData)
|
|
tableData && setTablePosition(size, margin, tableData)
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
if (layers) {
|
|
if (layers) {
|
|
return {
|
|
return {
|
|
...store,
|
|
...store,
|