diff --git a/messages/en.json b/messages/en.json index 85c59a8..f118339 100644 --- a/messages/en.json +++ b/messages/en.json @@ -60,7 +60,7 @@ "graphicCode": "Graphic verification code" }, "menu-manage":{ - "title":"Title", + "title":"Menu", "name":"Menu Name", "nameTip":"Please fill in the internationalization field", "path":"Path", diff --git a/src/components/GlobalHeader/index.tsx b/src/components/GlobalHeader/index.tsx index 9ae22f8..79e7d17 100644 --- a/src/components/GlobalHeader/index.tsx +++ b/src/components/GlobalHeader/index.tsx @@ -2,7 +2,7 @@ * @Author: 白雾茫茫丶 * @Date: 2024-12-10 11:01:36 * @LastEditors: 白雾茫茫丶 - * @LastEditTime: 2025-01-15 09:57:17 + * @LastEditTime: 2025-01-15 16:08:43 * @Description: 头部布局 */ 'use client'; @@ -19,24 +19,33 @@ import ThemeModeButton from '@/components/ThemeModeButton'; import { SidebarTrigger } from '@/components/ui/sidebar'; import { MenuIconMap } from '@/constants/icon'; import { ROUTES_NAME } from '@/enums'; +import { useUserStore } from '@/store/userStore'; export default function GlobalHeader() { const t = useTranslations('Route'); const segments = useSelectedLayoutSegments(); + + // 菜单列表 + const menuList = useUserStore((state) => state.menuList); return (
- {segments.map((path) => ( - {MenuIconMap[path as ROUTES_NAME]}
} - > - {t(path as ROUTES_NAME)} - - ))} + {segments.map((path) => { + const menuItem = menuList.find((item) => item.name === path) as App.SystemManage.Menu; + return ( + {MenuIconMap[menuItem.icon]} : undefined + } + > + {t(path as ROUTES_NAME)} + + ); + })}
diff --git a/src/components/NavMain/index.tsx b/src/components/NavMain/index.tsx index b0f276a..d2ad3d2 100644 --- a/src/components/NavMain/index.tsx +++ b/src/components/NavMain/index.tsx @@ -2,7 +2,7 @@ * @Author: 白雾茫茫丶 * @Date: 2024-12-06 14:47:26 * @LastEditors: 白雾茫茫丶 - * @LastEditTime: 2025-01-15 10:11:40 + * @LastEditTime: 2025-01-15 15:59:51 * @Description: 菜单布局 */ 'use client'; @@ -26,6 +26,7 @@ import { MenuIconMap } from '@/constants/icon'; import { get } from '@/lib/radash'; import { convertFlatDataToTree } from '@/lib/utils'; import { getMenuList } from '@/services/system-manage/menu-manage'; +import { useUserStore } from '@/store/userStore'; export default function NavMain() { const t = useTranslations('Route'); @@ -38,6 +39,7 @@ export default function NavMain() { // 获取菜单列表 const { data: menuList = [] } = useRequest(async () => { const res = get(await getMenuList(), 'data', []); + useUserStore.setState({ menuList: res }); return convertFlatDataToTree(res); }); diff --git a/src/middleware.ts b/src/middleware.ts index 25c6a15..3591d7c 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -2,7 +2,7 @@ * @Author: 白雾茫茫丶 * @Date: 2025-01-03 15:16:03 * @LastEditors: 白雾茫茫丶 - * @LastEditTime: 2025-01-13 13:54:37 + * @LastEditTime: 2025-01-15 15:13:52 * @Description: 全局中间件 */ @@ -29,7 +29,9 @@ export default auth(async (req: NextRequest) => { return NextResponse.json(responseMessage(null, '请先登录', -1)); } // 如果不是GET请求,返回一个带有消息的响应 - // return NextResponse.json(responseMessage(null, '演示系统,禁止操作', -1)); + if (!isProtectedRoute) { + return NextResponse.json(responseMessage(null, '演示系统,禁止操作', -1)); + } } // 检查是否为不受保护的路由 diff --git a/src/store/userStore.ts b/src/store/userStore.ts new file mode 100644 index 0000000..f2ff8cc --- /dev/null +++ b/src/store/userStore.ts @@ -0,0 +1,18 @@ +/* + * @Author: 白雾茫茫丶 + * @Date: 2025-01-15 15:54:17 + * @LastEditors: 白雾茫茫丶 + * @LastEditTime: 2025-01-15 15:57:00 + * @Description: 用户相关信息 + */ +import { create } from 'zustand'; + +type UserState = { + menuList: App.SystemManage.Menu[]; + setMenuList: (list: App.SystemManage.Menu[]) => void; +}; + +export const useUserStore = create((set) => ({ + menuList: [], + setMenuList: (list) => set({ menuList: list }), +}));