数据大屏跳转到新标签页,已修改

This commit is contained in:
fengerli
2025-10-10 11:41:42 +08:00
parent b6c64df004
commit ee4eec1e2e
2 changed files with 32 additions and 19 deletions

View File

@ -1,13 +1,16 @@
<template> <template>
<div v-if="!item.hidden"> <div v-if="!item.hidden">
<template v-if="hasOneShowingChild(item, item.children) && (!onlyOneChild.children || onlyOneChild.noShowingChildren) && !item.alwaysShow"> <template
v-if="hasOneShowingChild(item, item.children) && (!onlyOneChild.children || onlyOneChild.noShowingChildren) && !item.alwaysShow">
<app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path, onlyOneChild.query)"> <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path, onlyOneChild.query)">
<span @click="handleMenuClick(onlyOneChild, $event)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{ 'submenu-title-noDropdown': !isNest }"> <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{ 'submenu-title-noDropdown': !isNest }">
<svg-icon :icon-class="onlyOneChild.meta.icon || (item.meta && item.meta.icon)" /> <svg-icon :icon-class="onlyOneChild.meta.icon || (item.meta && item.meta.icon)" />
<template #title> <template #title>
<span class="menu-title" :title="hasTitle(onlyOneChild.meta.title)">{{ onlyOneChild.meta.title }}</span> <span class="menu-title" :title="hasTitle(onlyOneChild.meta.title)">{{ onlyOneChild.meta.title }}</span>
</template> </template>
</el-menu-item> </el-menu-item>
</span>
</app-link> </app-link>
</template> </template>
@ -17,14 +20,8 @@
<span class="menu-title" :title="hasTitle(item.meta?.title)">{{ item.meta?.title }}</span> <span class="menu-title" :title="hasTitle(item.meta?.title)">{{ item.meta?.title }}</span>
</template> </template>
<sidebar-item <sidebar-item v-for="(child, index) in item.children" :key="child.path + index" :is-nest="true" :item="child"
v-for="(child, index) in item.children" :base-path="resolvePath(child.path)" class="nest-menu" />
:key="child.path + index"
:is-nest="true"
:item="child"
:base-path="resolvePath(child.path)"
class="nest-menu"
/>
</el-sub-menu> </el-sub-menu>
</div> </div>
</template> </template>
@ -77,7 +74,23 @@ const hasOneShowingChild = (parent: RouteRecordRaw, children?: RouteRecordRaw[])
return false; return false;
}; };
const router = useRouter();
// 处理菜单点击,完全控制跳转行为
const handleMenuClick = (route, event) => {
console.log(route, 'route');
if (route.meta.openInNewTab) {
// 完全阻止默认行为和事件冒泡
event.preventDefault();
event.stopPropagation();
console.log('Opening in new tab:', route);
const resolvedRoute = router.resolve({
name: route.name || route.path
});
const fullUrl = new URL(resolvedRoute.href, window.location.origin).href;
window.open(fullUrl, '_blank');
} else {
}
};
const resolvePath = (routePath: string, routeQuery?: string): any => { const resolvePath = (routePath: string, routeQuery?: string): any => {
if (isExternal(routePath)) { if (isExternal(routePath)) {

View File

@ -43,7 +43,7 @@ export const constantRoutes: RouteRecordRaw[] = [
path: "/homeIndex", path: "/homeIndex",
name: "HomeIndex", name: "HomeIndex",
component: () => import("@/views/homeIndex/index.vue"), component: () => import("@/views/homeIndex/index.vue"),
meta: {title: '数据大屏', icon: 'home', preload: true, keepAlive: true }, meta: { title: '数据大屏', icon: '首页1.1', preload: true, keepAlive: true, openInNewTab: true },
}, },
{ {
path: '', path: '',
@ -54,7 +54,7 @@ export const constantRoutes: RouteRecordRaw[] = [
path: '/index', path: '/index',
component: () => import('@/views/index.vue'), component: () => import('@/views/index.vue'),
name: 'Index', name: 'Index',
meta: { title: '首页', icon: 'home', affix: true, keepAlive: false } meta: { title: '首页', icon: '首页1.1', affix: true, keepAlive: false }
} }
] ]
}, },