|
@@ -15,11 +15,20 @@ import { themeColor } from "@/constant/help-style";
|
|
import { dragListener } from "@/utils/event";
|
|
import { dragListener } from "@/utils/event";
|
|
import { Layer } from "konva/lib/Layer";
|
|
import { Layer } from "konva/lib/Layer";
|
|
import { useOperMode } from "./use-status";
|
|
import { useOperMode } from "./use-status";
|
|
-import { computed, markRaw, nextTick, reactive, ref, watch, watchEffect } from "vue";
|
|
|
|
|
|
+import {
|
|
|
|
+ computed,
|
|
|
|
+ markRaw,
|
|
|
|
+ nextTick,
|
|
|
|
+ reactive,
|
|
|
|
+ ref,
|
|
|
|
+ watch,
|
|
|
|
+ watchEffect,
|
|
|
|
+} from "vue";
|
|
import { EntityShape } from "@/deconstruction";
|
|
import { EntityShape } from "@/deconstruction";
|
|
import { Util } from "konva/lib/Util";
|
|
import { Util } from "konva/lib/Util";
|
|
import { useViewerInvertTransform } from "./use-viewer";
|
|
import { useViewerInvertTransform } from "./use-viewer";
|
|
import {
|
|
import {
|
|
|
|
+ debounce,
|
|
diffArrayChange,
|
|
diffArrayChange,
|
|
mergeFuns,
|
|
mergeFuns,
|
|
onlyId,
|
|
onlyId,
|
|
@@ -66,7 +75,7 @@ const normalSelectIds = (
|
|
);
|
|
);
|
|
nIds.push(...addIds);
|
|
nIds.push(...addIds);
|
|
}
|
|
}
|
|
- return nIds
|
|
|
|
|
|
+ return nIds;
|
|
};
|
|
};
|
|
|
|
|
|
export const normalSelectShapes = (
|
|
export const normalSelectShapes = (
|
|
@@ -118,12 +127,11 @@ export const useSelection = installGlobalVar(() => {
|
|
const boxRect = box.getClientRect();
|
|
const boxRect = box.getClientRect();
|
|
selections.value = [];
|
|
selections.value = [];
|
|
|
|
|
|
-
|
|
|
|
for (let i = 0; i < shapeBoxs.length; i++) {
|
|
for (let i = 0; i < shapeBoxs.length; i++) {
|
|
if (Util.haveIntersection(boxRect, shapeBoxs[i]))
|
|
if (Util.haveIntersection(boxRect, shapeBoxs[i]))
|
|
selections.value.push(shapes[i]);
|
|
selections.value.push(shapes[i]);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
const init = (dom: HTMLDivElement, layer: Layer) => {
|
|
const init = (dom: HTMLDivElement, layer: Layer) => {
|
|
const stopListener = dragListener(dom, {
|
|
const stopListener = dragListener(dom, {
|
|
@@ -137,7 +145,7 @@ export const useSelection = installGlobalVar(() => {
|
|
move({ end }) {
|
|
move({ end }) {
|
|
box.width(end.x - box.x());
|
|
box.width(end.x - box.x());
|
|
box.height(end.y - box.y());
|
|
box.height(end.y - box.y());
|
|
- updateSelections()
|
|
|
|
|
|
+ updateSelections();
|
|
},
|
|
},
|
|
up() {
|
|
up() {
|
|
selections.value = undefined;
|
|
selections.value = undefined;
|
|
@@ -154,27 +162,14 @@ export const useSelection = installGlobalVar(() => {
|
|
shapes = getChildren();
|
|
shapes = getChildren();
|
|
shapeBoxs = shapes.map((shape) => shape.getClientRect());
|
|
shapeBoxs = shapes.map((shape) => shape.getClientRect());
|
|
};
|
|
};
|
|
- const shpaesChange = () => {
|
|
|
|
- updateInitData()
|
|
|
|
- updateSelections()
|
|
|
|
- }
|
|
|
|
|
|
|
|
- const store = useStore()
|
|
|
|
const stopWatch = globalWatch(
|
|
const stopWatch = globalWatch(
|
|
() => operMode.value.mulSelection,
|
|
() => operMode.value.mulSelection,
|
|
(mulSelection, _, onCleanup) => {
|
|
(mulSelection, _, onCleanup) => {
|
|
if (!mulSelection) return;
|
|
if (!mulSelection) return;
|
|
const dom = stage.value?.getNode().container()!;
|
|
const dom = stage.value?.getNode().container()!;
|
|
updateInitData();
|
|
updateInitData();
|
|
-
|
|
|
|
- const unInit = init(dom, layer.value!);
|
|
|
|
- store.bus.on('dataChangeAfter', shpaesChange)
|
|
|
|
- store.bus.on('delItemAfter', shpaesChange)
|
|
|
|
- onCleanup(() => {
|
|
|
|
- unInit()
|
|
|
|
- store.bus.off('dataChangeAfter', shpaesChange)
|
|
|
|
- store.bus.off('delItemAfter', shpaesChange)
|
|
|
|
- })
|
|
|
|
|
|
+ onCleanup(init(dom, layer.value!));
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
@@ -286,25 +281,24 @@ export const useWatchSelectionGroup = () => {
|
|
export const useSelectionRevise = () => {
|
|
export const useSelectionRevise = () => {
|
|
const mParts = useMountParts();
|
|
const mParts = useMountParts();
|
|
const status = useMouseShapesStatus();
|
|
const status = useMouseShapesStatus();
|
|
|
|
+ const store = useStore();
|
|
const { addShapes, delShapes, watchSelectionGroup } =
|
|
const { addShapes, delShapes, watchSelectionGroup } =
|
|
useWatchSelectionGroup();
|
|
useWatchSelectionGroup();
|
|
|
|
|
|
useSelectionShowIcons();
|
|
useSelectionShowIcons();
|
|
|
|
|
|
const getFormatChildren = useGetFormalChildren();
|
|
const getFormatChildren = useGetFormalChildren();
|
|
- const mouseSelects = computed(() => {
|
|
|
|
|
|
+ const filterSelect = debounce(() => {
|
|
const children = getFormatChildren();
|
|
const children = getFormatChildren();
|
|
- const selectShapes = status.selects.filter((shape) => {
|
|
|
|
- return children.includes(shape);
|
|
|
|
- });
|
|
|
|
- return selectShapes;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- watchEffect(() => {
|
|
|
|
- if (mouseSelects.value.length !== status.selects.length) {
|
|
|
|
- status.selects = mouseSelects.value;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ const mouseSelects = status.selects.filter((shape) =>
|
|
|
|
+ children.includes(shape)
|
|
|
|
+ );
|
|
|
|
+ status.selects = mouseSelects;
|
|
|
|
+ }, 16);
|
|
|
|
+ store.bus.on("delItemAfter", filterSelect);
|
|
|
|
+ store.bus.on("clearAfter", filterSelect);
|
|
|
|
+ store.bus.on("dataChangeAfter", filterSelect);
|
|
|
|
+ store.bus.on("setCurrentLayerAfter", filterSelect);
|
|
|
|
|
|
const rectSelects = useSelection();
|
|
const rectSelects = useSelection();
|
|
let initSelections: EntityShape[] = [];
|
|
let initSelections: EntityShape[] = [];
|
|
@@ -313,7 +307,7 @@ export const useSelectionRevise = () => {
|
|
() => rectSelects.value && [...rectSelects.value],
|
|
() => rectSelects.value && [...rectSelects.value],
|
|
(rectSelects, oldRectSelects) => {
|
|
(rectSelects, oldRectSelects) => {
|
|
if (!oldRectSelects) {
|
|
if (!oldRectSelects) {
|
|
- initSelections = [...mouseSelects.value];
|
|
|
|
|
|
+ initSelections = [...status.selects];
|
|
stopWatchSelectionGroup();
|
|
stopWatchSelectionGroup();
|
|
} else if (!rectSelects) {
|
|
} else if (!rectSelects) {
|
|
initSelections = [];
|
|
initSelections = [];
|
|
@@ -340,7 +334,7 @@ export const useSelectionRevise = () => {
|
|
const layer = useFormalLayer();
|
|
const layer = useFormalLayer();
|
|
watch(
|
|
watch(
|
|
() => [!!ids.value.length, operMode.value.mulSelection],
|
|
() => [!!ids.value.length, operMode.value.mulSelection],
|
|
- () => {
|
|
|
|
|
|
+ (_a, _b) => {
|
|
const groupShape = layer.value?.findOne<Group>(`#${groupConfig.id}`);
|
|
const groupShape = layer.value?.findOne<Group>(`#${groupConfig.id}`);
|
|
if (!groupShape) return;
|
|
if (!groupShape) return;
|
|
if (ids.value.length && !operMode.value.mulSelection) {
|
|
if (ids.value.length && !operMode.value.mulSelection) {
|
|
@@ -352,32 +346,31 @@ export const useSelectionRevise = () => {
|
|
);
|
|
);
|
|
|
|
|
|
const stage = useStage();
|
|
const stage = useStage();
|
|
- const store = useStore();
|
|
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
const showItemId = useForciblyShowItemIds();
|
|
const showItemId = useForciblyShowItemIds();
|
|
watchEffect((onCleanup) => {
|
|
watchEffect((onCleanup) => {
|
|
if (!ids.value.length) return;
|
|
if (!ids.value.length) return;
|
|
const props = {
|
|
const props = {
|
|
data: { ...groupConfig, ids: ids.value },
|
|
data: { ...groupConfig, ids: ids.value },
|
|
|
|
+ key: groupConfig.id,
|
|
onUpdateShape(data: GroupData) {
|
|
onUpdateShape(data: GroupData) {
|
|
- status.selects
|
|
|
|
- data.ids
|
|
|
|
|
|
+ status.selects;
|
|
|
|
+ data.ids;
|
|
},
|
|
},
|
|
onDelShape() {
|
|
onDelShape() {
|
|
- console.log('delShape')
|
|
|
|
- status.selects = []
|
|
|
|
|
|
+ status.selects = [];
|
|
},
|
|
},
|
|
onAddShape(data: GroupData) {
|
|
onAddShape(data: GroupData) {
|
|
history.onceTrack(() => {
|
|
history.onceTrack(() => {
|
|
const ids = data.ids;
|
|
const ids = data.ids;
|
|
- const cIds = ids.filter(id => store.getType(id) !== "group")
|
|
|
|
|
|
+ const cIds = ids.filter((id) => store.getType(id) !== "group");
|
|
|
|
|
|
- const groups = store.typeItems.group
|
|
|
|
- const exists = groups?.some(group => {
|
|
|
|
- if (group.ids.length !== cIds.length) return false
|
|
|
|
- const diff = diffArrayChange(group.ids, cIds)
|
|
|
|
- return diff.added.length === 0 && diff.deleted.length == 0
|
|
|
|
- })
|
|
|
|
|
|
+ const groups = store.typeItems.group;
|
|
|
|
+ const exists = groups?.some((group) => {
|
|
|
|
+ if (group.ids.length !== cIds.length) return false;
|
|
|
|
+ const diff = diffArrayChange(group.ids, cIds);
|
|
|
|
+ return diff.added.length === 0 && diff.deleted.length == 0;
|
|
|
|
+ });
|
|
if (exists) return;
|
|
if (exists) return;
|
|
|
|
|
|
let selects = new Set(status.selects);
|
|
let selects = new Set(status.selects);
|