From 960b1eb250365f56b7a574b0bdffae28539d784d Mon Sep 17 00:00:00 2001 From: caiti Date: Wed, 18 May 2022 11:44:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B7=AF=E7=94=B1=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E8=BD=AC=E9=A6=96=E5=AD=97=E6=AF=8D=E5=A4=A7=E5=86=99=E9=A9=BC?= =?UTF-8?q?=E5=B3=B0=EF=BC=8C=E4=BD=9C=E4=B8=BA=E8=B7=AF=E7=94=B1=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8C=E9=80=82=E9=85=8DkeepAlive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/store/modules/permission.js | 3 +++ yudao-ui-admin/src/utils/index.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/yudao-ui-admin/src/store/modules/permission.js b/yudao-ui-admin/src/store/modules/permission.js index 005c98f0f..4ddd9d2ac 100644 --- a/yudao-ui-admin/src/store/modules/permission.js +++ b/yudao-ui-admin/src/store/modules/permission.js @@ -2,6 +2,7 @@ import { constantRoutes } from '@/router' import { getRouters } from '@/api/menu' import Layout from '@/layout/index' import ParentView from '@/components/ParentView'; +import { toCamelCase } from "@/utils"; const permission = { state: { @@ -56,6 +57,8 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { icon: route.icon, noCache: !route.keepAlive, } + // 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive + route.name = toCamelCase(route.path, true) route.hidden = !route.visible // 处理 component 属性 if (route.children) { // 父节点 diff --git a/yudao-ui-admin/src/utils/index.js b/yudao-ui-admin/src/utils/index.js index 5061c2228..075fd5af4 100644 --- a/yudao-ui-admin/src/utils/index.js +++ b/yudao-ui-admin/src/utils/index.js @@ -427,3 +427,15 @@ export function isNumberStr(str) { return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str) } +// -转驼峰 +export function toCamelCase(str, upperCaseFirst) { + str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) { + return group1.toUpperCase(); + }); + + if (upperCaseFirst && str) { + str = str.charAt(0).toUpperCase() + str.slice(1); + } + + return str; +}