支持配置后台页面入口
This commit is contained in:
@@ -1,131 +1,133 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
import { adminPath, ADMIN_DASHBOARD_PATH } from '@/shared/utils/adminPath'
|
||||
|
||||
const adminMeta = { layout: 'admin', requiresAdmin: true }
|
||||
|
||||
export const adminRoutes: RouteRecordRaw[] = [
|
||||
{ path: '/admin', redirect: '/admin/dashboard' },
|
||||
{ path: adminPath(), redirect: ADMIN_DASHBOARD_PATH },
|
||||
{
|
||||
path: '/admin/login',
|
||||
path: adminPath('login'),
|
||||
name: 'admin-login',
|
||||
component: () => import('@/features/admin/views/AdminLoginView.vue'),
|
||||
meta: { layout: 'blank' },
|
||||
},
|
||||
{
|
||||
path: '/admin/dashboard',
|
||||
path: adminPath('dashboard'),
|
||||
name: 'admin-dashboard',
|
||||
component: () => import('@/features/admin/views/AdminDashboardView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/users',
|
||||
path: adminPath('users'),
|
||||
name: 'admin-users',
|
||||
component: () => import('@/features/admin/views/AdminUsersView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/orders',
|
||||
path: adminPath('orders'),
|
||||
name: 'admin-orders',
|
||||
component: () => import('@/features/admin/views/AdminOrdersView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/orders/:id',
|
||||
path: adminPath('orders/:id'),
|
||||
name: 'admin-order-detail',
|
||||
component: () => import('@/features/admin/views/AdminOrderDetailView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/listings',
|
||||
path: adminPath('listings'),
|
||||
name: 'admin-listings',
|
||||
component: () => import('@/features/admin/views/AdminListingsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/listings/:id',
|
||||
path: adminPath('listings/:id'),
|
||||
name: 'admin-listing-detail',
|
||||
component: () => import('@/features/admin/views/AdminListingDetailView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/listings/review',
|
||||
path: adminPath('listings/review'),
|
||||
name: 'admin-listing-review',
|
||||
component: () => import('@/features/admin/views/AdminListingReviewView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/disputes',
|
||||
path: adminPath('disputes'),
|
||||
name: 'admin-disputes',
|
||||
component: () => import('@/features/admin/views/AdminDisputesView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/chats',
|
||||
path: adminPath('chats'),
|
||||
name: 'admin-chats',
|
||||
component: () => import('@/features/admin/views/AdminChatsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/finance/dashboard',
|
||||
path: adminPath('finance/dashboard'),
|
||||
name: 'admin-finance-dashboard',
|
||||
component: () => import('@/features/admin/views/AdminFinanceDashboardView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/finance/details',
|
||||
path: adminPath('finance/details'),
|
||||
name: 'admin-finance-details',
|
||||
component: () => import('@/features/admin/views/AdminFinanceDetailsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/wallet-ledger',
|
||||
path: adminPath('wallet-ledger'),
|
||||
name: 'admin-wallet-ledger',
|
||||
component: () => import('@/features/admin/views/AdminWalletLedgerView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/payments',
|
||||
path: adminPath('payments'),
|
||||
name: 'admin-payments',
|
||||
component: () => import('@/features/admin/views/AdminPaymentsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/withdrawals',
|
||||
path: adminPath('withdrawals'),
|
||||
name: 'admin-withdrawals',
|
||||
component: () => import('@/features/admin/views/AdminWithdrawalsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/system-configs',
|
||||
path: adminPath('system-configs'),
|
||||
name: 'admin-system-configs',
|
||||
component: () => import('@/features/admin/views/AdminSystemConfigsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/payment-configs',
|
||||
path: adminPath('payment-configs'),
|
||||
name: 'admin-payment-configs',
|
||||
component: () => import('@/features/admin/views/AdminPaymentConfigsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/audit-logs',
|
||||
path: adminPath('audit-logs'),
|
||||
name: 'admin-audit-logs',
|
||||
component: () => import('@/features/admin/views/AdminAuditLogsView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/admin-users',
|
||||
path: adminPath('admin-users'),
|
||||
name: 'admin-admin-users',
|
||||
component: () => import('@/features/admin/views/AdminMgrUsersView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/roles',
|
||||
path: adminPath('roles'),
|
||||
name: 'admin-roles',
|
||||
component: () => import('@/features/admin/views/AdminRolesView.vue'),
|
||||
meta: adminMeta,
|
||||
},
|
||||
{
|
||||
path: '/admin/announcements',
|
||||
path: adminPath('announcements'),
|
||||
name: 'admin-announcements',
|
||||
component: () => import('@/features/admin/views/AdminAnnouncementsView.vue'),
|
||||
meta: adminMeta,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { useAdminSessionStore } from '@/stores/adminSession'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
import { getAccessToken, getLoginPath } from '@/shared/utils/authStorage'
|
||||
import { ADMIN_DASHBOARD_PATH, ADMIN_LOGIN_PATH } from '@/shared/utils/adminPath'
|
||||
import { accountRoutes } from './accountRoutes'
|
||||
import { adminRoutes } from './adminRoutes'
|
||||
import { isMobileHost, isMobileDevice, getMobilePath, getPcPath } from './mobileHost'
|
||||
@@ -77,11 +78,11 @@ router.beforeEach(async to => {
|
||||
|
||||
const adminSession = useAdminSessionStore()
|
||||
adminSession.syncFromStorage()
|
||||
if (to.path === '/admin/login') {
|
||||
if (to.path === ADMIN_LOGIN_PATH) {
|
||||
if (!adminSession.hasSessionHint) return true
|
||||
try {
|
||||
await adminSession.loadMe()
|
||||
return '/admin/dashboard'
|
||||
return ADMIN_DASHBOARD_PATH
|
||||
} catch {
|
||||
adminSession.logout()
|
||||
return true
|
||||
@@ -98,7 +99,7 @@ router.beforeEach(async to => {
|
||||
}
|
||||
} catch {
|
||||
adminSession.logout()
|
||||
return { path: '/admin/login', query: { redirect: to.fullPath } }
|
||||
return { path: ADMIN_LOGIN_PATH, query: { redirect: to.fullPath } }
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isAdminPath } from '@/shared/utils/adminPath'
|
||||
|
||||
export function isMobileHost(hostname = window.location.hostname) {
|
||||
return hostname === 'm.localhost' || hostname.startsWith('m.')
|
||||
}
|
||||
@@ -14,7 +16,7 @@ export function getMobilePath(path: string): string {
|
||||
if (path === '/' || path === '') {
|
||||
return '/m'
|
||||
}
|
||||
if (path === '/m' || path.startsWith('/m/') || path.startsWith('/admin')) {
|
||||
if (path === '/m' || path.startsWith('/m/') || isAdminPath(path)) {
|
||||
return path
|
||||
}
|
||||
|
||||
@@ -44,7 +46,7 @@ export function getMobilePath(path: string): string {
|
||||
}
|
||||
|
||||
export function getPcPath(path: string): string {
|
||||
if ((path !== '/m' && !path.startsWith('/m/')) || path.startsWith('/admin')) {
|
||||
if ((path !== '/m' && !path.startsWith('/m/')) || isAdminPath(path)) {
|
||||
return path
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user