import Vue from 'vue' let baseUrl = 'https://api.lyiyuan.cn'; Vue.prototype.$baseUrl = baseUrl; export function request(prams) { return new Promise((resolve, reject) => { let url = baseUrl+"/prod-api/"+prams.url; uni.request({ url, data: prams.data, method: prams.method, header: { "token": uni.getStorageSync("userInfo").token, "Content-type": "application/json", "deviceSn": uni.getStorageSync("deviceSn"), }, success: (res) => { if (res.data.code == 200 || res.data.code == -1){ // console.log(prams) // console.log("返回结果:"+JSON.stringify(res.data)) resolve(res.data); }else if(res.data.code == 401){ uni.showModal({ title: "温馨提示", content: "当前账号已过期,是否重新登录", confirmColor: "#000", success(res) { uni.removeStorageSync("userInfo") uni.navigateTo({ url: "/pages/login/login" }) } }) } else if(res.data.code == -2){ uni.showModal({ title: "温馨提示", content: "当前账号未三方认证,请前往认证", confirmColor: "#000", confirmText: "前往", success(res) { uni.navigateTo({ url: "/pages/users/renzheng/index" }) } }) }else { reject(res.data); uni.showToast({ icon: "none", title: res.data.msg, duration: 3000 }); } }, fail: (err) => { reject(err); }, complete: () => { //console.log('请求完成') } }); }) }