mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-03 12:29:24 +08:00
fix(amis-saas-2815): 优化addChild方法
Change-Id: If016b68cdf7f8d3b7e42170ac5af89b411d0266c
This commit is contained in:
parent
4e67c09731
commit
45cf1ff60d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "amis-editor-core",
|
||||
"version": "5.2.3-beta.13",
|
||||
"version": "5.2.3-beta.15",
|
||||
"description": "amis 可视化编辑器",
|
||||
"main": "lib/index.js",
|
||||
"module": "esm/index.js",
|
||||
|
@ -43,6 +43,7 @@ import {
|
||||
guid,
|
||||
reactionWithOldValue,
|
||||
reGenerateID,
|
||||
JsonGenerateID,
|
||||
isString,
|
||||
isObject,
|
||||
isLayoutPlugin,
|
||||
@ -63,7 +64,7 @@ import {EditorDNDManager} from './dnd';
|
||||
import {IScopedContext} from 'amis';
|
||||
import {SchemaObject, SchemaCollection} from 'amis/lib/Schema';
|
||||
import type {RendererConfig} from 'amis-core/lib/factory';
|
||||
import {isPlainObject} from 'lodash';
|
||||
import isPlainObject from 'lodash/isPlainObject';
|
||||
|
||||
export interface EditorManagerConfig
|
||||
extends Omit<EditorProps, 'value' | 'onChange'> {}
|
||||
@ -1370,11 +1371,8 @@ export class EditorManager {
|
||||
let index: number = -1;
|
||||
const commonContext = this.buildEventContext(id);
|
||||
|
||||
// 填充id,有些脚手架生成了复杂的布局等,这里都填充一下id
|
||||
if (isPlainObject(json) && json.type && !json.id) {
|
||||
json = {...json, id: 'u:' + guid()};
|
||||
json = reGenerateID(json);
|
||||
}
|
||||
// 填充id,有些脚手架生成了复杂的布局等,自动填充一下id
|
||||
JsonGenerateID(json);
|
||||
|
||||
if (beforeId) {
|
||||
const arr = commonContext.schema[region];
|
||||
|
@ -556,6 +556,27 @@ export function reGenerateID(
|
||||
return json;
|
||||
}
|
||||
|
||||
// 遍历json,每层元素自动生成uid。
|
||||
export function JsonGenerateID(json: any) {
|
||||
if (Array.isArray(json)) {
|
||||
json.map((item: any) => JsonGenerateID(item));
|
||||
}
|
||||
if (!isObject(json) || isObservable(json)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (json.type && !json.id) {
|
||||
json.id = generateNodeId();
|
||||
}
|
||||
|
||||
Object.keys(json).forEach(key => {
|
||||
let curElem = json[key];
|
||||
if (isObject(curElem) || Array.isArray(curElem)) {
|
||||
JsonGenerateID(curElem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function createElementFromHTML(htmlString: string): HTMLElement {
|
||||
var div = document.createElement('div');
|
||||
// bca-disable-next-line
|
||||
|
Loading…
Reference in New Issue
Block a user