// let requestPath = 'https://qynx.qhdsafety.com/qa-education/'; // 后台请求地址 let requestPath = 'http://192.168.0.30:7450/'; // 后台请求地址 // let requestPath = 'http://192.168.0.31:7450/qa-education-exam-org'; // 测试请求地址 const app = getApp() function post(url, data) { return new Promise((resolve, reject) => { if (data && data.loading !== false) { wx.showLoading({ title: '加载中', mask: true }); } wx.request({ url: requestPath + url, data: { USER_ID:app.globalData?.userInfo?.USER_ID, ...data }, method: 'POST', header: { 'Content-type': 'application/x-www-form-urlencoded' }, success: (res) => { if (data && data.loading !== false) { wx.hideLoading(); } if (res.data.result === 'success') { resolve(res.data) } else { wx.showToast({ title: res.data.msg || '系统开小差了', icon: 'error', }); reject(res.data) } }, fail: (err) => { if (data && data.loading !== false) { wx.hideLoading(); } wx.showToast({ title: '网络错误请重试', icon: 'error', }); reject(err) } }); }) } function upload(url, data) { return new Promise((resolve, reject) => { if (data && data.loading !== false) { wx.showLoading({ title: '加载中', mask: true }); } wx.uploadFile({ url: requestPath + url, filePath: data.filePath, name: data.name || 'FFILE', formData: { USER_ID:app.globalData?.userInfo?.USER_ID, ...data.formData} || {}, success: (res) => { if (data && data.loading !== false) { wx.hideLoading(); } if (JSON.parse(res.data).result === 'success') { resolve(JSON.parse(res.data)) } else { wx.showToast({ title: JSON.parse(res.data).msg || '系统开小差了', icon: 'error', }); reject(JSON.parse(res.data)) } }, fail: (err) => { wx.hideLoading(); wx.showToast({ title: '网络错误请重试', icon: 'error', }); reject(err) } }); }) } export {post, upload}