forked from dyf/dyf-vue-ui
数据大屏跳转到新标签页,已修改
This commit is contained in:
@ -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)">
|
||||||
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{ 'submenu-title-noDropdown': !isNest }">
|
<span @click="handleMenuClick(onlyOneChild, $event)">
|
||||||
<svg-icon :icon-class="onlyOneChild.meta.icon || (item.meta && item.meta.icon)" />
|
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{ 'submenu-title-noDropdown': !isNest }">
|
||||||
<template #title>
|
<svg-icon :icon-class="onlyOneChild.meta.icon || (item.meta && item.meta.icon)" />
|
||||||
<span class="menu-title" :title="hasTitle(onlyOneChild.meta.title)">{{ onlyOneChild.meta.title }}</span>
|
<template #title>
|
||||||
</template>
|
<span class="menu-title" :title="hasTitle(onlyOneChild.meta.title)">{{ onlyOneChild.meta.title }}</span>
|
||||||
</el-menu-item>
|
</template>
|
||||||
|
</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)) {
|
||||||
|
|||||||
@ -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 }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user