From 9d8e0056cd35db09164a9c6b664882705f1886e2 Mon Sep 17 00:00:00 2001 From: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> Date: Wed, 20 Mar 2024 14:31:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=9F=9F=E6=94=B9=E5=8F=98=EF=BC=8Cnav=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=BF=AE=E6=94=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/Nav.tsx | 46 +++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/packages/amis/src/renderers/Nav.tsx b/packages/amis/src/renderers/Nav.tsx index 881a0f0f1..f446a397c 100644 --- a/packages/amis/src/renderers/Nav.tsx +++ b/packages/amis/src/renderers/Nav.tsx @@ -1056,29 +1056,29 @@ const ConditionBuilderWithRemoteOptions = withRemoteConfig({ if (!!link.disabled) { return false; } - return motivation !== 'location-change' && - typeof link.active !== 'undefined' - ? link.active - : (depth === level - ? !!findTree( - link.children || [], - l => - !!( - l.hasOwnProperty('to') && - env && - env.isCurrentUrl(filter(l.to as string, data), link) - ) - ) - : false) || - (link.activeOn - ? evalExpression(link.activeOn as string, data) || - evalExpression(link.activeOn as string, location) - : !!( - link.hasOwnProperty('to') && - link.to !== null && // 也可能出现{to: null}的情况(独立应用)filter会把null处理成'' 那默认首页会选中很多菜单项 {to: ''}认为是有效配置 + return ( + motivation !== 'location-change' && + ((depth === level + ? !!findTree( + link.children || [], + l => + !!( + l.hasOwnProperty('to') && env && - env.isCurrentUrl(filter(link.to as string, data), link) - )); + env.isCurrentUrl(filter(l.to as string, data), link) + ) + ) + : false) || + (link.activeOn + ? evalExpression(link.activeOn as string, data) || + evalExpression(link.activeOn as string, location) + : !!( + link.hasOwnProperty('to') && + link.to !== null && // 也可能出现{to: null}的情况(独立应用)filter会把null处理成'' 那默认首页会选中很多菜单项 {to: ''}认为是有效配置 + env && + env.isCurrentUrl(filter(link.to as string, data), link) + ))) + ); }; links = mapTree( @@ -1214,6 +1214,8 @@ const ConditionBuilderWithRemoteOptions = withRemoteConfig({ this.props.updateConfig(this.props.config, 'location-change'); } else if (!isEqual(this.props.links, prevProps.links)) { this.props.updateConfig(this.props.links, 'update'); + } else if (!isEqual(this.props.data, prevProps.data)) { + this.props.updateConfig(this.props.config, 'data-change'); } // 外部修改defaultOpenLevel 会影响菜单的unfolded属性 From f3dbe1015cbaea1eefdd51819d25682bcea9c9a8 Mon Sep 17 00:00:00 2001 From: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:31:59 +0800 Subject: [PATCH 2/3] fix: bugfix --- packages/amis/src/renderers/Nav.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/amis/src/renderers/Nav.tsx b/packages/amis/src/renderers/Nav.tsx index f446a397c..b485e2467 100644 --- a/packages/amis/src/renderers/Nav.tsx +++ b/packages/amis/src/renderers/Nav.tsx @@ -1056,6 +1056,10 @@ const ConditionBuilderWithRemoteOptions = withRemoteConfig({ if (!!link.disabled) { return false; } + // 如果是mount的时候,使用用户配置的active + if (motivation === 'mount' && link.active) { + return link.active; + } return ( motivation !== 'location-change' && ((depth === level From af17d417aad4afb60c457020f6ad58d120437ce2 Mon Sep 17 00:00:00 2001 From: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:12:08 +0800 Subject: [PATCH 3/3] fix: bugfix --- packages/amis/src/renderers/Nav.tsx | 50 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/packages/amis/src/renderers/Nav.tsx b/packages/amis/src/renderers/Nav.tsx index b485e2467..0d89a60c5 100644 --- a/packages/amis/src/renderers/Nav.tsx +++ b/packages/amis/src/renderers/Nav.tsx @@ -1056,33 +1056,31 @@ const ConditionBuilderWithRemoteOptions = withRemoteConfig({ if (!!link.disabled) { return false; } - // 如果是mount的时候,使用用户配置的active - if (motivation === 'mount' && link.active) { - return link.active; - } - return ( - motivation !== 'location-change' && - ((depth === level - ? !!findTree( - link.children || [], - l => - !!( - l.hasOwnProperty('to') && + + return motivation && + !['location-change', 'data-change'].includes(motivation) && + typeof link.active !== 'undefined' + ? link.active + : (depth === level + ? !!findTree( + link.children || [], + l => + !!( + l.hasOwnProperty('to') && + env && + env.isCurrentUrl(filter(l.to as string, data), link) + ) + ) + : false) || + (link.activeOn + ? evalExpression(link.activeOn as string, data) || + evalExpression(link.activeOn as string, location) + : !!( + link.hasOwnProperty('to') && + link.to !== null && // 也可能出现{to: null}的情况(独立应用)filter会把null处理成'' 那默认首页会选中很多菜单项 {to: ''}认为是有效配置 env && - env.isCurrentUrl(filter(l.to as string, data), link) - ) - ) - : false) || - (link.activeOn - ? evalExpression(link.activeOn as string, data) || - evalExpression(link.activeOn as string, location) - : !!( - link.hasOwnProperty('to') && - link.to !== null && // 也可能出现{to: null}的情况(独立应用)filter会把null处理成'' 那默认首页会选中很多菜单项 {to: ''}认为是有效配置 - env && - env.isCurrentUrl(filter(link.to as string, data), link) - ))) - ); + env.isCurrentUrl(filter(link.to as string, data), link) + )); }; links = mapTree(