Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复循环类组件绑定数据时,无法识别定义在root scope中的schema的问题(#11034) #11092

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading