const requestPath = ""; function post(url, data = {}) { return new Promise((resolve, reject) => { if (data && data.loading !== false) { uni.showLoading({ title: "加载中", mask: true, }); } uni.request({ url: requestPath + url, data: { ...data, }, header: { "Content-type": "application/x-www-form-urlencoded", }, method: "POST", success: (res) => { if (data && data.loading !== false) { uni.hideLoading(); } if (res.data.result === "success") { resolve(res.data); } else { uni.showToast({ title: res.data.msg || "系统开小差了", icon: "none", }); if (res.data.msg && res.data.msg.indexOf("动火超期") !== -1) { uni.navigateBack(); } reject(res.data); } }, fail: (err) => { if (data && data.loading !== false) { uni.hideLoading(); } uni.showToast({ title: "网络错误请重试", icon: "none", }); reject(err); }, }); }); } function upload(url, data = {}) { return new Promise((resolve, reject) => { if (data && data.loading !== false) { uni.showLoading({ title: "加载中", mask: true, }); } uni.uploadFile({ url: requestPath + url, filePath: data.filePath, name: data.name || "FFILE", formData: { ...data.formData, } || {}, success: (res) => { if (data && data.loading !== false) { uni.hideLoading(); } if (JSON.parse(res.data).result === "success") { resolve(JSON.parse(res.data)); } else { uni.showToast({ title: JSON.parse(res.data).msg || "系统开小差了", icon: "none", }); reject(JSON.parse(res.data)); } }, fail: (err) => { uni.hideLoading(); uni.showToast({ title: "网络错误请重试", icon: "none", }); reject(err); }, }); }); } export { post, upload };