修复(Fix): 修复自定义控制台URL无法在新标签页中打开的问题 #82
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR 类型 (Type of change)
问题背景 (Problem/Motivation)
在 FastAdmin 中,所有通过
Tree
类生成的菜单项,只要包含 URL (@url
),系统就会自动为其追加ref=addtabs
参数。这个设计虽然保证了大部分内部页面能在框架的 Tab 页中打开,但也带来了一个问题:当我们需要将某个菜单项(例如“控制台”或任何自定义菜单)指向一个外部网站,或者一个需要脱离框架独立显示的内部页面时,
ref=addtabs
参数会强制它在框架内打开,导致页面无法正常显示或不符合预期。解决方案 (Proposed Solution)
本次修改位于
extend/fast/Tree.php
文件中,调整了getTreeArray
方法内构建菜单属性的逻辑。核心改动是移除了判断条件中的
!
(NOT) 运算符。代码变更:
逻辑解释:
'@addtabs'
属性为空的条件是($childdata || !isset($value['@url']))
。这意味着,只有当一个菜单项是父级菜单(有子菜单)或没有设置URL时,ref=addtabs
才不会被添加。反之,只要是末级菜单且设置了URL,就会被添加。'@addtabs'
属性为空的条件变为($childdata || isset($value['@url']))
。这意味着,只要一个菜单项是父级菜单或设置了URL,ref=addtabs
就不会被添加。最终效果是,该 PHP 后端逻辑将不再为任何含有
@url
的菜单项自动附加ref=addtabs
参数。 这将控制权交还给前端或URL本身,允许我们自由定义哪些链接需要在框架内打开,哪些需要在新标签页打开。如何测试 (How to Test)
https://www.google.com
。https://www.google.com
。