上传文件调整:接口超时处理调整未30秒 --提交人:阳华祥

This commit is contained in:
yang.huaxiang
2020-12-03 13:09:44 +08:00
parent f0972cc9cf
commit 20e20b1a0f
2 changed files with 85 additions and 72 deletions

View File

@@ -61,7 +61,7 @@ export function getOrderDetail(data) {
})
}
export function getOrderDetail1(data) {
return request1({
return request({
url: getUrl('/sale/order/orderDetail', 1),
method: 'post',
data
@@ -85,7 +85,7 @@ export function autchCodeCheck(data) {
}
// 上传图片
export function uploadImg(data) {
return request({
return request1({
url: getUrl('/uploadImage', 1, 2),
method: 'post',
data

View File

@@ -1,94 +1,107 @@
import axios from 'axios'
import { Dialog, Toast } from 'vant'
import CacheUtils from '@/assets/js/utils/cacheUtils'
import configApp from "@/config";
import AESTools from "@/assets/js/utils/cryptoJsUtil";
import MD5 from 'js-md5';
import configApp from '@/config'
import AESTools from '@/assets/js/utils/cryptoJsUtil'
import MD5 from 'js-md5'
let sale = ['/sale/order/orderDetail'] //在线投保
// 卡单
// eslint-disable-next-line no-unused-vars
let cardList = []
let whiteList = [...sale]
// 创建axios实例
const service = axios.create({
timeout: 66666666 // 请求超时时间
timeout: 1000 * 30 // 请求超时时间 30 秒
})
// request拦截器
service.interceptors.request.use(
config => {
let relativePath = config.url && config.url.split(configApp.API_VERSION)[1]
if (whiteList.includes(relativePath)) {
Toast.loading({
duration: 0, // 持续展示 toast
forbidClick: true, // 禁用背景点击
loadingType: 'spinner',
message: '加载中……'
})
}
/**
* 请求拦截处理(待添加 判断走统一网关处理)
*/
if(config.url && /api\/$/.test(config.url.split(configApp.API_VERSION)[0]) && configApp.API_VERSION == 'v2'){
if(!config.data || config.data == null){
config.data = {}
}
if(!!config.data && config.data != null){
let encrypt = AESTools.AESEncrypt(JSON.stringify(config.data),configApp.REQ_PWD)
config.data = {"data": encrypt }
}
}
config.headers['token'] = CacheUtils.getLocItem('token')
// 添加请时间戳
let timeStr = new Date().getTime() + '';
config.headers['timeStr'] = timeStr;
config.headers['signature'] = MD5(timeStr + CacheUtils.getLocItem('token'));
return config
},
error => {
// Do something with request error
Promise.reject(error)
config => {
let relativePath = config.url && config.url.split(configApp.API_VERSION)[1]
if (whiteList.includes(relativePath)) {
Toast.loading({
duration: 0, // 持续展示 toast
forbidClick: true, // 禁用背景点击
loadingType: 'spinner',
message: '加载中……'
})
}
/**
* 请求拦截处理(待添加 判断走统一网关处理)
*/
if (config.url && /api\/$/.test(config.url.split(configApp.API_VERSION)[0]) && configApp.API_VERSION == 'v2') {
if (!config.data || config.data == null) {
config.data = {}
}
if (!!config.data && config.data != null) {
let encrypt = AESTools.AESEncrypt(JSON.stringify(config.data), configApp.REQ_PWD)
config.data = { data: encrypt }
}
}
config.headers['token'] = CacheUtils.getLocItem('token')
// 添加请时间戳
let timeStr = new Date().getTime() + ''
config.headers['timeStr'] = timeStr
config.headers['signature'] = MD5(timeStr + CacheUtils.getLocItem('token'))
return config
},
error => {
// Do something with request error
Promise.reject(error)
}
)
// respone拦截器
service.interceptors.response.use(
response => {
console.log(response)
console.log('----------------')
let res = response.data
if( configApp.API_VERSION == 'v2' && response.config.url && response.headers['content-type'].match(/application\/json/) && /api\/$/.test(response.config.url.split(configApp.API_VERSION)[0])){
if(res.response){// 正常情況返回必有response 节点
res = JSON.parse(AESTools.AESDecrypt(res.response,configApp.REQ_PWD))
}
}
Toast.clear()
if (res.code != 0) {
if (res.code == 10001 || res.code == 10002) {
Dialog.confirm({
confirmButtonText: '重新登录',
message: '你已被登出,可以取消继续留在该页面,或者重新登录'
}).then(() => {
//eslint-disable-next-line
EWebBridge.webCallAppInJs('bridge', {
flag: 'login'
})
})
} else {
//Toast.fail(res.msg)
}
return Promise.reject(res)
} else {
return res.content
}
},
error => {
Toast.clear()
console.log('err' + error) // for debug
//Toast.fail(error.message)
return Promise.reject(error)
response => {
let res = response.data
if (
configApp.API_VERSION == 'v2' &&
response.config.url &&
response.headers['content-type'].match(/application\/json/) &&
/api\/$/.test(response.config.url.split(configApp.API_VERSION)[0])
) {
if (res.response) {
// 正常情況返回必有response 节点
res = JSON.parse(AESTools.AESDecrypt(res.response, configApp.REQ_PWD))
}
}
Toast.clear()
if (res.code != 0) {
if (res.code == 10001 || res.code == 10002) {
Dialog.confirm({
confirmButtonText: '重新登录',
message: '你已被登出,可以取消继续留在该页面,或者重新登录'
}).then(() => {
//eslint-disable-next-line
EWebBridge.webCallAppInJs('bridge', {
flag: 'login'
})
})
} else {
//Toast.fail(res.msg)
}
return Promise.reject(res)
} else {
return res.content
}
},
error => {
Toast.clear()
if (error.code == 'ECONNABORTED ') {
Toast.loading({
duration: 2000, // 持续展示 toast
forbidClick: true, // 禁用背景点击
loadingType: 'spinner',
message: '请求超时,请稍后重试'
})
}
console.log('err' + error) // for debug
//Toast.fail(error.message)
return Promise.reject(error)
}
)
export default service