优惠券相关管理功能实现
This commit is contained in:
@@ -43,7 +43,7 @@ const router = createRouter({
|
||||
path: '/shop/:id',
|
||||
name: 'shop-detail',
|
||||
component: () => import('../views/ShopDetailView.vue'),
|
||||
meta: { requiresAuth: true, isAdmin: false }
|
||||
meta: { requiresAuth: true, hideNav: true, isAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/wishlist',
|
||||
@@ -148,15 +148,26 @@ router.beforeEach((to, _from, next) => {
|
||||
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)
|
||||
// 权限不足,重定向到首页
|
||||
next('/admin')
|
||||
try {
|
||||
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)
|
||||
// 权限不足,重定向到首页
|
||||
next('/admin')
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse user permissions:', parseError)
|
||||
// 解析失败,允许访问首页临时,直到权限加载完成
|
||||
if (to.path === '/admin') {
|
||||
console.log('Allowing access to home due to parse error')
|
||||
next()
|
||||
} else {
|
||||
next('/admin')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('No user permissions found')
|
||||
@@ -171,9 +182,13 @@ router.beforeEach((to, _from, next) => {
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse user info:', parseError)
|
||||
// 解析失败,允许访问所有页面临时,直到权限加载完成
|
||||
console.log('Allowing temporary access due to parse error')
|
||||
next()
|
||||
// 解析失败,允许访问首页临时,直到权限加载完成
|
||||
if (to.path === '/admin') {
|
||||
console.log('Allowing access to home due to parse error')
|
||||
next()
|
||||
} else {
|
||||
next('/admin')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('No user info found, redirecting to login')
|
||||
@@ -182,8 +197,13 @@ router.beforeEach((to, _from, next) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析用户信息失败:', error)
|
||||
// 解析失败,重定向到登录页
|
||||
next('/admin/login')
|
||||
// 解析失败,允许访问首页临时,直到权限加载完成
|
||||
if (to.path === '/admin') {
|
||||
console.log('Allowing access to home due to error')
|
||||
next()
|
||||
} else {
|
||||
next('/admin')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 没有权限要求,直接通过
|
||||
|
||||
Reference in New Issue
Block a user