import { createRouter, createWebHistory } from 'vue-router' import AdminLayout from '../components/layout/AdminLayout.vue' import OperationLog from '@/views/system/OperationLog.vue' const routes = [ { path: '/', redirect: '/dashboard' }, { path: '/redirect', component: AdminLayout, hidden: true, children: [ { path: '/redirect/:path(.*)', component: () => import('../views/Redirect.vue'), meta: { title: '重定向' } } ] }, { path: '/', component: AdminLayout, children: [ { path: 'dashboard', name: 'Dashboard', component: () => import('../views/dashboard/Dashboard.vue'), meta: { title: '仪表盘', icon: 'DataBoard' } }, { path: 'ticket', name: 'Ticket', meta: { title: '工单管理', icon: 'Tickets' }, component: () => import('../views/ticket/TicketChat.vue'), }, // ACS管理路由 { path: 'acs', name: 'ACS', meta: { title: 'ACS管理', icon: 'Monitor' }, redirect: '/acs/messages/announcements', children: [ // 消息管理路由 { path: 'messages', name: 'Messages', meta: { title: '消息管理' }, redirect: '/acs/messages/announcements', children: [ { path: 'announcements', name: 'Announcements', component: () => import('../views/acs/messages/Announcements.vue'), meta: { title: '官方公告' } }, { path: 'policies', name: 'Policies', component: () => import('../views/acs/messages/Policies.vue'), meta: { title: '官方政策' } }, { path: 'news', name: 'News', component: () => import('../views/acs/messages/News.vue'), meta: { title: '新闻咨询' } } ] }, // 镜像管理路由 { path: 'images', name: 'Images', meta: { title: '镜像管理' }, redirect: '/acs/images/vm', children: [ { path: 'vm', name: 'VmImages', component: () => import('../views/acs/images/VmImages.vue'), meta: { title: '虚拟机镜像' } }, { path: 'container', name: 'ContainerImages', component: () => import('../views/acs/images/ContainerImages.vue'), meta: { title: '容器镜像' } }, { path: 'categories', name: 'ImageCategories', component: () => import('../views/acs/images/ImageCategories.vue'), meta: { title: '镜像分类' } } ] }, // 节点管理路由 { path: 'nodes', name: 'Nodes', component: () => import('../views/acs/nodes/Nodes.vue'), meta: { title: '节点管理' } } ] }, { path: 'system', name: 'System', meta: { title: '系统管理', icon: 'Setting' }, redirect: '/system/users', children: [ { path: 'users', name: 'Users', component: () => import('../views/system/Users.vue'), meta: { title: '用户管理' } }, { path: 'operation-log', name: 'OperationLog', component: OperationLog, meta: { title: '操作日志' } }, { path: 'domain-whitelist', name: 'DomainWhitelist', component: () => import('../views/system/DomainWhitelist.vue'), meta: { title: '域名白名单' } } ] }, // 个人中心路由 { path: 'profile', name: 'Profile', component: () => import('../views/profile/UserInfo.vue'), meta: { title: '个人信息', hidden: true } }, // 修改密码路由 { path: 'change-password', name: 'ChangePassword', component: () => import('../views/profile/ChangePassword.vue'), meta: { title: '修改密码', hidden: true } }, // 服务器详情页面路由 { path: 'servers/server', name: 'ServerDetail', component: () => import('../views/acs/nodes/server.vue'), meta: { title: '服务器详情', hidden: true } }, // 虚拟机详情页面路由 { path: 'servers/vm', name: 'VmDetail', component: () => import('../views/acs/nodes/VmDetail.vue'), meta: { title: '虚拟机详情', hidden: true } }, // 容器详情页面路由 { path: 'servers/container', name: 'ContainerDetail', component: () => import('../views/acs/nodes/containDetail.vue'), meta: { title: '容器详情', hidden: true } },{ path:'servers/container/console', name:'ContainerConsole', component:()=>import('../views/acs/nodes/containerConsole.vue'), meta:{ title:'终端容器', hidden:true } },{ path:'servers/container/files', name:'ContainerFiles', component:()=>import('../views/acs/nodes/containFile.vue'), meta:{ title:'容器文件管理', hidden:true } } ] }, // 登录页 { path: '/login', name: 'Login', component: () => import('../views/Login.vue'), meta: { title: '登录' } }, // 404 页面 { path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('../views/NotFound.vue'), meta: { title: '页面不存在' } } ] const router = createRouter({ history: createWebHistory(), routes }) // 全局前置守卫 router.beforeEach((to, from, next) => { // 设置页面标题 document.title = to.meta.title ? `${to.meta.title} - 007UI管理系统` : '007UI管理系统' // 这里可以添加登录验证逻辑 const isAuthenticated = localStorage.getItem('token') if (to.path !== '/login' && !isAuthenticated) { next({ path: '/login' }) } else { next() } }) // 全局后置钩子 router.afterEach(() => { window.scrollTo(0, 0) }) export default router