From faf24f300bbd29cad78c0194fbb4822d4f98442a Mon Sep 17 00:00:00 2001 From: xiaoming <1923740402@qq.com> Date: Thu, 18 Sep 2025 10:05:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=8F`40?= =?UTF-8?q?3`=E3=80=81`404`=E3=80=81`500`=E9=A1=B5=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E5=85=A8=E5=B1=8F=E9=94=99=E8=AF=AF=E9=A1=B5=E9=9D=A2=E6=B8=85?= =?UTF-8?q?=E6=99=B0=E4=B8=94=E5=AE=89=E5=85=A8=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=20(#1226)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/en.yaml | 6 ++-- locales/zh-CN.yaml | 6 ++-- src/router/modules/error.ts | 6 ++-- src/router/modules/remaining.ts | 57 ++++++++++++++++++++++++++------- src/router/utils.ts | 12 ------- src/views/error/403.vue | 15 +++++++-- src/views/error/404.vue | 15 +++++++-- src/views/error/500.vue | 15 +++++++-- 8 files changed, 90 insertions(+), 42 deletions(-) diff --git a/locales/en.yaml b/locales/en.yaml index e0f81c91d..5ffd9f59f 100644 --- a/locales/en.yaml +++ b/locales/en.yaml @@ -80,9 +80,9 @@ menus: pureMarkdown: Markdown pureEditor: Editor pureAbnormal: Abnormal Page - pureFourZeroFour: "404" - pureFourZeroOne: "403" - pureFive: "500" + purePageNotFound: "404" + pureAccessDenied: "403" + pureServerError: "500" pureComponents: Components pureDialog: Dialog pureDrawer: Drawer diff --git a/locales/zh-CN.yaml b/locales/zh-CN.yaml index 422484349..2646e4364 100644 --- a/locales/zh-CN.yaml +++ b/locales/zh-CN.yaml @@ -80,9 +80,9 @@ menus: pureMarkdown: Markdown pureEditor: 编辑器 pureAbnormal: 异常页面 - pureFourZeroFour: "404" - pureFourZeroOne: "403" - pureFive: "500" + purePageNotFound: "404" + pureAccessDenied: "403" + pureServerError: "500" pureComponents: 组件 pureDialog: 函数式弹框 pureDrawer: 函数式抽屉 diff --git a/src/router/modules/error.ts b/src/router/modules/error.ts index bd6d7053b..cc6602de4 100644 --- a/src/router/modules/error.ts +++ b/src/router/modules/error.ts @@ -16,7 +16,7 @@ export default { name: "403", component: () => import("@/views/error/403.vue"), meta: { - title: $t("menus.pureFourZeroOne") + title: $t("menus.pureAccessDenied") } }, { @@ -24,7 +24,7 @@ export default { name: "404", component: () => import("@/views/error/404.vue"), meta: { - title: $t("menus.pureFourZeroFour") + title: $t("menus.purePageNotFound") } }, { @@ -32,7 +32,7 @@ export default { name: "500", component: () => import("@/views/error/500.vue"), meta: { - title: $t("menus.pureFive") + title: $t("menus.pureServerError") } } ] diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index 7e964198d..d7c8352c3 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -12,13 +12,46 @@ export default [ rank: 101 } }, + // 全屏403(无权访问)页面 + { + path: "/access-denied", + name: "AccessDenied", + component: () => import("@/views/error/403.vue"), + meta: { + title: $t("menus.pureAccessDenied"), + showLink: false, + rank: 102 + } + }, + // 全屏404(页面不存在)页面 + { + path: "/:pathMatch(.*)*", + name: "PageNotFound", + component: () => import("@/views/error/404.vue"), + meta: { + title: $t("menus.purePageNotFound"), + showLink: false, + rank: 103 + } + }, + // 全屏500(服务器出错)页面 + { + path: "/server-error", + name: "ServerError", + component: () => import("@/views/error/500.vue"), + meta: { + title: $t("menus.pureServerError"), + showLink: false, + rank: 104 + } + }, { path: "/redirect", component: Layout, meta: { title: $t("status.pureLoad"), showLink: false, - rank: 102 + rank: 105 }, children: [ { @@ -28,6 +61,16 @@ export default [ } ] }, + { + path: "/account-settings", + name: "AccountSettings", + component: () => import("@/views/account-settings/index.vue"), + meta: { + title: $t("buttons.pureAccountSettings"), + showLink: false, + rank: 106 + } + }, // 下面是一个无layout菜单的例子(一个全屏空白页面),因为这种情况极少发生,所以只需要在前端配置即可(配置路径:src/router/modules/remaining.ts) { path: "/empty", @@ -36,17 +79,7 @@ export default [ meta: { title: $t("menus.pureEmpty"), showLink: false, - rank: 103 - } - }, - { - path: "/account-settings", - name: "AccountSettings", - component: () => import("@/views/account-settings/index.vue"), - meta: { - title: $t("buttons.pureAccountSettings"), - showLink: false, - rank: 104 + rank: 107 } } ] satisfies Array; diff --git a/src/router/utils.ts b/src/router/utils.ts index 1e9157114..375351957 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -139,16 +139,6 @@ function findRouteByPath(path: string, routes: RouteRecordRaw[]) { } } -function addPathMatch() { - if (!router.hasRoute("pathMatch")) { - router.addRoute({ - path: "/:pathMatch(.*)", - name: "pathMatch", - redirect: "/error/404" - }); - } -} - /** 处理动态路由(后端返回的路由) */ function handleAsyncRoutes(routeList) { if (routeList.length === 0) { @@ -188,7 +178,6 @@ function handleAsyncRoutes(routeList) { ) ]); } - addPathMatch(); } /** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/ @@ -397,7 +386,6 @@ export { filterTree, initRouter, getTopMenu, - addPathMatch, isOneOfArray, getHistoryMode, addAsyncRoutes, diff --git a/src/views/error/403.vue b/src/views/error/403.vue index ffd9df440..fbd1f0f16 100644 --- a/src/views/error/403.vue +++ b/src/views/error/403.vue @@ -10,9 +10,11 @@ const router = useRouter();