export default class Api { syncRequest = function(option){ option.method = option.method || "GET" option.header = option.header || {} option.data = option.data || {} option.loading = option.loading ? true : false option.loadtext = option.loadtext || '加载中...' if(option.method == 'GET'){ option.header['Content-Type'] = 'application/json;charset=UTF-8' }else{ //option.header['Content-Type'] = 'application/x-www-form-urlencoded' option.header['Content-Type'] = 'application/json' } if(option.loading){ uni.showLoading({ mask: true, title: option.loadtext }); } return new Promise((resolve,reject)=>{ uni.request({ url: option.url, method: option.method, header: option.header, data: option.data, success: (res)=>{ if(option.loading){ uni.hideLoading() } console.log(res) if(res.statusCode==200){ resolve(res) }else{ uni.showToast({ icon: "none", title: "数据获取失败,请稍后重试" }) } }, fail: (err)=>{ console.log(err) if (option.loading) { uni.hideLoading() } uni.showToast({ icon: "none", title: "数据获取失败,请稍后重试" }) reject(err) } }) }) } }