init
This commit is contained in:
84
layouts/VabSideBar/components/VabMenuItem.vue
Normal file
84
layouts/VabSideBar/components/VabMenuItem.vue
Normal file
@@ -0,0 +1,84 @@
|
||||
<template>
|
||||
<el-menu-item :index="handlePath(routeChildren.path)" @click="handleLink">
|
||||
<vab-icon
|
||||
v-if="routeChildren.meta.icon"
|
||||
:icon="['fas', routeChildren.meta.icon]"
|
||||
class="vab-fas-icon"
|
||||
/>
|
||||
<span>{{ routeChildren.meta.title }}</span>
|
||||
<el-tag
|
||||
v-if="routeChildren.meta && routeChildren.meta.badge"
|
||||
effect="dark"
|
||||
type="danger"
|
||||
>
|
||||
{{ routeChildren.meta.badge }}
|
||||
</el-tag>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { isExternal } from '@/utils/validate'
|
||||
import path from 'path'
|
||||
|
||||
export default {
|
||||
name: 'VabMenuItem',
|
||||
props: {
|
||||
routeChildren: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null
|
||||
},
|
||||
},
|
||||
item: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null
|
||||
},
|
||||
},
|
||||
fullPath: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handlePath(routePath) {
|
||||
if (isExternal(routePath)) {
|
||||
return routePath
|
||||
}
|
||||
if (isExternal(this.fullPath)) {
|
||||
return this.fullPath
|
||||
}
|
||||
return path.resolve(this.fullPath, routePath)
|
||||
},
|
||||
handleLink() {
|
||||
const routePath = this.routeChildren.path
|
||||
const target = this.routeChildren.meta.target
|
||||
|
||||
if (target === '_blank') {
|
||||
if (isExternal(routePath)) {
|
||||
window.open(routePath)
|
||||
} else if (isExternal(this.fullPath)) {
|
||||
window.open(this.fullPath)
|
||||
} else if (
|
||||
this.$route.path !== path.resolve(this.fullPath, routePath)
|
||||
) {
|
||||
let routeData = this.$router.resolve(
|
||||
path.resolve(this.fullPath, routePath)
|
||||
)
|
||||
window.open(routeData.href)
|
||||
}
|
||||
} else {
|
||||
if (isExternal(routePath)) {
|
||||
window.location.href = routePath
|
||||
} else if (isExternal(this.fullPath)) {
|
||||
window.location.href = this.fullPath
|
||||
} else if (
|
||||
this.$route.path !== path.resolve(this.fullPath, routePath)
|
||||
) {
|
||||
this.$router.push(path.resolve(this.fullPath, routePath))
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
108
layouts/VabSideBar/components/VabSideBarItem.vue
Normal file
108
layouts/VabSideBar/components/VabSideBarItem.vue
Normal file
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<component
|
||||
:is="menuComponent"
|
||||
v-if="!item.hidden"
|
||||
:full-path="fullPath"
|
||||
:item="item"
|
||||
:route-children="routeChildren"
|
||||
>
|
||||
<template v-if="item.children && item.children.length">
|
||||
<vab-side-bar-item
|
||||
v-for="route in item.children"
|
||||
:key="route.path"
|
||||
:full-path="handlePath(route.path)"
|
||||
:item="route"
|
||||
/>
|
||||
</template>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { isExternal } from '@/utils/validate'
|
||||
import path from 'path'
|
||||
|
||||
export default {
|
||||
name: 'VabSideBarItem',
|
||||
props: {
|
||||
item: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
fullPath: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
data() {
|
||||
this.onlyOneChild = null
|
||||
return {}
|
||||
},
|
||||
computed: {
|
||||
menuComponent() {
|
||||
if (
|
||||
this.handleChildren(this.item.children, this.item) &&
|
||||
(!this.routeChildren.children ||
|
||||
this.routeChildren.notShowChildren) &&
|
||||
!this.item.alwaysShow
|
||||
) {
|
||||
return 'VabMenuItem'
|
||||
} else {
|
||||
return 'VabSubmenu'
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleChildren(children = [], parent) {
|
||||
if (children === null) children = []
|
||||
const showChildren = children.filter((item) => {
|
||||
if (item.hidden) {
|
||||
return false
|
||||
} else {
|
||||
this.routeChildren = item
|
||||
return true
|
||||
}
|
||||
})
|
||||
if (showChildren.length === 1) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (showChildren.length === 0) {
|
||||
this.routeChildren = {
|
||||
...parent,
|
||||
path: '',
|
||||
notShowChildren: true,
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
handlePath(routePath) {
|
||||
if (isExternal(routePath)) {
|
||||
return routePath
|
||||
}
|
||||
if (isExternal(this.fullPath)) {
|
||||
return this.fullPath
|
||||
}
|
||||
return path.resolve(this.fullPath, routePath)
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.vab-nav-icon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
::v-deep {
|
||||
.el-tag {
|
||||
float: right;
|
||||
height: 16px;
|
||||
padding-right: 4px;
|
||||
padding-left: 4px;
|
||||
margin-top: calc((#{$base-menu-item-height} - 16px) / 2);
|
||||
line-height: 16px;
|
||||
border: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
60
layouts/VabSideBar/components/VabSubmenu.vue
Normal file
60
layouts/VabSideBar/components/VabSubmenu.vue
Normal file
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<el-submenu
|
||||
ref="subMenu"
|
||||
:index="handlePath(item.path)"
|
||||
:popper-append-to-body="false"
|
||||
>
|
||||
<template slot="title">
|
||||
<vab-icon
|
||||
v-if="item.meta && item.meta.icon"
|
||||
:icon="['fas', item.meta.icon]"
|
||||
class="vab-fas-icon"
|
||||
/>
|
||||
<vab-remix-icon
|
||||
v-if="item.meta && item.meta.remixIcon"
|
||||
:icon-class="item.meta.remixIcon"
|
||||
class="vab-remix-icon"
|
||||
/>
|
||||
<span>{{ item.meta.title }}</span>
|
||||
</template>
|
||||
<slot />
|
||||
</el-submenu>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { isExternal } from '@/utils/validate'
|
||||
import path from 'path'
|
||||
|
||||
export default {
|
||||
name: 'VabSubmenu',
|
||||
props: {
|
||||
routeChildren: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null
|
||||
},
|
||||
},
|
||||
item: {
|
||||
type: Object,
|
||||
default() {
|
||||
return null
|
||||
},
|
||||
},
|
||||
fullPath: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handlePath(routePath) {
|
||||
if (isExternal(routePath)) {
|
||||
return routePath
|
||||
}
|
||||
if (isExternal(this.fullPath)) {
|
||||
return this.fullPath
|
||||
}
|
||||
return path.resolve(this.fullPath, routePath)
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
145
layouts/VabSideBar/index.vue
Normal file
145
layouts/VabSideBar/index.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<template>
|
||||
<el-scrollbar :class="{ 'is-collapse': collapse }" class="side-bar-container">
|
||||
<vab-logo />
|
||||
<el-menu
|
||||
:active-text-color="variables['menu-color-active']"
|
||||
:background-color="variables['menu-background']"
|
||||
:collapse="collapse"
|
||||
:collapse-transition="false"
|
||||
:default-active="activeMenu"
|
||||
:default-openeds="defaultOpens"
|
||||
:text-color="variables['menu-color']"
|
||||
:unique-opened="uniqueOpened"
|
||||
mode="vertical"
|
||||
>
|
||||
<template v-for="route in routes">
|
||||
<vab-side-bar-item
|
||||
:key="route.path"
|
||||
:full-path="route.path"
|
||||
:item="route"
|
||||
/>
|
||||
</template>
|
||||
</el-menu>
|
||||
</el-scrollbar>
|
||||
</template>
|
||||
<script>
|
||||
import variables from '@/styles/variables.scss'
|
||||
import { mapGetters } from 'vuex'
|
||||
import { defaultOopeneds, uniqueOpened } from '@/config'
|
||||
|
||||
export default {
|
||||
name: 'VabSideBar',
|
||||
data() {
|
||||
return {
|
||||
uniqueOpened,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters({
|
||||
collapse: 'settings/collapse',
|
||||
routes: 'routes/routes',
|
||||
}),
|
||||
defaultOpens() {
|
||||
if (this.collapse) {
|
||||
}
|
||||
return defaultOopeneds
|
||||
},
|
||||
activeMenu() {
|
||||
const route = this.$route
|
||||
const { meta, path } = route
|
||||
if (meta.activeMenu) {
|
||||
return meta.activeMenu
|
||||
}
|
||||
return path
|
||||
},
|
||||
variables() {
|
||||
return variables
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@mixin active {
|
||||
&:hover {
|
||||
color: $base-color-white;
|
||||
background-color: $base-menu-background-active !important;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
color: $base-color-white;
|
||||
background-color: $base-menu-background-active !important;
|
||||
}
|
||||
}
|
||||
|
||||
.side-bar-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: $base-z-index;
|
||||
width: $base-left-menu-width;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
background: $base-menu-background;
|
||||
box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
|
||||
transition: width $base-transition-time;
|
||||
|
||||
&.is-collapse {
|
||||
width: $base-left-menu-width-min;
|
||||
border-right: 0;
|
||||
|
||||
::v-deep {
|
||||
.el-menu {
|
||||
transition: width $base-transition-time;
|
||||
}
|
||||
|
||||
.el-menu--collapse {
|
||||
border-right: 0;
|
||||
|
||||
.el-submenu__icon-arrow {
|
||||
right: 10px;
|
||||
margin-top: -3px;
|
||||
}
|
||||
|
||||
.el-menu-item,
|
||||
.el-submenu {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep {
|
||||
.el-scrollbar__wrap {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.el-menu {
|
||||
border: 0;
|
||||
|
||||
.vab-fas-icon {
|
||||
padding-right: 3px;
|
||||
font-size: $base-font-size-default;
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
}
|
||||
|
||||
.vab-remix-icon {
|
||||
padding-right: 3px;
|
||||
font-size: $base-font-size-default + 2;
|
||||
}
|
||||
}
|
||||
|
||||
.el-menu-item,
|
||||
.el-submenu__title {
|
||||
height: $base-menu-item-height;
|
||||
line-height: $base-menu-item-height;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.el-menu-item {
|
||||
@include active;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user