Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
6
608-pdm-web-5g
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pdm
608-pdm-web-5g
Commits
854b0328
Commit
854b0328
authored
Jul 11, 2024
by
xioln
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
免登录处理
parent
b6edece5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
3 deletions
+52
-3
http.js
src/utils/http.js
+52
-3
No files found.
src/utils/http.js
View file @
854b0328
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
import
{
Notify
}
from
'vant'
import
{
Notify
}
from
'vant'
import
store
from
'../store'
import
store
from
'../store'
import
{
getToken
}
from
'./auth'
import
{
getToken
}
from
'./auth'
import
Cookies
from
'js-cookie'
import
RSA
from
'./rsa.js'
// import { VUE_APP_BASE_API } from '../../public/apiUrl'
// import { VUE_APP_BASE_API } from '../../public/apiUrl'
// axios.defaults.baseURL = process.env.VUE_APP_BASE_API
// axios.defaults.baseURL = process.env.VUE_APP_BASE_API
...
@@ -29,9 +31,19 @@ axios.interceptors.request.use(
...
@@ -29,9 +31,19 @@ axios.interceptors.request.use(
delete
config
.
data
.
userAction
delete
config
.
data
.
userAction
}
}
if
(
store
.
getters
.
token
)
{
if
(
store
.
getters
.
token
)
{
config
.
headers
.
authorization
=
getToken
()
const
queryUserAccount
=
queryURLParams
(
window
.
location
.
href
).
userAccount
||
sessionStorage
.
getItem
(
'Login-free-userAccount'
)
||
''
config
.
headers
[
'Dex-Token'
]
=
getToken
()
// eslint-disable-next-line no-prototype-builtins
config
.
headers
[
'Dex-Auth-Type'
]
=
'Token'
if
(
queryUserAccount
)
{
const
rsaUserAccount
=
RSA
.
rsaPublicData
(
queryUserAccount
)
sessionStorage
.
setItem
(
'Login-free-userAccount'
,
queryUserAccount
)
config
.
headers
.
authorization
=
rsaUserAccount
config
.
headers
[
'Dex-Ukey-Token'
]
=
rsaUserAccount
config
.
headers
[
'Dex-Auth-Type'
]
=
'Ukey'
}
else
{
config
.
headers
.
authorization
=
getToken
()
config
.
headers
[
'Dex-Token'
]
=
getToken
()
config
.
headers
[
'Dex-Auth-Type'
]
=
'Token'
}
if
(
!
getToken
())
{
if
(
!
getToken
())
{
delete
config
.
headers
.
authorization
delete
config
.
headers
.
authorization
delete
config
.
headers
[
'Dex-Token'
]
delete
config
.
headers
[
'Dex-Token'
]
...
@@ -168,6 +180,43 @@ function del(url, params) {
...
@@ -168,6 +180,43 @@ function del(url, params) {
})
})
}
}
function
queryURLParams
(
url
,
paramName
)
{
// 正则表达式模式,用于匹配URL中的参数部分。正则表达式的含义是匹配不包含 ?、&、= 的字符作为参数名,之后是等号和不包含 & 的字符作为参数值
const
pattern
=
/
([^
?&=
]
+
)
=
([^
&
]
+
)
/g
const
params
=
{}
// match用于存储正则匹配的结果
let
match
// while 循环和正则表达式 exec 方法来迭代匹配URL中的参数
while
((
match
=
pattern
.
exec
(
url
))
!==
null
)
{
// 在字符串url中循环匹配pattern,并对每个匹配项进行解码操作,将解码后的键和值分别存储在key和value变量中
const
key
=
decodeURIComponent
(
match
[
1
])
const
value
=
decodeURIComponent
(
match
[
2
])
if
(
params
[
key
])
{
if
(
Array
.
isArray
(
params
[
key
]))
{
params
[
key
].
push
(
value
)
}
else
{
params
[
key
]
=
[
params
[
key
],
value
]
}
}
else
{
// 参数名在 params 对象中不存在,将该参数名和对应的值添加到 params 对象中
params
[
key
]
=
value
}
}
if
(
!
paramName
)
{
// 没有传入参数名称, 返回含有所有参数的对象params
return
params
}
else
{
if
(
params
[
paramName
])
{
return
params
[
paramName
]
}
else
{
return
''
}
}
}
export
{
export
{
get
,
post
,
put
,
del
,
downloadFile
,
downloadFilePost
get
,
post
,
put
,
del
,
downloadFile
,
downloadFilePost
}
}
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