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
Unverified
Commit
10a5d4d2
authored
Jan 26, 2024
by
芋道源码
Committed by
Gitee
Jan 26, 2024
Browse files
Options
Browse Files
Download
Plain Diff
!373 update src/permission.ts.
Merge pull request !373 from AKING/N/A
parents
948ef085
024d0855
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
1 deletions
+37
-1
src/permission.ts
+37
-1
No files found.
src/permission.ts
View file @
10a5d4d2
...
@@ -12,6 +12,40 @@ import { usePermissionStoreWithOut } from '@/store/modules/permission'
...
@@ -12,6 +12,40 @@ import { usePermissionStoreWithOut } from '@/store/modules/permission'
const
{
start
,
done
}
=
useNProgress
()
const
{
start
,
done
}
=
useNProgress
()
const
{
loadStart
,
loadDone
}
=
usePageLoading
()
const
{
loadStart
,
loadDone
}
=
usePageLoading
()
const
parseURL
=
(
url
:
string
|
null
|
undefined
):
{
basePath
:
string
;
paramsObject
:
{
[
key
:
string
]:
string
}
}
=>
{
// 如果输入为 null 或 undefined,返回空字符串和空对象
if
(
url
==
null
)
{
return
{
basePath
:
''
,
paramsObject
:
{}
}
}
// 找到问号 (?) 的位置,它之前是基础路径,之后是查询参数
const
questionMarkIndex
=
url
.
indexOf
(
'?'
)
let
basePath
=
url
const
paramsObject
:
{
[
key
:
string
]:
string
}
=
{}
// 如果找到了问号,说明有查询参数
if
(
questionMarkIndex
!==
-
1
)
{
// 获取 basePath
basePath
=
url
.
substring
(
0
,
questionMarkIndex
)
// 从 URL 中获取查询字符串部分
const
queryString
=
url
.
substring
(
questionMarkIndex
+
1
)
// 使用 URLSearchParams 遍历参数
const
searchParams
=
new
URLSearchParams
(
queryString
)
searchParams
.
forEach
((
value
,
key
)
=>
{
// 封装进 paramsObject 对象
paramsObject
[
key
]
=
value
})
}
// 返回 basePath 和 paramsObject
return
{
basePath
,
paramsObject
}
}
// 路由不重定向白名单
// 路由不重定向白名单
const
whiteList
=
[
const
whiteList
=
[
'/login'
,
'/login'
,
...
@@ -47,8 +81,10 @@ router.beforeEach(async (to, from, next) => {
...
@@ -47,8 +81,10 @@ router.beforeEach(async (to, from, next) => {
router
.
addRoute
(
route
as
unknown
as
RouteRecordRaw
)
// 动态添加可访问路由表
router
.
addRoute
(
route
as
unknown
as
RouteRecordRaw
)
// 动态添加可访问路由表
})
})
const
redirectPath
=
from
.
query
.
redirect
||
to
.
path
const
redirectPath
=
from
.
query
.
redirect
||
to
.
path
// 修复跳转时不带参数的问题
const
redirect
=
decodeURIComponent
(
redirectPath
as
string
)
const
redirect
=
decodeURIComponent
(
redirectPath
as
string
)
const
nextData
=
to
.
path
===
redirect
?
{
...
to
,
replace
:
true
}
:
{
path
:
redirect
}
const
{
basePath
,
paramsObject
:
query
}
=
parseURL
(
redirect
)
const
nextData
=
to
.
path
===
redirect
?
{
...
to
,
replace
:
true
}
:
{
path
:
redirect
,
query
}
next
(
nextData
)
next
(
nextData
)
}
else
{
}
else
{
next
()
next
()
...
...
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