sidebar accept Nested Routes

This commit is contained in:
Pan 2017-05-31 15:52:27 +08:00
parent 677ef6dbe3
commit 327ed42e24
8 changed files with 69 additions and 36 deletions

View File

@ -51,10 +51,11 @@ const ExcelDownload = () => import('../views/excel/index');
const Theme = () => import('../views/theme/index'); const Theme = () => import('../views/theme/index');
/* example*/ /* example*/
const DynamicTable = () => import('../views/example/dynamictable'); const TableLayout = () => import('../views/example/table/index');
const Table = () => import('../views/example/table'); const DynamicTable = () => import('../views/example/table/dynamictable');
const DragTable = () => import('../views/example/dragTable'); const Table = () => import('../views/example/table/table');
const InlineEditTable = () => import('../views/example/inlineEditTable'); const DragTable = () => import('../views/example/table/dragTable');
const InlineEditTable = () => import('../views/example/table/inlineEditTable');
const Form1 = () => import('../views/example/form1'); const Form1 = () => import('../views/example/form1');
/* permission */ /* permission */
@ -192,10 +193,17 @@ export const asyncRouterMap = [
name: '综合实例', name: '综合实例',
icon: 'zonghe', icon: 'zonghe',
children: [ children: [
{ path: 'dynamictable', component: DynamicTable, name: '动态table' }, {
{ path: 'dragtable', component: DragTable, name: '拖拽table' }, path: '/table',
{ path: 'inline_edit_table', component: InlineEditTable, name: 'table内编辑' }, component: TableLayout,
{ path: 'table', component: Table, name: '综合table' }, name: 'table',
children: [
{ path: 'dynamictable', component: DynamicTable, name: '动态table' },
{ path: 'dragtable', component: DragTable, name: '拖拽table' },
{ path: 'inline_edit_table', component: InlineEditTable, name: 'table内编辑' },
{ path: 'table', component: Table, name: '综合table' }
]
},
{ path: 'form1', component: Form1, name: '综合form1' } { path: 'form1', component: Form1, name: '综合form1' }
] ]
}, },

View File

@ -0,0 +1,3 @@
<template>
<router-view></router-view>
</template>

View File

@ -1,30 +1,14 @@
<template> <template>
<el-menu :unique-opened='true' mode="vertical" theme="dark" :default-active="$route.path"> <el-menu mode="vertical" theme="dark" :default-active="$route.path">
<template v-for="item in permission_routers" v-if="!item.hidden"> <sidebar-item :routes='permission_routers'></sidebar-item>
<el-submenu :index="item.name" v-if="!item.noDropdown">
<template slot="title">
<wscn-icon-svg :icon-class="item.icon||'wenzhang1'" /> {{item.name}}
</template>
<router-link v-for="child in item.children" :key="child.path" v-if="!child.hidden" class="title-link" :to="item.path+'/'+child.path">
<el-menu-item :index="item.path+'/'+child.path">
{{child.name}}
</el-menu-item>
</router-link>
</el-submenu>
<router-link v-if="item.noDropdown&&item.children.length>0" :to="item.path+'/'+item.children[0].path">
<el-menu-item :index="item.path+'/'+item.children[0].path">
<wscn-icon-svg :icon-class="item.icon||'geren1'" /> {{item.children[0].name}}
</el-menu-item>
</router-link>
</template>
</el-menu> </el-menu>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import SidebarItem from './SidebarItem';
export default { export default {
name: 'Sidebar', components:{SidebarItem},
computed: { computed: {
...mapGetters([ ...mapGetters([
'permission_routers' 'permission_routers'
@ -32,16 +16,8 @@
} }
} }
</script> </script>
<style rel="stylesheet/scss" lang="scss" scoped> <style rel="stylesheet/scss" lang="scss" scoped>
.el-menu { .el-menu {
min-height: 100%; min-height: 100%;
} }
.wscn-icon {
margin-right: 10px;
}
.hideSidebar .title-link{
display: block;
text-indent: 10px;
}
</style> </style>

View File

@ -0,0 +1,46 @@
<template>
<div>
<template v-for="item in routes">
<router-link v-if="!item.hidden&&item.noDropdown&&item.children.length>0" :to="item.path+'/'+item.children[0].path">
<el-menu-item :index="item.path+'/'+item.children[0].path">
<wscn-icon-svg v-if='item.icon' :icon-class="item.icon" /> {{item.children[0].name}}
</el-menu-item>
</router-link>
<el-submenu :index="item.name" v-if="!item.noDropdown&&!item.hidden">
<template slot="title">
<wscn-icon-svg v-if='item.icon' :icon-class="item.icon" /> {{item.name}}
</template>
<template v-for="child in item.children" v-if='!child.hidden'>
<sidebar-item class='menu-indent' v-if='child.children&&child.children.length>0' :routes='[child]'> </sidebar-item>
<router-link v-else class="menu-indent" :to="item.path+'/'+child.path">
<el-menu-item :index="item.path+'/'+child.path">
{{child.name}}
</el-menu-item>
</router-link>
</template>
</el-submenu>
</template>
</div>
</template>
<script>
export default {
name: 'SidebarItem',
props: {
routes: {
type: Array
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.wscn-icon {
margin-right: 10px;
}
.hideSidebar .menu-indent{
display: block;
text-indent: 10px;
}
</style>