Skip to content

Commit 61394e5

Browse files
committed
feature: [sidebar] add external-link
1 parent 85c5d60 commit 61394e5

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

src/icons/svg/link.svg

Lines changed: 1 addition & 0 deletions
Loading

src/router/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ export const constantRouterMap = [
130130
]
131131
},
132132

133+
{
134+
path: 'external-link',
135+
component: Layout,
136+
children: [
137+
{
138+
path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
139+
meta: { title: 'externalLink', icon: 'link' }
140+
}
141+
]
142+
},
143+
133144
{ path: '*', redirect: '/404', hidden: true }
134145
]
135146

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script>
2+
export default {
3+
name: 'MenuItem',
4+
functional: true,
5+
props: {
6+
icon: {
7+
type: String,
8+
default: ''
9+
},
10+
title: {
11+
type: String,
12+
default: ''
13+
}
14+
},
15+
render(h, context) {
16+
const { icon, title } = context.props
17+
const vnodes = []
18+
19+
if (icon) {
20+
vnodes.push(<svg-icon icon-class={icon}/>)
21+
}
22+
23+
if (title) {
24+
vnodes.push(<span slot='title'>{(title)}</span>)
25+
}
26+
return vnodes
27+
}
28+
}
29+
</script>

src/views/layout/components/Sidebar/SidebarItem.vue

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<template>
22
<div v-if="!item.hidden&&item.children" class="menu-wrapper">
33

4-
<router-link v-if="hasOneShowingChild(item.children) && !onlyOneChild.children&&!item.alwaysShow" :to="resolvePath(onlyOneChild.path)">
5-
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
6-
<svg-icon v-if="onlyOneChild.meta&&onlyOneChild.meta.icon" :icon-class="onlyOneChild.meta.icon"/>
7-
<span v-if="onlyOneChild.meta&&onlyOneChild.meta.title" slot="title">{{ onlyOneChild.meta.title }}</span>
8-
</el-menu-item>
9-
</router-link>
4+
<template v-if="hasOneShowingChild(item.children) && !onlyOneChild.children&&!item.alwaysShow">
5+
<a v-if="isExternalLink(onlyOneChild.path)" :href="onlyOneChild.path" target="blank">
6+
apple
7+
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
8+
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
9+
</el-menu-item>
10+
</a>
11+
<router-link v-else :to="resolvePath(onlyOneChild.path)">
12+
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
13+
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon" :title="onlyOneChild.meta.title" />
14+
</el-menu-item>
15+
</router-link>
16+
</template>
1017

1118
<el-submenu v-else :index="item.name||item.path">
1219
<template slot="title">
13-
<svg-icon v-if="item.meta&&item.meta.icon" :icon-class="item.meta.icon"/>
14-
<span v-if="item.meta&&item.meta.title" slot="title">{{ item.meta.title }}</span>
20+
<item v-if="item.meta" :icon="item.meta.icon" :title="item.meta.title" />
1521
</template>
1622

1723
<template v-for="child in item.children" v-if="!child.hidden">
@@ -25,8 +31,7 @@
2531

2632
<router-link v-else :to="resolvePath(child.path)" :key="child.name">
2733
<el-menu-item :index="resolvePath(child.path)">
28-
<svg-icon v-if="child.meta&&child.meta.icon" :icon-class="child.meta.icon"/>
29-
<span v-if="child.meta&&child.meta.title" slot="title">{{ child.meta.title }}</span>
34+
<item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
3035
</el-menu-item>
3136
</router-link>
3237
</template>
@@ -37,9 +42,12 @@
3742

3843
<script>
3944
import path from 'path'
45+
import { validateURL } from '@/utils/validate'
46+
import Item from './Item'
4047
4148
export default {
4249
name: 'SidebarItem',
50+
components: { Item },
4351
props: {
4452
// route配置json
4553
item: {
@@ -76,8 +84,11 @@ export default {
7684
}
7785
return false
7886
},
79-
resolvePath(...paths) {
80-
return path.resolve(this.basePath, ...paths)
87+
resolvePath(routePath) {
88+
return path.resolve(this.basePath, routePath)
89+
},
90+
isExternalLink(routePath) {
91+
return validateURL(routePath)
8192
}
8293
}
8394
}

0 commit comments

Comments
 (0)