1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- //const ip = 'http://192.168.1.27:8686';
- //const ip = 'http://192.168.0.101: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/', //新闻资讯
- goods_type: ip + '/app/shop/goods/typeList', //商品分类
- goods_list: ip + '/app/shop/goods/list', //商品列表
- goods_detail: ip + '/app/shop/goods/', //商品详情
- }
- /**
- * 封装的请求
- */
- 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: '正在加载',
- mask:true
- });
- }
- 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
- };
|