1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| import operate from '../common/operate.js'
import store from '../store/index.js'
export default class Request { http(param) { var url = param.url, method = param.method, header = {}, data = param.data || {}, hideLoading = param.hideLoading || false;
var requestUrl = operate.api + url; console.log(requestUrl)
if (method) { method = method.toUpperCase(); if (method == "GET") { header = { 'content-type': "application/x-www-form-urlencoded" }; } else { header = { 'content-type': "application/json" }; } }
if (!hideLoading) { uni.showLoading({ title: '加载中...' }); }
return new Promise((resolve, reject) => { uni.request({ url: requestUrl, data: data, method: method, header: header, success: (res) => { if (res.statusCode && res.statusCode != 200) { uni.showToast({ title: "api错误" + res.errMsg, icon: 'none' }); return; } resolve(res.data) }, fail: (e) => { uni.showToast({ title: "" + e.data, icon: 'none' }); resolve(e.data); }, complete() { if (!hideLoading) { uni.hideLoading(); } resolve(); return; } }) }) } }
|