bonus-ui/src/layout/components/Navbar.vue

548 lines
14 KiB
Vue
Raw Normal View History

2024-06-26 15:11:05 +08:00
<template>
2026-01-20 17:40:38 +08:00
<div>
<div class="navbar">
<div class="app-title">
<span>{{ title }}</span>
</div>
<div class="menus" @mouseleave="handleMenuLeave">
<div
v-for="(item, index) in menuList"
:key="index"
class="menu-item"
@mouseenter="handleMenuEnter(item)"
@click="handleMenuClick(item)"
>
<div class="menu-btn">
<span v-if="item.redirect == 'index' || item.redirect == 'index1'">
{{ item.children[0].meta.title }}
</span>
2026-01-22 09:24:00 +08:00
<span v-else-if="item.meta && item.meta.title">{{ item.meta.title }}</span>
2026-01-20 17:40:38 +08:00
<div class="tab-item-btn"></div>
</div>
</div>
</div>
<div class="right-menu">
<template v-if="device !== 'mobile'">
<search id="header-search" class="right-menu-item" />
<!-- <screenfull id="screenfull" class="right-menu-item hover-effect" />
<el-tooltip content="布局大小" effect="dark" placement="bottom">
<size-select id="size-select" class="right-menu-item hover-effect" />
</el-tooltip> -->
</template>
<el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
<div>
<img :src="avatar" class="user-avatar" />
<span class="nick-name">{{ user.nickName }}</span>
<i class="el-icon-arrow-down" style="color: #fff"></i>
</div>
<el-dropdown-menu slot="dropdown">
<router-link to="/user/profile">
<el-dropdown-item>个人中心</el-dropdown-item>
</router-link>
<el-dropdown-item @click.native="setting = true">
<span>布局设置</span>
</el-dropdown-item>
<el-dropdown-item divided @click.native="logout">
<span>退出登录</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
2026-01-25 15:31:18 +08:00
<div style="height: 50px"></div>
<div class="menu-box" v-show="showMenuBox" @mouseenter="handleBoxEnter">
<div class="menu-warp" @mouseleave="handleBoxLeave">
<div class="menu-list">
<div class="list-box">
<div class="menu-title-top" v-if="currentMenu && currentMenu.meta">
<div class="title-tip"></div>
<span class="title-text">{{ currentMenu.meta.title }}</span>
</div>
2026-01-20 17:40:38 +08:00
2026-01-25 15:31:18 +08:00
<div v-for="(child, i) in currentMenu.children || []" :key="i" class="sub-menu-item" v-if="!child.hidden">
<div v-if="child.children && child.children.length">
<div class="menu-title" @click="toggleLevel1(child)">
<div class="children-title-tip"></div>
<span>
<span style="margin-right: 5px">{{ child.meta.title }}</span>
<img
v-if="openLevel1.includes(child.path)"
src="@/assets/images/up.png"
style="width: 14px; height: 14px"
/>
<img v-else src="@/assets/images/down.png" style="width: 14px; height: 14px" />
</span>
<span class="menu-star">
<img src="@/assets/images/star.png" style="width: 10px; height: 9px" />
</span>
</div>
2026-01-20 17:40:38 +08:00
2026-01-25 15:31:18 +08:00
<div v-show="openLevel1.includes(child.path)">
<div v-for="(c2, j) in child.children" :key="j" class="sub-menu-item" v-if="!c2.hidden">
<div v-if="c2.children && c2.children.length">
<div class="menu-title" @click="toggleLevel2(c2)">
{{ c2.meta.title }}
<img
v-if="openLevel2.includes(c2.path)"
src="@/assets/images/up.png"
style="width: 12px; height: 12px; margin-left: 6px"
/>
<img
v-else
src="@/assets/images/down.png"
style="width: 12px; height: 12px; margin-left: 6px"
/>
</div>
2026-01-20 17:40:38 +08:00
2026-01-25 15:31:18 +08:00
<div v-show="openLevel2.includes(c2.path)">
<div
v-for="(c3, k) in c2.children"
:key="k"
class="sub-menu-item"
v-if="!c3.hidden"
@click="goRoute(c3)"
>
{{ c3.meta.title }}
</div>
2026-01-20 17:40:38 +08:00
</div>
</div>
2026-01-25 15:31:18 +08:00
<div v-else class="menu-title" @click="goRoute(c2)">
<span class="child-left">- {{ c2.meta.title }}</span>
<span class="menu-star">
<img src="@/assets/images/star.png" style="width: 10px; height: 9px" />
</span>
</div>
2026-01-20 17:40:38 +08:00
</div>
</div>
</div>
2026-01-25 15:31:18 +08:00
<div v-else class="menu-title" @click="goRoute(child)">
<div class="children-title-tip"></div>
<span>{{ child.meta.title }}</span>
<span class="menu-star">
<img src="@/assets/images/star.png" style="width: 10px; height: 9px" />
</span>
</div>
2026-01-20 17:40:38 +08:00
</div>
</div>
</div>
</div>
2024-06-26 15:11:05 +08:00
</div>
</div>
</template>
<script>
2026-01-20 17:40:38 +08:00
import { mapGetters } from 'vuex'
import Search from '@/components/HeaderSearch'
import { getUserProfile } from '@/api/system/user'
2024-06-26 15:11:05 +08:00
export default {
2026-01-25 15:31:18 +08:00
components: { Search },
2026-01-20 17:40:38 +08:00
data() {
return {
title: process.env.VUE_APP_TITLE,
user: {},
menuList: [],
showMenuBox: false,
2026-01-25 15:31:18 +08:00
currentMenu: {},
openLevel1: [],
openLevel2: [],
2026-01-20 17:40:38 +08:00
}
},
2024-06-26 15:11:05 +08:00
computed: {
2026-01-25 15:31:18 +08:00
...mapGetters(['sidebarRouters', 'avatar', 'device']),
2024-06-26 15:11:05 +08:00
setting: {
get() {
2026-01-20 17:40:38 +08:00
return this.$store.state.settings.showSettings
2024-06-26 15:11:05 +08:00
},
set(val) {
2026-01-20 17:40:38 +08:00
this.$store.dispatch('settings/changeSetting', {
key: 'showSettings',
value: val,
2026-01-20 17:40:38 +08:00
})
},
2024-06-26 15:11:05 +08:00
},
},
2026-01-20 17:40:38 +08:00
created() {
this.getUser()
this.menuList = this.sidebarRouters.filter((route) => !route.hidden)
},
2024-06-26 15:11:05 +08:00
methods: {
2026-01-20 17:40:38 +08:00
getUser() {
getUserProfile().then((response) => {
this.user = response.data
})
},
2024-06-26 15:11:05 +08:00
async logout() {
2026-01-20 17:40:38 +08:00
this.$confirm('确定注销并退出系统吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
2026-01-20 17:40:38 +08:00
this.$store.dispatch('LogOut').then((res) => {
2026-01-05 18:07:00 +08:00
this.$store.dispatch('tagsView/delAllViews')
2025-04-21 13:20:14 +08:00
if (process.env.VUE_APP_BASE_API == '/iws/jxhzb-api') {
window.location.href = 'http://sgwpdm.ah.sgcc.com.cn/iws'
} else {
2026-01-20 17:40:38 +08:00
this.$router.push({ path: '/login' })
2025-04-21 13:20:14 +08:00
}
2026-01-20 17:40:38 +08:00
})
2024-06-26 15:11:05 +08:00
})
2025-10-29 08:56:04 +08:00
.catch((err) => {
console.log('🚀 ~ err-退出登录:', err)
2026-01-20 17:40:38 +08:00
})
},
handleMenuClick(item) {
if (item.redirect == 'index' || item.redirect == 'index1') {
2026-01-25 15:31:18 +08:00
this.$router.push({ path: '/' + item.redirect })
2026-01-20 17:40:38 +08:00
}
},
handleMenuEnter(item) {
if (item.redirect == 'index' || item.redirect == 'index1') {
this.showMenuBox = false
return
}
2026-01-25 15:31:18 +08:00
2026-01-20 17:40:38 +08:00
this.showMenuBox = true
const buildPath = (nodes, parentPath = '') => {
return nodes.map((n) => {
let currentPath = n.path || ''
if (!currentPath.startsWith('/')) {
currentPath = parentPath.replace(/\/$/, '') + '/' + currentPath
}
2026-01-25 15:31:18 +08:00
const newNode = { ...n, fullPath: currentPath }
2026-01-20 17:40:38 +08:00
if (n.children && n.children.length) {
newNode.children = buildPath(n.children, currentPath)
}
return newNode
})
}
2026-01-25 15:31:18 +08:00
const children = buildPath(item.children || [], item.path)
2026-01-20 17:40:38 +08:00
this.currentMenu = {
...item,
fullPath: item.path,
2026-01-25 15:31:18 +08:00
children,
2026-01-20 17:40:38 +08:00
}
2026-01-25 15:31:18 +08:00
const level1 = []
const level2 = []
children.forEach((l1) => {
if (l1.children && l1.children.length) {
level1.push(l1.path)
l1.children.forEach((l2) => {
if (l2.children && l2.children.length) {
level2.push(l2.path)
}
})
}
})
this.openLevel1 = level1
this.openLevel2 = level2
},
2026-01-20 17:40:38 +08:00
handleMenuLeave() {
this.showMenuBox = false
},
handleBoxEnter() {
this.showMenuBox = true
},
handleBoxLeave() {
this.showMenuBox = false
},
goRoute(route) {
if (route.fullPath) {
2026-01-25 15:31:18 +08:00
this.$router.push({ path: route.fullPath, query: route.query })
2026-01-20 17:40:38 +08:00
this.showMenuBox = false
}
},
toggleLevel1(item) {
2026-01-25 15:31:18 +08:00
const idx = this.openLevel1.indexOf(item.path)
if (idx > -1) this.openLevel1.splice(idx, 1)
else this.openLevel1.push(item.path)
2026-01-20 17:40:38 +08:00
},
toggleLevel2(item) {
2026-01-25 15:31:18 +08:00
const idx = this.openLevel2.indexOf(item.path)
if (idx > -1) this.openLevel2.splice(idx, 1)
else this.openLevel2.push(item.path)
},
},
2026-01-20 17:40:38 +08:00
}
2024-06-26 15:11:05 +08:00
</script>
<style lang="scss" scoped>
.navbar {
2026-01-25 15:31:18 +08:00
width: 100%;
2024-06-26 15:11:05 +08:00
height: 50px;
overflow: hidden;
2026-01-25 15:31:18 +08:00
position: fixed;
2026-01-20 17:40:38 +08:00
display: flex;
align-items: center;
justify-content: space-between;
2025-12-11 18:36:05 +08:00
// background: #fff;
2026-01-20 17:40:38 +08:00
// background-image: url('../../assets/images/titleGif.gif');
// background-size: cover;
// background-repeat: no-repeat;
// background-position: center;
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
2026-01-20 17:40:38 +08:00
background: linear-gradient(90deg, #00d2be 0%, #4eacff 100%);
2026-01-25 15:31:18 +08:00
z-index: 10;
2026-01-20 17:40:38 +08:00
.app-title {
width: 314px;
height: 50px;
padding-left: 14px;
font-family: Microsoft YaHei, Microsoft YaHei;
font-weight: bold;
font-size: 20px;
color: #fff;
text-align: center;
display: flex;
align-items: center;
}
.menus {
min-width: 998px;
height: 50px;
line-height: 50px;
flex: 1;
display: flex;
align-items: center;
justify-content: space-around;
margin: 0 20px;
.menu-item {
height: 50px;
cursor: pointer;
font-family: Microsoft YaHei, Microsoft YaHei;
font-weight: bold;
font-size: 16px;
color: #ffffff;
text-align: center;
font-style: normal;
text-transform: none;
.menu-btn {
width: 100%;
text-align: center;
}
// 移入下方横条
&:hover {
.tab-item-btn {
margin: 5px auto 0;
width: 15px;
height: 2px;
margin-top: -8px;
background: #fff;
}
}
}
}
2024-06-26 15:11:05 +08:00
.hamburger-container {
line-height: 46px;
height: 100%;
float: left;
cursor: pointer;
transition: background 0.3s;
-webkit-tap-highlight-color: transparent;
2024-06-26 15:11:05 +08:00
&:hover {
background: rgba(0, 0, 0, 0.025);
2024-06-26 15:11:05 +08:00
}
}
.breadcrumb-container {
float: left;
}
.topmenu-container {
position: absolute;
left: 50px;
}
.errLog-container {
display: inline-block;
vertical-align: top;
}
.right-menu {
float: right;
height: 100%;
line-height: 50px;
&:focus {
outline: none;
}
.right-menu-item {
display: inline-block;
padding: 0 8px;
height: 100%;
font-size: 18px;
2025-12-11 18:36:05 +08:00
color: #bfbfbf; /* 纯黑色,比#262626更黑 */
2024-06-26 15:11:05 +08:00
vertical-align: text-bottom;
&.hover-effect {
cursor: pointer;
transition: background 0.3s;
2024-06-26 15:11:05 +08:00
&:hover {
background: rgba(0, 0, 0, 0.025);
2024-06-26 15:11:05 +08:00
}
}
}
.avatar-container {
2026-01-20 17:40:38 +08:00
margin-right: 16px;
2024-06-26 15:11:05 +08:00
2025-12-11 18:36:05 +08:00
.user-avatar {
cursor: pointer;
width: 18px;
height: 18px;
vertical-align: text-bottom;
2026-01-20 17:40:38 +08:00
color: #262626;
2025-12-11 18:36:05 +08:00
/* 移除了opacity属性使用color属性实现颜色调整 */
2024-06-26 15:11:05 +08:00
}
2026-01-20 17:40:38 +08:00
.nick-name {
margin: 0 3px;
font-family: Microsoft YaHei, Microsoft YaHei;
font-weight: 400;
font-size: 14px;
color: #ffffff;
text-align: center;
font-style: normal;
text-transform: none;
}
}
}
}
.menu-box {
position: absolute;
z-index: 99999999;
width: 100%;
2026-01-25 15:31:18 +08:00
height: calc(100% - 50px);
// background: linear-gradient(90deg, #00d2be 0%, #4eacff 100%);
// 蒙层
background: rgba(0, 0, 0, 0.5);
.menu-warp {
width: 100%;
background: linear-gradient(90deg, #00d2be 0%, #4eacff 100%);
border-radius: 0 0 16px 16px;
}
2026-01-20 17:40:38 +08:00
.menu-list {
padding: 16px 20px;
width: 100%;
min-height: 287px;
background: #f8fdfc;
border-radius: 16px;
font-family: Microsoft YaHei, Microsoft YaHei;
font-weight: 400;
font-size: 14px;
2026-01-25 15:31:18 +08:00
color: #095a4d;
2026-01-20 17:40:38 +08:00
line-height: 30px;
.list-box {
padding: 16px;
width: 290px;
height: 100%;
2026-01-25 15:31:18 +08:00
// background: linear-gradient(0deg, rgba(44, 186, 178, 0) 0%, rgba(44, 186, 178, 0.1) 100%);
background: linear-gradient(180deg, #e6ffff, rgba(233, 255, 255, 0) 90px);
border-radius: 12px;
2024-06-26 15:11:05 +08:00
}
}
2026-01-20 17:40:38 +08:00
.menu-title-top {
width: 100%;
display: flex;
align-items: center;
2026-01-23 18:36:49 +08:00
span {
2026-01-25 15:31:18 +08:00
color: #095a4d;
2026-01-23 18:36:49 +08:00
font-weight: 800;
}
2026-01-20 17:40:38 +08:00
}
.menu-title {
width: 100%;
display: flex;
align-items: center;
cursor: pointer;
// 移入效果
&:hover {
2026-01-25 15:31:18 +08:00
color: #2cbab2;
2026-01-20 17:40:38 +08:00
background: rgba(44, 186, 178, 0.1);
border-radius: 4px;
}
}
.menu-star {
padding-right: 5px;
flex: 1;
display: flex;
justify-content: flex-end;
align-items: center;
opacity: 0; // 默认不显示
transition: opacity 0.2s;
}
/* hover 当前行时,显示星标 */
.menu-title:hover .menu-star {
opacity: 1;
}
.title-tip {
margin-right: 4px;
width: 8px;
height: 16px;
2026-01-25 15:31:18 +08:00
line-height: 24px;
2026-01-20 17:40:38 +08:00
background: #2cbab2;
2026-01-25 15:31:18 +08:00
margin-bottom: 20px;
2026-01-20 17:40:38 +08:00
border-radius: 4px 4px 4px 4px;
}
2026-01-25 15:31:18 +08:00
.title-text {
font-size: 18px;
// color: #0f7969;
line-height: 24px;
font-weight: 700;
margin-bottom: 20px;
}
2026-01-20 17:40:38 +08:00
.children-title-tip {
margin-right: 4px;
width: 8px;
height: 8px;
background: #2cbab2;
border-radius: 50%;
}
.child-left {
// 与父节点左边距2个字符
margin-left: 1rem;
}
2024-06-26 15:11:05 +08:00
}
2026-01-25 15:31:18 +08:00
/* 只改“下一级里的”二级、三级颜色 */
.menu-box {
/* 二级child.children 里面的 menu-title */
.sub-menu-item {
.sub-menu-item {
> .menu-title {
color: #333;
}
/* 三级:最里面的 sub-menu-item */
.sub-menu-item {
color: #333;
}
}
}
}
2026-01-20 17:40:38 +08:00
</style>