import JsonP from 'jsonp'
import axios from 'axios'
import { Modal } from 'antd'
export default class Axios {
static jsonp(options) {
return new Promise((resolve, reject) => {
JsonP(options.url, {
param: 'callback'
}, function (err, response) {
if (response.status === 'success') {
resolve(response);
} else {
reject(response.messsage);
}
})
})
}
static get(url,params){
let potions = {}
potions.url = url
potions.method = 'get'
potions.data = params || ''
return this.ajax(potions)
}
static post(url,params){
let potions = {}
potions.url = url
potions.method = 'post'
potions.data = params || ''
return this.ajax(potions)
}
static ajax(options){
let baseApi = 'http://172.0.0.1'
return new Promise((resolve,reject)=>{
axios({
url:options.url,
method:options.method,
baseURL:baseApi,
timeout:5000,
params:options.data ||''
}).then((response)=>{
if(response.status=='200'){
var res = response.data
if(res.success){
resolve(res)
}else{
Modal.info({
title:"提示",
content:res.msg
})
}
}else{
reject(response.data)
}
})
})
}
}