class HTTP { constructor({ baseUrl }) { this.baseUrl = baseUrl; } request({ url, data = {}, method = "POST", header = { 'content-type': 'application/json' }, showLoading = '' }) { return new Promise((resolve, reject) => { this._request(url, resolve, reject, data, method, header, showLoading); }) } _request(url, resolve, reject, data, method, header, showLoading) { if (showLoading) uni.showLoading({ title: showLoading, mask: true }) uni.request({ url: this.baseUrl + '/waserver/rest' + url, data: data, method: method, header: header, timeout: 60000, success: res => resolve(res.data), fial: err => reject(err), complete: (res) => { if (showLoading) uni.hideLoading() if (res.errMsg != 'request:ok') { uni.showToast({ title: '网络异常,请稍后再试', icon: "none" }) } else if (res.data.msg == '登陆状态已过期,请重新登陆!') { uni.redirectTo({ url: '/pages/login/login', success() { uni.showToast({ title: res.msg, icon: "none" }) } }); } } }) } } export { HTTP }