fix(editor): 修复新增组件时,组件列表配置的数据丢失问题

This commit is contained in:
roymondchen 2022-04-12 14:51:18 +08:00 committed by jia000
parent 31373500c2
commit 992ebbe3ce
5 changed files with 9 additions and 5 deletions

View File

@ -56,11 +56,11 @@ export default defineComponent({
collapseValue,
list,
appendComponent({ text, type, ...config }: ComponentItem): void {
appendComponent({ text, type, data = {} }: ComponentItem): void {
services?.editorService.add({
name: text,
type,
...config,
...data,
});
},
};

View File

@ -72,6 +72,7 @@ export default defineComponent({
services?.editorService.add({
name: config.text,
type: config.type,
...(config.data || {}),
});
},

View File

@ -229,7 +229,7 @@ class Editor extends BaseService {
const layout = await this.getLayout(parentNode);
const newNode = initPosition(
{ ...toRaw(await propsService.getPropsValue(type)), ...config },
{ ...toRaw(await propsService.getPropsValue(type, config)) },
layout,
parentNode,
this.get<StageCore>('stage'),

View File

@ -87,7 +87,7 @@ class Props extends BaseService {
* @param type
* @returns
*/
public async getPropsValue(type: string) {
public async getPropsValue(type: string, defaultValue = {}) {
if (type === 'area') {
const value = (await this.getPropsValue('button')) as MComponent;
value.className = 'action-area';
@ -100,6 +100,7 @@ class Props extends BaseService {
return cloneDeep({
...getDefaultPropsValue(type),
...defaultValue,
...(this.state.propsValueMap[type] || {}),
});
}

View File

@ -220,7 +220,9 @@ export interface ComponentItem {
type: string;
/** element-plus icon class */
icon?: string | Component;
[key: string]: any;
data?: {
[key: string]: any;
};
}
export interface ComponentGroup {