Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f75e8d1f
authored
May 01, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【新增】在菜单管理中,可通过“路由地址”添加 `?` 拼接参数
parent
bde55974
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletions
+13
-1
src/utils/routerHelper.ts
+13
-1
No files found.
src/utils/routerHelper.ts
View file @
f75e8d1f
...
@@ -2,6 +2,7 @@ import type { RouteLocationNormalized, Router, RouteRecordNormalized } from 'vue
...
@@ -2,6 +2,7 @@ import type { RouteLocationNormalized, Router, RouteRecordNormalized } from 'vue
import
{
createRouter
,
createWebHashHistory
,
RouteRecordRaw
}
from
'vue-router'
import
{
createRouter
,
createWebHashHistory
,
RouteRecordRaw
}
from
'vue-router'
import
{
isUrl
}
from
'@/utils/is'
import
{
isUrl
}
from
'@/utils/is'
import
{
cloneDeep
,
omit
}
from
'lodash-es'
import
{
cloneDeep
,
omit
}
from
'lodash-es'
import
qs
from
'qs'
const
modules
=
import
.
meta
.
glob
(
'../views/**/*.{vue,tsx}'
)
const
modules
=
import
.
meta
.
glob
(
'../views/**/*.{vue,tsx}'
)
/**
/**
...
@@ -64,6 +65,7 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
...
@@ -64,6 +65,7 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
const
res
:
AppRouteRecordRaw
[]
=
[]
const
res
:
AppRouteRecordRaw
[]
=
[]
const
modulesRoutesKeys
=
Object
.
keys
(
modules
)
const
modulesRoutesKeys
=
Object
.
keys
(
modules
)
for
(
const
route
of
routes
)
{
for
(
const
route
of
routes
)
{
// 1. 生成 meta 菜单元数据
const
meta
=
{
const
meta
=
{
title
:
route
.
name
,
title
:
route
.
name
,
icon
:
route
.
icon
,
icon
:
route
.
icon
,
...
@@ -73,10 +75,20 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
...
@@ -73,10 +75,20 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
route
.
children
&&
route
.
children
&&
route
.
children
.
length
===
1
&&
route
.
children
.
length
===
1
&&
(
route
.
alwaysShow
!==
undefined
?
route
.
alwaysShow
:
true
)
(
route
.
alwaysShow
!==
undefined
?
route
.
alwaysShow
:
true
)
}
as
any
// 特殊逻辑:如果后端配置的 MenuDO.component 包含 ?,则表示需要传递参数
// 此时,我们需要解析参数,并且将参数放到 meta.query 中
// 这样,后续在 Vue 文件中,可以通过 const { currentRoute } = useRouter() 中,通过 meta.query 获取到参数
if
(
route
.
component
&&
route
.
component
.
indexOf
(
'?'
)
>
-
1
)
{
const
query
=
route
.
component
.
split
(
'?'
)[
1
]
route
.
component
=
route
.
component
.
split
(
'?'
)[
0
]
meta
.
query
=
qs
.
parse
(
query
)
}
}
// 2. 生成 data(AppRouteRecordRaw)
// 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
// 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
let
data
:
AppRouteRecordRaw
=
{
let
data
:
AppRouteRecordRaw
=
{
path
:
route
.
path
,
path
:
route
.
path
.
indexOf
(
'?'
)
>
-
1
?
route
.
path
.
split
(
'?'
)[
0
]
:
route
.
path
,
name
:
name
:
route
.
componentName
&&
route
.
componentName
.
length
>
0
route
.
componentName
&&
route
.
componentName
.
length
>
0
?
route
.
componentName
?
route
.
componentName
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment