Files
gamegroup2/frontend/src/views/Layout.vue
T

455 lines
9.6 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { useGroupStore } from '@/stores/group'
import { useTeamStore } from '@/stores/team'
import { useNotificationStore } from '@/stores/notification'
import StatusToggle from '@/components/team/StatusToggle.vue'
import WorkScheduleModal from '@/components/team/WorkScheduleModal.vue'
import NotificationPanel from '@/components/common/NotificationPanel.vue'
import CreateGroupDialog from '@/components/group/CreateGroupDialog.vue'
import JoinGroupDialog from '@/components/group/JoinGroupDialog.vue'
const router = useRouter()
const route = useRoute()
const userStore = useUserStore()
const groupStore = useGroupStore()
const teamStore = useTeamStore()
const notificationStore = useNotificationStore()
const showScheduleModal = ref(false)
const showCreateGroup = ref(false)
const showJoinGroup = ref(false)
onMounted(async () => {
await userStore.initUser()
await groupStore.loadGroups()
await teamStore.loadActiveSession()
await notificationStore.loadPendingInvitations()
})
function handleLogout() {
userStore.logout()
router.push({ name: 'Login' })
}
function selectGroup(groupId: string) {
groupStore.setCurrentGroup(groupId)
router.push({ name: 'GroupView', params: { id: groupId } })
}
function goHome() {
router.push({ name: 'Home' })
}
</script>
<template>
<div class="app-layout">
<!-- 侧边栏 -->
<aside class="sidebar">
<div class="sidebar-top">
<div class="logo" @click="goHome">
<span class="logo-icon">🎮</span>
<span class="logo-text">Game Group</span>
</div>
</div>
<nav class="sidebar-nav">
<router-link to="/" class="nav-item" active-class="nav-item--active">
<span class="nav-icon">🏠</span>
<span>首页</span>
</router-link>
<router-link to="/games" class="nav-item" active-class="nav-item--active">
<span class="nav-icon">🎯</span>
<span>游戏库</span>
</router-link>
</nav>
<div class="sidebar-divider" />
<div class="sidebar-groups">
<div class="section-header">
<span class="section-title">我的群组</span>
<div class="section-actions">
<button class="section-btn" @click="showCreateGroup = true" title="创建群组">+</button>
<button class="section-btn" @click="showJoinGroup = true" title="加入群组">&#x1F517;</button>
</div>
</div>
<div v-if="groupStore.groups.length === 0" class="empty-groups">
暂无群组
</div>
<div
v-for="group in groupStore.groups"
:key="group.id"
class="group-item"
:class="{ 'group-item--active': route.params.id === group.id }"
@click="selectGroup(group.id)"
>
<span class="group-name">{{ group.name }}</span>
<span class="group-count">{{ group.members?.length || 0 }}</span>
</div>
</div>
<div class="sidebar-bottom">
<div class="sidebar-divider" />
<div class="user-section">
<StatusToggle />
<button class="schedule-btn" @click="showScheduleModal = true" title="设置工作时间">
</button>
</div>
<div class="user-info">
<img
:src="userStore.user?.avatar || '/default-avatar.png'"
class="user-avatar"
alt=""
/>
<span class="user-name">{{ userStore.user?.username }}</span>
<button class="logout-btn" @click="handleLogout" title="退出登录">
🚪
</button>
</div>
</div>
</aside>
<!-- 右侧 -->
<div class="main-wrapper">
<header class="top-header">
<h2 class="page-title">
{{ $route.name === 'GroupView' ? groupStore.currentGroup?.name : $route.name === 'GamesLibrary' ? '游戏库' : $route.name === 'Profile' ? '个人中心' : $route.name === 'Settings' ? '设置' : '首页' }}
</h2>
<div class="header-actions">
<button class="icon-btn" @click="notificationStore.togglePanel()">
<span v-if="notificationStore.unreadCount > 0" class="badge">
{{ notificationStore.unreadCount }}
</span>
🔔
</button>
</div>
</header>
<main class="main-content">
<router-view />
</main>
</div>
<!-- 弹窗 -->
<WorkScheduleModal v-model="showScheduleModal" />
<NotificationPanel />
<CreateGroupDialog v-model="showCreateGroup" />
<JoinGroupDialog v-model="showJoinGroup" />
</div>
</template>
<style scoped>
.app-layout {
display: flex;
min-height: 100vh;
background: var(--gg-bg);
}
/* ── 侧边栏 ── */
.sidebar {
width: 240px;
background: var(--gg-bg-card);
border-right: 1px solid var(--gg-border);
display: flex;
flex-direction: column;
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 100;
}
.sidebar-top {
padding: 20px;
}
.logo {
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
user-select: none;
}
.logo-icon {
font-size: 24px;
}
.logo-text {
font-size: 20px;
font-weight: 700;
background: var(--gg-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
/* ── 导航 ── */
.sidebar-nav {
padding: 0 12px;
display: flex;
flex-direction: column;
gap: 4px;
}
.nav-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border-radius: var(--gg-radius-sm);
color: var(--gg-text-secondary);
text-decoration: none;
font-size: 14px;
transition: all 0.2s;
}
.nav-item:hover {
background: var(--gg-bg-hover);
color: var(--gg-text);
}
.nav-item--active {
background: rgba(5, 150, 105, 0.1);
color: var(--gg-primary);
}
.nav-icon {
font-size: 16px;
}
/* ── 分割线 ── */
.sidebar-divider {
height: 1px;
background: var(--gg-border);
margin: 12px 20px;
}
/* ── 群组列表 ── */
.sidebar-groups {
flex: 1;
overflow-y: auto;
padding: 0 12px;
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 14px;
margin-bottom: 8px;
}
.section-title {
font-size: 12px;
font-weight: 600;
color: var(--gg-text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.section-actions {
display: flex;
gap: 4px;
}
.section-btn {
background: none;
border: 1px solid var(--gg-border);
border-radius: 6px;
color: var(--gg-text-secondary);
font-size: 14px;
cursor: pointer;
padding: 2px 8px;
transition: all 0.2s;
}
.section-btn:hover {
border-color: var(--gg-primary);
color: var(--gg-primary);
}
.empty-groups {
text-align: center;
color: var(--gg-text-muted);
font-size: 13px;
padding: 16px;
}
.group-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 14px;
border-radius: var(--gg-radius-sm);
cursor: pointer;
transition: all 0.2s;
}
.group-item:hover {
background: var(--gg-bg-hover);
}
.group-item--active {
background: rgba(5, 150, 105, 0.1);
border-left: 3px solid var(--gg-primary);
}
.group-name {
font-size: 14px;
color: var(--gg-text);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.group-count {
font-size: 12px;
color: var(--gg-text-muted);
background: var(--gg-bg-elevated);
padding: 2px 8px;
border-radius: 10px;
}
/* ── 底部用户区 ── */
.sidebar-bottom {
padding: 0 12px 16px;
}
.user-section {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 0;
}
.schedule-btn {
background: none;
border: none;
font-size: 16px;
cursor: pointer;
padding: 6px 10px;
border-radius: var(--gg-radius-sm);
transition: background-color 0.2s;
}
.schedule-btn:hover {
background: var(--gg-bg-hover);
}
.user-info {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
background: var(--gg-bg);
border-radius: var(--gg-radius-sm);
}
.user-avatar {
width: 32px;
height: 32px;
border-radius: 50%;
object-fit: cover;
}
.user-name {
flex: 1;
font-size: 14px;
color: var(--gg-text);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.logout-btn {
background: none;
border: none;
font-size: 16px;
cursor: pointer;
padding: 4px;
border-radius: 4px;
opacity: 0.6;
transition: opacity 0.2s;
}
.logout-btn:hover {
opacity: 1;
}
/* ── 右侧主区域 ── */
.main-wrapper {
flex: 1;
margin-left: 240px;
display: flex;
flex-direction: column;
min-height: 100vh;
}
.top-header {
height: 60px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 28px;
background: var(--gg-bg-card);
border-bottom: 1px solid var(--gg-border);
position: sticky;
top: 0;
z-index: 50;
}
.page-title {
font-size: 18px;
font-weight: 600;
color: var(--gg-text);
margin: 0;
}
.header-actions {
display: flex;
align-items: center;
gap: 12px;
}
.icon-btn {
position: relative;
background: none;
border: none;
font-size: 18px;
cursor: pointer;
padding: 8px;
border-radius: var(--gg-radius-sm);
transition: background-color 0.2s;
}
.icon-btn:hover {
background: var(--gg-bg-hover);
}
.badge {
position: absolute;
top: 2px;
right: 2px;
background: var(--gg-danger);
color: white;
font-size: 10px;
font-weight: 700;
min-width: 16px;
height: 16px;
line-height: 16px;
text-align: center;
border-radius: 8px;
padding: 0 4px;
}
.main-content {
flex: 1;
padding: 24px 28px;
}
</style>