You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.7 KiB

6 years ago
<template>
<aside
:class="sidebarClass"
6 years ago
@mouseenter="mouseOutside=false"
@mouseleave="mouseOutside=true"
>
<logo v-if="showLogo" :collapse="collapse"/>
6 years ago
<el-scrollbar>
<el-menu
ref="menu"
:active-text-color="variables.primary"
:background-color="variables.menuBg"
:collapse="collapse"
6 years ago
:collapse-transition="false"
:default-active="$route.path"
:text-color="variables.menuText"
:unique-opened="sidebarUniqueOpen"
mode="vertical"
@select="select"
6 years ago
>
<sidebar-item
v-for="route in routes"
:key="route.path"
:show-parent="sidebarShowParent"
:collapse="sidebarCollapse"
6 years ago
:item="route"
/>
</el-menu>
</el-scrollbar>
</aside>
</template>
<script>
import {mapState} from 'vuex'
import Logo from './components/Logo'
import SidebarItem from './components/SidebarItem'
import variables from '@/assets/styles/variables.scss'
export default {
name: 'sidebar',
components: {SidebarItem, Logo},
data() {
return {
variables,
mouseOutside: true
}
},
computed: {
...mapState('app', {
device: state => state.device
}),
6 years ago
...mapState('resource', {
routes: state => state.sidebarMenus
}),
...mapState('setting', {
showLogo: state => state.showLogo,
sidebarCollapse: state => state.sidebarCollapse,
sidebarUniqueOpen: state => state.sidebarUniqueOpen,
6 years ago
sidebarShowParent: state => state.sidebarShowParent,
sidebarAutoHidden: state => state.sidebarAutoHidden
}),
//仅在pc端可折叠
collapse() {
return this.sidebarCollapse && this.device === 'pc'
},
6 years ago
hideSidebar() {
return this.sidebarAutoHidden && this.mouseOutside
|| this.sidebarCollapse && this.device === 'mobile'
},
sidebarClass() {
return {
'sidebar-container': true,
'mobile': this.device === 'mobile',
'collapse-sidebar': this.collapse,
'hide-sidebar': this.hideSidebar
}
6 years ago
}
},
watch: {
hideSidebar(v) {
if (v) document.addEventListener('mousemove', this.moveEvent)
else document.removeEventListener('mousemove', this.moveEvent)
}
},
methods: {
moveEvent(e) {
if (e.clientX <= 15) this.mouseOutside = false
},
select(index) {
if (this.$route.path === index) {
this.$store.commit('tagsView/delCachedView', this.$route)
this.$nextTick(() => this.$router.replace({path: '/redirect' + this.$route.fullPath}))
}
else this.$router.push(index)
6 years ago
}
},
mounted() {
if (this.sidebarAutoHidden) {
document.addEventListener('mousemove', this.moveEvent)
}
},
beforeDestroy() {
document.removeEventListener('mousemove', this.moveEvent)
}
}
</script>
<style lang="scss">
@import "~@/assets/styles/sidebar";
</style>