import VUE_APP_BASE_URL from './constant.js'; let server_url = VUE_APP_BASE_URL; let token = uni.getStorageSync('tk'); export function service(options = {}) { console.log(("option",options)) options.url = `${server_url}${options.url}`; //配置请求头 if(uni.getStorageSync('tk')){ options.header = { 'Content-type': options.header || 'application/json', 'tk':uni.getStorageSync('tk'), 'uid': uni.getStorageSync('uid') }; } else { options.header = { 'Content-type': options.header || 'application/json' }; } return new Promise((resolved, rejected) => { //成功 options.success = (res) => { console.log("ressssss",res) // if (Number(res.data.code) == 100) { if(Number(res.data.code) == 405){ uni.showToast({ icon: 'none', duration: 2000, position: 'top', title: `${res.data.msg}` }); rejected(res.data.msg); setTimeout(()=>{ uni.clearStorageSync(); uni.clearStorage(); uni.navigateTo({ url: '/pages/index/index' }) },2000) }else if(Number(res.data.code) == 100){ if(res.data.msg == '您点击太快了,请稍后尝试'){ uni.showToast({ icon: 'none', duration: 2000, position: 'top', title: `${res.data.msg}` }); } } resolved(res.data); // } else { // uni.showToast({ // icon: 'none', // duration: 3000, // position: 'top', // title: `${res.data.msg}` // }); // rejected(res.data.msg); // setTimeout(()=>{ // uni.navigateTo({ // url: '/pages/index/index' // }) // },2000) // } } options.fail = (err) => { uni.showToast({ icon: "none", title: '服务响应失败' }); uni.clearStorageSync(); uni.clearStorage(); uni.navigateTo({ url: '/pages/index/index' }) rejected(err); } uni.request(options); }); }