提交正式官网

This commit is contained in:
parkiss
2026-07-09 14:35:32 +08:00
parent 5efbd6760e
commit e09f0eccda
792 changed files with 91499 additions and 0 deletions
+196
View File
@@ -0,0 +1,196 @@
<template>
<div class="breadcrumb-container" v-if="breadcrumbList.length > 0">
<el-breadcrumb separator=">" :separator-icon="ArrowRight">
<!-- 动态面包屑项 -->
<el-breadcrumb-item
v-for="(item, index) in breadcrumbList"
:key="item.id"
:to="index < breadcrumbList.length - 1 ? { path: item.path } : undefined"
>
<div class="breadcrumb-item">
<el-icon v-if="props.showIcon && item.icon" class="breadcrumb-icon">
<component :is="menuStore.iconComponents[item.icon]" />
</el-icon>
<span>{{ item.title }}</span>
</div>
</el-breadcrumb-item>
</el-breadcrumb>
</div>
</template>
<script setup lang="ts">
import { ArrowRight } from '@element-plus/icons-vue'
import type { IMenuItem } from '@/types/system/menu'
defineOptions({ name: 'BreadcrumbView' })
const props = withDefaults(
defineProps<{
showIcon: boolean
}>(),
{
showIcon: true,
},
)
const route = useRoute()
const menuStore = useMenuStore()
interface BreadcrumbItem {
id: string
title: string
path: string
icon?: string
}
// 从菜单列表中根据 path 递归查找节点
const findMenuByPath = (menus: IMenuItem[], path: string): IMenuItem | null => {
for (const item of menus) {
// 只匹配 type 为 'menu' 的项(实际页面路由)
if (item.type === 'menu' && item.path === path) {
return item
}
// 递归查找子菜单
if (item.children?.length) {
const child = findMenuByPath(item.children, path)
if (child) return child
}
}
return null
}
// 查找首页菜单项(path 为 '/' 或 '/home')
const findHomeMenu = (menus: IMenuItem[]): IMenuItem | null => {
for (const item of menus) {
// 检查是否为首页(path 为 '/' 或 '/home')
if (item.type === 'menu' && (item.path === '/' || item.path === '/dashboard/home')) {
return item
}
// 递归查找子菜单
if (item.children?.length) {
const child = findHomeMenu(item.children)
if (child) return child
}
}
return null
}
// 构建 id -> menuItem 的映射,用于快速查找父节点
const buildMenuMap = (
menus: IMenuItem[],
map: Map<string, IMenuItem> = new Map(),
): Map<string, IMenuItem> => {
menus.forEach((item) => {
map.set(item.id, item)
if (item.children?.length) {
buildMenuMap(item.children, map)
}
})
return map
}
// 根据 parentId 向上回溯,构建面包屑路径
const buildBreadcrumbPath = (
current: IMenuItem,
menuMap: Map<string, IMenuItem>,
): BreadcrumbItem[] => {
const path: BreadcrumbItem[] = []
let node: IMenuItem | null = current
while (node) {
// 只添加 type 为 'directory' 或 'menu' 的项到面包屑
if (node.type === 'directory' || node.type === 'menu') {
path.unshift({
id: node.id,
title: node.title,
path: node.path || '#',
icon: node.icon,
})
}
// 向上查找父节点
node = node.parentId && menuMap.has(node.parentId) ? menuMap.get(node.parentId)! : null
}
return path
}
// 计算面包屑列表
const breadcrumbList = computed<BreadcrumbItem[]>(() => {
// 如果菜单列表为空,返回空数组
if (!menuStore.menuList.length) return []
// 查找当前路由对应的菜单项
const currentMenu = findMenuByPath(menuStore.menuList, route.path)
// 如果找不到菜单项,尝试从路由 meta 中获取信息(处理不在菜单中的页面,如403、404、个人中心等)
if (!currentMenu) {
const path: BreadcrumbItem[] = []
// 查找首页菜单项
const homeMenu = findHomeMenu(menuStore.menuList)
// 如果找到首页,先添加首页
if (homeMenu && route.path !== homeMenu.path) {
path.push({
id: homeMenu.id,
title: homeMenu.title,
path: homeMenu.path || '/',
icon: homeMenu.icon,
})
}
// 从路由 meta 中获取当前页面的标题
const routeTitle = route.meta?.title as string | undefined
if (routeTitle) {
path.push({
id: (route.name as string) || route.path,
title: routeTitle,
path: route.path,
icon: route.meta?.icon as string | undefined,
})
}
return path
}
// 构建菜单映射
const menuMap = buildMenuMap(menuStore.menuList)
// 构建面包屑路径
const path = buildBreadcrumbPath(currentMenu, menuMap)
// 查找首页菜单项
const homeMenu = findHomeMenu(menuStore.menuList)
// 如果找到首页且当前路径不是首页,则在开头添加首页
if (homeMenu && route.path !== homeMenu.path) {
// 检查面包屑路径中是否已包含首页(避免重复)
const hasHome = path.some((item) => item.id === homeMenu.id)
if (!hasHome) {
path.unshift({
id: homeMenu.id,
title: homeMenu.title,
path: homeMenu.path || '/',
icon: homeMenu.icon,
})
}
}
return path
})
</script>
<style scoped lang="scss">
.breadcrumb-container {
.breadcrumb-item {
display: flex;
align-items: center;
gap: 0.25rem;
font-weight: 400;
.breadcrumb-icon {
font-size: 1.125rem;
}
}
}
</style>
+126
View File
@@ -0,0 +1,126 @@
<template>
<div class="header-container">
<!-- 菜单区域 -->
<div class="menu-container" v-if="showTopMenu">
<MenuView />
</div>
<!-- 左侧区域 -->
<div class="header-left" v-else>
<HoverAnimateWrapper name="rubber">
<IconButton
:icon="
menuStore.isMobile
? 'HOutline:Bars3CenterLeftIcon'
: menuStore.isCollapse
? 'HOutline:Bars3BottomRightIcon'
: 'HOutline:Bars3BottomLeftIcon'
"
:tooltip="menuStore.isMobile ? $t('tooltip.expandMenu') : $t('tooltip.collapseMenu')"
@click="handleMenuToggle"
/>
</HoverAnimateWrapper>
<BreadcrumbView :showIcon="false" v-if="!menuStore.isMobile" />
</div>
<!-- 右侧操作区 -->
<div class="header-right">
<div class="action-buttons">
<!-- 主题配置 -->
<HoverAnimateWrapper name="rotate" v-if="APP_CONFIG.showThemeConfig">
<IconButton
icon="HOutline:Cog6ToothIcon"
:tooltip="$t('tooltip.themeConfig')"
@click="themeStore.themeConfigDrawerOpen = true"
/>
</HoverAnimateWrapper>
<!-- 全屏 -->
<HoverAnimateWrapper name="pulse" v-if="APP_CONFIG.showFullscreen">
<IconButton
:tooltip="isFullscreen ? $t('tooltip.exitFullScreen') : $t('tooltip.fullScreen')"
:icon="
isFullscreen ? 'HOutline:ArrowsPointingInIcon' : 'HOutline:ArrowsPointingOutIcon'
"
@click="toggleFullscreen"
/>
</HoverAnimateWrapper>
<!-- 国际化 -->
<I18nDropdown v-if="APP_CONFIG.showI18n" />
<!-- 消息通知 -->
<NotificationDropdown v-if="APP_CONFIG.showNotification" />
</div>
<!-- 用户下拉菜单 -->
<UserDropdown />
</div>
</div>
</template>
<script setup lang="ts">
import { APP_CONFIG } from '@/config/app.config'
import MenuView from '@/layouts/menu.vue'
import UserDropdown from '@/layouts/userDropdown.vue'
import BreadcrumbView from '@/layouts/breadcrumb.vue'
import NotificationDropdown from '@/layouts/notificationDropdown.vue'
import I18nDropdown from '@/layouts/i18nDropdown.vue'
import { useFullscreen } from '@vueuse/core'
defineOptions({ name: 'HeaderView' })
const menuStore = useMenuStore()
const themeStore = useThemeStore()
// 全屏功能
const { isFullscreen, toggle: toggleFullscreen } = useFullscreen()
// 显示顶部菜单
const showTopMenu = computed(() => {
return themeStore.themeConfig.layout === 'topMode' && !menuStore.isMobile
})
// 处理菜单切换
const handleMenuToggle = () => {
if (menuStore.isMobile) {
menuStore.toggleMobileMenu()
} else {
menuStore.toggleCollapse()
}
}
</script>
<style scoped lang="scss">
.header-container {
display: flex;
align-items: center;
justify-content: space-between;
height: 100%;
}
.header-left {
display: flex;
align-items: center;
gap: 0.5rem;
}
.menu-container {
flex: 1;
height: 100%;
min-width: 0; // 允许 flex 子元素收缩
overflow: hidden; // 防止溢出
}
.header-right {
display: flex;
align-items: center;
gap: 16px;
}
.action-buttons {
display: flex;
align-items: center;
gap: 8px;
padding-right: 16px;
border-right: 1px solid var(--el-border-color-lighter);
}
</style>
+96
View File
@@ -0,0 +1,96 @@
<!-- 国际化下拉菜单 -->
<template>
<el-dropdown trigger="click" :show-arrow="false" popper-class="i18n-dropdown-popper">
<HoverAnimateWrapper name="rotate">
<IconButton icon="HOutline:GlobeAltIcon" />
</HoverAnimateWrapper>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="item in langStore.langOptions"
:key="item.code"
:class="{ 'is-active': langStore.currentLang === item.code }"
@click="langStore.setLang(item.code)"
>
<!-- shortCode 仅用于展示,不作为真实语言参数使用 -->
<span class="language-code">{{ item.shortCode }}</span>
<span class="language-name">{{ item.label }}</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
<script setup lang="ts">
const langStore = useLangStore()
</script>
<style scoped lang="scss">
:deep(.el-dropdown-menu__item) {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.25rem;
padding: 12px 20px;
transition:
background-color 0.2s,
color 0.2s;
&:hover {
background: var(--el-fill-color-light) !important;
color: var(--el-color-primary);
}
&:focus,
&:focus-visible {
background: var(--el-fill-color-light) !important;
color: var(--el-color-primary);
}
&.is-active {
background: var(--el-fill-color-light) !important;
color: var(--el-color-primary);
.language-code {
color: var(--el-color-primary);
font-weight: 700;
}
.language-name {
color: var(--el-color-primary);
font-weight: 600;
}
}
}
.language-code {
font-size: 13px;
letter-spacing: 0.5px;
min-width: 32px;
}
.language-name {
font-size: 14px;
flex: 1;
}
:deep(.el-dropdown-menu__item:hover) {
.language-code {
color: var(--el-color-primary);
}
.language-name {
color: var(--el-color-primary);
}
}
</style>
<style lang="scss">
.i18n-dropdown-popper {
border-radius: 8px !important;
.el-dropdown-menu {
border-radius: 8px !important;
}
}
</style>
+42
View File
@@ -0,0 +1,42 @@
<template>
<div class="layout-container">
<LeftMode v-if="themeStore.themeConfig.layout === 'leftMode'" />
<TopMode v-else />
<ThemeConfig />
<!-- 移动端菜单抽屉 -->
<el-drawer
v-model="menuStore.isMobileMenuOpen"
:direction="'ltr'"
:with-header="false"
:size="220"
class="mobile-menu-drawer"
>
<MenuView />
</el-drawer>
</div>
</template>
<script setup lang="ts">
import LeftMode from '@/layouts/leftMode.vue'
import TopMode from '@/layouts/topMode.vue'
import ThemeConfig from '@/components/ThemeConfig.vue'
import MenuView from '@/layouts/menu.vue'
defineOptions({ name: 'LayoutView' })
const menuStore = useMenuStore()
const themeStore = useThemeStore()
</script>
<style scoped lang="scss">
:deep(.mobile-menu-drawer) {
.el-drawer__body {
padding: 0;
}
}
.layout-container {
width: 100%;
height: 100vh;
}
</style>
+65
View File
@@ -0,0 +1,65 @@
<template>
<el-container class="left-mode-container">
<MenuView v-if="!menuStore.isMobile" class="menu-view" />
<el-container>
<el-header class="header">
<HeaderView />
</el-header>
<Transition name="fade-slide" mode="out-in">
<TabsView v-if="themeStore.themeConfig.showTabs" />
</Transition>
<el-scrollbar>
<el-main class="main">
<RouterView v-slot="{ Component, route }">
<Transition name="fade-slide" mode="out-in">
<KeepAlive :include="tabsStore.tabs.map((tab) => tab.name as string)">
<component :is="Component" :key="route.path" />
</KeepAlive>
</Transition>
</RouterView>
</el-main>
</el-scrollbar>
</el-container>
</el-container>
</template>
<script setup lang="ts">
import HeaderView from '@/layouts/header.vue'
import MenuView from '@/layouts/menu.vue'
import TabsView from '@/layouts/tabsView.vue'
defineOptions({ name: 'LeftMode' })
const tabsStore = useTabsStore()
const themeStore = useThemeStore()
const menuStore = useMenuStore()
</script>
<style scoped lang="scss">
.left-mode-container {
width: 100%;
height: 100%;
}
.menu-view {
flex-shrink: 0;
}
.header {
height: 50px;
background: var(--el-bg-color);
border-bottom: 1px solid var(--el-border-color-lighter);
padding-right: 0.25rem;
}
.main {
background: var(--el-bg-color-page);
padding: 1rem;
position: relative;
overflow-y: auto;
overflow-x: hidden;
min-height: calc(100vh - 50px - 2.5rem);
display: flex;
flex-direction: column;
}
</style>
+176
View File
@@ -0,0 +1,176 @@
<template>
<el-scrollbar>
<el-menu
:default-active="activeMenu"
:collapse="menuStore.isCollapse"
:background-color="menuBackgroundColor"
:text-color="menuTextColor"
:active-text-color="menuActiveTextColor"
:mode="menuMode"
@select="navigation"
class="menu-container"
:class="{ '--menu-border': menuStore.isMobile }"
>
<Transition name="bounce">
<el-menu-item class="logo" v-if="themeStore.themeConfig.showLogo">
<img :src="APP_CONFIG.logoSrc" alt="logo" class="logo-img" />
<span class="logo-title" :style="{ color: logoTitleColor }">{{ APP_CONFIG.name }}</span>
</el-menu-item>
</Transition>
<MenuItem v-for="item in menuStore.menuList" :key="item.path" :item="item" />
</el-menu>
</el-scrollbar>
</template>
<script setup lang="ts">
import { APP_CONFIG } from '@/config/app.config'
import MenuItem from '@/layouts/menuItem.vue'
defineOptions({ name: 'MenuView' })
const menuStore = useMenuStore()
const themeStore = useThemeStore()
const route = useRoute()
const router = useRouter()
// 当前激活的菜单项
const activeMenu = computed(() => route.path)
// 菜单模式
const menuMode = computed(() => {
if (menuStore.isMobile) return 'vertical'
return themeStore.themeConfig.layout === 'topMode' ? 'horizontal' : 'vertical'
})
// 菜单颜色配置
const menuBackgroundColor = computed(() => {
if (themeStore.themeConfig.themeMode === 'dark') return '#141414'
if (themeStore.themeConfig.layout === 'topMode') return '#ffffff'
return themeStore.themeConfig.sidebarMode === 'dark' ? '#141414' : '#ffffff'
})
const menuTextColor = computed(() => {
if (themeStore.themeConfig.themeMode === 'dark') return '#e5e7eb'
if (themeStore.themeConfig.layout === 'topMode') return '#303133'
return themeStore.themeConfig.sidebarMode === 'dark' ? '#e5e7eb' : '#303133'
})
const menuActiveTextColor = computed(() => {
return themeStore.themeConfig.primaryColor
})
const logoTitleColor = computed(() => {
if (themeStore.themeConfig.layout === 'topMode') return ''
if (themeStore.themeConfig.sidebarMode === 'dark') return '#ffffff'
return ''
})
const navigation = (key: string) => {
router.push(key)
// 移动端点击菜单项后自动关闭抽屉
if (menuStore.isMobile && menuStore.isMobileMenuOpen) {
menuStore.isMobileMenuOpen = false
}
}
</script>
<style scoped lang="scss">
.--menu-border {
border-right: none;
}
.menu-container {
height: 100vh;
.logo {
display: flex;
align-items: center;
gap: 0.75rem;
transition: all 0.3s ease;
.logo-img {
width: auto;
height: 36px;
max-width: 120px;
flex-shrink: 0;
object-fit: contain;
transition: transform 0.3s ease;
}
.logo-title {
font-size: 1.25rem;
font-weight: 700;
color: var(--el-text-color-primary);
letter-spacing: 0.5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
.menu-container:not(.el-menu--collapse) {
width: 13.75rem;
&.el-menu--horizontal {
width: 100%;
min-width: 0; // 允许收缩
height: 49px;
border: none !important;
border-bottom: none !important;
border-top: none !important;
border-left: none !important;
border-right: none !important;
white-space: nowrap; // 防止菜单项换行
.el-menu-item:nth-child(1) {
height: 49px;
padding: 0;
border-bottom: none !important;
&:hover {
background-color: transparent;
}
}
:deep(.el-menu-item) {
height: 49px;
line-height: 49px;
border: none !important;
border-bottom: none !important;
border-top: none !important;
border-left: none !important;
border-right: none !important;
flex-shrink: 0; // 防止菜单项收缩
white-space: nowrap; // 防止文字换行
}
:deep(.el-sub-menu) {
border: none !important;
border-bottom: none !important;
border-top: none !important;
border-left: none !important;
border-right: none !important;
.el-sub-menu__title {
height: 49px;
line-height: 49px;
border: none !important;
border-bottom: none !important;
border-top: none !important;
border-left: none !important;
border-right: none !important;
flex-shrink: 0; // 防止子菜单标题收缩
white-space: nowrap; // 防止文字换行
}
}
}
}
.el-menu > .el-menu-item:nth-child(1) {
height: 50px;
padding: 0 10px;
border-bottom: none !important;
&:hover {
background-color: transparent;
}
}
</style>
+26
View File
@@ -0,0 +1,26 @@
<template>
<el-sub-menu v-if="hasChildren" :index="item.id">
<template #title>
<el-icon v-if="item.icon">
<component :is="menuStore.iconComponents[item.icon]" />
</el-icon>
<span>{{ item.title }}</span>
</template>
<MenuItem v-for="child in item.children" :key="child.path" :item="child" />
</el-sub-menu>
<el-menu-item v-else :index="item.path">
<el-icon v-if="item.icon">
<component :is="menuStore.iconComponents[item.icon]" />
</el-icon>
<span>{{ item.title }}</span>
</el-menu-item>
</template>
<script setup lang="ts">
const props = defineProps(['item'])
const menuStore = useMenuStore()
const hasChildren = computed(() => props.item.children?.length)
</script>
+176
View File
@@ -0,0 +1,176 @@
<template>
<el-dropdown
trigger="click"
:show-arrow="false"
placement="bottom-end"
ref="notificationDropdownRef"
popper-class="notification-dropdown-popper"
>
<el-badge
:value="userStore.unreadCount"
:hidden="userStore.unreadCount === 0"
:max="99"
:offset="[-5, 5]"
>
<HoverAnimateWrapper name="bell" intensity="light" :duration="600">
<IconButton icon="HOutline:BellAlertIcon" />
</HoverAnimateWrapper>
</el-badge>
<template #dropdown>
<div class="notification-dropdown">
<div class="notification-header">
<span class="title">{{ $t('layout.notification') }}</span>
<el-button
v-if="userStore.unreadCount > 0"
type="primary"
link
size="small"
@click.stop="userStore.markAllAsRead()"
>
<el-icon class="button-icon"
><component :is="menuStore.iconComponents['Check']"
/></el-icon>
{{ $t('layout.allRead') }}
</el-button>
</div>
<div class="notification-list">
<el-scrollbar max-height="400px">
<Transition name="zoom" :style="{ '--animation-duration': '0.5s' }" mode="out-in">
<div v-if="unreadMessageList.length === 0" class="empty-message">
<el-empty description="{{ $t('layout.noMessage') }}" :image-size="80" />
</div>
<TransitionGroup name="group-slide-right" tag="div" v-else>
<div
v-for="message in unreadMessageList"
:key="message.id"
class="notification-item"
@click="userStore.markAsRead(message.id)"
>
<el-avatar :size="32" :src="message.avatar" />
<div class="message-content">
<div class="message-title">{{ message.title }}</div>
<div class="message-text">{{ message.content }}</div>
<div class="message-time">{{ message.time }}</div>
</div>
</div>
</TransitionGroup>
</Transition>
</el-scrollbar>
</div>
<div class="notification-footer">
<el-button type="primary" link @click="goToProfile">{{ $t('layout.viewAll') }}</el-button>
</div>
</div>
</template>
</el-dropdown>
</template>
<script setup lang="ts">
import type { ElDropdown } from 'element-plus'
const router = useRouter()
const userStore = useUserStore()
const menuStore = useMenuStore()
const notificationDropdownRef = ref<InstanceType<typeof ElDropdown>>()
// 未读消息列表
const unreadMessageList = computed(() => {
return userStore.userMessages.filter((msg) => !msg.read)
})
// 跳转到个人中心
const goToProfile = () => {
router.push('/profile')
userStore.currentTab = 'messages'
notificationDropdownRef.value?.handleClose()
}
</script>
<style scoped lang="scss">
.notification-dropdown {
width: 22rem;
background: var(--el-bg-color);
.notification-header {
padding: 1rem;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--el-border-color-lighter);
.title {
font-size: 1rem;
font-weight: 600;
color: var(--el-text-color-primary);
}
.button-icon {
margin-right: 0.25rem;
}
}
.notification-list {
max-height: 25rem;
.notification-item {
display: flex;
align-items: center;
gap: 12px;
padding: 1rem;
border-bottom: 1px solid var(--el-border-color-lighter);
cursor: pointer;
&:hover {
background: var(--el-fill-color-light);
}
.message-content {
flex: 1;
display: flex;
flex-direction: column;
gap: 6px;
min-width: 0;
.message-title {
font-size: 14px;
font-weight: 600;
color: var(--el-text-color-primary);
line-height: 1.4;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.message-text {
font-size: 13px;
color: var(--el-text-color-regular);
line-height: 1.5;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
}
.message-time {
font-size: 12px;
color: var(--el-text-color-secondary);
line-height: 1.4;
}
}
}
}
.notification-footer {
padding: 1rem;
border-top: 1px solid var(--el-border-color-lighter);
text-align: center;
}
}
</style>
<style lang="scss">
.notification-dropdown-popper {
border-radius: 8px !important;
overflow: hidden;
.el-dropdown-menu {
border-radius: 8px !important;
overflow: hidden;
}
}
</style>
+380
View File
@@ -0,0 +1,380 @@
<template>
<div class="tabs-container">
<HoverAnimateWrapper name="rubber">
<IconButton
icon="HOutline:ChevronLeftIcon"
size="1.75rem"
:tooltip="$t('layout.swipeLeft')"
@click="slideLeft"
/>
</HoverAnimateWrapper>
<div class="tabs-pages" ref="tabsPagesRef">
<div
class="tabs-page-item"
:class="{ active: tab.path === tabsStore.activePath }"
v-for="tab in tabsStore.tabs"
:key="tab.path"
:ref="(el) => setTabRef(el, tab.path)"
@click="navigation(tab.path)"
>
<HoverAnimateWrapper name="wobble" :duration="700">
<div style="display: flex; align-items: center; gap: 0.5rem">
<el-icon class="tabs-page-icon" size="18">
<component :is="menuStore.iconComponents[tab.icon as string]" />
</el-icon>
<div>{{ tab.title }}</div>
<el-icon v-if="tab.closable" class="close-icon" @click.stop="handleClose(tab)">
<component :is="menuStore.iconComponents['HSolid:XMarkIcon']" />
</el-icon>
</div>
</HoverAnimateWrapper>
</div>
</div>
<HoverAnimateWrapper name="rubber">
<IconButton
icon="HOutline:ChevronRightIcon"
size="1.75rem"
:tooltip="$t('layout.swipeRight')"
@click="slideRight"
/>
</HoverAnimateWrapper>
<div class="tabs-dropdown">
<el-dropdown
trigger="click"
:show-arrow="false"
class="tabs-dropdown-wrapper"
popper-class="tabs-dropdown-popper"
>
<div class="tabs-dropdown-icon">
<HoverAnimateWrapper name="rubber">
<IconButton icon="HOutline:EllipsisHorizontalIcon" size="1.75rem" />
</HoverAnimateWrapper>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
:icon="menuStore.iconComponents['HOutline:MinusCircleIcon']"
@click="tabsStore.closeOtherTabs(tabsStore.activePath)"
>
{{ $t('layout.closeOtherTabs') }}
</el-dropdown-item>
<el-dropdown-item
:icon="menuStore.iconComponents['HOutline:TrashIcon']"
@click="(tabsStore.closeAllTabs(), router.push(tabsStore.activePath))"
>
{{ $t('layout.closeAllTabs') }}
</el-dropdown-item>
<el-dropdown-item
:icon="menuStore.iconComponents['HOutline:ChevronDoubleRightIcon']"
@click="tabsStore.closeRightTabs(tabsStore.activePath)"
>
{{ $t('layout.closeRightTabs') }}
</el-dropdown-item>
<el-dropdown-item
:icon="menuStore.iconComponents['HOutline:ChevronDoubleLeftIcon']"
@click="tabsStore.closeLeftTabs(tabsStore.activePath)"
>
{{ $t('layout.closeLeftTabs') }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</template>
<script setup lang="ts">
defineOptions({ name: 'TabsView' })
const router = useRouter()
const menuStore = useMenuStore()
const tabsStore = useTabsStore()
const tabsPagesRef = useTemplateRef<HTMLDivElement>('tabsPagesRef')
// 存储每个标签页的 DOM 引用
const tabRefs = new Map<string, HTMLDivElement>()
// 设置标签页引用
const setTabRef = (el: Element | ComponentPublicInstance | null, path: string) => {
if (el && el instanceof HTMLElement) {
tabRefs.set(path, el as HTMLDivElement)
} else {
tabRefs.delete(path)
}
}
// 滚动到选中的标签页
const scrollToActiveTab = () => {
nextTick(() => {
const activeTab = tabRefs.get(tabsStore.activePath)
const container = tabsPagesRef.value
if (!activeTab || !container) return
const containerRect = container.getBoundingClientRect()
const tabRect = activeTab.getBoundingClientRect()
// 检查标签页是否在可视区域内
const isVisible = tabRect.left >= containerRect.left && tabRect.right <= containerRect.right
if (!isVisible) {
// 如果标签页在左侧不可见
if (tabRect.left < containerRect.left) {
container.scrollTo({
left: container.scrollLeft + (tabRect.left - containerRect.left) - 10,
behavior: 'smooth',
})
}
// 如果标签页在右侧不可见
else if (tabRect.right > containerRect.right) {
container.scrollTo({
left: container.scrollLeft + (tabRect.right - containerRect.right) + 10,
behavior: 'smooth',
})
}
}
})
}
// 监听 activePath 变化,自动滚动到选中的标签页
watch(
() => tabsStore.activePath,
() => {
scrollToActiveTab()
},
{ immediate: true },
)
// 监听 tabs 数组变化,确保在标签页添加或删除后也能正确滚动
watch(
() => tabsStore.tabs.length,
() => {
scrollToActiveTab()
},
)
// 导航到指定路径
const navigation = (path: string) => {
router.push(path)
tabsStore.activePath = path
scrollToActiveTab()
}
// 关闭标签页
const handleClose = (item: TabItem) => {
tabsStore.removeTab(item.path)
router.push(tabsStore.activePath)
scrollToActiveTab()
}
// 滚动步进值(容器宽度的80%)
const SCROLL_STEP_RATIO = 0.8
// 获取滚动容器信息
const getScrollInfo = () => {
const container = tabsPagesRef.value
if (!container) return null
return {
container,
containerWidth: container.offsetWidth,
contentWidth: container.scrollWidth,
scrollLeft: container.scrollLeft,
maxScrollLeft: container.scrollWidth - container.offsetWidth,
}
}
// 向左滑动
const slideLeft = () => {
const info = getScrollInfo()
if (!info) return
// 检查是否需要滚动(内容超出容器)
if (info.containerWidth >= info.contentWidth) return
// 计算滚动距离(容器宽度的80%)
const scrollDistance = info.containerWidth * SCROLL_STEP_RATIO
// 计算目标滚动位置
const targetScrollLeft = Math.max(0, info.scrollLeft - scrollDistance)
// 如果已经在最左边,不执行滚动
if (info.scrollLeft <= 0) return
info.container.scrollTo({
left: targetScrollLeft,
behavior: 'smooth',
})
}
// 向右滑动
const slideRight = () => {
const info = getScrollInfo()
if (!info) return
// 检查是否需要滚动(内容超出容器)
if (info.containerWidth >= info.contentWidth) return
// 计算滚动距离(容器宽度的80%)
const scrollDistance = info.containerWidth * SCROLL_STEP_RATIO
// 计算目标滚动位置
const targetScrollLeft = Math.min(info.maxScrollLeft, info.scrollLeft + scrollDistance)
// 如果已经在最右边,不执行滚动
if (info.scrollLeft >= info.maxScrollLeft) return
info.container.scrollTo({
left: targetScrollLeft,
behavior: 'smooth',
})
}
</script>
<style scoped lang="scss">
:deep(.el-dropdown-menu__item .el-icon) {
font-size: 1.125rem;
}
.tabs-container {
padding-top: 0.1rem;
height: 2.5rem;
padding-left: 1.25rem;
display: flex;
align-items: center;
.tabs-pages {
padding: 0 1.25rem;
height: 2.5rem;
flex: 1;
display: flex;
font-size: 0.875rem;
overflow-x: auto;
gap: 0.2rem;
&::-webkit-scrollbar {
display: none;
}
.tabs-page-item {
padding: 0 0.75rem;
display: flex;
align-items: center;
flex-shrink: 0;
gap: 0.5rem;
cursor: pointer;
color: var(--el-text-color-regular);
.close-icon {
margin-left: 0.25rem;
font-size: 0.75rem;
width: 0.875rem;
height: 0.875rem;
display: flex;
align-items: center;
justify-content: center;
border-radius: 20%;
transition: all 0.2s ease;
flex-shrink: 0;
color: var(--el-text-color-regular);
cursor: pointer;
&:hover {
background-color: var(--el-fill-color-darker);
color: var(--el-color-danger);
transform: scale(1.1);
}
}
&:hover {
background-color: var(--el-fill-color-light);
border-radius: 0.625rem 0.625rem 0.875rem 0.875rem;
font-weight: bold;
}
&.active {
position: relative;
border-radius: 0.625rem 0.625rem 0 0;
background-color: color-mix(in srgb, var(--el-color-primary) 20%, transparent);
color: var(--el-color-primary);
font-weight: bold;
&::before {
content: '';
position: absolute;
width: 20px;
height: 20px;
left: -20px;
bottom: 0;
background: #000;
background: radial-gradient(
circle at 0 0,
transparent 20px,
color-mix(in srgb, var(--el-color-primary) 20%, transparent) 21px
);
}
&::after {
content: '';
position: absolute;
width: 20px;
height: 20px;
right: -20px;
bottom: 0;
background: #000;
background: radial-gradient(
circle at 100% 0,
transparent 20px,
color-mix(in srgb, var(--el-color-primary) 20%, transparent) 21px
);
}
}
}
}
.tabs-dropdown {
height: 100%;
.tabs-dropdown-wrapper {
height: 100%;
cursor: pointer;
margin-right: 0.5rem;
.tabs-dropdown-icon {
display: flex;
align-items: center;
color: var(--el-text-color-regular);
&:hover {
color: var(--el-color-primary);
}
}
}
}
}
:deep(.el-dropdown-menu__item) {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 16px;
transition:
background-color 0.2s,
color 0.2s;
&:hover {
background: var(--el-fill-color-light) !important;
color: var(--el-color-primary);
}
&:focus,
&:focus-visible {
background: var(--el-fill-color-light) !important;
color: var(--el-color-primary);
}
}
</style>
<style lang="scss">
.tabs-dropdown-popper {
border-radius: 8px !important;
.el-dropdown-menu {
border-radius: 8px !important;
}
}
</style>
+53
View File
@@ -0,0 +1,53 @@
<template>
<el-container class="top-mode-container">
<el-header class="header">
<HeaderView />
</el-header>
<Transition name="fade-slide" mode="out-in">
<TabsView v-if="themeStore.themeConfig.showTabs" />
</Transition>
<el-scrollbar>
<el-main class="main">
<RouterView v-slot="{ Component, route }">
<Transition name="fade-slide" mode="out-in">
<component :is="Component" :key="route.path" />
</Transition>
</RouterView>
</el-main>
</el-scrollbar>
</el-container>
</template>
<script setup lang="ts">
import HeaderView from '@/layouts/header.vue'
import TabsView from '@/layouts/tabsView.vue'
defineOptions({ name: 'TopMode' })
const themeStore = useThemeStore()
</script>
<style scoped lang="scss">
.top-mode-container {
width: 100%;
height: 100%;
.header {
height: 50px;
background: var(--el-bg-color);
border-bottom: 1px solid var(--el-border-color-lighter);
padding-right: 0.25rem;
}
.main {
background: var(--el-bg-color-page);
padding: 1rem;
position: relative;
overflow-y: auto;
overflow-x: hidden;
min-height: calc(100vh - 50px - 2.5rem);
display: flex;
flex-direction: column;
}
}
</style>
+381
View File
@@ -0,0 +1,381 @@
<template>
<el-dropdown
@command="handleCommand"
trigger="click"
:show-arrow="false"
placement="bottom-end"
popper-class="user-dropdown-popper"
>
<div class="user-card">
<div class="avatar-wrapper">
<el-avatar :size="36" :src="userStore.userInfo?.avatar" />
<span class="status-badge"></span>
</div>
<div class="user-info">
<span class="username ellipsis-text">{{
userStore.userInfo?.name || userStore.userInfo?.username
}}</span>
<BaseTag :text="userRoleName" size="small" />
<!-- <span class="user-role-badge ellipsis-text">{{ userRoleName }}</span> -->
</div>
</div>
<template #dropdown>
<div class="user-menu-wrapper">
<!-- 用户信息头部 -->
<div class="user-header">
<div class="avatar-wrapper">
<el-avatar :size="48" :src="userStore.userInfo?.avatar" />
<span class="status-badge"></span>
</div>
<div class="user-info">
<div class="name-row">
<span class="user-name ellipsis-text">{{
userStore.userInfo?.name || userStore.userInfo?.username
}}</span>
<BaseTag :text="userRoleName" size="small" />
</div>
<div class="user-email">{{ userStore.userInfo?.email || '' }}</div>
</div>
</div>
<!-- 菜单项 -->
<el-dropdown-menu class="user-menu">
<el-dropdown-item command="profile">
<el-icon>
<component :is="menuStore.iconComponents['HOutline:UserCircleIcon']" />
</el-icon>
<span>{{ $t('layout.profile') }}</span>
</el-dropdown-item>
<el-dropdown-item divided command="password">
<el-icon>
<component :is="menuStore.iconComponents['HOutline:KeyIcon']" />
</el-icon>
<span>{{ $t('layout.changePassword') }}</span>
</el-dropdown-item>
<el-dropdown-item divided command="logout">
<el-icon>
<component :is="menuStore.iconComponents['HOutline:ArrowRightOnRectangleIcon']" />
</el-icon>
<span>{{ $t('layout.logout') }}</span>
<span class="shortcut">⌥ Q</span>
</el-dropdown-item>
</el-dropdown-menu>
</div>
</template>
</el-dropdown>
<UpdatePassword ref="updatePasswordRef" />
</template>
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { Dialog } from '@/utils/dialog'
const { t } = useI18n()
const router = useRouter()
const menuStore = useMenuStore()
const userStore = useUserStore()
const updatePasswordRef = useTemplateRef('updatePasswordRef')
// 用户角色名称
const userRoleName = computed(() => {
return userStore.roleList.find((role) => role.id === userStore.userInfo?.roleId)?.name ?? '无权限'
})
// 用户菜单命令处理
const showLogoutConfirm = () => {
Dialog.info({
showCancelButton: true,
content: t('layout.logoutContent'),
confirmText: t('layout.logoutConfirmText'),
cancelText: t('layout.logoutCancelText'),
onConfirm: () => {
userStore.logout()
},
})
}
const handleCommand = (command: string) => {
switch (command) {
case 'profile':
userStore.currentTab = 'personalInfo'
router.push('/profile')
break
case 'password':
updatePasswordRef.value?.showDialog()
break
case 'logout':
showLogoutConfirm()
break
}
}
// 监听快捷键:Alt/Option + Q 触发退出登录弹窗
const handleKeydown = (event: KeyboardEvent) => {
const target = event.target as HTMLElement | null
const isTyping =
(target && ['INPUT', 'TEXTAREA'].includes(target.tagName)) ||
target?.getAttribute('contenteditable') === 'true'
if (isTyping) return
// Mac 上 Option+Q 常返回 Dead key,改用 code 判断物理键位
if (event.altKey && event.code === 'KeyQ') {
event.preventDefault()
showLogoutConfirm()
}
}
onMounted(() => {
userStore.getUserInfo()
userStore.getUserRoleName()
window.addEventListener('keydown', handleKeydown)
})
onBeforeUnmount(() => {
window.removeEventListener('keydown', handleKeydown)
})
</script>
<style scoped lang="scss">
.user-card {
display: flex;
align-items: center;
gap: 0.25rem;
padding: 4px 8px 4px 4px;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.2s;
&:hover {
.arrow-icon {
color: var(--el-color-primary);
}
}
.avatar-wrapper {
position: relative;
flex-shrink: 0;
.status-badge {
position: absolute;
bottom: 0;
right: 0;
width: 10px;
height: 10px;
background: #52c41a;
border: 2px solid var(--el-bg-color);
border-radius: 50%;
}
}
.user-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 4px;
.username {
font-size: 14px;
font-weight: 600;
color: var(--el-text-color-primary);
line-height: 1.2;
max-width: 100px;
}
.user-role-badge {
display: inline-block;
align-items: center;
padding: 2px 8px;
background: var(--el-color-primary-light-9);
color: var(--el-color-primary);
font-size: 11px;
font-weight: 500;
border-radius: 4px;
white-space: nowrap;
line-height: 1.2;
max-width: 100px;
}
}
.arrow-icon {
font-size: 1rem;
color: var(--el-text-color-regular);
transition: color 0.2s;
margin-left: 4px;
}
}
.user-menu-wrapper {
background: var(--el-bg-color);
border-radius: 8px;
overflow: hidden;
}
.user-header {
display: flex;
align-items: center;
gap: 12px;
padding: 16px;
border-bottom: 1px solid var(--el-border-color-lighter);
background: var(--el-bg-color);
.avatar-wrapper {
position: relative;
flex-shrink: 0;
.status-badge {
position: absolute;
bottom: 0;
right: 0;
width: 12px;
height: 12px;
background: #52c41a;
border: 2px solid var(--el-bg-color);
border-radius: 50%;
}
}
.user-info {
flex: 1;
min-width: 0;
.name-row {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 4px;
.user-name {
font-size: 16px;
font-weight: 600;
color: var(--el-text-color-primary);
line-height: 1.2;
max-width: 100px;
}
.pro-badge {
display: inline-block;
align-items: center;
padding: 3px 10px;
background: var(--el-color-primary-light-9);
color: var(--el-color-primary);
font-size: 11px;
font-weight: 500;
border-radius: 4px;
line-height: 1.2;
max-width: 100px;
}
}
.user-email {
font-size: 13px;
color: var(--el-text-color-regular);
opacity: 0.8;
line-height: 1.2;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
.avatar-wrapper {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.avatar-wrapper .user-avatar,
.avatar-wrapper .header-avatar {
border-radius: 50%;
overflow: hidden;
img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
}
.avatar-wrapper .user-avatar {
width: 36px;
height: 36px;
}
.avatar-wrapper .header-avatar {
width: 48px;
height: 48px;
}
:deep(.user-menu) {
padding: 4px 0;
min-width: 200px;
background: var(--el-bg-color);
.el-dropdown-menu__item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 16px;
transition: background-color 0.2s;
background: transparent;
&:hover {
background: var(--el-fill-color-light);
color: var(--el-color-primary);
}
.el-icon {
font-size: 1.25rem;
flex-shrink: 0;
}
span:not(.shortcut) {
font-size: 14px;
flex: 1;
}
.shortcut {
font-size: 12px;
color: var(--el-text-color-placeholder);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
opacity: 0.6;
}
}
}
.logout-dialog-content {
display: flex;
align-items: center;
gap: 12px;
padding: 8px 0;
.warning-icon {
font-size: 24px;
color: var(--el-color-warning);
flex-shrink: 0;
}
.dialog-text {
font-size: 14px;
color: var(--el-text-color-primary);
line-height: 1.5;
}
}
</style>
<style lang="scss">
.user-dropdown-popper {
border-radius: 8px !important;
.el-dropdown-menu {
border-radius: 8px !important;
}
}
</style>