|
@@ -1,6 +1,9 @@
|
|
import { defineStore } from "pinia";
|
|
import { defineStore } from "pinia";
|
|
import { AlignEnum } from "@/enum/alignEnum";
|
|
import { AlignEnum } from "@/enum/alignEnum";
|
|
|
|
+import { LayerEnum } from "@/enum/layerEnum";
|
|
import { useProjectStore } from "@/store/modules/project";
|
|
import { useProjectStore } from "@/store/modules/project";
|
|
|
|
+import { cloneDeep } from "lodash";
|
|
|
|
+import { CustomElement } from "#/project";
|
|
|
|
|
|
export const useAcionStore = defineStore({
|
|
export const useAcionStore = defineStore({
|
|
id: 'action',
|
|
id: 'action',
|
|
@@ -71,6 +74,7 @@ export const useAcionStore = defineStore({
|
|
}
|
|
}
|
|
case AlignEnum.Top: {
|
|
case AlignEnum.Top: {
|
|
const minY = Math.min(...activeElements.map((item) => item.container.props.y));
|
|
const minY = Math.min(...activeElements.map((item) => item.container.props.y));
|
|
|
|
+ console.log(this.projectStore.currentSelectedElements, minY)
|
|
activeElements.forEach((item) => {
|
|
activeElements.forEach((item) => {
|
|
this.projectStore.updateElement(item.key, 'container.props.y', minY);
|
|
this.projectStore.updateElement(item.key, 'container.props.y', minY);
|
|
});
|
|
});
|
|
@@ -78,6 +82,66 @@ export const useAcionStore = defineStore({
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ // 图层调整
|
|
|
|
+ actionLayer(type: LayerEnum) {
|
|
|
|
+ const activeElements = this.projectStore.currentSelectedElements;
|
|
|
|
+ const elements = cloneDeep(this.projectStore.elements.sort((a, b) => a.zIndex - b.zIndex)) as CustomElement[];
|
|
|
|
+
|
|
|
|
+ switch (type) {
|
|
|
|
+ case LayerEnum.UP: {
|
|
|
|
+ activeElements.forEach((item) => {
|
|
|
|
+ const index = elements.findIndex((element) => element.key === item.key);
|
|
|
|
+ if (item.zIndex === elements.length) return;
|
|
|
|
+ elements.splice(index, 1);
|
|
|
|
+ elements.splice(index + 1, 0, {...item});
|
|
|
|
+ });
|
|
|
|
+ elements.forEach((item, index) => { item.zIndex = index + 1});
|
|
|
|
+ elements.forEach(item => {
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex);
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case LayerEnum.DOWN: {
|
|
|
|
+ activeElements.forEach((item) => {
|
|
|
|
+ const index = elements.findIndex((element) => element.key === item.key);
|
|
|
|
+ if (item.zIndex === 1) return;
|
|
|
|
+ elements.splice(index, 1);
|
|
|
|
+ elements.splice(index - 1, 0, {...item});
|
|
|
|
+ });
|
|
|
|
+ elements.forEach((item, index) => { item.zIndex = index + 1});
|
|
|
|
+ elements.forEach(item => {
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex);
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case LayerEnum.TOP: {
|
|
|
|
+ activeElements.forEach((item) => {
|
|
|
|
+ const index = elements.findIndex((element) => element.key === item.key);
|
|
|
|
+ if (item.zIndex === elements.length) return;
|
|
|
|
+ elements.splice(index, 1);
|
|
|
|
+ elements.push({...item});
|
|
|
|
+ });
|
|
|
|
+ elements.forEach((item, index) => { item.zIndex = index + 1});
|
|
|
|
+ elements.forEach(item => {
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex);
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case LayerEnum.BOTTOM: {
|
|
|
|
+ activeElements.forEach((item) => {
|
|
|
|
+ const index = elements.findIndex((element) => element.key === item.key);
|
|
|
|
+ if (item.zIndex === 1) return;
|
|
|
|
+ elements.splice(index, 1);
|
|
|
|
+ elements.unshift({...item});
|
|
|
|
+ });
|
|
|
|
+ elements.forEach((item, index) => { item.zIndex = index + 1});
|
|
|
|
+ elements.forEach(item => {
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex);
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|