mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
fix(amis-editor): 优化reGenerateID逻辑
This commit is contained in:
parent
a151561269
commit
377db11b7c
@ -535,9 +535,9 @@ export default class Editor extends Component<EditorProps> {
|
|||||||
);
|
);
|
||||||
if (this.store.activeId === this.curCopySchemaData.$$id) {
|
if (this.store.activeId === this.curCopySchemaData.$$id) {
|
||||||
// 复制和粘贴是同一个元素,则直接追加到当前元素后面
|
// 复制和粘贴是同一个元素,则直接追加到当前元素后面
|
||||||
this.manager.appendSiblingSchema(reGenerateID(curSimpleSchema));
|
this.manager.appendSiblingSchema(reGenerateID(curSimpleSchema), false);
|
||||||
} else {
|
} else {
|
||||||
this.manager.addElem(reGenerateID(curSimpleSchema));
|
this.manager.addElem(reGenerateID(curSimpleSchema), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -923,7 +923,13 @@ export class EditorManager {
|
|||||||
!isSpecialLayout
|
!isSpecialLayout
|
||||||
) {
|
) {
|
||||||
// 布局能力提升: 点击插入新元素,当wrapper为空插入布局容器时,自动改为置换,避免过多层级
|
// 布局能力提升: 点击插入新元素,当wrapper为空插入布局容器时,自动改为置换,避免过多层级
|
||||||
this.replaceChild(curActiveId, curElemSchema);
|
this.replaceChild(
|
||||||
|
curActiveId,
|
||||||
|
curElemSchema,
|
||||||
|
subRenderer,
|
||||||
|
store.insertRegion,
|
||||||
|
reGenerateId
|
||||||
|
);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.updateConfigPanel();
|
this.updateConfigPanel();
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -1009,7 +1015,7 @@ export class EditorManager {
|
|||||||
regionNodeRegion,
|
regionNodeRegion,
|
||||||
value,
|
value,
|
||||||
nextId,
|
nextId,
|
||||||
subRenderer,
|
subRenderer || node.info,
|
||||||
{
|
{
|
||||||
id: store.dragId,
|
id: store.dragId,
|
||||||
type: store.dragType,
|
type: store.dragType,
|
||||||
@ -1055,7 +1061,8 @@ export class EditorManager {
|
|||||||
async appendSiblingSchema(
|
async appendSiblingSchema(
|
||||||
rendererSchema: Object,
|
rendererSchema: Object,
|
||||||
beforeInsert?: boolean,
|
beforeInsert?: boolean,
|
||||||
disabledAutoSelectInsertElem?: boolean
|
disabledAutoSelectInsertElem?: boolean,
|
||||||
|
reGenerateId?: boolean
|
||||||
) {
|
) {
|
||||||
if (!rendererSchema) {
|
if (!rendererSchema) {
|
||||||
return;
|
return;
|
||||||
@ -1113,7 +1120,14 @@ export class EditorManager {
|
|||||||
regionNodeId,
|
regionNodeId,
|
||||||
regionNodeRegion,
|
regionNodeRegion,
|
||||||
rendererSchema,
|
rendererSchema,
|
||||||
nextId
|
nextId,
|
||||||
|
node.info,
|
||||||
|
{
|
||||||
|
id: store.dragId,
|
||||||
|
type: store.dragType,
|
||||||
|
data: store.dragSchema
|
||||||
|
},
|
||||||
|
reGenerateId
|
||||||
);
|
);
|
||||||
if (child && !disabledAutoSelectInsertElem) {
|
if (child && !disabledAutoSelectInsertElem) {
|
||||||
// mobx 修改数据是异步的
|
// mobx 修改数据是异步的
|
||||||
@ -1542,7 +1556,7 @@ export class EditorManager {
|
|||||||
region: string,
|
region: string,
|
||||||
json: any,
|
json: any,
|
||||||
beforeId?: string,
|
beforeId?: string,
|
||||||
subRenderer?: SubRendererInfo,
|
subRenderer?: SubRendererInfo | RendererInfo,
|
||||||
dragInfo?: {
|
dragInfo?: {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
@ -1625,7 +1639,7 @@ export class EditorManager {
|
|||||||
replaceChild(
|
replaceChild(
|
||||||
id: string,
|
id: string,
|
||||||
json: any,
|
json: any,
|
||||||
subRenderer?: SubRendererInfo,
|
subRenderer?: SubRendererInfo | RendererInfo,
|
||||||
region?: string,
|
region?: string,
|
||||||
reGenerateId?: boolean
|
reGenerateId?: boolean
|
||||||
): boolean {
|
): boolean {
|
||||||
|
@ -529,7 +529,7 @@ export interface InsertEventContext extends BaseEventContext {
|
|||||||
beforeId?: string;
|
beforeId?: string;
|
||||||
index: number;
|
index: number;
|
||||||
data: any;
|
data: any;
|
||||||
subRenderer?: SubRendererInfo;
|
subRenderer?: SubRendererInfo | RendererInfo;
|
||||||
dragInfo?: {
|
dragInfo?: {
|
||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
@ -539,7 +539,7 @@ export interface InsertEventContext extends BaseEventContext {
|
|||||||
|
|
||||||
export interface ReplaceEventContext extends BaseEventContext {
|
export interface ReplaceEventContext extends BaseEventContext {
|
||||||
data: any;
|
data: any;
|
||||||
subRenderer?: SubRendererInfo;
|
subRenderer?: SubRendererInfo | RendererInfo;
|
||||||
region?: string;
|
region?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,14 +586,14 @@ export function reGenerateID(
|
|||||||
JSONTraverse(json, (value: any, key: string, host: any) => {
|
JSONTraverse(json, (value: any, key: string, host: any) => {
|
||||||
const isNodeIdFormat =
|
const isNodeIdFormat =
|
||||||
typeof value === 'string' && value.indexOf('u:') === 0;
|
typeof value === 'string' && value.indexOf('u:') === 0;
|
||||||
if (key === 'id' && isNodeIdFormat && host) {
|
if ((key === 'id' || key === 'componentId') && isNodeIdFormat && host) {
|
||||||
|
if (reIds[value]) {
|
||||||
|
host[key] = reIds[value];
|
||||||
|
} else {
|
||||||
const newID = generateNodeId();
|
const newID = generateNodeId();
|
||||||
reIds[host.id] = newID;
|
reIds[value] = newID;
|
||||||
host.id = newID;
|
host[key] = newID;
|
||||||
}
|
}
|
||||||
// 组件ID,给新的id内容
|
|
||||||
else if (key === 'componentId' && isNodeIdFormat) {
|
|
||||||
host.componentId = reIds[value] ?? value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
Loading…
Reference in New Issue
Block a user