From 4b28baa80f3e2c29abb89589028ce2d73e5bfb59 Mon Sep 17 00:00:00 2001 From: xiaowang Date: Thu, 26 Feb 2026 22:51:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E7=9A=84=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=92=8C=E6=A0=A1=E9=AA=8C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/src/router/index.ts | 69 ++++-------- Frontend/src/views/admin/AdminLayout.vue | 10 +- Frontend/src/views/admin/PermissionsView.vue | 10 +- Frontend/src/views/admin/ProductsView.vue | 6 +- Frontend/src/views/admin/ShopsView.vue | 6 +- Frontend/src/views/admin/UsersView.vue | 8 +- .../src/main/resources/files/YumiNail.sql | 104 ++++++++++++++++++ 7 files changed, 143 insertions(+), 70 deletions(-) diff --git a/Frontend/src/router/index.ts b/Frontend/src/router/index.ts index 0ca3f4eb..96e408e7 100644 --- a/Frontend/src/router/index.ts +++ b/Frontend/src/router/index.ts @@ -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) diff --git a/Frontend/src/views/admin/AdminLayout.vue b/Frontend/src/views/admin/AdminLayout.vue index ec062d51..13c8aa08 100644 --- a/Frontend/src/views/admin/AdminLayout.vue +++ b/Frontend/src/views/admin/AdminLayout.vue @@ -148,20 +148,12 @@ const selectedKeys = ref([route.path]) const filteredMenuItems = computed(() => { // 访问 userPermissions 以建立依赖关系 userPermissions.value - // 管理员用户(type === 4)拥有所有权限 - if (userInfo.value?.type === 4) { - return menuItems - } - // 其他用户类型根据实际权限过滤菜单 + // 所有用户类型都根据实际权限过滤菜单 return menuItems.filter(item => { // 空权限码的菜单项(如首页)总是可见 if (!item.permissionCode) { return true } - // 美甲师用户(type === 3)不显示仪表盘 - if (userInfo.value?.type === 3 && item.key === '/admin/dashboard') { - return false - } return hasPermission(item.permissionCode) }) }) diff --git a/Frontend/src/views/admin/PermissionsView.vue b/Frontend/src/views/admin/PermissionsView.vue index dbebcd87..11890ba4 100644 --- a/Frontend/src/views/admin/PermissionsView.vue +++ b/Frontend/src/views/admin/PermissionsView.vue @@ -6,7 +6,7 @@