mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-28 19:09:57 +08:00
fix(editor): 新增组件id不对
This commit is contained in:
parent
ec1bf1dcb7
commit
fff587d9eb
@ -506,7 +506,7 @@ class Editor extends BaseService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await propsService.setNewItemId(config, this.get('root'));
|
config = await propsService.setNewItemId(config, this.get('root'));
|
||||||
if (config.style) {
|
if (config.style) {
|
||||||
config.style = {
|
config.style = {
|
||||||
...config.style,
|
...config.style,
|
||||||
|
@ -25,7 +25,7 @@ import { NodeType } from '@tmagic/schema';
|
|||||||
import { isPop, toLine } from '@tmagic/utils';
|
import { isPop, toLine } from '@tmagic/utils';
|
||||||
|
|
||||||
import type { PropsState } from '@editor/type';
|
import type { PropsState } from '@editor/type';
|
||||||
import { DEFAULT_CONFIG, fillConfig, getDefaultPropsValue } from '@editor/utils/props';
|
import { DEFAULT_CONFIG, fillConfig } from '@editor/utils/props';
|
||||||
|
|
||||||
import BaseService from './BaseService';
|
import BaseService from './BaseService';
|
||||||
|
|
||||||
@ -36,7 +36,15 @@ class Props extends BaseService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(['setPropsConfig', 'getPropsConfig', 'setPropsValue', 'getPropsValue', 'createId', 'setNewItemId']);
|
super([
|
||||||
|
'setPropsConfig',
|
||||||
|
'getPropsConfig',
|
||||||
|
'setPropsValue',
|
||||||
|
'getPropsValue',
|
||||||
|
'createId',
|
||||||
|
'setNewItemId',
|
||||||
|
'getDefaultPropsValue',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setPropsConfigs(configs: Record<string, FormConfig>) {
|
public setPropsConfigs(configs: Record<string, FormConfig>) {
|
||||||
@ -99,12 +107,20 @@ class Props extends BaseService {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = cloneDeep(defaultValue as any);
|
const [id, defaultPropsValue, data] = await Promise.all([
|
||||||
|
this.createId(type),
|
||||||
await this.setNewItemId(data);
|
this.getDefaultPropsValue(type),
|
||||||
|
this.setNewItemId(
|
||||||
|
cloneDeep({
|
||||||
|
type,
|
||||||
|
...defaultValue,
|
||||||
|
} as any),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...getDefaultPropsValue(type, await this.createId(type)),
|
id,
|
||||||
|
...defaultPropsValue,
|
||||||
...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data),
|
...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -133,6 +149,29 @@ class Props extends BaseService {
|
|||||||
await this.setNewItemId(item, config as MPage);
|
await this.setNewItemId(item, config as MPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取默认属性配置
|
||||||
|
* @param type 组件类型
|
||||||
|
* @returns Object
|
||||||
|
*/
|
||||||
|
public async getDefaultPropsValue(type: string) {
|
||||||
|
return ['page', 'container'].includes(type)
|
||||||
|
? {
|
||||||
|
type,
|
||||||
|
layout: 'absolute',
|
||||||
|
style: {},
|
||||||
|
name: type,
|
||||||
|
items: [],
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
type,
|
||||||
|
style: {},
|
||||||
|
name: type,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,25 +237,3 @@ export const fillConfig = (config: FormConfig = []) => [
|
|||||||
|
|
||||||
// 默认组件属性表单配置
|
// 默认组件属性表单配置
|
||||||
export const DEFAULT_CONFIG: FormConfig = fillConfig([]);
|
export const DEFAULT_CONFIG: FormConfig = fillConfig([]);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取默认属性配置
|
|
||||||
* @param type 组件类型
|
|
||||||
* @returns Object
|
|
||||||
*/
|
|
||||||
export const getDefaultPropsValue = (type: string, id: string) =>
|
|
||||||
['page', 'container'].includes(type)
|
|
||||||
? {
|
|
||||||
type,
|
|
||||||
id,
|
|
||||||
layout: 'absolute',
|
|
||||||
style: {},
|
|
||||||
name: type,
|
|
||||||
items: [],
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
type,
|
|
||||||
id,
|
|
||||||
style: {},
|
|
||||||
name: type,
|
|
||||||
};
|
|
||||||
|
@ -61,3 +61,8 @@ describe('setNewItemId', () => {
|
|||||||
expect(config.items[1].id === config.items[0].pop).toBeTruthy();
|
expect(config.items[1].id === config.items[0].pop).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getDefaultValue', async () => {
|
||||||
|
const value = await props.getDefaultPropsValue('text');
|
||||||
|
expect(value.type).toBe('text');
|
||||||
|
});
|
||||||
|
@ -42,10 +42,4 @@ describe('util form', () => {
|
|||||||
|
|
||||||
expect(config[0].items[0].items.length - defaultConfig[0].items[0].items.length).toBe(1);
|
expect(config[0].items[0].items.length - defaultConfig[0].items[0].items.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getDefaultValue', () => {
|
|
||||||
const value = props.getDefaultPropsValue('text', '1');
|
|
||||||
expect(value.id).toBe('1');
|
|
||||||
expect(value.type).toBe('text');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user