菜单上支持使用 el-icon 了

This commit is contained in:
Cat73 2020-03-10 14:09:51 +08:00
parent a45e64fcb2
commit 69bd4da009
No known key found for this signature in database
GPG Key ID: B1E75BD2530FA16F
5 changed files with 67 additions and 3 deletions

View File

@ -0,0 +1,39 @@
<template>
<i :class="iconName" :style="appendStyle" />
</template>
<script>
export default {
name: 'ElIcon',
props: {
iconClass: {
type: String,
required: true
},
iconColor: {
type: String,
required: false,
default: ''
}
},
computed: {
iconName() {
return `sub-el-icon el-icon-${this.iconClass}`
},
appendStyle() {
if (this.iconColor) {
return 'color: ' + this.iconColor + ';'
} else {
return ''
}
}
}
}
</script>
<style scoped>
.sub-el-icon {
width: 1em;
height: 1em;
}
</style>

View File

@ -1,8 +1,10 @@
import Vue from 'vue'
import SvgIcon from '@/components/SvgIcon'// svg component
import ElIcon from '@/components/ElIcon'
// register globally
Vue.component('svg-icon', SvgIcon)
Vue.component('el-icon', ElIcon)
const req = require.context('./svg', false, /\.svg$/)
const requireAll = requireContext => requireContext.keys().map(requireContext)

View File

@ -1,4 +1,6 @@
<script>
import variables from '@/styles/variables.scss'
export default {
name: 'MenuItem',
functional: true,
@ -7,19 +9,27 @@ export default {
type: String,
default: ''
},
elicon: {
type: String,
default: ''
},
title: {
type: String,
default: ''
}
},
render(h, context) {
const { icon, title } = context.props
const { icon, elicon, title } = context.props
const vnodes = []
if (icon) {
vnodes.push(<svg-icon icon-class={icon}/>)
}
if (elicon) {
vnodes.push(<el-icon icon-class={elicon} icon-color={variables.menuText}/>)
}
if (title) {
vnodes.push(<span slot='title'>{(title)}</span>)
}

View File

@ -3,14 +3,14 @@
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow">
<app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" />
<item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :elicon="onlyOneChild.meta.elicon||item.meta && item.meta.elicon" :title="onlyOneChild.meta.title" />
</el-menu-item>
</app-link>
</template>
<el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
<template slot="title">
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :elicon="item.meta && item.meta.elicon" :title="item.meta.title" />
</template>
<sidebar-item
v-for="child in item.children"

View File

@ -57,6 +57,11 @@
margin-right: 16px;
}
.sub-el-icon {
margin-right: 13px;
margin-left: -1px;
}
.el-menu {
border: none;
height: 100%;
@ -105,6 +110,10 @@
.svg-icon {
margin-left: 20px;
}
.sub-el-icon {
margin-left: 19px;
}
}
}
@ -118,6 +127,10 @@
margin-left: 20px;
}
.sub-el-icon {
margin-left: 19px;
}
.el-submenu__icon-arrow {
display: none;
}