Browse Source

动态左侧列表完成

main
pixelqm 5 years ago
parent
commit
650da4f85e
  1. 2
      QMPlusVuePage/src/store/module/router.js
  2. 39
      QMPlusVuePage/src/view/layout/aside/asideComponent/index.vue
  3. 19
      QMPlusVuePage/src/view/layout/aside/asideComponent/menuItem.vue
  4. 25
      QMPlusVuePage/src/view/layout/aside/asideComponent/submenu.vue
  5. 39
      QMPlusVuePage/src/view/layout/aside/index.vue
  6. 47
      QMPlusVuePage/src/view/layout/index.vue

2
QMPlusVuePage/src/store/module/router.js

@ -23,7 +23,7 @@ export const router = {
redirect: '/404'
})
asyncRouterHandle(asyncRouter) // 等待动态使用 VUEX持久化 会将其放入 vuex并且动态生成左侧列表
asyncRouterHandle(asyncRouter)
commit('setAsyncRouter', asyncRouter)
}
},

39
QMPlusVuePage/src/view/layout/aside/asideComponent/index.vue

@ -0,0 +1,39 @@
<template>
<component :is="menuComponent" :routerInfo="routerInfo">
<template v-if="routerInfo.children.length">
<AsideComponent :key="item.name" :routerInfo="item" v-for="item in routerInfo.children" />
</template>
</component>
</template>
<script>
import MenuItem from './menuItem'
import SubMenu from './submenu'
export default {
name: 'AsideComponent',
computed:{
menuComponent(){
if(this.routerInfo.children.length){
return 'SubMenu'
}else{
return 'menuItem'
}
}
},
props: {
routerInfo: {
default: function() {
return null
},
type: Object
}
},
components: {
MenuItem,
SubMenu
}
}
</script>
<style lang="scss">
</style>

19
QMPlusVuePage/src/view/layout/aside/asideComponent/menuItem.vue

@ -0,0 +1,19 @@
<template>
<el-menu-item :index="routerInfo.name">{{routerInfo.meta.title}}</el-menu-item>
</template>
<script>
export default {
name: 'MenuItem',
props: {
routerInfo: {
default: function() {
return null
},
type: Object
}
},
}
</script>
<style lang="scss">
</style>

25
QMPlusVuePage/src/view/layout/aside/asideComponent/submenu.vue

@ -0,0 +1,25 @@
<template>
<el-submenu :index="routerInfo.name">
<template slot="title">
<i class="el-icon-location"></i>
<span slot="title">{{routerInfo.meta.title}}</span>
</template>
<slot></slot>
</el-submenu>
</template>
<script>
export default {
name: 'SubMenu',
props: {
routerInfo: {
default: function() {
return null
},
type: Object
}
}
}
</script>
<style lang="scss">
</style>

39
QMPlusVuePage/src/view/layout/aside/index.vue

@ -0,0 +1,39 @@
<template>
<el-menu
mode="vertical"
:collapse="isCollapse"
:default-active="active"
@select="selectMenuItem"
:class="['el-menu-vertical',!isCollapse&&'noCollapse']"
>
<AsideComponent :routerInfo="asyncRouters[0]"/>
</el-menu>
</template>
<script>
import {mapGetters} from 'vuex'
import AsideComponent from '@/view/layout/aside/asideComponent'
export default {
name: 'Aside',
data() {
return {
active: '',
isCollapse: true
}
},
methods: {
selectMenuItem(index) {
this.$router.push({name:index})
}
},
computed:{
...mapGetters('router',['asyncRouters'])
},
components: {
AsideComponent
},
created() {
this.active = this.$route.name
}
}
</script>

47
QMPlusVuePage/src/view/layout/index.vue

@ -1,16 +1,49 @@
<template>
<div>
模板框
<router-view></router-view>
</div>
<el-container class="layout-cont">
<el-header class="header-cont">顶部</el-header>
<el-container>
<el-aside class="main-cont main-left">
<Aside />
</el-aside>
<el-main class="main-cont main-right">
<transition name="el-fade-in-linear" mode="out-in">
<router-view></router-view>
</transition>
</el-main>
</el-container>
</el-container>
</template>
<script>
import Aside from '@/view/layout/aside'
export default {
name:"Layout"
name: 'Layout',
components: {
Aside
}
}
</script>
<style scoped>
<style lang="scss">
$headerHigh: 52px;
$mainHight: calc(100vh - 52px);
.layout-cont {
.header-cont {
height: $headerHigh !important;
background: palevioletred;
}
.main-cont {
.el-menu-vertical {
min-height: $mainHight !important;
}
&::-webkit-scrollbar {
display: none;
}
&.main-left {
width: auto !important;
}
background: blueviolet;
height: $mainHight !important;
}
}
</style>
Loading…
Cancel
Save