Commit b0098973 by li_hongchao

http.js 添加取消loading和tip

parent bbd1f073
...@@ -14,9 +14,8 @@ export default { ...@@ -14,9 +14,8 @@ export default {
return fHttp.postJson( return fHttp.postJson(
_path.drFptx + url, _path.drFptx + url,
_parameter, _parameter,
{ fHttp.closeLoad({
loading: false,
onUploadProgress: onProgress onUploadProgress: onProgress
}) }))
}, },
} }
...@@ -53,8 +53,8 @@ export default { ...@@ -53,8 +53,8 @@ export default {
}, },
queryGzl(_parameter) { queryGzl(_parameter) {
return fHttp.post(_path.gzl + 'queryByLogicIdAndType', _parameter,{ return fHttp.post(_path.gzl + 'queryByLogicIdAndType', _parameter, {
"Content-Type": 'application/x-www-form-urlencoded' headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}) })
}, },
} }
...@@ -14,6 +14,13 @@ axios.defaults.headers = { ...@@ -14,6 +14,13 @@ axios.defaults.headers = {
} }
axios.defaults.responseType = 'json' axios.defaults.responseType = 'json'
var _HTTP_TYPE = {
LOADING: 'loading',
LOADING_TARGET: 'loadingTarget',
TIP: 'isShowTip'
}
var common = axios.create() var common = axios.create()
var instance = axios.create({// post 常规请求 var instance = axios.create({// post 常规请求
...@@ -50,8 +57,8 @@ let initConfig = (config) => { ...@@ -50,8 +57,8 @@ let initConfig = (config) => {
window._axiosPromiseArr.push({cancel}) window._axiosPromiseArr.push({cancel})
}) })
// 判断当前请求是否设置了不显示Loading,默认显示 // 判断当前请求是否设置了不显示Loading,默认显示
if (config.loading !== false) { if (config[_HTTP_TYPE.LOADING] !== false) {
showLoading(config.loadingTarget) // 如果设置了targer,使用设置的target,比如el-table showLoading(config[_HTTP_TYPE.LOADING_TARGET]) // 如果设置了targer,使用设置的target,比如el-table
} }
// console.log('initConfig', config) // console.log('initConfig', config)
return config return config
...@@ -66,7 +73,8 @@ let onError = (error) => { ...@@ -66,7 +73,8 @@ let onError = (error) => {
logger.error('onError-error.toString', error.toString()) logger.error('onError-error.toString', error.toString())
let result = { let result = {
code: 999, code: 999,
message: '' message: '',
[_HTTP_TYPE.TIP]: error.config[_HTTP_TYPE.TIP]
} }
if (error.toString().indexOf('400') >= 0) { if (error.toString().indexOf('400') >= 0) {
result.code = 400 result.code = 400
...@@ -108,6 +116,7 @@ let onResponse = (response) => { ...@@ -108,6 +116,7 @@ let onResponse = (response) => {
if (response.data && response.data.code >= 0) { if (response.data && response.data.code >= 0) {
let status = response.data.code let status = response.data.code
let message = response.data.message let message = response.data.message
response.data[_HTTP_TYPE.TIP] = response.config[_HTTP_TYPE.TIP]
if (status === 0) { if (status === 0) {
// return response.data // return response.data
} else if (status === '200' || status === 200) { } else if (status === '200' || status === 200) {
...@@ -182,7 +191,7 @@ let handleError = (response) => { ...@@ -182,7 +191,7 @@ let handleError = (response) => {
break break
} }
if (isShowTip !== false) { if (response[_HTTP_TYPE.TIP] !== false) {
Message({ Message({
message: message, message: message,
type: type type: type
...@@ -295,12 +304,12 @@ export default { ...@@ -295,12 +304,12 @@ export default {
}, },
closeTip(params = {}) { // 关闭提示 closeTip(params = {}) { // 关闭提示
params.isShowTip = false params[_HTTP_TYPE.TIP] = false
return params return params
}, },
closeLoad(params = {}) { // 关闭加载进度 closeLoad(params = {}) { // 关闭加载进度
params.loading = false params[_HTTP_TYPE.LOADING] = false
return params return params
}, },
......
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