mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复多页面同时渲染场景查找组件优先级问题 (#9972)
This commit is contained in:
parent
c890d8dc1b
commit
b1ea4d236b
@ -107,6 +107,10 @@ export interface IScopedContext {
|
||||
unRegisterComponent: (component: ScopedComponentType) => void;
|
||||
getComponentByName: (name: string) => ScopedComponentType;
|
||||
getComponentById: (id: string) => ScopedComponentType | undefined;
|
||||
getComponentByIdUnderCurrentScope: (
|
||||
id: string,
|
||||
ignoreScope?: IScopedContext
|
||||
) => ScopedComponentType | undefined;
|
||||
getComponents: () => Array<ScopedComponentType>;
|
||||
reload: (target: string, ctx: RendererData) => void;
|
||||
send: (target: string, ctx: RendererData) => void;
|
||||
@ -183,16 +187,15 @@ function createScopedTools(
|
||||
return resolved || (parent && parent.getComponentByName(name));
|
||||
},
|
||||
|
||||
getComponentById(id: string) {
|
||||
let root: AliasIScopedContext = this;
|
||||
// 找到顶端scoped
|
||||
while (root.parent && root.parent !== rootScopedContext) {
|
||||
root = root.parent;
|
||||
}
|
||||
|
||||
// 向下查找
|
||||
getComponentByIdUnderCurrentScope(
|
||||
id: string,
|
||||
ignoreScope?: IScopedContext
|
||||
) {
|
||||
let component = undefined;
|
||||
findTree([root], (item: TreeItem) =>
|
||||
findTree(
|
||||
[this],
|
||||
(item: TreeItem) =>
|
||||
item !== ignoreScope &&
|
||||
item.getComponents().find((cmpt: ScopedComponentType) => {
|
||||
if (filter(cmpt.props.id, cmpt.props.data) === id) {
|
||||
component = cmpt;
|
||||
@ -205,6 +208,34 @@ function createScopedTools(
|
||||
return component;
|
||||
},
|
||||
|
||||
getComponentById(id: string) {
|
||||
let root: AliasIScopedContext = this;
|
||||
let ignoreScope: AliasIScopedContext | undefined = undefined;
|
||||
|
||||
// 找到顶端scoped
|
||||
while (root) {
|
||||
// 优先从当前scope查找
|
||||
// 直接跑到顶层查找,对于有历史标签一次渲染多个页面的情况,会有问题
|
||||
const component = root.getComponentByIdUnderCurrentScope(
|
||||
id,
|
||||
ignoreScope
|
||||
);
|
||||
|
||||
if (component) {
|
||||
return component;
|
||||
}
|
||||
|
||||
if (!root.parent || root.parent === rootScopedContext) {
|
||||
break;
|
||||
}
|
||||
|
||||
ignoreScope = root;
|
||||
root = root.parent;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
* 基于绑定的变量名称查找组件
|
||||
* 支持形如${xxx}的格式
|
||||
|
Loading…
Reference in New Issue
Block a user