支持配置后台页面入口
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const DEFAULT_ADMIN_BASE_PATH = '/admin'
|
||||
|
||||
function normalizeAdminBasePath(value: string | undefined) {
|
||||
const raw = (value || DEFAULT_ADMIN_BASE_PATH).trim()
|
||||
if (!raw || raw === '/') return DEFAULT_ADMIN_BASE_PATH
|
||||
const withLeadingSlash = raw.startsWith('/') ? raw : `/${raw}`
|
||||
return withLeadingSlash.replace(/\/+$/, '') || DEFAULT_ADMIN_BASE_PATH
|
||||
}
|
||||
|
||||
export const ADMIN_BASE_PATH = normalizeAdminBasePath(import.meta.env.VITE_ADMIN_BASE_PATH)
|
||||
|
||||
export function adminPath(path = '') {
|
||||
const suffix = path.trim().replace(/^\/+/, '')
|
||||
if (!suffix) return ADMIN_BASE_PATH
|
||||
return `${ADMIN_BASE_PATH}/${suffix}`
|
||||
}
|
||||
|
||||
export const ADMIN_LOGIN_PATH = adminPath('login')
|
||||
export const ADMIN_DASHBOARD_PATH = adminPath('dashboard')
|
||||
|
||||
export function isAdminPath(path: string) {
|
||||
return path === ADMIN_BASE_PATH || path.startsWith(`${ADMIN_BASE_PATH}/`)
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ADMIN_LOGIN_PATH } from '@/shared/utils/adminPath'
|
||||
|
||||
export type AuthScope = 'user' | 'admin'
|
||||
|
||||
export interface AuthTokenPair {
|
||||
@@ -53,7 +55,7 @@ export function clearAuthStorage(scope: AuthScope) {
|
||||
}
|
||||
|
||||
export function getLoginPath(scope: AuthScope, currentPath: string) {
|
||||
if (scope === 'admin') return '/admin/login'
|
||||
if (scope === 'admin') return ADMIN_LOGIN_PATH
|
||||
return currentPath.startsWith('/m') ? '/m/login' : '/login'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user