Commit 7874b383 by liimin

菜单框架改版

1 parent 18f1945f
......@@ -8,3 +8,10 @@
@mixin leftpadding {
padding: 0 $left;
}
@mixin menu-highlight {
outline: 0 !important;
color: $main-color !important;
background-color: rgba(88, 80, 255, 0.2) !important;
border-bottom: none;
}
......@@ -75,6 +75,9 @@ video {
vertical-align: baseline;
background: transparent;
}
li {
list-style-type: none;
}
body {
line-height: 1;
......
......@@ -22,7 +22,7 @@ module.exports = {
header_background: '#a3b6c6',
header_color: '#fff',
header_padding: '15px',
logo_height: '124px',
logo_height: '70px',
// 左侧菜单样式变量
menu_background: '#2a3f54',
menu_color: '#fff',
......@@ -32,7 +32,7 @@ module.exports = {
main_background_color: '#f0f1f7',
main_color: '#5f5efb',
menu_width: '208px',
menu_width_collapse: '80px',
menu_width_collapse: '48px',
base_border: '#5f5efb',
font_family: `'PingFangSC-Regular', 'Microsoft YaHei', '微软雅黑', 'MicrosoftJhengHei', 'STHeiti', 'MingLiu'`,
min_width: '1280px',
......
<template>
<div class="side-bar">
<div class="logo">
<Logo></Logo>
</div>
<div class="side-bar-menu">
<LeftSideMenuLv1 :menuList="menuList"></LeftSideMenuLv1>
<LeftSideMenuLv2></LeftSideMenuLv2>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import Vue from 'vue'
const bus = new Vue()
export default {
name: 'LeftSideMenu',
computed: {
...mapGetters(['app'])
},
watch: {
'app.currentPage.id': {
handler(n) {
const [lv1, lv2, lv3, lv4] = n.split('-')
bus.$emit('current', { lv1, lv2, lv3, lv4 })
}
}
},
data() {
return {
menuList: []
}
},
created() {
this.menuList = this.app.menuList.noHidden()
},
provide() {
return {
bus
}
}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
.side-bar {
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
background-color: #fff;
> .logo {
flex: 0 0 $logo-height;
height: $logo-height;
}
.side-bar-menu {
flex: 1;
user-select: none;
overflow-y: auto;
background-color: #fff;
padding-top: 36px;
display: flex;
&-left {
height: 100%;
width: $menu-width;
.el-menu {
height: 100%;
}
}
&-scroll-y {
/deep/.el-scrollbar__wrap {
margin-bottom: 0 !important ;
}
height: calc(100vh - #{$logo-height});
}
}
&::before {
position: absolute;
content: '';
width: 1px;
border-right: 1px solid #f5f7fa;
height: 100%;
left: 48px;
}
}
</style>
<template>
<div class="com-left-side-menu-lv1">
<GLScroll class="side-bar-menu-scroll-y">
<LeftSideMenuLv1Item v-for="item in menuList" :key="item.id" :menuData="item"></LeftSideMenuLv1Item>
</GLScroll>
<el-popover v-if="showPop && menu.isCollapse" ref="pop" :reference="reference" placement="right-start" :visible-arrow="false" width="160" trigger="hover" popper-class="el-submenu-popper-base">
<LeftSideMenuLv2></LeftSideMenuLv2>
</el-popover>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'LeftSideMenuLv1',
inject: ['bus'],
props: {
menuList: {
type: Array,
default: () => []
},
bus: {
type: Object,
default: () => {}
}
},
computed: {
...mapGetters(['menu'])
},
data() {
return {
reference: {},
// 控制渲染条件
showPop: false,
// 保存当前激活的refrence id
activeId: ''
}
},
mounted() {
this.bus.$on('mouseenter', this.mouseenter)
},
beforeDestroy() {
this.bus.$off('mouseenter', this.mouseenter)
},
methods: {
mouseenter(item, reference, onReady) {
// 这个操作是为了避免与源码中的 doToggle方法冲突
// if (this.activeId === item.id && this.showPop) return
this.showPop = false
this.activeId = item.id
// 因为reference是需要获取dom的引用 所以需要是$el
this.reference = reference
this.$nextTick(() => {
// 等待显示的popover销毁后再 重新渲染新的popover
this.showPop = true
this.$nextTick(() => {
// 此时才能获取refs引用
this.$refs.pop.doShow()
onReady()
setTimeout(() => this.$refs.pop.updatePopper(), 100)
})
})
}
}
}
</script>
<style lang="scss">
$width: 160px;
@mixin popup_width {
width: $width !important;
min-width: $width !important;
}
// .el-menu--vertical {
.el-popover.el-submenu-popper-base {
padding: 0px !important;
margin-left: 0px;
box-shadow: 0 6px 20px 0 #7a7a7a33;
border-radius: 4px;
}
// }
</style>
<style lang="scss" scoped>
.com-left-side-menu-lv1 {
width: 48px;
height: 100%;
display: flex;
flex-direction: column;
gap: 16px;
box-sizing: border-box;
// border-right: 1px solid #f5f7fa;
}
</style>
<template>
<div :ref="`bt` + menuData.id" :class="['com-left-side-menu-lv1-item', isHighlight ? 'highlight' : '']" @mouseenter.stop="mouseenter" @mouseleave.stop="mouseleave" @click.stop="handleClick()">
<i :class="['i', icon]"></i>
<span class="title">{{ menuData.title }}</span>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
export default {
name: 'LeftSideMenuLv1Item',
inject: ['bus'],
props: {
menuData: {
type: Object,
default: () => {}
}
},
computed: {
...mapGetters(['app', 'menu']),
icon() {
return `i-${this.menuData.icon}${['', '-active'][+this.isHighlight]}`
},
isHighlight() {
return this.app?.currentPage?.id?.split('-')[0] == this.menuData.id || this.menu.hoverId == this.menuData.id
}
},
methods: {
mouseenter: function () {
if (this.menu.hoverId === this.menu.id) return
this.setHoverId(this.menuData.id)
this.menu.isCollapse && this.bus.$emit('mouseenter', this.menuData, this.$refs['bt' + this.menuData.id], () => this.bus.$emit('menuChanged', this.menuData.children.noHidden()))
},
mouseleave: function () {
this.menu.hoverId && this.setHoverId('')
},
handleClick() {
this.bus.$emit('menuChanged', this.menuData.children.noHidden())
},
...mapActions('menu', ['setHoverId'])
}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
.com-left-side-menu-lv1-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;
gap: 4px;
cursor: pointer;
&.highlight {
background-color: #edecff;
.title {
color: $main-color;
}
}
.title {
font-size: 10px;
color: #666;
// transform: scale(0.9);
overflow: hidden;
// text-overflow: ellipsis;
// white-space: nowrap;
// max-width: 5em;
// user-select: none;
}
}
</style>
<template>
<div class="com-left-side-menu-lv2">
<GLScroll class="com-left-side-menu-lv2-scroll-y">
<!-- <div class="menu-wrap"> -->
<el-menu class="flex-1 none-border" background-color="#fff" active-text-color="#409EFF" text-color="#999" :default-openeds="cur.openeds" :default-active="cur.active" :collapse-transition="false">
<LeftSideMenuLv2Item></LeftSideMenuLv2Item>
</el-menu>
<!-- </div> -->
</GLScroll>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
import { currentId } from './mixins/index'
export default {
name: 'LeftSideMenuLv2',
mixins: [currentId],
inject: ['bus'],
created() {
this.bus.$on('current', this.handleCurrentChange)
this.bus.$on('menuChanged', this.handleMenuChanged)
},
computed: {
...mapGetters(['app', 'menu'])
},
mounted() {
this.handleCurrentChange(this.current)
},
beforeDestroy() {
this.bus.$off('current', this.handleCurrentChange)
this.bus.$off('menuChanged', this.handleMenuChanged)
},
data() {
return {
cur: {
openeds: [],
active: ''
}
}
},
methods: {
...mapActions('menu', ['setOpenId', 'setHoverId']),
open(index) {
this.setOpenId(index)
},
close() {
this.setOpenId('')
// this.setHoverId('')
},
handleCurrentChange({ lv1, lv2, lv3 }) {
this.cur.active = `${lv1}-${lv2}-${lv3}`
},
handleMenuChanged(menus) {
this.cur.openeds = menus.map(({ id }) => id)
}
}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
.com-left-side-menu-lv2 {
width: 100%;
height: 100%;
user-select: none;
overflow-y: auto;
.menu-wrap {
height: 100%;
/deep/.el-menu {
height: 100%;
}
}
&-scroll-y {
/deep/.el-scrollbar__wrap {
margin-bottom: 0 !important ;
}
height: 100%;
}
}
</style>
<template>
<div class="com-left-side-menu-lv2-item">
<div v-for="item in menus" :key="item.id">
<!-- 没有二级菜单的一级菜单 -->
<div class="el-submenu" :class="{ active: `${current.lv1}-${current.lv2}` == item.id }" v-if="isMenuNoChildren(item)" @click.stop="handleModuleClick(item)">
<div class="el-submenu__title">
<span>{{ item.title }}</span>
</div>
</div>
<!-- 有二级菜单的一级菜单 -->
<el-submenu v-else :index="item.id" popper-class="el-submenu-popper-base" :hide-timeout="hideTimeout" :show-timeout="showTimeout">
<span slot="title">{{ item.title }}</span>
<!-- 渲染二级菜单 -->
<LeftSideMenuLv3 :menuItems="item.children" :parentTitle="item.title"></LeftSideMenuLv3>
</el-submenu>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { currentId } from './mixins/index'
export default {
name: 'LeftSideMenuLv2Item',
mixins: [currentId],
inject: ['bus'],
data() {
return {
menus: [],
showTimeout: 0,
hideTimeout: 0
}
},
computed: {
...mapGetters(['app', 'menu'])
},
watch: {
'menu.isCollapse': {
handler(n) {
!n && this.reload()
}
}
},
mounted() {
this.bus.$on('menuChanged', this.handleMenuChanged)
this.reload()
},
beforeDestroy() {
this.bus.$off('menuChanged', this.handleMenuChanged)
},
methods: {
handleModuleClick(menu) {
this.$router.push(menu.path)
},
isMenuNoChildren({ children = [] }) {
return children.noHidden().length == 0
},
handleMenuChanged(menus) {
this.menus = menus
},
reload() {
const { lv1 } = this.current
this.menus = this.app.menuList.find(({ id }) => id == lv1).children.noHidden()
this.bus.$emit('menuChanged', this.menus)
}
}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
@import '~@/assets/style/mixins.scss';
$active-background-color: rgba(88, 80, 255, 0.2) !important;
.com-left-side-menu-lv2-item {
height: 100%;
padding: 8px;
/deep/.el-submenu {
height: 100%;
border-radius: 4px;
&__title {
height: 36px;
line-height: 36px;
background-color: transparent !important;
padding: 0 8px !important;
&:hover {
// background-color: #fff !important;
span,
i {
color: $main-color !important;
}
}
span {
font-size: 16px;
color: #444;
font-weight: 600;
}
.el-submenu__icon-arrow {
right: 0;
}
}
// &.is-opened {
// .el-submenu__title {
// background-color: transparent !important;
// span,
// i {
// color: $main-color !important;
// }
// }
// }
&.is-active {
.el-submenu__title {
background-color: transparent !important;
span,
i {
color: $main-color !important;
}
}
}
&.active {
@include menu-highlight;
span {
color: $main-color !important;
}
}
}
}
</style>
<template>
<el-menu-item-group :title="parentTitle" class="com-left-side-menu-lv3" v-if="menuItems">
<el-menu-item v-for="item in menuItems.noHidden()" :key="item.id" :index="item.id" @click.native.stop="handleSelect(item)">
<span>{{ item.title }}</span>
</el-menu-item>
</el-menu-item-group>
</template>
<script>
export default {
name: 'LeftSideMenuLv3',
props: {
parentTitle: {
type: String,
required: false,
default: ''
},
menuItems: {
type: Array,
required: true
}
},
methods: {
handleSelect({ path }) {
if (path) {
this.$router.push(path)
}
}
}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
@import '~@/assets/style/mixins.scss';
$menu-item-width: 144px !important;
.com-left-side-menu-lv3 {
/deep/.el-menu-item-group__title {
display: none;
}
/deep/ul {
display: flex;
flex-direction: column;
align-items: center;
.el-menu-item {
width: $menu-item-width;
min-width: $menu-item-width;
height: 32px;
line-height: 32px;
align-self: center;
border-radius: 4px;
padding-left: 8px !important;
span {
color: #777;
font-size: 14px;
}
&:hover,
&.is-active {
@include menu-highlight;
span {
color: $main-color !important;
}
}
&:hover:not(.is-active) {
background-color: transparent !important;
}
}
}
}
</style>
<style lang="scss">
$width: 150px;
@mixin popup_width {
width: $width !important;
min-width: $width !important;
}
.el-menu--vertical {
&.el-submenu-popper-base {
.el-menu--popup {
@include popup_width;
margin-left: -8px;
box-shadow: 0px 6px 20px 0px rgba(122, 122, 122, 0.2);
border-radius: 4px;
.scrm-base-submenu-item {
.el-menu-item {
@include popup_width;
padding-left: 20px !important;
border-radius: 0;
}
.el-menu-item-group__title {
display: block;
}
}
}
}
}
</style>
<template>
<li class="com-left-side-menu-lv3-item">{{ menu3 }}</li>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'LeftSideMenuLv3Item',
props: {
menu3: {
type: Object,
default: () => {}
}
},
computed: {
...mapGetters(['app', 'menu'])
},
methods: {}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
.com-left-side-menu-lv3-item {
width: 100%;
min-height: 36px;
background-color: blue;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 16px;
color: #333;
}
</style>
<template>
<div class="com-left-side-right">
<LeftSideMenuNav></LeftSideMenuNav>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'LeftSideRight',
computed: {
...mapGetters(['app', 'menu'])
},
methods: {}
}
</script>
<style lang="scss" scoped>
@import '~@/assets/style/collapse.scss';
.com-left-side-right {
flex: 1;
}
</style>
import { mapGetters } from 'vuex'
export const currentId = {
computed: {
...mapGetters(['app']),
current() {
let _current = {}
if (this.app.currentPage) {
const [lv1, lv2, lv3, lv4] = this.app.currentPage.id.split('-')
Object.assign(_current, { lv1, lv2, lv3, lv4 })
}
return _current
}
}
}
......@@ -2,7 +2,7 @@
* @Author: lizhijie429
* @Date: 2021-08-19 11:16:08
* @LastEditors: limin
* @LastEditTime: 2023-04-12 09:38:06
* @LastEditTime: 2023-09-12 13:54:49
* @Description:
-->
<template>
......@@ -25,8 +25,8 @@ export default {
config() {
const { cdn, customized, assets = customized.assets } = this.$config
const src = `${cdn}/assets/${assets}`
const src_logo_menu = `${src}/logo_menu.png`
const src_logo_collapse = `${src}/logo_collapse.png`
const src_logo_menu = `${src}/logo_menu_new.png`
const src_logo_collapse = `${src}/logo_collapse_new.png`
return { src_logo_menu, src_logo_collapse, isCollapse: this.menu.isCollapse }
}
},
......@@ -46,14 +46,14 @@ export default {
height: 100%;
background: #fff;
position: relative;
padding-left: 12px;
/deep/.el-image {
margin: 24px auto;
}
// padding-left: 12px;
// /deep/.el-image {
// margin: 8px auto;
// }
.folder {
position: absolute;
right: 0;
bottom: 18px;
bottom: -24px;
width: 30px;
height: 24px;
background-color: #f1f1f5;
......
......@@ -26,6 +26,9 @@ export default {
this.$router.push(path)
}
}
},
mounted(){
console.log(this.menuItems);
}
}
</script>
......
<template>
<el-container class="base-container" :class="{ 'menu-collapse': menu.isCollapse }">
<el-aside class="base-container-aside">
<SideMenu></SideMenu>
<LeftSideMenu></LeftSideMenu>
</el-aside>
<el-container class="base-container-right">
<el-header>
......
......@@ -92,7 +92,7 @@ module.exports = {
}
}
])
process.env.NODE_ENV === 'development' && config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
// process.env.NODE_ENV === 'development' && config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!