refactor(web): router

This commit is contained in:
Acbox
2026-02-11 16:08:36 +08:00
parent 5021aed307
commit b46cb0c4e3
3 changed files with 87 additions and 84 deletions
@@ -72,7 +72,7 @@ const route = useRoute()
const { t } = i18n.global
const curSlider = ref()
const curSelectSlide = (cur: string) => computed(() => {
return curSlider.value === cur || new RegExp(`^/main/${cur}$`).test(route.path)
return curSlider.value === cur || new RegExp(`^/${cur}$`).test(route.path)
})
const sidebarInfo = computed(() => [
{
+1 -1
View File
@@ -141,7 +141,7 @@ const login = form.handleSubmit(async (values) => {
} else {
throw new Error(t('auth.loginFailed'))
}
router.replace({ name: 'Main' })
router.replace({ path: '/chat' })
} catch {
toast.error(t('auth.invalidCredentials'), {
description: t('auth.retryHint'),
+85 -82
View File
@@ -1,4 +1,8 @@
import { createRouter, createWebHistory, type RouteLocationNormalized } from 'vue-router'
import {
createRouter,
createWebHistory,
type RouteLocationNormalized,
} from 'vue-router'
import { h } from 'vue'
import { RouterView } from 'vue-router'
import { i18nRef } from './i18n'
@@ -6,102 +10,101 @@ import { i18nRef } from './i18n'
const routes = [
{
path: '/',
redirect: '/login'
redirect: '/login',
component: () => import('@/pages/main-section/index.vue'),
children: [
{
name: 'chat',
path: '/chat',
component: () => import('@/pages/chat/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.chat'),
},
},
{
name: 'home',
path: '/home',
component: () => import('@/pages/home/index.vue'),
meta: {
breadcrumb: i18nRef('home.title'),
},
},
{
path: '/bots',
component: { render: () => h(RouterView) },
meta: {
breadcrumb: i18nRef('sidebar.bots'),
},
children: [
{
name: 'bots',
path: '',
component: () => import('@/pages/bots/index.vue'),
},
{
name: 'bot-detail',
path: ':botId',
component: () => import('@/pages/bots/detail.vue'),
meta: {
breadcrumb: (route: RouteLocationNormalized) => route.params.botId,
},
},
],
},
{
name: 'models',
path: '/models',
component: () => import('@/pages/models/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.models'),
},
},
{
name: 'settings',
path: '/settings',
component: () => import('@/pages/settings/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.settings'),
},
},
{
name: 'mcp',
path: '/mcp',
component: () => import('@/pages/mcp/index.vue'),
meta: {
breadcrumb: 'MCP',
},
},
{
name: 'platform',
path: '/platform',
component: () => import('@/pages/platform/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.platform'),
},
},
]
},
{
name: 'Login',
path: '/login',
component: () => import('@/pages/login/index.vue')
}, {
name: 'Main',
component: () => import('@/pages/main-section/index.vue'),
path: '/main',
redirect: '/main/chat',
meta: {
breadcrumb: i18nRef('breadcrumb.main')
},
children: [{
name: 'chat',
path: 'chat',
component: () => import('@/pages/chat/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.chat')
}
}, {
name: 'home',
path: 'home',
component: () => import('@/pages/home/index.vue'),
meta: {
breadcrumb: i18nRef('home.title')
}
}, {
path: 'bots',
component: { render: () => h(RouterView) },
meta: {
breadcrumb: i18nRef('sidebar.bots')
},
children: [
{
name: 'bots',
path: '',
component: () => import('@/pages/bots/index.vue'),
},
{
name: 'bot-detail',
path: ':botId',
component: () => import('@/pages/bots/detail.vue'),
meta: {
breadcrumb: (route: RouteLocationNormalized) => route.params.botId,
},
},
],
}, {
name: 'models',
path: 'models',
component: () => import('@/pages/models/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.models')
}
}, {
name: 'settings',
path: 'settings',
component: () => import('@/pages/settings/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.settings')
}
}, {
name: 'mcp',
path: 'mcp',
component: () => import('@/pages/mcp/index.vue'),
meta: {
breadcrumb: 'MCP'
}
}, {
name: 'platform',
path: 'platform',
component: () => import('@/pages/platform/index.vue'),
meta: {
breadcrumb: i18nRef('sidebar.platform')
}
}]
}
component: () => import('@/pages/login/index.vue'),
},
]
const router = createRouter({
history: createWebHistory(),
routes,
})
router.beforeEach((to) => {
const token = localStorage.getItem('token')
if (to.fullPath !== '/login') {
return token ? true : { name: 'Login' }
} else {
return token ? { path:'Main' } : true
return token ? { path: '/chat' } : true
}
})
export default router
export default router