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, collapseValue,
list, list,
appendComponent({ text, type, ...config }: ComponentItem): void { appendComponent({ text, type, data = {} }: ComponentItem): void {
services?.editorService.add({ services?.editorService.add({
name: text, name: text,
type, type,
...config, ...data,
}); });
}, },
}; };

View File

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

View File

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

View File

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

View File

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