权限的管理和校验修改
This commit is contained in:
@@ -136,55 +136,32 @@ router.beforeEach((to, _from, next) => {
|
||||
try {
|
||||
const adminUserInfo = JSON.parse(adminUserInfoStr)
|
||||
console.log('Parsed admin user info:', adminUserInfo)
|
||||
// 管理员用户(type === 4)拥有所有权限
|
||||
if (adminUserInfo.type === 4) {
|
||||
console.log('Admin user, allowing access')
|
||||
next()
|
||||
}
|
||||
// 店长用户(type === 2)拥有所有权限
|
||||
else if (adminUserInfo.type === 2) {
|
||||
console.log('Shop manager user, allowing access')
|
||||
next()
|
||||
}
|
||||
// 美甲师用户(type === 3)需要检查权限
|
||||
else if (adminUserInfo.type === 3) {
|
||||
console.log('美甲师 user, checking permissions')
|
||||
// 获取用户权限
|
||||
const userPermissionsStr = localStorage.getItem('userPermissions')
|
||||
console.log('User permissions:', userPermissionsStr)
|
||||
if (userPermissionsStr) {
|
||||
const userPermissions = JSON.parse(userPermissionsStr)
|
||||
// 检查用户是否拥有该权限
|
||||
if (userPermissions.includes(permissionCode)) {
|
||||
console.log('User has required permission:', permissionCode)
|
||||
next()
|
||||
} else {
|
||||
console.log('User missing required permission:', permissionCode)
|
||||
// 权限不足,检查是否是首页
|
||||
if (to.path === '/admin') {
|
||||
// 如果是首页,允许访问(作为默认页面)
|
||||
console.log('Allowing access to home as default page')
|
||||
next()
|
||||
} else {
|
||||
// 对于其他页面,重定向到首页
|
||||
next('/admin')
|
||||
}
|
||||
}
|
||||
// 所有用户类型都根据实际权限检查
|
||||
console.log('Checking permissions for user type:', adminUserInfo.type)
|
||||
// 获取用户权限
|
||||
const userPermissionsStr = localStorage.getItem('userPermissions')
|
||||
console.log('User permissions:', userPermissionsStr)
|
||||
if (userPermissionsStr) {
|
||||
const userPermissions = JSON.parse(userPermissionsStr)
|
||||
// 检查用户是否拥有该权限
|
||||
if (userPermissions.includes(permissionCode)) {
|
||||
console.log('User has required permission:', permissionCode)
|
||||
next()
|
||||
} else {
|
||||
console.log('No user permissions found')
|
||||
// 没有权限信息,允许访问首页临时,直到权限加载完成
|
||||
if (to.path === '/admin') {
|
||||
console.log('Allowing access to home to load permissions')
|
||||
next()
|
||||
} else {
|
||||
// 对于其他页面,重定向到首页
|
||||
next('/admin')
|
||||
}
|
||||
console.log('User missing required permission:', permissionCode)
|
||||
// 权限不足,重定向到首页
|
||||
next('/admin')
|
||||
}
|
||||
} else {
|
||||
console.log('Unknown user type, redirecting to login')
|
||||
// 未知用户类型,重定向到登录页
|
||||
next('/admin/login')
|
||||
console.log('No user permissions found')
|
||||
// 没有权限信息,允许访问首页临时,直到权限加载完成
|
||||
if (to.path === '/admin') {
|
||||
console.log('Allowing access to home to load permissions')
|
||||
next()
|
||||
} else {
|
||||
// 对于其他页面,重定向到首页
|
||||
next('/admin')
|
||||
}
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse user info:', parseError)
|
||||
|
||||
Reference in New Issue
Block a user