Files
dy/frontend/src/App.vue
T
2026-08-07 15:35:02 +08:00

304 lines
6.4 KiB
Vue

<script setup>
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import {
DashboardOutlined,
UserOutlined,
SettingOutlined,
FileTextOutlined,
RobotOutlined,
ApiOutlined,
MessageOutlined,
BugOutlined,
TeamOutlined,
LogoutOutlined,
ControlOutlined,
PayCircleOutlined,
UnorderedListOutlined,
QuestionCircleOutlined,
RocketOutlined,
CloudDownloadOutlined,
InboxOutlined
} from '@ant-design/icons-vue'
import { useAuthStore } from './stores/auth'
import { HEADER_TITLES } from './config/menus'
const ICON_MAP = {
DashboardOutlined,
UserOutlined,
SettingOutlined,
FileTextOutlined,
MessageOutlined,
BugOutlined,
TeamOutlined,
ControlOutlined,
PayCircleOutlined,
UnorderedListOutlined,
QuestionCircleOutlined,
RocketOutlined,
CloudDownloadOutlined,
InboxOutlined
}
const route = useRoute()
const router = useRouter()
const auth = useAuthStore()
const selectedKeys = computed(() => [route.path])
const isLoginPage = computed(() => route.path === '/login')
const headerTitle = computed(
() => HEADER_TITLES[route.name] || route.name || '工作台'
)
const navigate = ({ key }) => {
router.push(key)
}
const handleLogout = () => {
auth.logout()
message.success('已退出登录')
router.push('/login')
}
</script>
<template>
<router-view v-if="isLoginPage" />
<a-layout v-else style="min-height: 100vh;">
<a-layout-sider width="240" collapsible breakpoint="lg" class="app-sider">
<div class="logo-container">
<RobotOutlined class="logo-icon" />
<span class="logo-text">抖音回复助手</span>
</div>
<a-menu
v-model:selectedKeys="selectedKeys"
theme="dark"
mode="inline"
@click="navigate"
class="custom-menu"
>
<a-menu-item v-for="item in auth.visibleMenus" :key="item.path">
<template #icon>
<component :is="ICON_MAP[item.icon]" />
</template>
<span>{{ item.title }}</span>
</a-menu-item>
</a-menu>
</a-layout-sider>
<a-layout>
<a-layout-header class="app-header">
<div class="header-left">
<h2 class="header-title">{{ headerTitle }}</h2>
</div>
<div class="header-right">
<a-space size="middle">
<span class="header-status">
<ApiOutlined style="margin-right: 6px; color: #aa3bff;" />
后端引擎已连接
</span>
<a-tag color="purple">{{ auth.roleLabel }}</a-tag>
<span class="user-name">{{ auth.user?.display_name || auth.user?.username }}</span>
<a-button type="text" class="logout-btn" @click="handleLogout">
<LogoutOutlined />
退出
</a-button>
</a-space>
</div>
</a-layout-header>
<a-layout-content class="main-content">
<div class="content-wrapper">
<router-view v-slot="{ Component }">
<transition name="fade" mode="out-in">
<component :is="Component" />
</transition>
</router-view>
</div>
</a-layout-content>
</a-layout>
</a-layout>
</template>
<style scoped>
.logo-container {
height: 64px;
display: flex;
align-items: center;
padding: 0 24px;
background: rgba(0, 0, 0, 0.15);
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.logo-icon {
font-size: 24px;
color: #c084fc;
margin-right: 12px;
}
.logo-text {
font-family: 'Outfit', sans-serif;
font-size: 1.15rem;
font-weight: 700;
letter-spacing: 0.5px;
white-space: nowrap;
overflow: hidden;
background: linear-gradient(135deg, #aa3bff 0%, #c084fc 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.app-sider.ant-layout-sider-collapsed .logo-container {
justify-content: center;
padding: 0;
}
.app-sider.ant-layout-sider-collapsed .logo-icon {
margin-right: 0;
}
.app-sider.ant-layout-sider-collapsed .logo-text {
display: none;
}
.custom-menu {
background: transparent !important;
border-right: none !important;
margin-top: 16px;
}
.custom-menu :deep(.ant-menu-item) {
border-radius: 8px;
margin: 4px 12px !important;
width: calc(100% - 24px) !important;
height: 48px;
line-height: 48px;
transition: all 0.3s ease;
}
.custom-menu :deep(.ant-menu-item-selected) {
background: linear-gradient(135deg, rgba(170, 59, 255, 0.25) 0%, rgba(192, 132, 252, 0.1) 100%) !important;
border: 1px solid rgba(192, 132, 252, 0.35) !important;
color: #fff !important;
box-shadow: 0 0 12px rgba(170, 59, 255, 0.15);
}
.custom-menu :deep(.ant-menu-item:focus-visible) {
outline: none;
box-shadow: 0 0 0 2px rgba(192, 132, 252, 0.3);
}
.custom-menu :deep(.ant-menu-item-selected .ant-menu-item-icon) {
color: #c084fc !important;
}
.main-content {
padding: 24px;
overflow-y: auto;
max-height: calc(100vh - 64px);
}
.content-wrapper {
max-width: 1400px;
margin: 0 auto;
}
.header-status {
font-size: 0.85rem;
color: #9ca3af;
background: rgba(170, 59, 255, 0.1);
padding: 6px 14px;
border-radius: 20px;
border: 1px solid rgba(170, 59, 255, 0.2);
}
.user-name {
color: #e5e7eb;
font-size: 0.9rem;
}
.logout-btn {
color: #9ca3af !important;
}
.logout-btn:hover {
color: #f87171 !important;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.25s ease, transform 0.25s ease;
}
.fade-enter-from {
opacity: 0;
transform: translateY(10px);
}
.fade-leave-to {
opacity: 0;
transform: translateY(-10px);
}
.header-title {
margin: 0;
color: #fff;
font-size: 1.25rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header-left {
min-width: 0;
flex: 1;
}
.header-right {
flex-shrink: 0;
}
.app-header {
gap: 12px;
}
@media (max-width: 768px) {
.main-content {
padding: 12px;
}
.header-title {
font-size: 1rem;
}
.header-right :deep(.ant-space) {
gap: 8px !important;
}
.header-status,
.user-name {
display: none;
}
.logout-btn {
padding-inline: 8px !important;
}
.logout-btn :deep(span:not(.anticon)) {
display: none;
}
}
@media (max-width: 375px) {
.header-right :deep(.ant-tag) {
max-width: 72px;
overflow: hidden;
text-overflow: ellipsis;
color: #e9d5ff !important;
background: rgba(147, 51, 234, 0.16) !important;
border-color: rgba(192, 132, 252, 0.42) !important;
}
}
</style>