✨ 菜单上支持使用 el-icon 了
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/components/ElIcon/index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/components/ElIcon/index.vue
									
									
									
									
									
										Normal 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>
 | 
				
			||||||
@@ -1,8 +1,10 @@
 | 
				
			|||||||
import Vue from 'vue'
 | 
					import Vue from 'vue'
 | 
				
			||||||
import SvgIcon from '@/components/SvgIcon'// svg component
 | 
					import SvgIcon from '@/components/SvgIcon'// svg component
 | 
				
			||||||
 | 
					import ElIcon from '@/components/ElIcon'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// register globally
 | 
					// register globally
 | 
				
			||||||
Vue.component('svg-icon', SvgIcon)
 | 
					Vue.component('svg-icon', SvgIcon)
 | 
				
			||||||
 | 
					Vue.component('el-icon', ElIcon)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const req = require.context('./svg', false, /\.svg$/)
 | 
					const req = require.context('./svg', false, /\.svg$/)
 | 
				
			||||||
const requireAll = requireContext => requireContext.keys().map(requireContext)
 | 
					const requireAll = requireContext => requireContext.keys().map(requireContext)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,6 @@
 | 
				
			|||||||
<script>
 | 
					<script>
 | 
				
			||||||
 | 
					import variables from '@/styles/variables.scss'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
  name: 'MenuItem',
 | 
					  name: 'MenuItem',
 | 
				
			||||||
  functional: true,
 | 
					  functional: true,
 | 
				
			||||||
@@ -7,19 +9,27 @@ export default {
 | 
				
			|||||||
      type: String,
 | 
					      type: String,
 | 
				
			||||||
      default: ''
 | 
					      default: ''
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    elicon: {
 | 
				
			||||||
 | 
					      type: String,
 | 
				
			||||||
 | 
					      default: ''
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    title: {
 | 
					    title: {
 | 
				
			||||||
      type: String,
 | 
					      type: String,
 | 
				
			||||||
      default: ''
 | 
					      default: ''
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  render(h, context) {
 | 
					  render(h, context) {
 | 
				
			||||||
    const { icon, title } = context.props
 | 
					    const { icon, elicon, title } = context.props
 | 
				
			||||||
    const vnodes = []
 | 
					    const vnodes = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (icon) {
 | 
					    if (icon) {
 | 
				
			||||||
      vnodes.push(<svg-icon icon-class={icon}/>)
 | 
					      vnodes.push(<svg-icon icon-class={icon}/>)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (elicon) {
 | 
				
			||||||
 | 
					      vnodes.push(<el-icon icon-class={elicon} icon-color={variables.menuText}/>)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (title) {
 | 
					    if (title) {
 | 
				
			||||||
      vnodes.push(<span slot='title'>{(title)}</span>)
 | 
					      vnodes.push(<span slot='title'>{(title)}</span>)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,14 +3,14 @@
 | 
				
			|||||||
    <template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow">
 | 
					    <template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow">
 | 
				
			||||||
      <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
 | 
					      <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
 | 
				
			||||||
        <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
 | 
					        <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>
 | 
					        </el-menu-item>
 | 
				
			||||||
      </app-link>
 | 
					      </app-link>
 | 
				
			||||||
    </template>
 | 
					    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
 | 
					    <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
 | 
				
			||||||
      <template slot="title">
 | 
					      <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>
 | 
					      </template>
 | 
				
			||||||
      <sidebar-item
 | 
					      <sidebar-item
 | 
				
			||||||
        v-for="child in item.children"
 | 
					        v-for="child in item.children"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,6 +57,11 @@
 | 
				
			|||||||
      margin-right: 16px;
 | 
					      margin-right: 16px;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    .sub-el-icon {
 | 
				
			||||||
 | 
					      margin-right: 13px;
 | 
				
			||||||
 | 
					      margin-left: -1px;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    .el-menu {
 | 
					    .el-menu {
 | 
				
			||||||
      border: none;
 | 
					      border: none;
 | 
				
			||||||
      height: 100%;
 | 
					      height: 100%;
 | 
				
			||||||
@@ -105,6 +110,10 @@
 | 
				
			|||||||
        .svg-icon {
 | 
					        .svg-icon {
 | 
				
			||||||
          margin-left: 20px;
 | 
					          margin-left: 20px;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .sub-el-icon {
 | 
				
			||||||
 | 
					          margin-left: 19px;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -118,6 +127,10 @@
 | 
				
			|||||||
          margin-left: 20px;
 | 
					          margin-left: 20px;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .sub-el-icon {
 | 
				
			||||||
 | 
					          margin-left: 19px;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        .el-submenu__icon-arrow {
 | 
					        .el-submenu__icon-arrow {
 | 
				
			||||||
          display: none;
 | 
					          display: none;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user