init
This commit is contained in:
93
src/config/http.js
Normal file
93
src/config/http.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import axios from 'axios'
|
||||
// import qs from 'qs'
|
||||
import { Dialog } from './utils.js'
|
||||
// import { Dialog, toast } from './utils.js'
|
||||
import store from '../vuex/store'
|
||||
// import router from './../router'
|
||||
|
||||
axios.defaults.timeout = 50000
|
||||
// axios.defaults.retry = 5
|
||||
// axios.defaults.retryDelay = 10000
|
||||
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
|
||||
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
if (config.method === 'post') {
|
||||
if (!config.data.flag) {
|
||||
config.data = config.data
|
||||
} else {
|
||||
config.data = config.data.formData
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
Dialog('错误的传参')
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
return Promise.resolve(response)
|
||||
},
|
||||
error => {
|
||||
// let condata = error.config.data.split('&')
|
||||
// console.log('condata', condata)
|
||||
// if (condata[1] === '_SRVMETHOD=queryProduceOrderReprot' || condata[1] === '_SRVMETHOD=queryQCRecord' || condata[1] === '_SRVMETHOD=queryEquipWorkTeam') {
|
||||
// toast(error.message)
|
||||
// setTimeout(() => {
|
||||
// router.replace({
|
||||
// path: '/login'
|
||||
// })
|
||||
// }, 10000)
|
||||
// } else {
|
||||
// if (condata[1] === '_SRVMETHOD=queryEquip') {
|
||||
// toast(error.message)
|
||||
// } else {
|
||||
// Dialog(error.message)
|
||||
// }
|
||||
// // Dialog(error.message)
|
||||
// }
|
||||
// toast(error.message)
|
||||
// - 20201215-x
|
||||
// router.push({
|
||||
// path: '/500',
|
||||
// query: {redirect: router.currentRoute.fullPath}
|
||||
// })
|
||||
// - 20201215-x
|
||||
return Promise.reject(error)
|
||||
// let config = error.config
|
||||
// if (!config || !config.retry) return Promise.reject(error)
|
||||
// config.__retryCount = config.__retryCount || 0
|
||||
// if (config.__retryCount >= config.retry) {
|
||||
// return Promise.reject(error)
|
||||
// }
|
||||
// config.__retryCount += 1
|
||||
// let backoff = new Promise(resolve => {
|
||||
// setTimeout(() => {
|
||||
// resolve()
|
||||
// }, config.retryDelay || 1)
|
||||
// })
|
||||
// return backoff.then(() => {
|
||||
// return axios(config)
|
||||
// })
|
||||
}
|
||||
)
|
||||
|
||||
export const post = (sevmethod, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(`${store.getters.baseUrl}/` + sevmethod, params)
|
||||
.then(response => {
|
||||
// if (response.data.code === '0') {
|
||||
// Dialog(response.data.desc)
|
||||
// }
|
||||
resolve(response.data)
|
||||
}, error => {
|
||||
reject(error.message)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user