- 新增 terminalTabs store 管理标签页状态 - 新增 TerminalWorkspaceView 终端工作区视图 - 修改 ConnectionsView 终端按钮改用标签页模式 - 修改 TerminalView 作为兼容入口自动跳转到工作区 - 同一连接默认只保留一个标签页 - 切换标签时保持各自 SSH 会话不断开
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import type { RouteRecordRaw } from 'vue-router'
|
|
import { useAuthStore } from '../stores/auth'
|
|
|
|
const routes: RouteRecordRaw[] = [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('../views/LoginView.vue'),
|
|
meta: { public: true },
|
|
},
|
|
{
|
|
path: '/',
|
|
component: () => import('../layouts/MainLayout.vue'),
|
|
meta: { requiresAuth: true },
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'Home',
|
|
redirect: '/connections',
|
|
},
|
|
{
|
|
path: 'transfers',
|
|
name: 'Transfers',
|
|
component: () => import('../views/TransfersView.vue'),
|
|
},
|
|
{
|
|
path: 'connections',
|
|
name: 'Connections',
|
|
component: () => import('../views/ConnectionsView.vue'),
|
|
},
|
|
{
|
|
path: 'terminal',
|
|
name: 'TerminalWorkspace',
|
|
component: () => import('../views/TerminalWorkspaceView.vue'),
|
|
},
|
|
{
|
|
path: 'terminal/:id',
|
|
name: 'Terminal',
|
|
component: () => import('../views/TerminalView.vue'),
|
|
},
|
|
{
|
|
path: 'sftp/:id',
|
|
name: 'Sftp',
|
|
component: () => import('../views/SftpView.vue'),
|
|
},
|
|
],
|
|
},
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
})
|
|
|
|
router.beforeEach(async (to, _from, next) => {
|
|
const authStore = useAuthStore()
|
|
if (to.meta.public) {
|
|
if (authStore.isAuthenticated && to.path === '/login') {
|
|
next('/connections')
|
|
} else {
|
|
next()
|
|
}
|
|
return
|
|
}
|
|
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
|
|
next('/login')
|
|
return
|
|
}
|
|
next()
|
|
})
|
|
|
|
export default router
|