import Vue from 'vue' const config = { timeout: 15000, baseURL: 'http://wdkl.natapp1.cc', headers: { 'Content-Type':'application/x-www-form-urlencoded' } } export const Method = { GET: 'GET', POST: 'POST', PUT: 'PUT', DELETE: 'DELETE' } function service(options) { let url = config.baseURL + '/' + options.url if (options.url.includes("http")){ url = options.url } let headers = config.headers if (options.config.isJson){ headers['Content-Type']='application/json' } else { headers['Content-Type']='application/x-www-form-urlencoded' } if (options.config.loading){ uni.showLoading() } return new Promise((resolve,reject)=>{ // console.log(options, config); uni.request({ url: url, data: options.params, header: headers, timeout: config.timeout, method: options.config.method, success(res) { uni.hideLoading() if (res.statusCode == 200){ resolve(res.data) } else{ if (url.indexOf("/wx_mobile") === -1) { Vue.prototype.$message.error(res.data.message) } reject(res) } }, fail(err){ uni.hideLoading() console.log(err); Vue.prototype.$message.error(err.data.message) reject(err) } }); }) } export default function request(options){ return service(options) }