|
@@ -1,24 +1,9 @@
|
|
|
import axios from 'axios'
|
|
|
|
|
|
const TIME_OUT_MS = 60 * 1000 // 默认请求超时时间
|
|
|
+const BASE_URL = process.env.API_ROOT
|
|
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
|
|
|
|
|
|
-// // 请求拦截器
|
|
|
-// axios.interceptors.request.use(function (config) {
|
|
|
-// console.log('正确拦截')
|
|
|
-// console.log(config)
|
|
|
-// return config
|
|
|
-// }, function (error) {
|
|
|
-// console.log('错误拦截')
|
|
|
-// return Promise.reject(error)
|
|
|
-// })
|
|
|
-// // 响应拦截器
|
|
|
-// axios.interceptors.response.use(function (response) {
|
|
|
-// return response
|
|
|
-// }, function (error) {
|
|
|
-// return Promise.reject(error)
|
|
|
-// })
|
|
|
-
|
|
|
/*
|
|
|
* @param response 返回数据列表
|
|
|
*/
|
|
@@ -51,8 +36,7 @@ function handleResults (response) {
|
|
|
}
|
|
|
|
|
|
function handleUrl (url) {
|
|
|
- //url = 'http://crowd.mooctest.net' + url
|
|
|
- return url
|
|
|
+ return BASE_URL + url
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -66,7 +50,7 @@ function handleParams (data) {
|
|
|
export default {
|
|
|
post (url, data) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- axios.post(url, handleParams(data)).then(
|
|
|
+ axios.post(handleUrl(url), handleParams(data)).then(
|
|
|
(result) => {
|
|
|
resolve(result.data)
|
|
|
}
|
|
@@ -91,7 +75,7 @@ export default {
|
|
|
},
|
|
|
put (url, data) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- axios.put(url, JSON.parse(JSON.stringify(data))).then(
|
|
|
+ axios.put(handleUrl(url), JSON.parse(JSON.stringify(data))).then(
|
|
|
(result) => {
|
|
|
resolve(result.data)
|
|
|
}
|
|
@@ -104,7 +88,7 @@ export default {
|
|
|
},
|
|
|
delete (url, data) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- axios.delete(url, {data: handleParams(data)}).then(
|
|
|
+ axios.delete(handleUrl(url), {data: handleParams(data)}).then(
|
|
|
(result) => {
|
|
|
resolve(result)
|
|
|
}
|
|
@@ -117,7 +101,7 @@ export default {
|
|
|
},
|
|
|
upload (url, data, config) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- axios.post(url, data, config).then(
|
|
|
+ axios.post(handleUrl(url), data, config).then(
|
|
|
(result) => {
|
|
|
resolve(result)
|
|
|
}
|