mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
pick: 同步 master 中关于 id 重新计算的逻辑 (#8721)
This commit is contained in:
parent
3157498c88
commit
118aaf5da8
@ -73,13 +73,13 @@ let themeUselessPropKeys: Array<string> = [];
|
||||
* 给每个节点加个 $$id 这样方便编辑
|
||||
* @param obj
|
||||
*/
|
||||
export function JSONPipeIn(obj: any, generateId = false): any {
|
||||
export function JSONPipeIn(obj: any, generateId = false, idMap: any = {}): any {
|
||||
if (!isObject(obj) || obj.$$typeof) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item, index) => JSONPipeIn(item, generateId));
|
||||
return obj.map((item, index) => JSONPipeIn(item, generateId, idMap));
|
||||
}
|
||||
|
||||
let toUpdate: any = {};
|
||||
@ -122,8 +122,13 @@ export function JSONPipeIn(obj: any, generateId = false): any {
|
||||
flag = true;
|
||||
|
||||
/** 脚手架构建的Schema提前构建好了组件 ID,此时无需生成 ID,避免破坏事件动作 */
|
||||
if (!obj.__origin || obj.__origin !== 'scaffold') {
|
||||
toUpdate.id = generateNodeId();
|
||||
if (
|
||||
(!obj.__origin || obj.__origin !== 'scaffold') &&
|
||||
(typeof obj.id !== 'string' || !obj.id || obj.id.startsWith('u:'))
|
||||
) {
|
||||
const newId = generateNodeId();
|
||||
obj.id && (idMap[obj.id] = newId);
|
||||
toUpdate.id = newId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,7 +142,7 @@ export function JSONPipeIn(obj: any, generateId = false): any {
|
||||
let flag2 = false;
|
||||
|
||||
let patched = prop.map((item: any) => {
|
||||
let patched = JSONPipeIn(item, generateId);
|
||||
let patched = JSONPipeIn(item, generateId, idMap);
|
||||
|
||||
if (patched !== item) {
|
||||
flag2 = true;
|
||||
@ -151,7 +156,14 @@ export function JSONPipeIn(obj: any, generateId = false): any {
|
||||
toUpdate[key] = patched;
|
||||
}
|
||||
} else {
|
||||
let patched = JSONPipeIn(prop, generateId);
|
||||
let patched = JSONPipeIn(prop, generateId, idMap);
|
||||
|
||||
if (generateId && typeof patched === 'string') {
|
||||
Object.keys(idMap).forEach(oldId => {
|
||||
const newId = idMap[oldId];
|
||||
patched = (patched as string).replaceAll(oldId, newId);
|
||||
});
|
||||
}
|
||||
|
||||
if (patched !== prop) {
|
||||
flag = true;
|
||||
|
Loading…
Reference in New Issue
Block a user