Files
tianze_front/src/App.vue
T
2026-11-15 00:50:52 +08:00

391 lines
8.9 KiB
Vue

<script setup lang="ts">
import { computed, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useUserInfoStore } from './stores/UserInfo'
import Popup from './components/popUP.vue'
const router = useRoute();
const navigation = useRouter();
const isLoginPage = computed(() => router.path === '/login');
const isActiveNav = (path: string) => router.path === path;
const userStore = useUserInfoStore();
const role = computed(() => userStore.userInfo.role);
const showLogoutMenu = ref(false);
function toggleLogoutMenu() {
showLogoutMenu.value = !showLogoutMenu.value;
}
function logout() {
userStore.clearUserInfo();
showLogoutMenu.value = false;
localStorage.removeItem('token');
navigation.push('/login');
}
</script>
<template>
<header v-if="!isLoginPage&&role != 'admin'&&role" class="topbar">
<a class="brand" href="#">
<span class="brand-mark">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path
d="M21 7.5a6.6 6.6 0 0 1-8.8 6.2L6.2 19.7a2.1 2.1 0 0 1-3-3l6-6A6.6 6.6 0 0 1 15.5 3l-2.7 2.7 1.5 1.5L17 4.5A6.6 6.6 0 0 1 21 7.5Z" />
</svg>
</span>
<span>天泽汽修</span>
</a>
<nav class="nav-links" aria-label="主导航">
<a :class="{ active: isActiveNav('/userinfo') }" href="/userinfo">首页</a>
<a :class="{ active: isActiveNav('/wait') }" href="/wait">车辆保养</a>
<a :class="{ active: isActiveNav('/wait1') }" href="/wait1">维修服务</a>
<a :class="{ active: isActiveNav('/wait2') }" href="/wait2">联系我们</a>
</nav>
<div class="topbar-actions">
<button class="icon-button" aria-label="搜索服务">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="10.8" cy="10.8" r="6.8" />
<path d="m16 16 5 5" />
</svg>
</button>
<button class="icon-button notification" aria-label="在线咨询">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path
d="M20 11.5a7.5 7.5 0 0 1-8 7.5 8.5 8.5 0 0 1-3.5-.8L4 20l1.5-3.5A7.3 7.3 0 0 1 4.5 12 7.5 7.5 0 0 1 12 4.5a7.5 7.5 0 0 1 8 7Z" />
<path d="M8 12h.01M12 12h.01M16 12h.01" />
</svg>
</button>
<div class="user-menu" :class="{ open: showLogoutMenu }">
<button class="user-trigger" type="button" aria-label="打开用户菜单" @click="toggleLogoutMenu">
<span class="user-avatar">{{ userStore.userInfo?.plateNumber.slice(0) || '客' }}</span>
<span class="user-name">在线客服</span>
</button>
<button class="logout-menu" type="button" @click="logout">退出登录</button>
</div>
</div>
</header>
<header v-if="!isLoginPage&&role == 'admin'" class="topbar">
<a class="brand" href="#">
<span class="brand-mark">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path
d="M21 7.5a6.6 6.6 0 0 1-8.8 6.2L6.2 19.7a2.1 2.1 0 0 1-3-3l6-6A6.6 6.6 0 0 1 15.5 3l-2.7 2.7 1.5 1.5L17 4.5A6.6 6.6 0 0 1 21 7.5Z" />
</svg>
</span>
<span>天泽汽修</span>
</a>
<nav class="nav-links" aria-label="主导航">
<a :class="{ active: isActiveNav('/adduser') }" href="/adduser">添加用户</a>
<a :class="{ active: isActiveNav('/search') }" href="/search">用户查询</a>
<a :class="{ active: isActiveNav('/wait1') }" href="/wait1">维修服务</a>
<a :class="{ active: isActiveNav('/wait2') }" href="/wait2">联系我们</a>
</nav>
<div class="topbar-actions">
<button class="icon-button" aria-label="搜索服务">
<svg viewBox="0 0 24 24" aria-hidden="true">
<circle cx="10.8" cy="10.8" r="6.8" />
<path d="m16 16 5 5" />
</svg>
</button>
<button class="icon-button notification" aria-label="在线咨询">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path
d="M20 11.5a7.5 7.5 0 0 1-8 7.5 8.5 8.5 0 0 1-3.5-.8L4 20l1.5-3.5A7.3 7.3 0 0 1 4.5 12 7.5 7.5 0 0 1 12 4.5a7.5 7.5 0 0 1 8 7Z" />
<path d="M8 12h.01M12 12h.01M16 12h.01" />
</svg>
</button>
<div class="user-menu" :class="{ open: showLogoutMenu }">
<button class="user-trigger" type="button" aria-label="打开用户菜单" @click="toggleLogoutMenu">
<span class="user-avatar">{{ userStore.userInfo?.plateNumber.slice(0) || '客' }}</span>
<!--<span class="user-name">{{ userStore.userInfo?.plateNumber || '客人' }}</span>-->
</button>
<button class="logout-menu" type="button" @click="logout">退出登录</button>
</div>
</div>
</header>
<router-view />
<Popup />
<!-- <HelloWorld /> -->
</template>
<style scoped>
.topbar {
position: relative;
height: 74px;
padding: 0 clamp(24px, 5vw, 76px);
display: flex;
align-items: center;
gap: 58px;
background: #fff;
border-bottom: 1px solid #e8edf5;
animation: nav-slide-down 0.55s cubic-bezier(.22, 1, .36, 1) both;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
color: #13213b;
font-size: 19px;
font-weight: 800;
text-decoration: none;
white-space: nowrap;
transition: color .25s ease, transform .25s ease;
}
.brand:hover {
color: #1769e0;
transform: translateY(-2px);
}
.brand-mark {
width: 36px;
height: 36px;
display: grid;
place-items: center;
color: #fff;
background: #1769e0;
border-radius: 10px;
transition: transform .35s cubic-bezier(.22, 1, .36, 1), box-shadow .35s ease;
}
.brand:hover .brand-mark {
transform: rotate(-8deg) scale(1.08);
box-shadow: 0 7px 15px #1769e14d;
}
.brand-mark svg {
width: 22px;
fill: currentColor;
}
.user-menu {
position: relative;
}
.user-menu::after {
content: "";
position: absolute;
top: 100%;
right: 0;
width: 100px;
height: 10px;
}
.user-trigger {
display: flex;
padding: 0;
align-items: center;
gap: 8px;
color: #34415a;
background: none;
border: 0;
cursor: pointer;
font: inherit;
}
.logout-menu {
position: absolute;
z-index: 3;
top: calc(100% + 10px);
right: 0;
width: 100px;
padding: 10px 12px;
color: #40506a;
background: #fff;
border: 1px solid #e8edf5;
border-radius: 7px;
box-shadow: 0 8px 20px #29466b1c;
cursor: pointer;
font: inherit;
font-size: 12px;
opacity: 0;
pointer-events: none;
transform: translateY(-5px);
transition: opacity .2s ease, transform .2s ease;
}
.logout-menu:hover {
color: #dc635b;
background: #fff7f6;
}
.user-menu:hover .logout-menu,
.user-menu.open .logout-menu {
opacity: 1;
pointer-events: auto;
transform: translateY(0);
}
.nav-links {
display: flex;
align-self: stretch;
gap: 34px;
}
.nav-links a {
position: relative;
display: flex;
align-items: center;
color: #78849a;
font-size: 14px;
text-decoration: none;
opacity: 0;
animation: nav-item-in .45s cubic-bezier(.22, 1, .36, 1) both;
transition: color .25s ease, transform .25s ease;
}
.nav-links a:nth-child(1) {
animation-delay: .18s;
}
.nav-links a:nth-child(2) {
animation-delay: .25s;
}
.nav-links a:nth-child(3) {
animation-delay: .32s;
}
.nav-links a:nth-child(4) {
animation-delay: .39s;
}
.nav-links a:hover {
color: #1769e0;
transform: translateY(-2px);
}
.nav-links a.active {
padding: 8px 13px;
color: #1769e0;
font-weight: 700;
background: #eaf2ff;
border-radius: 7px;
}
@keyframes nav-slide-down {
from {
opacity: 0;
transform: translateY(-18px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes nav-item-in {
from {
opacity: 0;
transform: translateY(-8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (prefers-reduced-motion: reduce) {
.topbar,
.nav-links a {
animation: none;
}
.nav-links a {
opacity: 1;
}
}
@media (max-width: 760px) {
.topbar {
height: auto;
min-height: 68px;
padding: 12px 18px 0;
gap: 0;
flex-wrap: wrap;
}
.brand {
font-size: 17px;
}
.brand-mark {
width: 32px;
height: 32px;
border-radius: 9px;
}
.brand-mark svg {
width: 20px;
}
.nav-links {
width: 100%;
height: 48px;
margin-top: 8px;
align-self: auto;
align-items: center;
justify-content: space-between;
gap: 4px;
overflow-x: auto;
scrollbar-width: none;
}
.nav-links::-webkit-scrollbar {
display: none;
}
.nav-links a {
flex: 0 0 auto;
min-height: 32px;
padding: 7px 10px;
font-size: 12px;
white-space: nowrap;
}
.nav-links a.active {
padding: 7px 12px;
}
.topbar-actions {
gap: 8px;
}
.topbar-actions .icon-button {
width: 30px;
}
.user-name {
display: none;
}
.user-menu:hover .logout-menu {
opacity: 0;
pointer-events: none;
transform: translateY(-5px);
}
.user-menu.open .logout-menu {
opacity: 1;
pointer-events: auto;
transform: translateY(0);
}
.user-avatar {
width: 30px;
height: 30px;
font-size: 12px;
}
}
@media (prefers-reduced-motion: reduce) {
.brand,
.brand-mark,
.nav-links a {
transition: none;
}
}
</style>