const apiUrl = 'https://jyshd.pp1008.top/api'//项目API接口 const req = (url, data, isloading = false) => { return new Promise((resolve, reject) => { isloading && uni.showLoading({ // title: '加载中...', mask: true }) var lang = 'jp' if (uni.getStorageSync('Language')) { lang = uni.getStorageSync('Language').toLowerCase() } if (uni.getStorageSync('token')) { data = { ...data, token: uni.getStorageSync('token') } } uni.request({ url: apiUrl + url + "?lang=" + lang, data: data, sslVerify: false, header: { // "Content-Type": "application/json", "Content-Type": "application/x-www-form-urlencoded" }, method: 'POST', success: function(res) { resolve(res.data) }, fail: function(e) { reject(e) }, complete(res) { // console.log(res) isloading && uni.hideLoading() if (res.data.code == 0) { if (res.data.msg != '') { uni.showToast({ title: res.data.msg, icon: "none", duration: 2000, success() { setTimeout(() => { uni.hideToast() }, 2000) } }) } } if (res.data.code == 401) { const hadToken = !!uni.getStorageSync('token') // uni.clearStorageSync() uni.removeStorageSync('token'); uni.removeStorageSync('user_id'); uni.removeStorageSync('userinfo'); if (hadToken) { uni.reLaunch({ url: "/pages/login/index" }) } } } }) }) } const req1 = (url, data, isloading = false) => { return new Promise((resolve, reject) => { isloading && uni.showLoading({ // title: '加载中...', mask: true }) uni.request({ url: url, data: data, sslVerify: false, header: { // "Content-Type": "application/json", "Content-Type": "application/x-www-form-urlencoded" }, method: 'GET', success: function(res) { resolve(res.data) }, fail: function(e) { reject(e) }, complete() { isloading && uni.hideLoading() } }) }) } export { req, req1, apiUrl }