|
@@ -11,14 +11,15 @@ import { MenuItem } from "./menu";
|
|
|
import { copy } from "@/utils/shared";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
import { getRealPixel } from "@/example/fuse/views/tabulation/gen-tab";
|
|
|
-
|
|
|
+import { Mode } from "@/constant/mode";
|
|
|
+import { nextTick } from "vue";
|
|
|
+import { Rect } from "konva/lib/shapes/Rect";
|
|
|
|
|
|
export type PresetAdd<T extends ShapeType = ShapeType> = {
|
|
|
type: T;
|
|
|
preset?: Partial<DrawItem<T>>;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
const genDrawItem = <T extends ShapeType>(
|
|
|
type: T,
|
|
|
preset: PresetAdd<T>["preset"] = {}
|
|
@@ -34,7 +35,7 @@ export const draw: MenuItem = {
|
|
|
value: uuid(),
|
|
|
children: [
|
|
|
// { icon: "line", ...genDrawItem('sequentLine') },
|
|
|
- { icon: "line", ...genDrawItem('line') },
|
|
|
+ { icon: "line", ...genDrawItem("line") },
|
|
|
{ icon: "arrows", ...genDrawItem("arrow"), single: true },
|
|
|
{ icon: "rectangle", ...genDrawItem("rectangle"), single: true },
|
|
|
{ icon: "circle", ...genDrawItem("circle"), single: true },
|
|
@@ -46,7 +47,7 @@ export const draw: MenuItem = {
|
|
|
export const text: MenuItem = {
|
|
|
icon: "text",
|
|
|
...genDrawItem("text", { content: "文本" }),
|
|
|
- single: true
|
|
|
+ single: true,
|
|
|
};
|
|
|
|
|
|
export const table: MenuItem = {
|
|
@@ -60,7 +61,7 @@ export const serial: MenuItem = {
|
|
|
};
|
|
|
|
|
|
export const imp: MenuItem = {
|
|
|
- icon: 'import',
|
|
|
+ icon: "import",
|
|
|
name: "导入",
|
|
|
value: uuid(),
|
|
|
children: [
|
|
@@ -71,53 +72,57 @@ export const imp: MenuItem = {
|
|
|
handler: async (draw: Draw) => {
|
|
|
const aiData = await selectAI();
|
|
|
drawPlatformResource(aiData, draw);
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
value: uuid(),
|
|
|
icon: "local_i",
|
|
|
name: "本地",
|
|
|
handler: async (draw: Draw) => {
|
|
|
- let files: File[]
|
|
|
+ let files: File[];
|
|
|
try {
|
|
|
- files = await selectFile(false, '.png, .jpg, .jpeg')
|
|
|
+ files = await selectFile(false, ".png, .jpg");
|
|
|
} catch (e: any) {
|
|
|
- ElMessage.error(e.message)
|
|
|
+ ElMessage.error(e.message);
|
|
|
return;
|
|
|
}
|
|
|
- const url = await window.platform.uploadResourse(files[0])
|
|
|
- const image = await getImage(url)
|
|
|
- ElMessage.warning('请在画图面板中选择放置位置,鼠标右键取消')
|
|
|
- console.log(image)
|
|
|
- draw.enterDrawShape('image', {
|
|
|
- width: image.width,
|
|
|
- height: image.height,
|
|
|
- url
|
|
|
- }, true)
|
|
|
- }
|
|
|
- }
|
|
|
- ]
|
|
|
-}
|
|
|
+ const url = await window.platform.uploadResourse(files[0]);
|
|
|
+ const image = await getImage(url);
|
|
|
+ ElMessage.warning("请在画图面板中选择放置位置,鼠标右键取消");
|
|
|
+ console.log(image);
|
|
|
+ draw.enterDrawShape(
|
|
|
+ "image",
|
|
|
+ {
|
|
|
+ width: image.width,
|
|
|
+ height: image.height,
|
|
|
+ url,
|
|
|
+ },
|
|
|
+ true
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+};
|
|
|
|
|
|
export const getPaperConfig = (p: number[], scale: number) => {
|
|
|
const pad = 5 * scale;
|
|
|
const size = { width: p[0] * scale, height: p[1] * scale };
|
|
|
const margin = [pad, pad, pad, pad * 5];
|
|
|
- console.log(margin)
|
|
|
- const a = getRealPixel(5, 'a4')
|
|
|
- console.log([a, getRealPixel(25, 'a4')])
|
|
|
- return {size, margin}
|
|
|
-}
|
|
|
+ console.log(margin);
|
|
|
+ const a = getRealPixel(5, "a4");
|
|
|
+ console.log([a, getRealPixel(25, "a4")]);
|
|
|
+ return { size, margin };
|
|
|
+};
|
|
|
export const paperConfigs = {
|
|
|
- 'a4': { size: [297, 210], scale: 2.5 },
|
|
|
- 'a3': { size: [420, 297], scale: 2.5 }
|
|
|
-}
|
|
|
-export type PaperKey = keyof typeof paperConfigs
|
|
|
+ a4: { size: [297, 210], scale: 2.5 },
|
|
|
+ a3: { size: [420, 297], scale: 2.5 },
|
|
|
+};
|
|
|
+export type PaperKey = keyof typeof paperConfigs;
|
|
|
|
|
|
const setPaper = (draw: Draw, p: number[], scale: number) => {
|
|
|
- const { size, margin } = getPaperConfig(p, scale)
|
|
|
+ const { size, margin } = getPaperConfig(p, scale);
|
|
|
// draw.config.size = size;
|
|
|
- draw.viewer.setViewSize(size)
|
|
|
+ draw.viewer.setViewSize(size);
|
|
|
draw.config.back = { color: "#fff", opacity: 1 };
|
|
|
draw.config.border = {
|
|
|
margin: margin,
|
|
@@ -131,7 +136,7 @@ const setPaper = (draw: Draw, p: number[], scale: number) => {
|
|
|
export const paper = {
|
|
|
icon: "drawing",
|
|
|
name: "纸张",
|
|
|
- type: 'sub-menu-horizontal',
|
|
|
+ type: "sub-menu-horizontal",
|
|
|
value: uuid(),
|
|
|
children: [
|
|
|
// {
|
|
@@ -144,9 +149,10 @@ export const paper = {
|
|
|
{
|
|
|
value: uuid(),
|
|
|
icon: "A4_h",
|
|
|
- key: 'a4',
|
|
|
+ key: "a4",
|
|
|
name: "A4横版",
|
|
|
- handler: (draw: Draw) => setPaper(draw, paperConfigs.a4.size, paperConfigs.a4.scale),
|
|
|
+ handler: (draw: Draw) =>
|
|
|
+ setPaper(draw, paperConfigs.a4.size, paperConfigs.a4.scale),
|
|
|
},
|
|
|
// {
|
|
|
// value: uuid(),
|
|
@@ -158,9 +164,10 @@ export const paper = {
|
|
|
{
|
|
|
value: uuid(),
|
|
|
icon: "A3_h",
|
|
|
- key: 'a3',
|
|
|
+ key: "a3",
|
|
|
name: "A3横版",
|
|
|
- handler: (draw: Draw) => setPaper(draw, paperConfigs.a3.size, paperConfigs.a3.scale),
|
|
|
+ handler: (draw: Draw) =>
|
|
|
+ setPaper(draw, paperConfigs.a3.size, paperConfigs.a3.scale),
|
|
|
},
|
|
|
],
|
|
|
};
|
|
@@ -183,7 +190,9 @@ export const dbImage: MenuItem = {
|
|
|
} else if (info.ratio > 1) {
|
|
|
proportion = { scale: info.ratio, unit: "m" };
|
|
|
}
|
|
|
- const url = await window.platform.uploadResourse(new File([info.blob], 'map.png'))
|
|
|
+ const url = await window.platform.uploadResourse(
|
|
|
+ new File([info.blob], "map.png")
|
|
|
+ );
|
|
|
|
|
|
draw.history.onceTrack(() => {
|
|
|
draw.addShape(
|
|
@@ -207,14 +216,14 @@ export const test: MenuItem = {
|
|
|
value: uuid(),
|
|
|
icon: "debugger",
|
|
|
name: "测试",
|
|
|
- type: 'sub-menu-horizontal',
|
|
|
+ type: "sub-menu-horizontal",
|
|
|
children: [
|
|
|
{
|
|
|
value: uuid(),
|
|
|
icon: "",
|
|
|
name: "视图恢复",
|
|
|
handler: (draw: Draw) => {
|
|
|
- draw.viewer.setViewMat( [1, 0, 0, 1, 0, 0])
|
|
|
+ draw.viewer.setViewMat([1, 0, 0, 1, 0, 0]);
|
|
|
},
|
|
|
},
|
|
|
{
|
|
@@ -262,8 +271,29 @@ export const test: MenuItem = {
|
|
|
icon: "",
|
|
|
name: "获取当前数据",
|
|
|
handler: (draw: Draw) => {
|
|
|
- console.log(copy(draw.store.$state))
|
|
|
+ console.log(copy(draw.store.$state));
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: uuid(),
|
|
|
+ icon: "",
|
|
|
+ name: "切换a4导出视图",
|
|
|
+ async handler(draw) {
|
|
|
+ draw.viewer.setViewMat([1, 0, 0, 1, 0, 0]);
|
|
|
+ await nextTick();
|
|
|
+
|
|
|
+ const viewSize = draw.viewer.viewSize!;
|
|
|
+ const size = {
|
|
|
+ width: draw.stage!.width(),
|
|
|
+ height: draw.stage!.height(),
|
|
|
+ };
|
|
|
+ const rect = {
|
|
|
+ x: (size.width - viewSize.width) / 2,
|
|
|
+ y: (size.height - viewSize.height) / 2,
|
|
|
+ ...viewSize,
|
|
|
+ };
|
|
|
+ draw.stage?.children[2].add(new Rect({ ...rect, fill: 'red' }))
|
|
|
},
|
|
|
- }
|
|
|
+ },
|
|
|
],
|
|
|
};
|