|
@@ -1,272 +1,241 @@
|
|
|
-import { defineStore } from "pinia";
|
|
|
|
|
-import { AlignEnum } from "@/enum/alignEnum";
|
|
|
|
|
-import { LayerEnum } from "@/enum/layerEnum";
|
|
|
|
|
-import { useProjectStore } from "@/store/modules/project";
|
|
|
|
|
-import { cloneDeep } from "lodash";
|
|
|
|
|
-import { CustomElement } from "#/project";
|
|
|
|
|
-import { uuid } from "@/utils";
|
|
|
|
|
|
|
+import { defineStore } from 'pinia'
|
|
|
|
|
+import { AlignEnum } from '@/enum/alignEnum'
|
|
|
|
|
+import { LayerEnum } from '@/enum/layerEnum'
|
|
|
|
|
+import { useProjectStore } from '@/store/modules/project'
|
|
|
|
|
+import { cloneDeep } from 'lodash'
|
|
|
|
|
+import { CustomElement } from '#/project'
|
|
|
|
|
+import { uuid } from '@/utils'
|
|
|
|
|
|
|
|
type ActionState = {
|
|
type ActionState = {
|
|
|
// 操作记录--最大记录10条
|
|
// 操作记录--最大记录10条
|
|
|
- records: string[];
|
|
|
|
|
|
|
+ records: string[]
|
|
|
// 当前操作索引
|
|
// 当前操作索引
|
|
|
- activeIndex: number;
|
|
|
|
|
- appKey: number;
|
|
|
|
|
- copyCache: any;
|
|
|
|
|
-};
|
|
|
|
|
|
|
+ activeIndex: number
|
|
|
|
|
+ appKey: number
|
|
|
|
|
+ copyCache: any
|
|
|
|
|
+}
|
|
|
export const useAcionStore = defineStore('action', {
|
|
export const useAcionStore = defineStore('action', {
|
|
|
state(): ActionState {
|
|
state(): ActionState {
|
|
|
return {
|
|
return {
|
|
|
records: [],
|
|
records: [],
|
|
|
activeIndex: -1,
|
|
activeIndex: -1,
|
|
|
appKey: 0,
|
|
appKey: 0,
|
|
|
- copyCache: null,
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ copyCache: null
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
getters: {
|
|
getters: {
|
|
|
projectStore: () => useProjectStore(),
|
|
projectStore: () => useProjectStore(),
|
|
|
undoDisabled: (state) => state.activeIndex <= 0,
|
|
undoDisabled: (state) => state.activeIndex <= 0,
|
|
|
- redoDisabled: (state) => state.activeIndex === state.records.length - 1,
|
|
|
|
|
|
|
+ redoDisabled: (state) => state.activeIndex === state.records.length - 1
|
|
|
},
|
|
},
|
|
|
actions: {
|
|
actions: {
|
|
|
initRecord() {
|
|
initRecord() {
|
|
|
- this.records = [JSON.stringify(this.projectStore.projectInfo)];
|
|
|
|
|
- this.activeIndex = 0;
|
|
|
|
|
|
|
+ this.records = [JSON.stringify(this.projectStore.projectInfo)]
|
|
|
|
|
+ this.activeIndex = 0
|
|
|
},
|
|
},
|
|
|
// addRecord({type, info }: RecordItem & { snapshot?: ProjectInfo}) {
|
|
// addRecord({type, info }: RecordItem & { snapshot?: ProjectInfo}) {
|
|
|
addRecord() {
|
|
addRecord() {
|
|
|
// 新增如果当前索引不是最后一条, 覆盖后面的记录
|
|
// 新增如果当前索引不是最后一条, 覆盖后面的记录
|
|
|
if (this.activeIndex < this.records.length - 1) {
|
|
if (this.activeIndex < this.records.length - 1) {
|
|
|
- this.records.splice(this.activeIndex + 1, this.records.length);
|
|
|
|
|
|
|
+ this.records.splice(this.activeIndex + 1, this.records.length)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.records.push(JSON.stringify(this.projectStore.projectInfo));
|
|
|
|
|
|
|
+ this.records.push(JSON.stringify(this.projectStore.projectInfo))
|
|
|
|
|
|
|
|
// 新增如果超过10条记录,删除最早的一条
|
|
// 新增如果超过10条记录,删除最早的一条
|
|
|
if (this.records.length > 10) {
|
|
if (this.records.length > 10) {
|
|
|
- this.records.shift();
|
|
|
|
|
- this.activeIndex--;
|
|
|
|
|
|
|
+ this.records.shift()
|
|
|
|
|
+ this.activeIndex--
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.activeIndex = this.records.length - 1;
|
|
|
|
|
|
|
+ this.activeIndex = this.records.length - 1
|
|
|
},
|
|
},
|
|
|
/* 撤销 */
|
|
/* 撤销 */
|
|
|
actionUndo() {
|
|
actionUndo() {
|
|
|
- if (this.activeIndex <= 0) return;
|
|
|
|
|
- --this.activeIndex;
|
|
|
|
|
- const projectInfo = JSON.parse(this.records[this.activeIndex]);
|
|
|
|
|
- this.projectStore.updateProjectInfo(projectInfo);
|
|
|
|
|
- this.appKey++;
|
|
|
|
|
|
|
+ if (this.activeIndex <= 0) return
|
|
|
|
|
+ --this.activeIndex
|
|
|
|
|
+ const projectInfo = JSON.parse(this.records[this.activeIndex])
|
|
|
|
|
+ this.projectStore.updateProjectInfo(projectInfo)
|
|
|
|
|
+ this.appKey++
|
|
|
},
|
|
},
|
|
|
/* 重做 */
|
|
/* 重做 */
|
|
|
actionRedo() {
|
|
actionRedo() {
|
|
|
- ++this.activeIndex;
|
|
|
|
|
- const projectInfo = JSON.parse(this.records[this.activeIndex]);
|
|
|
|
|
- this.projectStore.updateProjectInfo(projectInfo);
|
|
|
|
|
- this.appKey++;
|
|
|
|
|
|
|
+ ++this.activeIndex
|
|
|
|
|
+ const projectInfo = JSON.parse(this.records[this.activeIndex])
|
|
|
|
|
+ this.projectStore.updateProjectInfo(projectInfo)
|
|
|
|
|
+ this.appKey++
|
|
|
},
|
|
},
|
|
|
actionClear() {},
|
|
actionClear() {},
|
|
|
/* 对齐 */
|
|
/* 对齐 */
|
|
|
actionAlign(type: AlignEnum) {
|
|
actionAlign(type: AlignEnum) {
|
|
|
- const activeElements = this.projectStore.currentSelectedElements;
|
|
|
|
|
|
|
+ const activeElements = this.projectStore.currentSelectedElements
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
case AlignEnum.Bottom: {
|
|
case AlignEnum.Bottom: {
|
|
|
const maxY = Math.max(
|
|
const maxY = Math.max(
|
|
|
- ...activeElements.map(
|
|
|
|
|
- (item) => item.container.props.y + item.container.props.height
|
|
|
|
|
- )
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ ...activeElements.map((item) => item.container.props.y + item.container.props.height)
|
|
|
|
|
+ )
|
|
|
activeElements.forEach((item) => {
|
|
activeElements.forEach((item) => {
|
|
|
this.projectStore.updateElement(
|
|
this.projectStore.updateElement(
|
|
|
item.key,
|
|
item.key,
|
|
|
- "container.props.y",
|
|
|
|
|
|
|
+ 'container.props.y',
|
|
|
maxY - item.container.props.height
|
|
maxY - item.container.props.height
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
case AlignEnum.HorizontalCenter: {
|
|
case AlignEnum.HorizontalCenter: {
|
|
|
const maxX = Math.max(
|
|
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.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) => {
|
|
activeElements.forEach((item) => {
|
|
|
this.projectStore.updateElement(
|
|
this.projectStore.updateElement(
|
|
|
item.key,
|
|
item.key,
|
|
|
- "container.props.x",
|
|
|
|
|
|
|
+ 'container.props.x',
|
|
|
centerX - item.container.props.width / 2
|
|
centerX - item.container.props.width / 2
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
case AlignEnum.VerticalCenter: {
|
|
case AlignEnum.VerticalCenter: {
|
|
|
const maxY = Math.max(
|
|
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.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) => {
|
|
activeElements.forEach((item) => {
|
|
|
this.projectStore.updateElement(
|
|
this.projectStore.updateElement(
|
|
|
item.key,
|
|
item.key,
|
|
|
- "container.props.y",
|
|
|
|
|
|
|
+ 'container.props.y',
|
|
|
centerY - item.container.props.height / 2
|
|
centerY - item.container.props.height / 2
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
case AlignEnum.Left: {
|
|
case AlignEnum.Left: {
|
|
|
- const minX = Math.min(
|
|
|
|
|
- ...activeElements.map((item) => item.container.props.x)
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const minX = Math.min(...activeElements.map((item) => item.container.props.x))
|
|
|
activeElements.forEach((item) => {
|
|
activeElements.forEach((item) => {
|
|
|
- this.projectStore.updateElement(
|
|
|
|
|
- item.key,
|
|
|
|
|
- "container.props.x",
|
|
|
|
|
- minX
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.x', minX)
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
case AlignEnum.Right: {
|
|
case AlignEnum.Right: {
|
|
|
const maxX = Math.max(
|
|
const maxX = Math.max(
|
|
|
- ...activeElements.map(
|
|
|
|
|
- (item) => item.container.props.x + item.container.props.width
|
|
|
|
|
- )
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ ...activeElements.map((item) => item.container.props.x + item.container.props.width)
|
|
|
|
|
+ )
|
|
|
activeElements.forEach((item) => {
|
|
activeElements.forEach((item) => {
|
|
|
this.projectStore.updateElement(
|
|
this.projectStore.updateElement(
|
|
|
item.key,
|
|
item.key,
|
|
|
- "container.props.x",
|
|
|
|
|
|
|
+ 'container.props.x',
|
|
|
maxX - item.container.props.width
|
|
maxX - item.container.props.width
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
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))
|
|
|
activeElements.forEach((item) => {
|
|
activeElements.forEach((item) => {
|
|
|
- this.projectStore.updateElement(
|
|
|
|
|
- item.key,
|
|
|
|
|
- "container.props.y",
|
|
|
|
|
- minY
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ this.projectStore.updateElement(item.key, 'container.props.y', minY)
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
default:
|
|
default:
|
|
|
}
|
|
}
|
|
|
- this.addRecord();
|
|
|
|
|
|
|
+ this.addRecord()
|
|
|
},
|
|
},
|
|
|
/* 图层调整 */
|
|
/* 图层调整 */
|
|
|
actionLayer(type: LayerEnum) {
|
|
actionLayer(type: LayerEnum) {
|
|
|
- const activeElements = this.projectStore.currentSelectedElements;
|
|
|
|
|
|
|
+ const activeElements = this.projectStore.currentSelectedElements
|
|
|
const elements = cloneDeep(
|
|
const elements = cloneDeep(
|
|
|
this.projectStore.elements.sort((a, b) => a.zIndex - b.zIndex)
|
|
this.projectStore.elements.sort((a, b) => a.zIndex - b.zIndex)
|
|
|
- ) as CustomElement[];
|
|
|
|
|
|
|
+ ) as CustomElement[]
|
|
|
|
|
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
case LayerEnum.UP: {
|
|
case LayerEnum.UP: {
|
|
|
activeElements.forEach((item) => {
|
|
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 });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ 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) => {
|
|
elements.forEach((item, index) => {
|
|
|
- item.zIndex = index + 1;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ item.zIndex = index + 1
|
|
|
|
|
+ })
|
|
|
elements.forEach((item) => {
|
|
elements.forEach((item) => {
|
|
|
- this.projectStore.updateElement(item.key, "zIndex", item.zIndex);
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex)
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
case LayerEnum.DOWN: {
|
|
case LayerEnum.DOWN: {
|
|
|
activeElements.forEach((item) => {
|
|
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 });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ 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) => {
|
|
elements.forEach((item, index) => {
|
|
|
- item.zIndex = index + 1;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ item.zIndex = index + 1
|
|
|
|
|
+ })
|
|
|
elements.forEach((item) => {
|
|
elements.forEach((item) => {
|
|
|
- this.projectStore.updateElement(item.key, "zIndex", item.zIndex);
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex)
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
case LayerEnum.TOP: {
|
|
case LayerEnum.TOP: {
|
|
|
activeElements.forEach((item) => {
|
|
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 });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ 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) => {
|
|
elements.forEach((item, index) => {
|
|
|
- item.zIndex = index + 1;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ item.zIndex = index + 1
|
|
|
|
|
+ })
|
|
|
elements.forEach((item) => {
|
|
elements.forEach((item) => {
|
|
|
- this.projectStore.updateElement(item.key, "zIndex", item.zIndex);
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex)
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
case LayerEnum.BOTTOM: {
|
|
case LayerEnum.BOTTOM: {
|
|
|
activeElements.forEach((item) => {
|
|
activeElements.forEach((item) => {
|
|
|
- const index = elements.findIndex(
|
|
|
|
|
- (element) => element.key === item.key
|
|
|
|
|
- );
|
|
|
|
|
- if (item.zIndex === 1) return;
|
|
|
|
|
- elements.splice(index, 1);
|
|
|
|
|
- elements.unshift({ ...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) => {
|
|
elements.forEach((item, index) => {
|
|
|
- item.zIndex = index + 1;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ item.zIndex = index + 1
|
|
|
|
|
+ })
|
|
|
elements.forEach((item) => {
|
|
elements.forEach((item) => {
|
|
|
- this.projectStore.updateElement(item.key, "zIndex", item.zIndex);
|
|
|
|
|
- });
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ this.projectStore.updateElement(item.key, 'zIndex', item.zIndex)
|
|
|
|
|
+ })
|
|
|
|
|
+ break
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- this.addRecord();
|
|
|
|
|
|
|
+ this.addRecord()
|
|
|
},
|
|
},
|
|
|
/* 添加组合 */
|
|
/* 添加组合 */
|
|
|
actionGroup() {
|
|
actionGroup() {
|
|
|
- const elements = this.projectStore.currentSelectedElements;
|
|
|
|
|
- const key = uuid();
|
|
|
|
|
|
|
+ const elements = this.projectStore.currentSelectedElements
|
|
|
|
|
+ const key = uuid()
|
|
|
// 1、移除元素
|
|
// 1、移除元素
|
|
|
elements.forEach((element) => {
|
|
elements.forEach((element) => {
|
|
|
- this.projectStore.removeElement(element.key);
|
|
|
|
|
- });
|
|
|
|
|
- const { minX, minY, maxX, maxY, maxZIndex } = calcComboInfo(elements);
|
|
|
|
|
- const groupIndex = this.projectStore.elements.filter((item) => item.componentType === "group").length + 1;
|
|
|
|
|
|
|
+ this.projectStore.removeElement(element.key)
|
|
|
|
|
+ })
|
|
|
|
|
+ const { minX, minY, maxX, maxY, maxZIndex } = calcComboInfo(elements)
|
|
|
|
|
+ const groupIndex =
|
|
|
|
|
+ this.projectStore.elements.filter((item) => item.componentType === 'group').length + 1
|
|
|
// 重新计算子元素位置
|
|
// 重新计算子元素位置
|
|
|
elements.forEach((item) => {
|
|
elements.forEach((item) => {
|
|
|
- item.container.props.x -= minX;
|
|
|
|
|
- item.container.props.y -= minY;
|
|
|
|
|
- item.parentKey = key;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ item.container.props.x -= minX
|
|
|
|
|
+ item.container.props.y -= minY
|
|
|
|
|
+ item.parentKey = key
|
|
|
|
|
+ })
|
|
|
const group: CustomElement = {
|
|
const group: CustomElement = {
|
|
|
key,
|
|
key,
|
|
|
- name: "组合" + groupIndex,
|
|
|
|
|
- componentType: "group",
|
|
|
|
|
|
|
+ name: '组合' + groupIndex,
|
|
|
|
|
+ componentType: 'group',
|
|
|
visible: true,
|
|
visible: true,
|
|
|
locked: false,
|
|
locked: false,
|
|
|
zIndex: maxZIndex,
|
|
zIndex: maxZIndex,
|
|
@@ -276,8 +245,8 @@ export const useAcionStore = defineStore('action', {
|
|
|
width: maxX - minX,
|
|
width: maxX - minX,
|
|
|
height: maxY - minY,
|
|
height: maxY - minY,
|
|
|
x: minX,
|
|
x: minX,
|
|
|
- y: minY,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ y: minY
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
children: elements,
|
|
children: elements,
|
|
|
collapsed: false,
|
|
collapsed: false,
|
|
@@ -286,49 +255,49 @@ export const useAcionStore = defineStore('action', {
|
|
|
props: {}
|
|
props: {}
|
|
|
}
|
|
}
|
|
|
// 2、添加组合元素
|
|
// 2、添加组合元素
|
|
|
- this.projectStore.addElement(group);
|
|
|
|
|
|
|
+ this.projectStore.addElement(group)
|
|
|
},
|
|
},
|
|
|
- /* 拆分组合元素 */
|
|
|
|
|
|
|
+ /* 拆分组合元素 */
|
|
|
actionUngroup() {
|
|
actionUngroup() {
|
|
|
- const group = this.projectStore.currentSelectedElements[0];
|
|
|
|
|
|
|
+ const group = this.projectStore.currentSelectedElements[0]
|
|
|
// 1、取出子元素
|
|
// 1、取出子元素
|
|
|
const elements = group.children?.map((item) => {
|
|
const elements = group.children?.map((item) => {
|
|
|
// 2、计算子元素位置
|
|
// 2、计算子元素位置
|
|
|
- item.container.props.x += group.container.props.x;
|
|
|
|
|
- item.container.props.y += group.container.props.y;
|
|
|
|
|
- delete item.parentKey;
|
|
|
|
|
- return item;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ item.container.props.x += group.container.props.x
|
|
|
|
|
+ item.container.props.y += group.container.props.y
|
|
|
|
|
+ delete item.parentKey
|
|
|
|
|
+ return item
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
// 3、移除组
|
|
// 3、移除组
|
|
|
- this.projectStore.removeElement(group.key);
|
|
|
|
|
|
|
+ this.projectStore.removeElement(group.key)
|
|
|
// 4、添加子元素
|
|
// 4、添加子元素
|
|
|
elements?.forEach((item) => {
|
|
elements?.forEach((item) => {
|
|
|
- this.projectStore.addElement(item, undefined, true);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ this.projectStore.addElement(item, undefined, true)
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
/* 复制 */
|
|
/* 复制 */
|
|
|
actionCopy() {
|
|
actionCopy() {
|
|
|
- const elements = this.projectStore.currentSelectedElements;
|
|
|
|
|
- this.copyCache = JSON.stringify(elements);
|
|
|
|
|
|
|
+ const elements = this.projectStore.currentSelectedElements
|
|
|
|
|
+ this.copyCache = JSON.stringify(elements)
|
|
|
},
|
|
},
|
|
|
/* 粘贴 */
|
|
/* 粘贴 */
|
|
|
actionPaste() {
|
|
actionPaste() {
|
|
|
- if (!this.copyCache) return;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (!this.copyCache) return
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
- const elements = JSON.parse(this.copyCache);
|
|
|
|
|
- const offsetX = 10;
|
|
|
|
|
- const offsetY = 10;
|
|
|
|
|
|
|
+ const elements = JSON.parse(this.copyCache)
|
|
|
|
|
+ const offsetX = 10
|
|
|
|
|
+ const offsetY = 10
|
|
|
elements.forEach((element: CustomElement) => {
|
|
elements.forEach((element: CustomElement) => {
|
|
|
- element.key = uuid();
|
|
|
|
|
- element.container.props.x += offsetX;
|
|
|
|
|
- element.container.props.y += offsetY;
|
|
|
|
|
- this.projectStore.addElement(element);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ element.key = uuid()
|
|
|
|
|
+ element.container.props.x += offsetX
|
|
|
|
|
+ element.container.props.y += offsetY
|
|
|
|
|
+ this.projectStore.addElement(element)
|
|
|
|
|
+ })
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- console.log(error);
|
|
|
|
|
|
|
+ console.log(error)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
-});
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+})
|