//const ip = 'http://192.168.0.101:8080'; const ip = 'https://qfnj.gaswkj.com/prod-api'; //const ip = 'http://127.0.0.1:8080'; /** * 全部接口 */ const urls = { ip: ip, home: ip + '/app/home/index', //首页数据 bindPhone: ip + '/app/user/bindPhone', //绑定手机 login: ip + '/app/user/login', //用户登陆 goods_list: ip + '/app/goods/goodsList', //商品服务列表 goods_detail: ip + '/app/goods/detail/', //商品详情 cart_list: ip + '/app/cart/list', //购物车列表 cart_add: ip + '/app/cart/add', //添加购物车 cart_del: ip + '/app/cart/del/', //删除购物车 notice: ip + '/app/other/notice', //消息公告 notice_detail: ip + '/app/other/notice/', //公告详情 pay: ip + '/app/wxPay/pay', //微信支付 order_list: ip + '/app/order/list', //我的订单 order_cancel: ip + '/app/order/cancel', //取消订单 order_detail: ip + '/app/order/detail', //订单详情 dictType: ip + '/app/other/type/', //根据字典类型查询字典数据信息 } /** * 封装的http请求 */ 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("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data)); console.log("************************************************************************************************"); if (opt.loading == 'true') { uni.showLoading({ title: '正在加载', mask: true }); } uni.request({ url: opt.url, data: opt.data, method: opt.method, header: opt.header, dataType: 'json', success: res => { setTimeout(() => { uni.hideLoading(); }, 500) /*******************未登录***************************/ if (res.data.code === 606) { uni.removeStorageSync('user'); uni.showModal({ title: '提示', content: '您还未登陆,请先登陆!', success: res => { if (res.confirm) { uni.navigateTo({ url: '/pages/user/login' }) } } }); return; } /*******************未授权或账号被锁定***************************/ if (res.data.code === 401) { uni.removeStorageSync('user'); uni.showModal({ content: res.data.msg, showCancel: false }); return; } /*******************系统内部错误***************************/ if (res.data.code === 500) { uni.showModal({ content: res.data.msg, showCancel: false }); return; } opt.success(res); }, fail: e => { uni.hideLoading(); uni.getNetworkType({ success: res => { if (res.networkType == 'none') { uni.showModal({ content: '当前网络不可用,请检查网络稍后重试', showCancel: false }); } else { uni.showModal({ content: '服务异常,请稍后重试', showCancel: false }) } } }); } }) } const getUser = () => { return uni.getStorageSync('user'); } module.exports = { urls, request, getUser };