Commit 0163b473 by li_hongchao

http.js 优化

parent 88f72f55
...@@ -41,6 +41,8 @@ var down = axios.create({ // 文件下载 ...@@ -41,6 +41,8 @@ var down = axios.create({ // 文件下载
}, },
}) })
var _IS_SHOW_TIP = true
// 初始化参数 // 初始化参数
let initConfig = (config) => { let initConfig = (config) => {
if (config.url.indexOf('/login/myLoginForm') <= 0) { if (config.url.indexOf('/login/myLoginForm') <= 0) {
...@@ -60,12 +62,14 @@ let initConfig = (config) => { ...@@ -60,12 +62,14 @@ let initConfig = (config) => {
if (config[_HTTP_TYPE.LOADING] !== false) { if (config[_HTTP_TYPE.LOADING] !== false) {
showLoading(config[_HTTP_TYPE.LOADING_TARGET]) // 如果设置了targer,使用设置的target,比如el-table showLoading(config[_HTTP_TYPE.LOADING_TARGET]) // 如果设置了targer,使用设置的target,比如el-table
} }
_IS_SHOW_TIP = config[_HTTP_TYPE.TIP]
// console.log('initConfig', config) // console.log('initConfig', config)
return config return config
} }
let onError = (error) => { let onError = (error) => {
logger.info('error-config', error.config) // logger.info('error-config', error.config)
if (error) { if (error) {
hideLoading() hideLoading()
} }
...@@ -74,7 +78,7 @@ let onError = (error) => { ...@@ -74,7 +78,7 @@ let onError = (error) => {
let result = { let result = {
code: 999, code: 999,
message: '', message: '',
[_HTTP_TYPE.TIP]: error.config[_HTTP_TYPE.TIP] [_HTTP_TYPE.TIP]: _IS_SHOW_TIP
} }
if (error.toString().indexOf('400') >= 0) { if (error.toString().indexOf('400') >= 0) {
result.code = 400 result.code = 400
...@@ -111,7 +115,7 @@ let onResponse = (response) => { ...@@ -111,7 +115,7 @@ let onResponse = (response) => {
if (response.headers && response.headers.token) localStorage.setItem(ACCESS_TOKEN, response.headers.token) if (response.headers && response.headers.token) localStorage.setItem(ACCESS_TOKEN, response.headers.token)
if (response.config && response.config.loading !== false) hideLoading(response.config.loadingTarget) if (response.config && response.config.loading !== false) hideLoading(response.config.loadingTarget)
logger.info('response-config', response.config) // logger.info('response-config', response.config)
if (response.data && response.data.code >= 0) { if (response.data && response.data.code >= 0) {
let status = response.data.code let status = response.data.code
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment