|
@@ -1,5 +1,5 @@
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref } from 'vue'
|
|
|
|
|
|
|
+import { ref, computed } from 'vue'
|
|
|
import { useRouter } from 'vue-router'
|
|
import { useRouter } from 'vue-router'
|
|
|
import Button from 'primevue/button'
|
|
import Button from 'primevue/button'
|
|
|
import Menu from 'primevue/menu'
|
|
import Menu from 'primevue/menu'
|
|
@@ -17,64 +17,107 @@ import { useUserStore } from '@/stores/user'
|
|
|
import { resetPasswordApi } from '@/services/api'
|
|
import { resetPasswordApi } from '@/services/api'
|
|
|
import { zodResolver } from '@primevue/forms/resolvers/zod'
|
|
import { zodResolver } from '@primevue/forms/resolvers/zod'
|
|
|
import { z } from 'zod'
|
|
import { z } from 'zod'
|
|
|
|
|
+import { UserRole } from '@/enums'
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
const router = useRouter()
|
|
|
const sidebarVisible = ref(false)
|
|
const sidebarVisible = ref(false)
|
|
|
const userMenuRef = ref()
|
|
const userMenuRef = ref()
|
|
|
const toast = useToast()
|
|
const toast = useToast()
|
|
|
|
|
+const userStore = useUserStore()
|
|
|
|
|
+
|
|
|
const showUserMenu = (event) => {
|
|
const showUserMenu = (event) => {
|
|
|
userMenuRef.value.toggle(event)
|
|
userMenuRef.value.toggle(event)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const navItems = [
|
|
|
|
|
|
|
+const allNavItems = [
|
|
|
{
|
|
{
|
|
|
label: '首页',
|
|
label: '首页',
|
|
|
icon: 'pi pi-fw pi-home',
|
|
icon: 'pi pi-fw pi-home',
|
|
|
- name: 'dashboard'
|
|
|
|
|
|
|
+ name: 'dashboard',
|
|
|
|
|
+ roles: ['admin', 'team', 'user']
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
label: '团队管理',
|
|
label: '团队管理',
|
|
|
icon: 'pi pi-fw pi-building',
|
|
icon: 'pi pi-fw pi-building',
|
|
|
|
|
+ roles: ['admin', 'team'],
|
|
|
items: [
|
|
items: [
|
|
|
{
|
|
{
|
|
|
label: '团队信息',
|
|
label: '团队信息',
|
|
|
icon: 'pi pi-fw pi-info-circle',
|
|
icon: 'pi pi-fw pi-info-circle',
|
|
|
- name: 'team-info'
|
|
|
|
|
|
|
+ name: 'team-info',
|
|
|
|
|
+ roles: ['admin', 'team']
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
label: '成员信息',
|
|
label: '成员信息',
|
|
|
icon: 'pi pi-fw pi-users',
|
|
icon: 'pi pi-fw pi-users',
|
|
|
- name: 'team-members'
|
|
|
|
|
|
|
+ name: 'team-members',
|
|
|
|
|
+ roles: ['admin', 'team']
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
label: '推广链接',
|
|
label: '推广链接',
|
|
|
icon: 'pi pi-fw pi-link',
|
|
icon: 'pi pi-fw pi-link',
|
|
|
- name: 'link'
|
|
|
|
|
|
|
+ name: 'link',
|
|
|
|
|
+ roles: ['admin', 'team', 'user']
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
label: '财务记录',
|
|
label: '财务记录',
|
|
|
icon: 'pi pi-fw pi-credit-card',
|
|
icon: 'pi pi-fw pi-credit-card',
|
|
|
- name: 'finance'
|
|
|
|
|
|
|
+ name: 'finance',
|
|
|
|
|
+ roles: ['admin', 'team']
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
label: '收入记录',
|
|
label: '收入记录',
|
|
|
icon: 'pi pi-fw pi-wallet',
|
|
icon: 'pi pi-fw pi-wallet',
|
|
|
- name: 'income'
|
|
|
|
|
|
|
+ name: 'income',
|
|
|
|
|
+ roles: ['admin', 'team', 'user']
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
label: '用户管理',
|
|
label: '用户管理',
|
|
|
icon: 'pi pi-fw pi-user',
|
|
icon: 'pi pi-fw pi-user',
|
|
|
- name: 'user'
|
|
|
|
|
|
|
+ name: 'user',
|
|
|
|
|
+ roles: ['admin']
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
label: '参数配置',
|
|
label: '参数配置',
|
|
|
icon: 'pi pi-fw pi-cog',
|
|
icon: 'pi pi-fw pi-cog',
|
|
|
- name: 'sys-config'
|
|
|
|
|
|
|
+ name: 'sys-config',
|
|
|
|
|
+ roles: ['admin']
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
+// 根据用户角色过滤菜单项
|
|
|
|
|
+const navItems = computed(() => {
|
|
|
|
|
+ const userRole = userStore.userInfo?.role || 'user'
|
|
|
|
|
+
|
|
|
|
|
+ const filterItemsByRole = (items) => {
|
|
|
|
|
+ return items
|
|
|
|
|
+ .map((item) => {
|
|
|
|
|
+ if (item.roles && !item.roles.includes(userRole)) {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果有子菜单,也需要过滤
|
|
|
|
|
+ if (item.items) {
|
|
|
|
|
+ const filteredSubItems = filterItemsByRole(item.items)
|
|
|
|
|
+ if (filteredSubItems.length === 0) {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...item,
|
|
|
|
|
+ items: filteredSubItems
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return item
|
|
|
|
|
+ })
|
|
|
|
|
+ .filter((item) => item !== null)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return filterItemsByRole(allNavItems)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
const userMenuItems = [
|
|
const userMenuItems = [
|
|
|
{
|
|
{
|
|
|
label: '修改密码',
|
|
label: '修改密码',
|