|
@@ -7,16 +7,23 @@ import {
|
|
Ref,
|
|
Ref,
|
|
ref,
|
|
ref,
|
|
shallowReactive,
|
|
shallowReactive,
|
|
- watch,
|
|
|
|
watchEffect,
|
|
watchEffect,
|
|
} from "vue";
|
|
} from "vue";
|
|
import { useAutomaticData } from "./use-automatic-data";
|
|
import { useAutomaticData } from "./use-automatic-data";
|
|
-import { useMouseMigrateTempLayer, useZIndex } from "./use-layer";
|
|
|
|
|
|
+import { useCurrentZIndex, useZIndex } from "./use-layer";
|
|
import { useAnimationMouseStyle } from "./use-mouse-status";
|
|
import { useAnimationMouseStyle } from "./use-mouse-status";
|
|
import { components, DrawItem, ShapeType } from "../components";
|
|
import { components, DrawItem, ShapeType } from "../components";
|
|
import { useMatCompTransformer, useLineTransformer } from "./use-transformer";
|
|
import { useMatCompTransformer, useLineTransformer } from "./use-transformer";
|
|
import { useGetShapeCopyTransform } from "./use-copy";
|
|
import { useGetShapeCopyTransform } from "./use-copy";
|
|
-import { Delete, DocumentCopy, Location } from "@element-plus/icons-vue";
|
|
|
|
|
|
+import {
|
|
|
|
+ Bottom,
|
|
|
|
+ Delete,
|
|
|
|
+ DocumentCopy,
|
|
|
|
+ Location,
|
|
|
|
+ Lock,
|
|
|
|
+ Top,
|
|
|
|
+ Unlock,
|
|
|
|
+} from "@element-plus/icons-vue";
|
|
import { mergeFuns, onlyId } from "@/utils/shared";
|
|
import { mergeFuns, onlyId } from "@/utils/shared";
|
|
import { Shape } from "konva/lib/Shape";
|
|
import { Shape } from "konva/lib/Shape";
|
|
import { Transform } from "konva/lib/Util";
|
|
import { Transform } from "konva/lib/Util";
|
|
@@ -31,6 +38,93 @@ type Emit<T> = EmitFn<{
|
|
delShape: () => void;
|
|
delShape: () => void;
|
|
}>;
|
|
}>;
|
|
|
|
|
|
|
|
+export const useComponentMenus = <T extends DrawItem>(
|
|
|
|
+ shape: Ref<DC<EntityShape> | undefined>,
|
|
|
|
+ data: Ref<T>,
|
|
|
|
+ emit: Emit<T>,
|
|
|
|
+ alignment?: (data: T, mat: Transform) => void,
|
|
|
|
+ copyHandler?: (transform: Transform, data: T) => T
|
|
|
|
+) => {
|
|
|
|
+ const operateMenus: Array<{
|
|
|
|
+ icon?: any;
|
|
|
|
+ label?: string;
|
|
|
|
+ handler: () => void;
|
|
|
|
+ }> = shallowReactive([]);
|
|
|
|
+
|
|
|
|
+ // 锁定 解锁
|
|
|
|
+ operateMenus.push(
|
|
|
|
+ reactive({
|
|
|
|
+ label: computed(() => (data.value.lock ? "解锁" : "锁定")) as any,
|
|
|
|
+ icon: computed(() => (data.value.lock ? Unlock : Lock)),
|
|
|
|
+ handler() {
|
|
|
|
+ data.value.lock = !data.value.lock;
|
|
|
|
+ emit("updateShape", { ...data.value });
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // 置顶 置底
|
|
|
|
+ const currentZIndex = useCurrentZIndex();
|
|
|
|
+ operateMenus.push(
|
|
|
|
+ {
|
|
|
|
+ label: `置顶`,
|
|
|
|
+ icon: Top,
|
|
|
|
+ handler() {
|
|
|
|
+ data.value.zIndex = currentZIndex.max + 1;
|
|
|
|
+ emit("updateShape", { ...data.value });
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ label: `置底`,
|
|
|
|
+ icon: Bottom,
|
|
|
|
+ handler() {
|
|
|
|
+ data.value.zIndex = currentZIndex.min - 1;
|
|
|
|
+ emit("updateShape", { ...data.value });
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (alignment) {
|
|
|
|
+ const [alignmentShape] = useAlignmentShape(shape);
|
|
|
|
+ operateMenus.push({
|
|
|
|
+ label: "对齐",
|
|
|
|
+ async handler() {
|
|
|
|
+ const mat = await alignmentShape();
|
|
|
|
+ alignment(data.value, mat);
|
|
|
|
+ emit("updateShape", { ...data.value });
|
|
|
|
+ },
|
|
|
|
+ icon: Location,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (copyHandler) {
|
|
|
|
+ const getCopyTransform = useGetShapeCopyTransform(shape);
|
|
|
|
+ operateMenus.push({
|
|
|
|
+ label: `复制`,
|
|
|
|
+ icon: DocumentCopy,
|
|
|
|
+ handler() {
|
|
|
|
+ const transform = getCopyTransform();
|
|
|
|
+ const copyData = copyHandler(
|
|
|
|
+ transform,
|
|
|
|
+ JSON.parse(JSON.stringify(data.value)) as T
|
|
|
|
+ );
|
|
|
|
+ copyData.id = onlyId();
|
|
|
|
+ emit("addShape", copyData);
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ operateMenus.push({
|
|
|
|
+ label: `删除`,
|
|
|
|
+ icon: Delete,
|
|
|
|
+ handler() {
|
|
|
|
+ emit("delShape");
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return operateMenus;
|
|
|
|
+};
|
|
|
|
+
|
|
export type UseComponentStatusProps<
|
|
export type UseComponentStatusProps<
|
|
T extends DrawItem,
|
|
T extends DrawItem,
|
|
S extends EntityShape
|
|
S extends EntityShape
|
|
@@ -38,8 +132,7 @@ export type UseComponentStatusProps<
|
|
emit: Emit<T>;
|
|
emit: Emit<T>;
|
|
type?: ShapeType;
|
|
type?: ShapeType;
|
|
props: { data: T };
|
|
props: { data: T };
|
|
- disMouseStatus?: boolean
|
|
|
|
- alignment?: (data: T, mat: Transform) => void
|
|
|
|
|
|
+ alignment?: (data: T, mat: Transform) => void;
|
|
getMouseStyle: any;
|
|
getMouseStyle: any;
|
|
defaultStyle: any;
|
|
defaultStyle: any;
|
|
propertys: PropertyKeys;
|
|
propertys: PropertyKeys;
|
|
@@ -56,104 +149,57 @@ export type UseComponentStatusProps<
|
|
export const useComponentStatus = <S extends EntityShape, T extends DrawItem>(
|
|
export const useComponentStatus = <S extends EntityShape, T extends DrawItem>(
|
|
args: UseComponentStatusProps<T, S>
|
|
args: UseComponentStatusProps<T, S>
|
|
) => {
|
|
) => {
|
|
- const {
|
|
|
|
- emit,
|
|
|
|
- props,
|
|
|
|
- getMouseStyle,
|
|
|
|
- transformType,
|
|
|
|
- alignment,
|
|
|
|
- defaultStyle,
|
|
|
|
- customTransform,
|
|
|
|
- getRepShape,
|
|
|
|
- disMouseStatus,
|
|
|
|
- propertys,
|
|
|
|
- copyHandler,
|
|
|
|
- } = args;
|
|
|
|
-
|
|
|
|
const shape = ref<DC<S>>();
|
|
const shape = ref<DC<S>>();
|
|
- const data = useAutomaticData(() => props.data);
|
|
|
|
- let style: any
|
|
|
|
- if (!disMouseStatus) {
|
|
|
|
- [style] = useAnimationMouseStyle({
|
|
|
|
- data: data,
|
|
|
|
- shape,
|
|
|
|
- getMouseStyle,
|
|
|
|
- }) as any;
|
|
|
|
- } else {
|
|
|
|
- console.log(props.data)
|
|
|
|
- }
|
|
|
|
|
|
+ const data = useAutomaticData(() => args.props.data);
|
|
|
|
+ const [style] = useAnimationMouseStyle({
|
|
|
|
+ data: data,
|
|
|
|
+ shape,
|
|
|
|
+ getMouseStyle: args.getMouseStyle,
|
|
|
|
+ }) as any;
|
|
|
|
|
|
- if (transformType === "line") {
|
|
|
|
|
|
+ if (args.transformType === "line") {
|
|
useLineTransformer(
|
|
useLineTransformer(
|
|
shape as any,
|
|
shape as any,
|
|
data as any,
|
|
data as any,
|
|
- (newData) => emit("updateShape", newData as T),
|
|
|
|
- getRepShape as any
|
|
|
|
|
|
+ (newData) => args.emit("updateShape", newData as T),
|
|
|
|
+ args.getRepShape as any
|
|
);
|
|
);
|
|
- } else if (transformType === "mat") {
|
|
|
|
|
|
+ } else if (args.transformType === "mat") {
|
|
useMatCompTransformer(shape, data as any, (nData) =>
|
|
useMatCompTransformer(shape, data as any, (nData) =>
|
|
- emit("updateShape", nData as any)
|
|
|
|
|
|
+ args.emit("updateShape", nData as any)
|
|
|
|
+ );
|
|
|
|
+ } else if (args.transformType === "custom" && args.customTransform) {
|
|
|
|
+ args.customTransform(
|
|
|
|
+ () => args.emit("updateShape", data.value as any),
|
|
|
|
+ shape,
|
|
|
|
+ data
|
|
);
|
|
);
|
|
- } else if (transformType === "custom" && customTransform) {
|
|
|
|
- customTransform(() => emit("updateShape", data.value as any), shape, data);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
useZIndex(shape, data);
|
|
useZIndex(shape, data);
|
|
- // useMouseMigrateTempLayer(shape);
|
|
|
|
- const name = args.type ? components[args.type].shapeName : "";
|
|
|
|
- const getCopyTransform = useGetShapeCopyTransform(shape);
|
|
|
|
- const [alignmentShape] = useAlignmentShape(shape);
|
|
|
|
- const operateMenus = shallowReactive([
|
|
|
|
- {
|
|
|
|
- label: `删除${name}`,
|
|
|
|
- icon: Delete,
|
|
|
|
- handler() {
|
|
|
|
- emit("delShape");
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- label: `复制${name}`,
|
|
|
|
- icon: DocumentCopy,
|
|
|
|
- handler() {
|
|
|
|
- const transform = getCopyTransform();
|
|
|
|
- const copyData = copyHandler(
|
|
|
|
- transform,
|
|
|
|
- JSON.parse(JSON.stringify(data.value)) as T
|
|
|
|
- );
|
|
|
|
- copyData.id = onlyId();
|
|
|
|
- emit("addShape", copyData);
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- ]);
|
|
|
|
-
|
|
|
|
- if (alignment) {
|
|
|
|
- operateMenus.push({
|
|
|
|
- label: "对齐",
|
|
|
|
- async handler() {
|
|
|
|
- const mat = await alignmentShape();
|
|
|
|
- alignment(data.value, mat)
|
|
|
|
- emit('updateShape', { ...data.value })
|
|
|
|
- },
|
|
|
|
- icon: Location,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const describes = mergeDescribes(data, defaultStyle, propertys || []);
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
data,
|
|
data,
|
|
style,
|
|
style,
|
|
- tData: computed(() => {
|
|
|
|
- const tData = {...defaultStyle, ...data.value}
|
|
|
|
|
|
+ tData: computed(() => {
|
|
|
|
+ const tData = { ...args.defaultStyle, ...data.value };
|
|
if (style) {
|
|
if (style) {
|
|
- Object.assign(tData, style.value )
|
|
|
|
|
|
+ Object.assign(tData, style.value);
|
|
}
|
|
}
|
|
- return tData
|
|
|
|
|
|
+ return tData;
|
|
}),
|
|
}),
|
|
shape,
|
|
shape,
|
|
- operateMenus,
|
|
|
|
- describes,
|
|
|
|
|
|
+ operateMenus: useComponentMenus(
|
|
|
|
+ shape,
|
|
|
|
+ data,
|
|
|
|
+ args.emit,
|
|
|
|
+ args.alignment,
|
|
|
|
+ args.copyHandler
|
|
|
|
+ ),
|
|
|
|
+ describes: mergeDescribes(
|
|
|
|
+ data,
|
|
|
|
+ args.defaultStyle,
|
|
|
|
+ args.propertys || []
|
|
|
|
+ )
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
@@ -168,8 +214,6 @@ export const useGetComponentData = <D extends DrawItem>() => {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
export const useComponentsAttach = <T>(
|
|
export const useComponentsAttach = <T>(
|
|
getter: <K extends ShapeType>(type: K, data: DrawItem<K>) => T,
|
|
getter: <K extends ShapeType>(type: K, data: DrawItem<K>) => T,
|
|
types = Object.keys(components) as ShapeType[]
|
|
types = Object.keys(components) as ShapeType[]
|