| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- <template>
- <el-container class="main-layout">
- <!-- 头部导航 -->
- <el-header class="layout-header">
- <div class="header-left">
- <div class="logo">
- <i class="el-icon-monitor logo-icon"></i>
- <span class="system-name">管理系统</span>
- </div>
- <!-- 移动端菜单切换按钮 -->
- <el-button
- class="mobile-menu-btn"
- icon="el-icon-menu"
- @click="toggleMobileMenu"
- v-show="isMobile"
- />
- </div>
- <div class="header-right">
- <el-dropdown @command="handleUserCommand">
- <div class="user-info">
- <el-avatar :size="32" :src="userInfo.avatar" />
- <span class="username">{{ userInfo.name }}</span>
- <i class="el-icon-arrow-down"></i>
- </div>
- <template #dropdown>
- <el-dropdown-menu>
- <!--<el-dropdown-item command="profile">-->
- <!-- <i class="el-icon-user"></i>个人信息-->
- <!--</el-dropdown-item>-->
- <!--<el-dropdown-item command="settings">-->
- <!-- <i class="el-icon-setting"></i>系统设置-->
- <!--</el-dropdown-item>-->
- <el-dropdown-item divided command="logout">
- <i class="el-icon-switch-button"></i>退出登录
- </el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- <el-tooltip content="全屏切换" placement="bottom">
- <el-button
- class="header-btn"
- :icon="isFullscreen ? 'el-icon-close' : 'el-icon-full-screen'"
- @click="toggleFullscreen"
- />
- </el-tooltip>
- <!--<el-tooltip content="消息通知" placement="bottom">-->
- <!-- <el-badge :value="5" class="header-btn">-->
- <!-- <el-button icon="el-icon-bell" @click="showNotifications" />-->
- <!-- </el-badge>-->
- <!--</el-tooltip>-->
- </div>
- </el-header>
- <el-container class="layout-body">
- <!-- 侧边栏菜单 -->
- <el-aside
- :width="isCollapse ? '64px' : '240px'"
- :class="['layout-aside', { 'mobile-open': mobileMenuOpen }]"
- >
- <div class="menu-toggle" @click="toggleCollapse" v-if="!isMobile">
- <i :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"></i>
- </div>
- <el-menu
- :default-active="activeMenu"
- :collapse="isCollapse && !isMobile"
- :collapse-transition="false"
- router
- class="sidebar-menu"
- background-color="#001529"
- text-color="#bfbfbf"
- active-text-color="#1890ff"
- @select="handleMenuSelect"
- >
- <template v-for="menu in menuList" :key="menu.path">
- <!-- 有子菜单的项 -->
- <el-sub-menu v-if="menu.children && menu.children.length" :index="menu.path">
- <template #title>
- <i :class="menu.icon"></i>
- <span>{{ menu.title }}</span>
- </template>
- <el-menu-item
- v-for="child in menu.children"
- :key="child.path"
- :index="child.path"
- >
- <i :class="child.icon"></i>
- <span>{{ child.title }}</span>
- </el-menu-item>
- </el-sub-menu>
- <!-- 没有子菜单的项 -->
- <el-menu-item v-else :index="menu.path">
- <i :class="menu.icon"></i>
- <span>{{ menu.title }}</span>
- </el-menu-item>
- </template>
- </el-menu>
- </el-aside>
- <!-- 主内容区域 -->
- <el-main class="layout-main">
- <div class="main-content">
- <router-view v-slot="{ Component }">
- <transition name="fade-transform" mode="out-in">
- <component :is="Component" />
- </transition>
- </router-view>
- </div>
- </el-main>
- </el-container>
- <!-- 移动端遮罩层 -->
- <div
- v-show="isMobile && mobileMenuOpen"
- class="mobile-mask"
- @click="closeMobileMenu"
- ></div>
- </el-container>
- </template>
- <script setup>
- import { ref, computed, onMounted, onUnmounted } from 'vue'
- import { useRouter, useRoute } from 'vue-router'
- import { ElMessage, ElMessageBox } from 'element-plus'
- import {getUserName, getUserAvatar, clearTokenAndUserInfo, getUserRole} from "/src/commom/utils/auth.js";
- const router = useRouter()
- const route = useRoute()
- // 响应式数据
- const isCollapse = ref(false)
- const isFullscreen = ref(false)
- const mobileMenuOpen = ref(false)
- const isMobile = ref(false)
- const name = computed(()=>getUserName())
- const avatar = 'https://www.loliapi.com/acg/pp/'
- // 用户信息
- const userInfo = ref({
- name: name?name:'管理员',
- avatar: avatar &&avatar !=='' ?avatar:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
- })
- // 菜单数据
- const menuList = computed(()=>{
- //根据用户角色显示菜单
- const role = getUserRole();
- console.log(role)
- if(role === '管理员'){
- return [
- {
- path: '/interfaceInfo',
- title: '接口管理',
- icon: 'el-icon-document',
- children: [
- {
- path: '/manage/interfaceInfo',
- title: '接口管理',
- icon: 'el-icon-notebook-2'
- }
- ]
- },
- ]
- }else if (role === '用户'){
- return [
- {
- path: '/home',
- title: '主页',
- icon: 'el-icon-document',
- children: [
- {
- path: '/home/interfaceInfo',
- title: '接口信息',
- icon: 'el-icon-notebook-2'
- }
- ]
- },
- ]
- }else{
- return [
- {
- path: '/home',
- title: '主页',
- icon: 'el-icon-document',
- children: [
- {
- path: '/home/interfaceInfo',
- title: '接口信息',
- icon: 'el-icon-notebook-2'
- }
- ]
- },
- ]
- }
- })
- const menuList1 = ref([
- {
- path: '/dashboard',
- title: '仪表盘',
- icon: 'el-icon-data-analysis',
- children: [
- {
- path: '/dashboard/overview',
- title: '数据概览',
- icon: 'el-icon-trend-charts'
- },
- {
- path: '/dashboard/analytics',
- title: '数据分析',
- icon: 'el-icon-data-line'
- }
- ]
- },
- {
- path: '/user',
- title: '用户管理',
- icon: 'el-icon-user',
- children: [
- {
- path: '/user/list',
- title: '用户列表',
- icon: 'el-icon-user-solid'
- },
- {
- path: '/user/role',
- title: '角色管理',
- icon: 'el-icon-s-custom'
- },
- {
- path: '/user/permission',
- title: '权限管理',
- icon: 'el-icon-key'
- }
- ]
- },
- {
- path: '/interfaceInfo',
- title: '接口管理',
- icon: 'el-icon-document',
- children: [
- {
- path: '/manage/interfaceInfo',
- title: '接口管理',
- icon: 'el-icon-notebook-2'
- }
- ]
- },
- // {
- // path: '/system',
- // title: '系统设置',
- // icon: 'el-icon-setting',
- // children: [
- // {
- // path: '/system/basic',
- // title: '基础设置',
- // icon: 'el-icon-tools'
- // },
- // {
- // path: '/system/logs',
- // title: '系统日志',
- // icon: 'el-icon-document-checked'
- // }
- // ]
- // },
- // {
- // path: '/monitor',
- // title: '系统监控',
- // icon: 'el-icon-monitor',
- // children: [
- // {
- // path: '/monitor/server',
- // title: '服务器监控',
- // icon: 'el-icon-cpu'
- // },
- // {
- // path: '/monitor/performance',
- // title: '性能监控',
- // icon: 'el-icon-odometer'
- // }
- // ]
- // }
- ])
- // 计算属性
- const activeMenu = computed(() => route.path)
- // 方法
- const toggleCollapse = () => {
- isCollapse.value = !isCollapse.value
- }
- const toggleMobileMenu = () => {
- mobileMenuOpen.value = !mobileMenuOpen.value
- }
- const closeMobileMenu = () => {
- mobileMenuOpen.value = false
- }
- const handleMenuSelect = () => {
- if (isMobile.value) {
- closeMobileMenu()
- }
- }
- const toggleFullscreen = () => {
- if (!document.fullscreenElement) {
- document.documentElement.requestFullscreen()
- isFullscreen.value = true
- } else {
- if (document.exitFullscreen) {
- document.exitFullscreen()
- isFullscreen.value = false
- }
- }
- }
- const handleUserCommand = (command) => {
- switch (command) {
- // case 'profile':
- // router.push('/profile')
- // break
- // case 'settings':
- // router.push('/system/basic')
- // break
- case 'logout':
- handleLogout()
- break
- }
- }
- const handleLogout = async () => {
- try {
- await ElMessageBox.confirm('确定要退出登录吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- // 清除用户信息
- clearTokenAndUserInfo()
- ElMessage.success('退出成功')
- router.push('/login')
- } catch (error) {
- // 用户取消退出
- }
- }
- const showNotifications = () => {
- ElMessage.info('这是消息通知')
- }
- // 检测屏幕尺寸
- const checkMobile = () => {
- isMobile.value = window.innerWidth <= 768
- if (!isMobile.value) {
- mobileMenuOpen.value = false
- }
- }
- // 监听全屏状态变化
- const handleFullscreenChange = () => {
- isFullscreen.value = !!document.fullscreenElement
- }
- // 监听窗口大小变化
- const handleResize = () => {
- checkMobile()
- }
- // 生命周期
- onMounted(() => {
- document.addEventListener('fullscreenchange', handleFullscreenChange)
- window.addEventListener('resize', handleResize)
- checkMobile() // 初始化时检测一次
- })
- onUnmounted(() => {
- document.removeEventListener('fullscreenchange', handleFullscreenChange)
- window.removeEventListener('resize', handleResize)
- })
- </script>
- <style scoped>
- .main-layout {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- height: 100vh !important;
- width: 100vw !important;
- margin: 0;
- padding: 0;
- overflow: hidden;
- }
- /* 头部样式 */
- .layout-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- background: #fff;
- border-bottom: 1px solid #e6e6e6;
- padding: 0 20px;
- box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
- z-index: 1001;
- height: 60px !important;
- position: relative;
- }
- .header-left {
- display: flex;
- align-items: center;
- gap: 16px;
- }
- .logo {
- display: flex;
- align-items: center;
- gap: 12px;
- font-weight: 600;
- font-size: 18px;
- color: #1890ff;
- }
- .logo-icon {
- font-size: 24px;
- }
- .system-name {
- font-size: 18px;
- font-weight: 600;
- color: #333;
- }
- .mobile-menu-btn {
- display: none;
- border: none;
- background: transparent;
- font-size: 18px;
- color: #666;
- }
- .header-right {
- display: flex;
- align-items: center;
- gap: 16px;
- }
- .user-info {
- display: flex;
- align-items: center;
- gap: 8px;
- padding: 8px 12px;
- border-radius: 6px;
- cursor: pointer;
- transition: background-color 0.3s;
- }
- .user-info:hover {
- background-color: #f5f5f5;
- }
- .username {
- font-size: 14px;
- color: #333;
- }
- .header-btn {
- border: none;
- background: transparent;
- font-size: 16px;
- color: #666;
- cursor: pointer;
- padding: 8px;
- border-radius: 6px;
- transition: all 0.3s;
- }
- .header-btn:hover {
- background-color: #f5f5f5;
- color: #1890ff;
- }
- /* 主体样式 */
- .layout-body {
- height: calc(100vh - 60px) !important;
- width: 100%;
- position: relative;
- }
- /* 侧边栏样式 */
- .layout-aside {
- background: #001529;
- transition: all 0.3s;
- position: relative;
- overflow: hidden;
- height: 100%;
- }
- .menu-toggle {
- height: 48px;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #fff;
- cursor: pointer;
- border-bottom: 1px solid #002140;
- transition: all 0.3s;
- }
- .menu-toggle:hover {
- background: #002140;
- }
- .menu-toggle i {
- font-size: 18px;
- }
- .sidebar-menu {
- border: none;
- height: calc(100% - 48px);
- overflow-y: auto;
- }
- .sidebar-menu:not(.el-menu--collapse) {
- width: 240px;
- }
- /* 主内容区域样式 */
- .layout-main {
- padding: 0;
- background: #f0f2f5;
- overflow: hidden;
- height: 100%;
- width: 100%;
- }
- .main-content {
- height: 100%;
- padding: 20px;
- overflow-y: auto;
- }
- /* 移动端遮罩层 */
- .mobile-mask {
- position: fixed;
- top: 60px;
- left: 0;
- right: 0;
- bottom: 0;
- background: rgba(0, 0, 0, 0.5);
- z-index: 999;
- }
- /* 过渡动画 */
- .fade-transform-leave-active,
- .fade-transform-enter-active {
- transition: all 0.3s;
- }
- .fade-transform-enter-from {
- opacity: 0;
- transform: translateX(-30px);
- }
- .fade-transform-leave-to {
- opacity: 0;
- transform: translateX(30px);
- }
- /* 响应式设计 */
- @media (max-width: 768px) {
- .layout-header {
- padding: 0 16px;
- }
- .system-name {
- font-size: 16px;
- }
- .username {
- display: none;
- }
- .mobile-menu-btn {
- display: block;
- }
- .layout-aside {
- position: fixed;
- top: 60px;
- left: 0;
- bottom: 0;
- z-index: 1000;
- transform: translateX(-100%);
- transition: transform 0.3s;
- width: 240px !important;
- }
- .layout-aside.mobile-open {
- transform: translateX(0);
- }
- .menu-toggle {
- display: none;
- }
- .sidebar-menu {
- height: 100%;
- }
- .main-content {
- padding: 16px;
- }
- }
- @media (max-width: 480px) {
- .layout-header {
- padding: 0 12px;
- }
- .header-right {
- gap: 8px;
- }
- .main-content {
- padding: 12px;
- }
- .logo {
- gap: 8px;
- }
- .logo-icon {
- font-size: 20px;
- }
- .system-name {
- font-size: 16px;
- }
- }
- /* 滚动条样式 */
- .main-content::-webkit-scrollbar {
- width: 6px;
- }
- .main-content::-webkit-scrollbar-track {
- background: #f1f1f1;
- border-radius: 3px;
- }
- .main-content::-webkit-scrollbar-thumb {
- background: #c1c1c1;
- border-radius: 3px;
- }
- .main-content::-webkit-scrollbar-thumb:hover {
- background: #a8a8a8;
- }
- .sidebar-menu::-webkit-scrollbar {
- width: 4px;
- }
- .sidebar-menu::-webkit-scrollbar-track {
- background: #001529;
- }
- .sidebar-menu::-webkit-scrollbar-thumb {
- background: #003366;
- border-radius: 2px;
- }
- .sidebar-menu::-webkit-scrollbar-thumb:hover {
- background: #004488;
- }
- /* 确保全局样式 */
- :global(html), :global(body) {
- margin: 0;
- padding: 0;
- height: 100%;
- width: 100%;
- overflow: hidden;
- }
- :global(#app) {
- height: 100vh;
- width: 100vw;
- overflow: hidden;
- }
- </style>
|