|
@@ -1,25 +1,83 @@
|
|
|
import { defineStore } from "pinia";
|
|
|
+import { AlignEnum } from "@/enum/alignEnum";
|
|
|
+import { useProjectStore } from "@/store/modules/project";
|
|
|
|
|
|
export const useAcionStore = defineStore({
|
|
|
id: 'action',
|
|
|
state() {
|
|
|
return {
|
|
|
// 操作记录
|
|
|
- records: []
|
|
|
+ records: [],
|
|
|
}
|
|
|
},
|
|
|
+ getters: {
|
|
|
+ projectStore: () => useProjectStore(),
|
|
|
+ },
|
|
|
actions: {
|
|
|
addRecord(record) {
|
|
|
|
|
|
},
|
|
|
- undo() {
|
|
|
+ actionUndo() {
|
|
|
|
|
|
},
|
|
|
- redo() {
|
|
|
+ actionRedo() {
|
|
|
|
|
|
},
|
|
|
- clear() {
|
|
|
+ actionClear() {
|
|
|
|
|
|
+ },
|
|
|
+ // 对齐
|
|
|
+ actionAlign(type: AlignEnum) {
|
|
|
+ const activeElements = this.projectStore.currentSelectedElements;
|
|
|
+ switch (type) {
|
|
|
+ case AlignEnum.Bottom: {
|
|
|
+ const maxY = Math.max(...activeElements.map((item) => item.container.props.y + item.container.props.height));
|
|
|
+ activeElements.forEach((item) => {
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.y', maxY - item.container.props.height);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case AlignEnum.HorizontalCenter: {
|
|
|
+ const maxX = Math.max(...activeElements.map((item) => item.container.props.x + item.container.props.width));
|
|
|
+ const minX = Math.min(...activeElements.map((item) => item.container.props.x));
|
|
|
+ const centerX = minX + (maxX - minX) / 2;
|
|
|
+ activeElements.forEach((item) => {
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.x', centerX - item.container.props.width / 2);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case AlignEnum.VerticalCenter: {
|
|
|
+ const maxY = Math.max(...activeElements.map((item) => item.container.props.y + item.container.props.height));
|
|
|
+ const minY = Math.min(...activeElements.map((item) => item.container.props.y));
|
|
|
+ const centerY = minY + (maxY - minY) / 2;
|
|
|
+ activeElements.forEach((item) => {
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.y', centerY - item.container.props.height / 2);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case AlignEnum.Left: {
|
|
|
+ const minX = Math.min(...activeElements.map((item) => item.container.props.x));
|
|
|
+ activeElements.forEach((item) => {
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.x', minX);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case AlignEnum.Right: {
|
|
|
+ const maxX = Math.max(...activeElements.map((item) => item.container.props.x + item.container.props.width));
|
|
|
+ activeElements.forEach((item) => {
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.x', maxX - item.container.props.width);
|
|
|
+ });
|
|
|
+ break
|
|
|
+ }
|
|
|
+ case AlignEnum.Top: {
|
|
|
+ const minY = Math.min(...activeElements.map((item) => item.container.props.y));
|
|
|
+ activeElements.forEach((item) => {
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.y', minY);
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
})
|