From a00488be5d33eb85ec2abc2c14bd4e247e18ed2d Mon Sep 17 00:00:00 2001 From: siujamo Date: Mon, 5 Jan 2026 09:59:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/dashboard-layout/index.tsx | 27 +++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/layouts/dashboard-layout/index.tsx b/src/layouts/dashboard-layout/index.tsx index d82943d..51d494f 100644 --- a/src/layouts/dashboard-layout/index.tsx +++ b/src/layouts/dashboard-layout/index.tsx @@ -1,16 +1,27 @@ import React, { useEffect, useMemo, useState } from "react" import { useNavigate } from "react-router" -import { App, Avatar, Breadcrumb, Dropdown, Layout, Menu, type MenuProps, Space } from "antd" +import { + App, + Avatar, + Breadcrumb, + Dropdown, + Layout, + Menu, + type MenuProps, + message, + Space, +} from "antd" import { DownOutlined } from "@ant-design/icons" import { ApplicationLogo } from "@/components/icon" import { useAppDispatch, useAppSelector } from "@/store" import { useAntBreadcrumbs } from "@/hooks" import { logout } from "@/store/auth-slice" import { MenuApi } from "@/api" -import type { AxiosError } from "axios" +import axios, { type AxiosError } from "axios" import type { TreeNode } from "@/types/tree" import type { MenuItem } from "@/types/entity" import { AppUtils } from "@/utils" +import type { GeneralErrorResponse } from "@/types/web/response" const { Header, Footer, Sider, Content } = Layout type AntMenuItem = Required["items"][number] @@ -41,7 +52,7 @@ function transformMenuData(nodes: TreeNode[]): AntMenuItem[] { } export default function DashboardLayout({ children }: { children: React.ReactNode }) { - const { modal } = App.useApp() + const { modal, message } = App.useApp() const user = useAppSelector((store) => store.auth.user!) const dispatch = useAppDispatch() const breadcrumbItems = useAntBreadcrumbs() @@ -71,8 +82,14 @@ export default function DashboardLayout({ children }: { children: React.ReactNod setMenuItems(transformMenuData(response)) }) .catch((error: unknown) => { - const err = error as AxiosError - console.log(err) + console.log(error) + const errorMessage = + axios.isAxiosError(error) && error.response?.data.message + ? error.response?.data.message + : "无法读取菜单数据" + void message.error({ + content: errorMessage, + }) }) }, [])