Skip to content

Commit

Permalink
fix: 修复循环类组件绑定数据时,无法识别定义在root scope中的schema的问题(#11034) (#11092)
Browse files Browse the repository at this point in the history
Co-authored-by: chenfan02 <[email protected]>
  • Loading branch information
franckchen and chenfan02 authored Oct 22, 2024
1 parent 8624ec5 commit be91702
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 44 deletions.
28 changes: 17 additions & 11 deletions packages/amis-editor/src/plugin/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,24 @@ export class CardsPlugin extends BasePlugin {
node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/);
let field = node.schema.name || match?.[1];
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
const schema = scope?.parent?.getSchemaByPath(field);
if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};

// 列表添加序号方便处理
set(dataSchema, 'properties.index', {
type: 'number',
title: '索引'
});
if (scope) {
const origin = this.manager.dataSchema.current;
this.manager.dataSchema.switchTo(scope.parent!);
const schema = this.manager.dataSchema.getSchemaByPath(field);
this.manager.dataSchema.switchTo(origin);
if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};

// 列表添加序号方便处理
set(dataSchema, 'properties.index', {
type: 'number',
title: '索引'
});
}
}

return dataSchema;
Expand Down
27 changes: 16 additions & 11 deletions packages/amis-editor/src/plugin/Each.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,24 @@ export class EachPlugin extends BasePlugin {
node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/);
let field = node.schema.name || match?.[1];
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
const schema = scope?.parent?.getSchemaByPath(field);

if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};
if (scope) {
const origin = this.manager.dataSchema.current;
this.manager.dataSchema.switchTo(scope.parent!);
const schema = this.manager.dataSchema.getSchemaByPath(field);
this.manager.dataSchema.switchTo(origin);
if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};

// 循环添加索引方便渲染序号
set(dataSchema, 'properties.index', {
type: 'number',
title: '索引'
});
// 列表添加序号方便处理
set(dataSchema, 'properties.index', {
type: 'number',
title: '索引'
});
}
}

return dataSchema;
Expand Down
27 changes: 16 additions & 11 deletions packages/amis-editor/src/plugin/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,24 @@ export class ListPlugin extends BasePlugin {
node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/);
let field = node.schema.name || match?.[1];
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
const schema = scope?.parent?.getSchemaByPath(field);

if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};
if (scope) {
const origin = this.manager.dataSchema.current;
this.manager.dataSchema.switchTo(scope.parent!);
const schema = this.manager.dataSchema.getSchemaByPath(field);
this.manager.dataSchema.switchTo(origin);
if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};

// 循环添加序号方便处理
set(dataSchema, 'properties.index', {
type: 'number',
title: '序号'
});
// 列表添加序号方便处理
set(dataSchema, 'properties.index', {
type: 'number',
title: '索引'
});
}
}

return dataSchema;
Expand Down
28 changes: 17 additions & 11 deletions packages/amis-editor/src/plugin/List2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,24 @@ export class List2Plugin extends BasePlugin {
node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/);
let field = node.schema.name || match?.[1];
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
const schema = scope?.parent?.getSchemaByPath(field);
if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};

// 列表添加序号方便处理
set(dataSchema, 'properties.index', {
type: 'number',
title: '索引'
});
if (scope) {
const origin = this.manager.dataSchema.current;
this.manager.dataSchema.switchTo(scope.parent!);
const schema = this.manager.dataSchema.getSchemaByPath(field);
this.manager.dataSchema.switchTo(origin);
if (isObject(schema?.items)) {
dataSchema = {
...dataSchema,
...(schema!.items as any)
};

// 列表添加序号方便处理
set(dataSchema, 'properties.index', {
type: 'number',
title: '索引'
});
}
}

return dataSchema;
Expand Down

0 comments on commit be91702

Please sign in to comment.