Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
study
Project
Project
Details
Activity
Releases
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
Damon
study
Commits
3b4ddfda
Commit
3b4ddfda
authored
Jul 12, 2021
by
Facius
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-v1.0.0' of
https://git.banshouhui.com/wuzhenzhe/study
into dev-v1.0.0
parents
aec1f34b
39a0da0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
http.interceptor.js
src/common/http.interceptor.js
+19
-19
No files found.
src/common/http.interceptor.js
View file @
3b4ddfda
const
globalUrl
=
process
.
uniEnv
||
{}
const
globalUrl
=
process
.
uniEnv
||
{}
;
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token变量
// 这里的vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token变量
const
install
=
(
Vue
,
vm
)
=>
{
const
install
=
(
Vue
,
vm
)
=>
{
const
systemApiUrl
=
globalUrl
.
apiUrl
const
systemApiUrl
=
globalUrl
.
apiUrl
;
// 此为自定义配置参数,具体参数见上方说明
// 此为自定义配置参数,具体参数见上方说明
Vue
.
prototype
.
$u
.
http
.
setConfig
({
Vue
.
prototype
.
$u
.
http
.
setConfig
({
baseUrl
:
systemApiUrl
,
baseUrl
:
systemApiUrl
,
...
@@ -11,7 +11,7 @@ const install = (Vue, vm) => {
...
@@ -11,7 +11,7 @@ const install = (Vue, vm) => {
},
},
loadingTime
:
0
,
loadingTime
:
0
,
originalData
:
true
,
originalData
:
true
,
})
})
;
// 请求拦截,配置Token等参数
// 请求拦截,配置Token等参数
Vue
.
prototype
.
$u
.
http
.
interceptor
.
request
=
(
config
)
=>
{
Vue
.
prototype
.
$u
.
http
.
interceptor
.
request
=
(
config
)
=>
{
...
@@ -28,40 +28,40 @@ const install = (Vue, vm) => {
...
@@ -28,40 +28,40 @@ const install = (Vue, vm) => {
// }
// }
// 最后需要将config进行return
// 最后需要将config进行return
return
config
return
config
;
// 如果return一个false值,则会取消本次请求
// 如果return一个false值,则会取消本次请求
// if(config.url == '/user/rest') return false; // 取消某次请求
// if(config.url == '/user/rest') return false; // 取消某次请求
}
}
;
// 响应拦截,判断状态码是否通过
// 响应拦截,判断状态码是否通过
Vue
.
prototype
.
$u
.
http
.
interceptor
.
response
=
(
res
)
=>
{
Vue
.
prototype
.
$u
.
http
.
interceptor
.
response
=
(
res
)
=>
{
const
data
=
res
.
data
const
data
=
res
.
data
;
if
(
res
.
statusCode
===
200
)
{
if
(
res
.
statusCode
===
200
)
{
if
(
data
.
code
===
0
)
{
if
(
data
.
code
===
0
)
{
return
data
.
data
return
data
.
data
;
}
else
if
(
data
.
code
===
401
)
{
}
else
if
(
data
.
code
===
401
)
{
vm
.
$u
.
toast
(
data
.
msg
)
vm
.
$u
.
toast
(
data
.
msg
)
;
let
pages
=
getCurrentPages
()
let
pages
=
getCurrentPages
()
;
let
route
=
pages
[
pages
.
length
-
1
].
route
let
route
=
pages
[
pages
.
length
-
1
].
route
;
// 如果不是在登录页,则跳转到登录页
// 如果不是在登录页,则跳转到登录页
if
(
route
!==
'pages/login/index'
)
{
if
(
route
!==
'pages/login/index'
)
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
vm
.
$u
.
route
(
'/pages/login/index'
)
vm
.
$u
.
route
(
'/pages/login/index'
)
;
},
1500
)
},
1500
)
;
}
}
return
false
return
false
;
}
else
{
}
else
{
// 如果返回false,则会调用Promise的reject回调,
// 如果返回false,则会调用Promise的reject回调,
vm
.
$u
.
toast
(
data
.
msg
)
vm
.
$u
.
toast
(
data
.
msg
)
;
return
false
return
false
;
}
}
}
else
{
}
else
{
// HTTP状态非200
// HTTP状态非200
vm
.
$u
.
toast
(
data
.
msg
||
'服务器错误'
)
vm
.
$u
.
toast
(
data
.
msg
||
'服务器错误'
)
;
}
}
}
}
;
}
}
;
export
default
{
export
default
{
install
,
install
,
}
}
;
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