import axios from ‘axios’; import {Message} from “element-ui”; axios.defaults.headers.post[‘Content-Type’] = ‘application/json; charset=UTF-8’; axios.defaults.withCredentials = true; const Domain = require(“.. /.. /static/domain”); const service = { getdata(arr) { let axiosList = []; arr.map((item) => { let httpDefaultOpts = { method: item.method, baseURL: Domain.default.BASE, url: Domain.default.BASE+item.url, timeout: 10000, params: item.params, data: item.params, withCredentials : true, headers: item.method == ‘get’ ? { ‘X-Requested-With’: ‘XMLHttpRequest’, “Accept”: “application/json”, “Content-Type”: “application/x-www-form-urlencoded” } : { ‘X-Requested-With’: ‘XMLHttpRequest’, ‘Content-Type’: ‘application/json; charset=UTF-8’ } } if(item.method == ‘get’){ httpDefaultOpts.params = item.params; httpDefaultOpts.data = item.params; } else if(item.method == ‘get’){ httpDefaultOpts.data = item.params; } axiosList.push(axios(httpDefaultOpts)); }) return new Promise((resolve) => { axios.all(axiosList).then((resp) => { resolve(resp); }).catch(e => { if (e.response && e.response.status == 500) { Message({ showClose: true, message: ${e.esponse. status}, type: “error”}); } else if (e.response && e.response.status == 404) { Message({ showClose: true, message: ${e.esponse. status}, type: “error”}); } else {Message({showClose: true, Message: server failed to connect, please check the network and refresh the page, type: “error”}); }})}); } } export default service;