Files
geo/apps/ops-web/src/router/index.ts
T

92 lines
2.3 KiB
TypeScript
Raw Normal View History

import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { pinia } from '@/stores/pinia'
export const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/login',
name: 'login',
component: () => import('@/views/LoginView.vue'),
meta: { title: '登录' },
},
{
path: '/',
component: () => import('@/layouts/AppShell.vue'),
meta: { requiresAuth: true },
children: [
{ path: '', redirect: '/admin-users' },
{
path: 'admin-users',
name: 'admin-users',
component: () => import('@/views/AdminUsersView.vue'),
meta: { title: '用户管理' },
},
{
path: 'kol-subscriptions',
name: 'kol-subscriptions',
component: () => import('@/views/KolSubscriptionsView.vue'),
meta: { title: '订阅包审批' },
},
{
path: 'accounts',
name: 'accounts',
component: () => import('@/views/AccountsView.vue'),
meta: { title: '操作员管理' },
},
{
path: 'audits',
name: 'audits',
component: () => import('@/views/AuditLogsView.vue'),
meta: { title: '审计日志' },
},
{
path: 'site-domain-mappings',
name: 'site-domain-mappings',
component: () => import('@/views/SiteDomainMappingsView.vue'),
meta: { title: '站点映射' },
},
{
path: 'profile',
name: 'profile',
component: () => import('@/views/ProfileView.vue'),
meta: { title: '个人资料' },
},
],
},
{
path: '/:pathMatch(.*)*',
redirect: '/',
},
],
})
router.beforeEach((to) => {
const auth = useAuthStore(pinia)
if (!auth.initialized) {
auth.hydrate()
}
if (to.meta.requiresAuth && !auth.isAuthenticated) {
return {
name: 'login',
query: to.fullPath !== '/' ? { redirect: to.fullPath } : undefined,
}
}
if (to.name === 'login' && auth.isAuthenticated) {
return { name: 'admin-users' }
}
return true
})
router.afterEach((to) => {
if (typeof document !== 'undefined') {
const t = (to.meta.title as string | undefined) ?? '运营后台'
document.title = `${t} · 省心推`
}
})