Commit 960b1eb250365f56b7a574b0bdffae28539d784d
1 parent
9ee2fe5e
fix: 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
Showing
2 changed files
with
15 additions
and
0 deletions
yudao-ui-admin/src/store/modules/permission.js
| @@ -2,6 +2,7 @@ import { constantRoutes } from '@/router' | @@ -2,6 +2,7 @@ import { constantRoutes } from '@/router' | ||
| 2 | import { getRouters } from '@/api/menu' | 2 | import { getRouters } from '@/api/menu' |
| 3 | import Layout from '@/layout/index' | 3 | import Layout from '@/layout/index' |
| 4 | import ParentView from '@/components/ParentView'; | 4 | import ParentView from '@/components/ParentView'; |
| 5 | +import { toCamelCase } from "@/utils"; | ||
| 5 | 6 | ||
| 6 | const permission = { | 7 | const permission = { |
| 7 | state: { | 8 | state: { |
| @@ -56,6 +57,8 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { | @@ -56,6 +57,8 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { | ||
| 56 | icon: route.icon, | 57 | icon: route.icon, |
| 57 | noCache: !route.keepAlive, | 58 | noCache: !route.keepAlive, |
| 58 | } | 59 | } |
| 60 | + // 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive | ||
| 61 | + route.name = toCamelCase(route.path, true) | ||
| 59 | route.hidden = !route.visible | 62 | route.hidden = !route.visible |
| 60 | // 处理 component 属性 | 63 | // 处理 component 属性 |
| 61 | if (route.children) { // 父节点 | 64 | if (route.children) { // 父节点 |
yudao-ui-admin/src/utils/index.js
| @@ -427,3 +427,15 @@ export function isNumberStr(str) { | @@ -427,3 +427,15 @@ export function isNumberStr(str) { | ||
| 427 | return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str) | 427 | return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str) |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | +// -转驼峰 | ||
| 431 | +export function toCamelCase(str, upperCaseFirst) { | ||
| 432 | + str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) { | ||
| 433 | + return group1.toUpperCase(); | ||
| 434 | + }); | ||
| 435 | + | ||
| 436 | + if (upperCaseFirst && str) { | ||
| 437 | + str = str.charAt(0).toUpperCase() + str.slice(1); | ||
| 438 | + } | ||
| 439 | + | ||
| 440 | + return str; | ||
| 441 | +} |