From df744014031c57bf69fd1d94767a3c6e07f2ecb8 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期六, 31 十二月 2022 13:20:38 +0800
Subject: [PATCH] 1.横向竖向菜单模式切换功能
---
src/layout/components/Navbar.vue | 311 +++++++++++++++++++++++++++++++--------------------
1 files changed, 190 insertions(+), 121 deletions(-)
diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue
index 687336b..47c2260 100644
--- a/src/layout/components/Navbar.vue
+++ b/src/layout/components/Navbar.vue
@@ -1,113 +1,141 @@
<template>
- <!-- <div class="navbar">-->
- <div class="navbar" :style="{background: $store.state.settings.headBackgroundColorValue? '#304156':'#fff'}">
- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
-
- <breadcrumb class="breadcrumb-container" />
-
- <div class="right-menu">
-
- <!-- <template v-if="device!=='mobile'">-->
- <template>
- <search id="header-search" class="right-menu-item" />
- <!-- <error-log class="errLog-container right-menu-item hover-effect" />-->
- <screenfull id="screenfull" class="right-menu-item hover-effect" />
- <!-- <el-tooltip content="Global Size" effect="dark" placement="bottom">-->
- <!-- <size-select id="size-select" class="right-menu-item hover-effect" />-->
- <!-- </el-tooltip>-->
- </template>
-
- <el-dropdown class="avatar-container" trigger="click">
- <div class="avatar-wrapper">
- <!-- <img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar">-->
- <div style="display: flex;align-items: center;margin-top: -5px">
-
- <i class="el-icon-user" style="font-weight: bolder;font-size: 18px;margin-right: 5px;color:#A7A7A7" />
- <div style=" font-size: 18px;font-family: 'Microsoft YaHei';color:#AAAAAA">{{ username }}</div>
- </div>
-
- <!-- <i class="el-icon-caret-bottom" />-->
- </div>
- <el-dropdown-menu slot="dropdown" class="user-dropdown" style="text-align: center">
- <!-- <router-link to="/">-->
- <!-- <el-dropdown-item>-->
- <!-- Home-->
- <!-- </el-dropdown-item>-->
- <!-- </router-link>-->
- <!-- <a target="_blank" href="https://github.com/PanJiaChen/vue-admin-template/">-->
- <!-- <el-dropdown-item>Github</el-dropdown-item>-->
- <!-- </a>-->
- <!-- <a target="_blank" href="https://panjiachen.github.io/vue-element-admin-site/#/">-->
- <!-- <el-dropdown-item>Docs</el-dropdown-item>-->
- <!-- </a>-->
- <el-dropdown-item @click.native="editPassword">
- <span style="display:block;">淇敼瀵嗙爜</span>
- </el-dropdown-item>
- <el-dropdown-item divided @click.native="logout">
- <span style="display:block;font-weight: bolder">閫�鍑�</span>
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </div>
- <el-dialog
- title="淇敼瀵嗙爜"
- :visible.sync="dialogVisible"
- width="500px"
- :close-on-click-modal="false"
- @close="handleClose"
- @closed="handleClose"
+ <div>
+ <div
+ class="navbar"
+ :class="{'display_btw':$store.state.settings.menuIsHorizontal}"
+ :style="{background: $store.state.settings.headBackgroundColorValue? '#304156':'#fff'}"
>
- <el-form ref="dialogForm" :rules="formRules" :model="form" label-width="100px">
- <!-- <el-form-item label="鐢ㄦ埛缂栫爜锛�">-->
- <!-- <div>{{ usercode }}</div>-->
- <!-- </el-form-item>-->
- <!-- <el-form-item label="鐢ㄦ埛鍚嶇О锛�">-->
- <!-- <div> {{ username }}</div>-->
- <!-- </el-form-item>-->
- <el-form-item label="鍘熷瘑鐮侊細" prop="password">
- <el-input v-model="form.password" style="width: 220px;" />
- </el-form-item>
- <el-form-item label="鏂板瘑鐮侊細" prop="newpassword">
- <el-input v-model="form.newpassword" style="width: 220px;" />
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <div class="footerButton">
- <el-button @click="dialogVisibleCancel">杩斿洖</el-button>
- <el-button type="primary" @click="dialogVisibleConfirm">纭� 瀹�</el-button>
- </div>
- </span>
- </el-dialog>
+ <hamburger
+ v-if="!$store.state.settings.menuIsHorizontal"
+ :is-active="sidebar.opened"
+ class="hamburger-container"
+ @toggleClick="toggleSideBar"
+ />
+
+ <breadcrumb
+ class="breadcrumb-container"
+ :style="{marginLeft:$store.state.settings.menuIsHorizontal?'20px':''}"
+ />
+
+ <el-menu
+ v-if="$store.state.settings.menuIsHorizontal"
+ router
+ class="menuHorizontal el-menu-demo"
+ mode="horizontal"
+ :default-active="activeMenu"
+ :text-color="$store.state.settings.headBackgroundColorValue?'#fff':'#87909c'"
+ :background-color="$store.state.settings.headBackgroundColorValue?variables.menuBg:'#fff'"
+ :active-text-color="variables.menuActiveText"
+ @select="handleSelect"
+ >
+ <!-- menu-trigger="click"-->
+ <!-- :text-color="variables.menuText"-->
+ <menu-item-ex
+ v-for="route in permission_routes"
+ :key="route.path"
+ :item="route"
+ :base-path="route.path"
+ />
+ </el-menu>
+
+ <div class="right-menu">
+
+ <!-- <template v-if="device!=='mobile'">-->
+ <template>
+ <search id="header-search" class="right-menu-item" />
+ <!-- <error-log class="errLog-container right-menu-item hover-effect" />-->
+ <screenfull id="screenfull" class="right-menu-item hover-effect" />
+ <!-- <el-tooltip content="Global Size" effect="dark" placement="bottom">-->
+ <!-- <size-select id="size-select" class="right-menu-item hover-effect" />-->
+ <!-- </el-tooltip>-->
+ </template>
+
+ <el-dropdown class="avatar-container" trigger="click">
+ <div class="avatar-wrapper">
+ <!-- <img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar">-->
+ <div style="display: flex;align-items: center;margin-top: -5px">
+
+ <i class="el-icon-user" style="font-weight: bolder;font-size: 18px;margin-right: 5px;color:#A7A7A7" />
+ <div style=" font-size: 18px;font-family: 'Microsoft YaHei';color:#AAAAAA">{{ username }}</div>
+ </div>
+
+ <!-- <i class="el-icon-caret-bottom" />-->
+ </div>
+ <el-dropdown-menu slot="dropdown" class="user-dropdown" style="text-align: center">
+ <!-- <router-link to="/">-->
+ <!-- <el-dropdown-item>-->
+ <!-- Home-->
+ <!-- </el-dropdown-item>-->
+ <!-- </router-link>-->
+ <!-- <a target="_blank" href="https://github.com/PanJiaChen/vue-admin-template/">-->
+ <!-- <el-dropdown-item>Github</el-dropdown-item>-->
+ <!-- </a>-->
+ <!-- <a target="_blank" href="https://panjiachen.github.io/vue-element-admin-site/#/">-->
+ <!-- <el-dropdown-item>Docs</el-dropdown-item>-->
+ <!-- </a>-->
+ <el-dropdown-item @click.native="editPassword">
+ <span style="display:block;">淇敼瀵嗙爜</span>
+ </el-dropdown-item>
+ <el-dropdown-item divided @click.native="logout">
+ <span style="display:block;font-weight: bolder">閫�鍑�</span>
+ </el-dropdown-item>
+ </el-dropdown-menu>
+ </el-dropdown>
+ </div>
+ <el-dialog
+ title="淇敼瀵嗙爜"
+ :visible.sync="dialogVisible"
+ width="500px"
+ :close-on-click-modal="false"
+ @close="handleClose"
+ @closed="handleClose"
+ >
+ <el-form ref="dialogForm" :rules="formRules" :model="form" label-width="100px">
+ <!-- <el-form-item label="鐢ㄦ埛缂栫爜锛�">-->
+ <!-- <div>{{ usercode }}</div>-->
+ <!-- </el-form-item>-->
+ <!-- <el-form-item label="鐢ㄦ埛鍚嶇О锛�">-->
+ <!-- <div> {{ username }}</div>-->
+ <!-- </el-form-item>-->
+ <el-form-item label="鍘熷瘑鐮侊細" prop="password">
+ <el-input v-model="form.password" style="width: 220px;" />
+ </el-form-item>
+ <el-form-item label="鏂板瘑鐮侊細" prop="newpassword">
+ <el-input v-model="form.newpassword" style="width: 220px;" />
+ </el-form-item>
+ </el-form>
+ <span slot="footer" class="dialog-footer">
+ <div class="footerButton">
+ <el-button @click="dialogVisibleCancel">杩斿洖</el-button>
+ <el-button type="primary" @click="dialogVisibleConfirm">纭� 瀹�</el-button>
+ </div>
+ </span>
+ </el-dialog>
+
+ </div>
</div>
+
</template>
<script>
+const SER_HZ = /^[\u4e00-\u9fa5]+$/
import { mapGetters } from 'vuex'
+import MenuItemEx from './Sidebar/MenuItemEx'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import { getCookie } from '@/utils/auth'
import { UpdateUserPassword } from '@/api/user'
import Search from '@/components/HeaderSearch'
import Screenfull from '@/components/Screenfull'
+import variables from '@/styles/variables.scss'
-const SER_HZ = /^[\u4e00-\u9fa5]+$/
export default {
components: {
+ MenuItemEx,
Breadcrumb,
Hamburger,
Search,
Screenfull
- },
- computed: {
- ...mapGetters([
- 'sidebar',
- 'avatar',
- 'device'
- ])
- },
- created() {
- this.usercode = getCookie('navTabId')
- this.username = getCookie('username')
},
data() {
const validatePassword1 = (rule, value, callback) => {
@@ -150,7 +178,43 @@
}
}
},
+ created() {
+ this.usercode = getCookie('navTabId')
+ this.username = getCookie('username')
+ },
+ computed: {
+ ...mapGetters([
+ 'sidebar',
+ 'avatar',
+ 'permission_routes'
+ ]),
+ routes() {
+ return this.$router.options.routes
+ },
+ activeMenu() {
+ const route = this.$route
+ const { meta, path } = route
+ // if set path, the sidebar will highlight the path you set
+ if (meta.activeMenu) {
+ return meta.activeMenu
+ }
+ // const p = '/' + path.split('/')[1]
+ // console.log(p)
+ return path
+ },
+ variables() {
+ console.log(variables, 2333)
+ // 鍏堣緭鍑鸿繖涓獀ariables鍊� 鐒跺悗淇敼鍏跺睘鎬у��
+ variables.menuActiveText = this.$store.state.settings.theme
+ // background: rgb(48, 65, 86);
+ // variables.menuBg = this.$store.state.settings.headBackgroundColorValue && this.$store.state.settings.menuIsHorizontal ? `rgb(48,65,86)` : '#fff'
+ return variables
+ }
+ },
methods: {
+ handleSelect(key, keyPath) {
+ // console.log(key, keyPath)
+ },
toggleSideBar() {
this.$store.dispatch('app/toggleSideBar')
},
@@ -174,7 +238,6 @@
password: this.form.password,
newpassword: this.form.newpassword
}
- console.log(data)
UpdateUserPassword(data).then(res => {
if (res.code === '200') {
this.$message.success('淇敼鎴愬姛锛�')
@@ -192,9 +255,11 @@
}
}
</script>
-
<style lang="scss" scoped>
-$main_color: #42b983;
+.display_btw {
+ display: flex;
+ justify-content: space-between;
+}
.navbar {
height: 50px;
@@ -220,6 +285,30 @@
.breadcrumb-container {
float: left;
+ width: 200px;
+ }
+
+ .menuHorizontal {
+ display: flex !important;
+ justify-content: center !important;
+
+ ::v-deep .svg-icon {
+ margin-right: 8px;
+ //margin-left: 8px !important;
+ }
+
+ ::v-deep .el-submenu__title > span {
+ //margin-right: 8px !important;
+ }
+
+ ::v-deep .submenu-title-noDropdown > span {
+ //margin-right: 8px !important;
+ }
+
+ ::v-deep .el-submenu__icon-arrow {
+ display: none;
+ }
+
}
.right-menu {
@@ -227,6 +316,7 @@
height: 100%;
line-height: 50px;
display: flex;
+ //min-width: 300px;
&:focus {
outline: none;
@@ -275,33 +365,12 @@
}
}
}
-
- //.footerButton {
- // display: flex;
- // justify-content: end;
- //}
- //
- //::v-deep .el-button--primary {
- // background-color: $main_color !important;
- // height: 30px;
- // display: flex;
- // align-items: center;
- // //border: 1px solid $main_color;
- // border: none;
- // padding: 0 20px;
- //}
- //
- //::v-deep .el-button--default {
- // background-color: #ffffff !important;
- // height: 30px;
- // display: flex;
- // align-items: center;
- // padding: 0 20px;
- //}
- //
- //::v-deep .el-input__inner {
- // height: 30px;
- // line-height: 30px;
- //}
}
</style>
+<style>
+.el-menu--horizontal .el-menu {
+ background-color: transparent !important;
+ margin-top: -2px;
+}
+
+</style>
--
Gitblit v1.9.3