fix(layout): 菜单点击/高亮统一走 resolveMenuPage,修 /approval 尾空格导致要点多次+不高亮
build / build (push) Successful in 2m35s
build / build (push) Successful in 2m35s
- 之前模板与 linkMenu 用 raw item.page,后端 GetUserMod 待审核 page="/approval "(带尾空格) 与 routeChange 解析后的 "/approval" 不一致 → router.push 带空格需多次才命中、active 比对不等不高亮。 - linkMenu 与 active-class 改用 resolveMenuPage 解析后的 path(顺带修复外链 item.external 之前从 raw 取不到)。 - 不改数据;根治建议:平台模块管理把该 page 的尾空格去掉。
This commit is contained in:
@@ -95,15 +95,21 @@ const routeChange = (to: any) => {
|
||||
navPath.value = [];
|
||||
};
|
||||
|
||||
/** 统一解析菜单项目标:容忍平台配置的尾空格/旧 /notice 前缀/外链,返回内部路由 path 或外链 URL。
|
||||
* 模板高亮与点击都走这里,避免「raw page(带尾空格)vs 解析后 path」不一致导致点不动/不高亮。 */
|
||||
const resolveItemPage = (item: any) =>
|
||||
resolveMenuPage(item?.page, item?.modId ?? item?.id, item?.name);
|
||||
const pageOf = (item: any): string => resolveItemPage(item).path;
|
||||
|
||||
const linkMenu = (item: any) => {
|
||||
const page: string = item?.page || "";
|
||||
const { path: page, external } = resolveItemPage(item);
|
||||
if (!page) {
|
||||
// 解析不出有效页面:显式提示,而不是静默不动或被重定向吞到默认页
|
||||
Message.warning(`菜单「${item?.name || "未命名"}」未配置有效页面路径,请检查基础平台模块设置`);
|
||||
return;
|
||||
}
|
||||
// 平台配置的外部链接模块:整页跳转
|
||||
if (item?.external) {
|
||||
if (external) {
|
||||
window.location.href = page;
|
||||
return;
|
||||
}
|
||||
@@ -183,7 +189,7 @@ function linkHomePage() {
|
||||
<transition name="fade_child_ul">
|
||||
<div class="child-item-wrap" v-show="item.childState">
|
||||
<li
|
||||
:class="citem.page == currPath ? 'active child-item' : 'child-item'"
|
||||
:class="pageOf(citem) == currPath ? 'active child-item' : 'child-item'"
|
||||
v-for="citem in item.children"
|
||||
:key="citem.id"
|
||||
>
|
||||
@@ -194,7 +200,7 @@ function linkHomePage() {
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
<li v-else :class="item.page == currPath ? 'active' : ''">
|
||||
<li v-else :class="pageOf(item) == currPath ? 'active' : ''">
|
||||
<a href="javascript:;" @click="linkMenu(item)">
|
||||
<i v-if="getMenuIcon(item)" :class="['iconfont', getMenuIcon(item)]"></i>
|
||||
{{ item.name }}
|
||||
|
||||
Reference in New Issue
Block a user