206 lines
4.5 KiB
Vue
206 lines
4.5 KiB
Vue
<script lang="ts" setup>
|
|
import {
|
|
CircleClose,
|
|
User,
|
|
} from '@element-plus/icons-vue'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
import { useUserStore } from '@/store/user'
|
|
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
const userStore = useUserStore()
|
|
|
|
const menuList = [
|
|
{ name: '首页', path: '/' },
|
|
{ name: '企业名录', path: '/company' },
|
|
{ name: '论坛中心', path: '/post' },
|
|
{ name: '关于我们', path: '/aboutus' },
|
|
{ name: '联系我们', path: '/forum' },
|
|
]
|
|
|
|
function navigateTo(path: string) {
|
|
router.push(path)
|
|
}
|
|
|
|
function exitLogin() {
|
|
userStore.clearUserInfo()
|
|
|
|
router.push('/auth/login')
|
|
}
|
|
|
|
function isActive(path: string) {
|
|
if (path === '/') {
|
|
return route.path === '/'
|
|
}
|
|
return route.path === path || route.path.startsWith(`${path}/`)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<header class="header">
|
|
<nav class="container">
|
|
<img src="/logo.png" class="logo">
|
|
<div class="menu">
|
|
<span
|
|
v-for="item in menuList"
|
|
:key="item.path"
|
|
:class="{ active: isActive(item.path) }"
|
|
class="menu-item"
|
|
@click="navigateTo(item.path)"
|
|
>
|
|
<span class="menu-item-name">
|
|
{{ item.name }}
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div class="action">
|
|
<i-tdesign:search class="action-item" />
|
|
|
|
<i-tdesign:notification v-if="userStore.isLogined" class="action-item" />
|
|
|
|
<template v-if="userStore.isLogined">
|
|
<el-divider direction="vertical" />
|
|
|
|
<el-dropdown>
|
|
<div class="user">
|
|
<el-avatar :size="36" :src="userStore.userInfo.company.logo ? userStore.userInfo.company.logo : '/no-avatar.png'" />
|
|
<div class="info">
|
|
<span class="name">{{ userStore.userInfo.user.name }}</span>
|
|
<span class="company">{{ userStore.userInfo.company.name }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<template #dropdown>
|
|
<el-dropdown-menu>
|
|
<el-dropdown-item :icon="User" @click="navigateTo('/settings')">
|
|
个人中心
|
|
</el-dropdown-item>
|
|
<el-dropdown-item :icon="CircleClose" @click="exitLogin()">
|
|
退出登录
|
|
</el-dropdown-item>
|
|
</el-dropdown-menu>
|
|
</template>
|
|
</el-dropdown>
|
|
</template>
|
|
|
|
<template v-else>
|
|
<el-button
|
|
type="primary"
|
|
round
|
|
@click="navigateTo('/auth/login')"
|
|
>
|
|
登录
|
|
</el-button>
|
|
</template>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
.header {
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 1000;
|
|
background-color: #fff;
|
|
|
|
.container {
|
|
padding: 0rem 3rem;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
height: var(--header-height);
|
|
border-bottom: 1px solid rgb(232.9, 232.9, 232.9);
|
|
flex-shrink: 0;
|
|
min-width: 0;
|
|
|
|
.logo {
|
|
width: 160px;
|
|
height: 50px;
|
|
flex-shrink: 0;
|
|
min-width: 0;
|
|
}
|
|
|
|
.menu {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
min-width: 0;
|
|
|
|
.menu-item {
|
|
display: flex;
|
|
align-items: center;
|
|
cursor: pointer;
|
|
color: #9aa0a6;
|
|
outline: none;
|
|
margin-left: 36px;
|
|
transition: color 0.3s ease;
|
|
position: relative;
|
|
|
|
&:hover {
|
|
color: #2f2f2f !important;
|
|
}
|
|
&:first-child {
|
|
margin-left: 0px;
|
|
}
|
|
|
|
&.active {
|
|
color: #2f2f2f !important;
|
|
|
|
.menu-item-name {
|
|
font-weight: 500;
|
|
}
|
|
}
|
|
|
|
.menu-item-name {
|
|
font-size: 18px;
|
|
font-weight: 400;
|
|
}
|
|
}
|
|
}
|
|
|
|
.action {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
min-width: 0;
|
|
|
|
.action-item {
|
|
font-size: 20px;
|
|
margin-right: 24px;
|
|
color: #000;
|
|
cursor: pointer;
|
|
&:last-child {
|
|
margin-right: 0px;
|
|
}
|
|
}
|
|
|
|
.user {
|
|
margin-left: 24px;
|
|
display: flex;
|
|
align-items: center;
|
|
cursor: pointer;
|
|
outline: 0;
|
|
|
|
.info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
margin-left: 12px;
|
|
|
|
.name {
|
|
font-size: 16px;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.company {
|
|
font-size: 12px;
|
|
color: #888;
|
|
margin-top: 6px;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|