修复:修复无店铺后台登录引导

This commit is contained in:
xiaowang
2026-03-21 12:37:52 +08:00
parent 4d4439dc94
commit 4d5ea2996b
8 changed files with 162 additions and 23 deletions
+16 -6
View File
@@ -176,6 +176,17 @@ router.beforeEach((to, _from, next) => {
if (isAdminRoute) {
const adminToken = localStorage.getItem('adminAccessToken') || sessionStorage.getItem('adminAccessToken')
const adminUserInfoStr = localStorage.getItem('adminUserInfo')
let adminUserInfo: any = null
let isBootstrapAdmin = false
if (adminUserInfoStr) {
try {
adminUserInfo = JSON.parse(adminUserInfoStr)
isBootstrapAdmin = adminUserInfo?.type === 4 && !adminUserInfo?.shopId
} catch (parseError) {
console.error('Failed to parse admin user info in guard:', parseError)
}
}
if (requiresAuth && (!adminToken || !adminUserInfoStr)) {
// 清除可能存在的过期信息
@@ -186,11 +197,12 @@ router.beforeEach((to, _from, next) => {
sessionStorage.removeItem('adminAccessToken')
next('/admin/login')
} else if (to.path === '/admin/login' && adminToken && adminUserInfoStr) {
next('/admin/dashboard')
next(isBootstrapAdmin ? '/admin/shops' : '/admin/dashboard')
} else {
// 检查用户权限
const permissionCode = to.meta.permissionCode as string
if (permissionCode) {
const fallbackAdminPath = isBootstrapAdmin ? '/admin/shops' : '/admin'
// 获取用户信息
try {
const adminUserInfoStr = localStorage.getItem('adminUserInfo')
@@ -206,8 +218,7 @@ router.beforeEach((to, _from, next) => {
if (userPermissions.includes(permissionCode)) {
next()
} else {
// 权限不足,重定向到首页
next('/admin')
next(fallbackAdminPath)
}
} catch (parseError) {
console.error('Failed to parse user permissions:', parseError)
@@ -215,7 +226,7 @@ router.beforeEach((to, _from, next) => {
if (to.path === '/admin') {
next()
} else {
next('/admin')
next(fallbackAdminPath)
}
}
} else {
@@ -223,8 +234,7 @@ router.beforeEach((to, _from, next) => {
if (to.path === '/admin') {
next()
} else {
// 对于其他页面,重定向到首页
next('/admin')
next(fallbackAdminPath)
}
}
} catch (parseError) {