Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vipSupplier
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王淑敏
vipSupplier
Commits
b28cf914
Commit
b28cf914
authored
Jul 29, 2020
by
初志鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
全局axios请求全面支持Status Code拦截处理
parent
0a1d6ff6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
8 deletions
+18
-8
mock/controller/changeLog.js
+4
-0
mock/mockServer.js
+3
-2
src/utils/request.js
+4
-0
vue.config.js
+7
-6
No files found.
mock/controller/changeLog.js
View file @
b28cf914
...
@@ -158,6 +158,10 @@ const data = [
...
@@ -158,6 +158,10 @@ const data = [
content
:
"主题配置添加海洋之心、绿荫草场、荣耀典藏、暗黑之子模式"
,
content
:
"主题配置添加海洋之心、绿荫草场、荣耀典藏、暗黑之子模式"
,
timestamp
:
"2020-07-18"
,
timestamp
:
"2020-07-18"
,
},
},
{
content
:
"全局axios请求全面支持Status Code拦截处理"
,
timestamp
:
"2020-07-29"
,
},
];
];
export
default
[
export
default
[
...
...
mock/mockServer.js
View file @
b28cf914
...
@@ -11,7 +11,7 @@ const mockDir = path.join(process.cwd(), "mock");
...
@@ -11,7 +11,7 @@ const mockDir = path.join(process.cwd(), "mock");
* @param app
* @param app
* @returns {{mockStartIndex: number, mockRoutesLength: number}}
* @returns {{mockStartIndex: number, mockRoutesLength: number}}
*/
*/
function
registerRoutes
(
app
)
{
const
registerRoutes
=
(
app
)
=>
{
let
mockLastIndex
;
let
mockLastIndex
;
const
{
default
:
mocks
}
=
require
(
"./index.js"
);
const
{
default
:
mocks
}
=
require
(
"./index.js"
);
const
mocksForServer
=
mocks
.
map
((
route
)
=>
{
const
mocksForServer
=
mocks
.
map
((
route
)
=>
{
...
@@ -26,7 +26,7 @@ function registerRoutes(app) {
...
@@ -26,7 +26,7 @@ function registerRoutes(app) {
mockRoutesLength
:
mockRoutesLength
,
mockRoutesLength
:
mockRoutesLength
,
mockStartIndex
:
mockLastIndex
-
mockRoutesLength
,
mockStartIndex
:
mockLastIndex
-
mockRoutesLength
,
};
};
}
}
;
/**
/**
*
*
...
@@ -40,6 +40,7 @@ const responseFake = (url, type, respond) => {
...
@@ -40,6 +40,7 @@ const responseFake = (url, type, respond) => {
url
:
new
RegExp
(
`
${
baseURL
}${
url
}
`
),
url
:
new
RegExp
(
`
${
baseURL
}${
url
}
`
),
type
:
type
||
"get"
,
type
:
type
||
"get"
,
response
(
req
,
res
)
{
response
(
req
,
res
)
{
res
.
status
(
200
);
if
(
JSON
.
stringify
(
req
.
body
)
!==
"{}"
)
{
if
(
JSON
.
stringify
(
req
.
body
)
!==
"{}"
)
{
console
.
log
(
chalk
.
green
(
`> 请求地址:
${
req
.
path
}
`
));
console
.
log
(
chalk
.
green
(
`> 请求地址:
${
req
.
path
}
`
));
console
.
log
(
chalk
.
green
(
`> 请求参数:
${
JSON
.
stringify
(
req
.
body
)}
\n`
));
console
.
log
(
chalk
.
green
(
`> 请求参数:
${
JSON
.
stringify
(
req
.
body
)}
\n`
));
...
...
src/utils/request.js
View file @
b28cf914
...
@@ -127,6 +127,10 @@ service.interceptors.response.use(
...
@@ -127,6 +127,10 @@ service.interceptors.response.use(
if
(
message
.
includes
(
"Request failed with status code"
))
{
if
(
message
.
includes
(
"Request failed with status code"
))
{
message
=
"后端接口"
+
message
.
substr
(
message
.
length
-
3
)
+
"异常"
;
message
=
"后端接口"
+
message
.
substr
(
message
.
length
-
3
)
+
"异常"
;
}
}
if
(
error
.
response
)
{
const
{
data
}
=
error
.
response
;
message
=
data
.
msg
;
}
errorMsg
(
message
||
"后端接口未知异常"
);
errorMsg
(
message
||
"后端接口未知异常"
);
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
}
}
...
...
vue.config.js
View file @
b28cf914
...
@@ -24,26 +24,27 @@ const Webpack = require("webpack");
...
@@ -24,26 +24,27 @@ const Webpack = require("webpack");
const
WebpackBar
=
require
(
"webpackbar"
);
const
WebpackBar
=
require
(
"webpackbar"
);
const
FileManagerPlugin
=
require
(
"filemanager-webpack-plugin"
);
const
FileManagerPlugin
=
require
(
"filemanager-webpack-plugin"
);
const
dayjs
=
require
(
"dayjs"
);
const
dayjs
=
require
(
"dayjs"
);
const
date
=
new
dayjs
().
format
(
"YYYY_M_D"
);
const
date
=
dayjs
().
format
(
"YYYY_M_D"
);
const
time
=
new
dayjs
().
format
(
"YYYY-M-D HH:mm:ss"
);
const
time
=
dayjs
().
format
(
"YYYY-M-D HH:mm:ss"
);
const
CompressionWebpackPlugin
=
require
(
"compression-webpack-plugin"
);
const
CompressionWebpackPlugin
=
require
(
"compression-webpack-plugin"
);
const
productionGzipExtensions
=
[
"html"
,
"js"
,
"css"
,
"svg"
];
const
productionGzipExtensions
=
[
"html"
,
"js"
,
"css"
,
"svg"
];
process
.
env
.
VUE_APP_TITLE
=
title
||
"vue-admin-beautiful"
;
process
.
env
.
VUE_APP_TITLE
=
title
||
"vue-admin-beautiful"
;
process
.
env
.
VUE_APP_AUTHOR
=
author
||
"chuzhixin"
;
process
.
env
.
VUE_APP_AUTHOR
=
author
||
"chuzhixin"
;
process
.
env
.
VUE_APP_UPDATE_TIME
=
time
;
process
.
env
.
VUE_APP_UPDATE_TIME
=
time
;
process
.
env
.
VUE_APP_VERSION
=
version
;
process
.
env
.
VUE_APP_VERSION
=
version
;
function
resolve
(
dir
)
{
const
resolve
=
(
dir
)
=>
{
return
path
.
join
(
__dirname
,
dir
);
return
path
.
join
(
__dirname
,
dir
);
}
}
;
function
mockServer
()
{
const
mockServer
=
()
=>
{
if
(
process
.
env
.
NODE_ENV
===
"development"
)
{
if
(
process
.
env
.
NODE_ENV
===
"development"
)
{
const
mockServer
=
require
(
"./mock/mockServer.js"
);
const
mockServer
=
require
(
"./mock/mockServer.js"
);
return
mockServer
;
return
mockServer
;
}
else
{
}
else
{
return
""
;
return
""
;
}
}
}
}
;
module
.
exports
=
{
module
.
exports
=
{
publicPath
,
publicPath
,
...
...
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