/** |-------------------------------------------------- | Fetchx | The available instance methods are listed below. The specified config will be merged with the instance config. Methods: axios#request(config) axios#get(url[, config]) axios#delete(url[, config]) axios#head(url[, config]) axios#options(url[, config]) axios#post(url[, data[, config]]) axios#put(url[, data[, config]]) axios#patch(url[, data[, config]]) |-------------------------------------------------- */ import axios from 'axios' import API from './Restful' import Toast from 'react-native-root-toast' // "http://123.103.9.212:18095/"; //测试环境外网 // "http://172.20.11.88/"; //测试环境 // "http://192.168.199.112/occ-b2b-buyer/";//bingxv // "http://192.168.199.177:8769/"; //gaopeng // "http://192.168.199.225:8080/"; //shuifeng // "http://172.20.15.52/"; //开发环境 // "http://10.11.112.37/:8769"; //shuifeng开发环境 // //init let Fetchx, LoginFetchx, MyHeaders, BaseUrl, ImageBaseUrl, ApiPrefix = '/api' let Token, toast export const setBaseUrl = data => { // let LoginUrl = "http://172.20.11.88:80"; BaseUrl = 'http://' + data.url + ':' + data.port ImageBaseUrl = 'http://' + data.url + ':' + data.port Fetchx = createFetchx(BaseUrl, 30000) LoginFetchx = createFetchx(BaseUrl, 60000) // LoginFetchx = createFetchx(LoginUrl, 4000); } //factory fetch fn const createFetchx = (baseURL, timeout) => { MyHeaders = new Headers() _Fetchx = axios.create({ baseURL: baseURL, timeout: timeout, headers: MyHeaders, }) //Fetchx.interceptors // Add a request interceptor global _Fetchx.interceptors.request.use( config => { return config }, error => { // Do something with request error return Promise.reject(error) } ) // Add a response interceptor _Fetchx.interceptors.response.use( function(response) { // Do something with response data return response }, function(error) { //timeout handler if (error.code === 'ECONNABORTED') { if (toast) { Toast.hide(toast) } toast = Toast.show( '登陆超时,请尝试重新登陆', { position: toastHeight } ) return { data: { result: 9, code: 'timeOut' } } } // Do something with response error return Promise.reject(error) } ) return _Fetchx } // function setToken(token) { // axios.defaults.headers.common["Cookie"] = token; // } export { Fetchx, BaseUrl, API, ImageBaseUrl, LoginFetchx, createFetchx }