Files
digital-psychology/apps/admin-h5/src/router/index.ts
T
jackyu66gitandCursor 1db5fcc018 feat(ECR-047): FunnelDefinition 写面闭环并 Closed
growth.write POST/PUT · migration 000056 · 无新 C 端 · Loop STOP

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 22:14:21 +08:00

83 lines
3.8 KiB
TypeScript

import { createRouter, createWebHistory } from 'vue-router'
import { getToken } from '@/api/client'
import { useAuthStore } from '@/stores/auth'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{ path: '/login', name: 'login', component: () => import('@/pages/LoginPage.vue'), meta: { public: true } },
{
path: '/',
component: () => import('@/layouts/AdminShell.vue'),
children: [
{ path: '', name: 'dashboard', component: () => import('@/pages/DashboardPage.vue') },
{ path: 'analytics', name: 'analytics', component: () => import('@/pages/AnalyticsPage.vue') },
{ path: 'content', name: 'content', component: () => import('@/pages/ContentPage.vue') },
{ path: 'users', name: 'users', component: () => import('@/pages/UsersPage.vue') },
{ path: 'users/:id', name: 'user', component: () => import('@/pages/UserDetailPage.vue') },
{ path: 'orders', name: 'orders', component: () => import('@/pages/OrdersPage.vue') },
{ path: 'plans', name: 'plans', component: () => import('@/pages/MembershipPlansPage.vue') },
{ path: 'codes', name: 'codes', component: () => import('@/pages/RedemptionPage.vue') },
{ path: 'pricing', name: 'pricing', component: () => import('@/pages/PricingPage.vue'), meta: { permission: 'admin.membership.plans.read' } },
{ path: 'ask', name: 'ask', component: () => import('@/pages/AskPage.vue') },
{ path: 'safety', name: 'safety', component: () => import('@/pages/SafetyPage.vue') },
{ path: 'ai', name: 'ai', component: () => import('@/pages/AIConfigPage.vue') },
{ path: 'crisis', name: 'crisis', component: () => import('@/pages/CrisisPage.vue') },
{ path: 'cms', name: 'cms', component: () => import('@/pages/CMSPage.vue') },
{
path: 'star-configs',
name: 'star-configs',
component: () => import('@/pages/StarConfigPage.vue'),
meta: { permission: 'admin.explore.read' },
},
{
path: 'rhythm-configs',
name: 'rhythm-configs',
component: () => import('@/pages/RhythmConfigPage.vue'),
meta: { permission: 'admin.explore.read' },
},
{
path: 'image-card-decks',
name: 'image-card-decks',
component: () => import('@/pages/ImageCardDeckPage.vue'),
meta: { permission: 'admin.explore.read' },
},
{
path: 'scale-definitions',
name: 'scale-definitions',
component: () => import('@/pages/ScaleDefinitionPage.vue'),
meta: { permission: 'admin.explore.read' },
},
{
path: 'funnel-definitions',
name: 'funnel-definitions',
component: () => import('@/pages/FunnelDefinitionPage.vue'),
meta: { permission: 'admin.growth.read' },
},
{ path: 'catalogs', name: 'catalogs', component: () => import('@/pages/CatalogHubPage.vue') },
{ path: 'push', name: 'push', component: () => import('@/pages/PushJobsPage.vue') },
{ path: 'admins', name: 'admins', component: () => import('@/pages/AdminsPage.vue'), meta: { superOnly: true } },
{ path: 'audit', name: 'audit', component: () => import('@/pages/AuditPage.vue') },
],
},
],
})
router.beforeEach(async (to) => {
if (to.meta.public) return true
if (!getToken()) return { name: 'login', query: { redirect: to.fullPath } }
if (to.meta.superOnly) {
const auth = useAuthStore()
if (!auth.username) await auth.hydrate()
if (!auth.isSuper) return { name: 'dashboard' }
}
if (typeof to.meta.permission === 'string') {
const auth = useAuthStore()
if (!auth.username) await auth.hydrate()
if (!auth.can(to.meta.permission)) return { name: 'dashboard' }
}
return true
})
export default router