const ip = 'http://192.168.1.42:8686'; //const ip = 'http://114.215.150.32:8686'; /** * 全部接口 */ const urls = { ip: ip, login: ip + '/app/login', //app登陆 captchaSend: ip + '/app/captchaSend', //发送短信验证码 news: ip + '/app/news/list', //新闻资讯 news_detail: ip + '/app/news/', //新闻资讯 } /** * 封装的请求 */ const request = (opt) => { opt = opt || {}; opt.url = opt.url || ''; opt.data = opt.data || null; opt.method = opt.method || 'GET'; opt.header = opt.header || { "Content-Type": "application/json;charset=UTF-8", "Authorization": getUser().token || '' }; opt.loading = opt.loading || 'true'; opt.success = opt.success || function() {}; console.log("**************************************参数调式***************************************************"); console.log("token:" + getUser().token) console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data)); console.log("************************************************************************************************"); if (opt.loading == 'true') { uni.showLoading({ title: '正在加载' }); } uni.request({ url: opt.url, data: opt.data, method: opt.method, header: opt.header, dataType: 'json', success: function(res) { setTimeout(() => { uni.hideLoading(); }, 500) if (res.data.code === 500) { uni.showModal({ content: res.data.msg, showCancel: false }); return; } opt.success(res); }, fail: function(e) { uni.hideLoading(); uni.showModal({ content: '服务异常,请稍后重试', showCancel: false }) } }) } const getUser = () => { return uni.getStorageSync('user'); } module.exports = { urls, request, getUser };