const Url = 'https://chat.lihaink.cn' function toLogin() { uni.showToast({ title: '请先登录', icon: 'none', duration: 1000 }); } function baseRequestTwo(url, method, data, { noAuth = false, noVerify = false, onReLogin = false }) { return new Promise((reslove, reject) => { uni.showLoading({ title: '加载中' }) uni.request({ // url: Url + '/api/v1' + url, url: Url + url, method: method || 'GET', data: method != 'GET' ? data || {} : {}, params: method == 'GET' ? data : {}, success: (res) => { uni.hideLoading() if (noVerify) reslove(res.data); else if (res.data.code == -1) { reject(res.data); } else if (res.data.code == 0) { reslove(res.data); } else if (res.data.code == 1) { reslove(res.data); } else if (res.data.code == 200) { reslove(res.data.data); } else if ([410000, 410001, 410002, 40000].indexOf(res.data.code) !== -1) { toLogin(); reject(res.data); } else if (res.data.code == 501) { reject(res.data); } else { uni.showToast({ title: res.data.msg || '请检查网络', icon: 'none' }) reject(res.data.msg || '请检查网络'); } }, fail: (message) => { // uni.hideLoading() uni.showModal({ title: '请求错误', content: JSON.stringify(message) }) reject('请求失败'); } }) }); } const oahttp = {}; ['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => { oahttp[method] = (api, data, opt) => baseRequestTwo(api, method, data, opt || {}) }); export default oahttp;