@@ -81,36 +81,51 @@ const route = useRoute()
8181const hoveredIndex = ref <number | null >(null )
8282const isNavHovered = ref (false )
8383
84- const menuItems = computed (() => [
85- {
86- icon: Home ,
87- label: t (' nav.home' ),
88- href: ' /' ,
89- gradient: ' radial-gradient(circle, rgba(59,130,246,0.15) 0%, rgba(37,99,235,0.06) 50%, rgba(29,78,216,0) 100%)' ,
90- iconColor: ' text-blue-500' ,
91- },
92- {
93- icon: UserPlus ,
94- label: t (' nav.register' ),
95- href: ' /register' ,
96- gradient: ' radial-gradient(circle, rgba(249,115,22,0.15) 0%, rgba(234,88,12,0.06) 50%, rgba(194,65,12,0) 100%)' ,
97- iconColor: ' text-orange-500' ,
98- },
99- {
100- icon: LogIn ,
101- label: t (' nav.login' ),
102- href: ' /login' ,
103- gradient: ' radial-gradient(circle, rgba(34,197,94,0.15) 0%, rgba(22,163,74,0.06) 50%, rgba(21,128,61,0) 100%)' ,
104- iconColor: ' text-green-500' ,
105- },
106- {
107- icon: Settings ,
108- label: t (' nav.admin' ),
109- href: ' /admin' ,
110- gradient: ' radial-gradient(circle, rgba(239,68,68,0.15) 0%, rgba(220,38,38,0.06) 50%, rgba(185,28,28,0) 100%)' ,
111- iconColor: ' text-red-500' ,
112- },
113- ])
84+ const isAdminLoggedIn = computed (() => {
85+ // 绑定路由,确保登录/跳转后菜单可及时响应
86+ route .fullPath
87+ return !! localStorage .getItem (' admin_token' )
88+ })
89+
90+ const menuItems = computed (() => {
91+ const items = [
92+ {
93+ icon: Home ,
94+ label: t (' nav.home' ),
95+ href: ' /' ,
96+ gradient: ' radial-gradient(circle, rgba(59,130,246,0.15) 0%, rgba(37,99,235,0.06) 50%, rgba(29,78,216,0) 100%)' ,
97+ iconColor: ' text-blue-500' ,
98+ },
99+ ]
100+
101+ if (isAdminLoggedIn .value ) {
102+ items .push ({
103+ icon: Settings ,
104+ label: t (' nav.admin' ),
105+ href: ' /admin' ,
106+ gradient: ' radial-gradient(circle, rgba(239,68,68,0.15) 0%, rgba(220,38,38,0.06) 50%, rgba(185,28,28,0) 100%)' ,
107+ iconColor: ' text-red-500' ,
108+ })
109+ } else {
110+ items .push ({
111+ icon: UserPlus ,
112+ label: t (' nav.register' ),
113+ href: ' /register' ,
114+ gradient: ' radial-gradient(circle, rgba(249,115,22,0.15) 0%, rgba(234,88,12,0.06) 50%, rgba(194,65,12,0) 100%)' ,
115+ iconColor: ' text-orange-500' ,
116+ })
117+
118+ items .push ({
119+ icon: LogIn ,
120+ label: t (' nav.login' ),
121+ href: ' /login' ,
122+ gradient: ' radial-gradient(circle, rgba(34,197,94,0.15) 0%, rgba(22,163,74,0.06) 50%, rgba(21,128,61,0) 100%)' ,
123+ iconColor: ' text-green-500' ,
124+ })
125+ }
126+
127+ return items
128+ })
114129
115130const isActive = (href : string ) => {
116131 if (href === ' /' ) {
@@ -321,4 +336,4 @@ const isActive = (href: string) => {
321336 display : none !important ;
322337 }
323338}
324- </style >
339+ </style >
0 commit comments