|
@@ -20,6 +20,9 @@ export const store = EditorModule.store({
|
|
currComp(state) {
|
|
currComp(state) {
|
|
return state.designData.compMap[state.currCompId];
|
|
return state.designData.compMap[state.currCompId];
|
|
},
|
|
},
|
|
|
|
+ pageCompIds(state): string[] {
|
|
|
|
+ return state.designData.compMap.root?.children.default || [];
|
|
|
|
+ },
|
|
},
|
|
},
|
|
actions: {
|
|
actions: {
|
|
setCompData(id: string, data: any) {
|
|
setCompData(id: string, data: any) {
|
|
@@ -32,10 +35,11 @@ export const store = EditorModule.store({
|
|
this.store.designData = new DesignTemp(data);
|
|
this.store.designData = new DesignTemp(data);
|
|
},
|
|
},
|
|
insertDesignContent(compKey: ICompKeys, index?: number) {
|
|
insertDesignContent(compKey: ICompKeys, index?: number) {
|
|
- index === undefined && (index = this.store.designData.content.length);
|
|
|
|
|
|
+ const { pageCompIds } = this.store;
|
|
|
|
+ index === undefined && (index = pageCompIds.length);
|
|
const compId = createCompId(compKey);
|
|
const compId = createCompId(compKey);
|
|
addCacheToMap(this.store.designData.compMap);
|
|
addCacheToMap(this.store.designData.compMap);
|
|
- this.store.designData.content.splice(index, 0, compId);
|
|
|
|
|
|
+ pageCompIds.splice(index, 0, compId);
|
|
return compId;
|
|
return compId;
|
|
},
|
|
},
|
|
insertCompContainer(compKey: ICompKeys, container: DesignComp) {
|
|
insertCompContainer(compKey: ICompKeys, container: DesignComp) {
|
|
@@ -49,20 +53,18 @@ export const store = EditorModule.store({
|
|
this.store.currCompId = compId;
|
|
this.store.currCompId = compId;
|
|
},
|
|
},
|
|
deleteComp(compId: string) {
|
|
deleteComp(compId: string) {
|
|
- const { content, compMap } = this.store.designData;
|
|
|
|
|
|
+ const { compMap } = this.store.designData;
|
|
const parentComp = this.helper.findParentComp(compId);
|
|
const parentComp = this.helper.findParentComp(compId);
|
|
let deleteOK = false;
|
|
let deleteOK = false;
|
|
if (parentComp) {
|
|
if (parentComp) {
|
|
- // 只能删除children中以compId作为key的组件
|
|
|
|
- if (parentComp.children?.[compId]) {
|
|
|
|
- delete parentComp.children[compId];
|
|
|
|
- deleteOK = true;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- const index = content.findIndex((id) => id === compId);
|
|
|
|
- if (index >= 0) {
|
|
|
|
- content.splice(index, 1);
|
|
|
|
- deleteOK = true;
|
|
|
|
|
|
+ const ids = parentComp.children.default;
|
|
|
|
+ // 只能删除children.default中的组件
|
|
|
|
+ if (ids?.includes(compId)) {
|
|
|
|
+ const index = ids.findIndex((id) => id === compId);
|
|
|
|
+ if (index >= 0) {
|
|
|
|
+ ids.splice(index, 1);
|
|
|
|
+ deleteOK = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -75,9 +77,9 @@ export const store = EditorModule.store({
|
|
}
|
|
}
|
|
},
|
|
},
|
|
moveComp(selIndex: number, targetIndex: number) {
|
|
moveComp(selIndex: number, targetIndex: number) {
|
|
- const { content } = this.store.designData;
|
|
|
|
- const [selComp] = content.splice(selIndex, 1);
|
|
|
|
- content.splice(targetIndex, 0, selComp);
|
|
|
|
|
|
+ const { pageCompIds } = this.store;
|
|
|
|
+ const [selComp] = pageCompIds.splice(selIndex, 1);
|
|
|
|
+ pageCompIds.splice(targetIndex, 0, selComp);
|
|
},
|
|
},
|
|
clearUnusedComps() {
|
|
clearUnusedComps() {
|
|
const used = new Set<string>();
|
|
const used = new Set<string>();
|
|
@@ -90,7 +92,8 @@ export const store = EditorModule.store({
|
|
});
|
|
});
|
|
return used;
|
|
return used;
|
|
};
|
|
};
|
|
- getUsedIds(this.store.designData.content);
|
|
|
|
|
|
+ const rootId = (this.helper.findRootComp() as DesignComp).id;
|
|
|
|
+ getUsedIds([rootId]);
|
|
Object.keys(this.store.designData.compMap).forEach((compId) => {
|
|
Object.keys(this.store.designData.compMap).forEach((compId) => {
|
|
if (!used.has(compId)) {
|
|
if (!used.has(compId)) {
|
|
delete this.store.designData.compMap[compId];
|
|
delete this.store.designData.compMap[compId];
|