http.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //const ip = 'http://192.168.0.109:8080';
  2. //const ip = 'https://qfnj.gaswkj.com/prod-api';
  3. //const ip = 'http://192.168.2.102:8080';
  4. const ip = 'https://xdmly.qiyiiot.com/prod-api';
  5. /**
  6. * 全部接口(集中管理)
  7. */
  8. const urls = {
  9. ip: ip,
  10. home: ip + '/app/home/index', //首页数据
  11. wxLogin: ip + '/api/login/wxLogin/', //游客微信小程序登录
  12. bindWxMobile: ip + '/api/index/bindWxMobile', //绑定会员微信手机号
  13. getPageContent: ip + '/api/index/getPageContent', //分页获取主要内容信息
  14. getContentInfo: ip + '/api/index/getContentInfo/', //获取主要内容详细信息
  15. getAboutUs: ip + '/api/index/getAboutUs/', //获取关于我们的信息
  16. pushRecord: ip + '/api/index/pushRecord', //门店数据上报
  17. shopApply: ip + '/api/index/shopApply', //商铺开通申请
  18. getShopList: ip + '/api/index/getShopList', //获取商铺列表
  19. updateShop: ip + '/api/index/updateShop', //更新门店信息
  20. getMarkerList: ip + '/api/index/getMarkerList/', //根据景区id获取标记物
  21. pushHelp: ip + '/api/index/pushHelp', //上传会员拨打记录
  22. uploadImg: ip + '/api/index/uploadImg', //图片上传请求
  23. }
  24. /**
  25. * 封装的http请求
  26. */
  27. const request = (opt) => {
  28. opt = opt || {};
  29. opt.url = opt.url || '';
  30. opt.data = opt.data || null;
  31. opt.method = opt.method || 'GET';
  32. opt.header = opt.header || {
  33. "Content-Type": "application/json;charset=UTF-8",
  34. "apiToken": getUser().apiToken || ''
  35. };
  36. opt.loading = opt.loading || 'true';
  37. opt.success = opt.success || function() {};
  38. console.log("**************************************参数调式***************************************************");
  39. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  40. console.log("************************************************************************************************");
  41. if (opt.loading == 'true') {
  42. uni.showLoading({
  43. title: '正在加载',
  44. mask: true
  45. });
  46. }
  47. uni.request({
  48. url: opt.url,
  49. data: opt.data,
  50. method: opt.method,
  51. header: opt.header,
  52. dataType: 'json',
  53. success: res => {
  54. setTimeout(() => {
  55. uni.hideLoading();
  56. }, 500)
  57. if (res.data.code == 200) {
  58. opt.success(res);
  59. } else {
  60. uni.showModal({
  61. content: res.data.msg,
  62. showCancel: false
  63. });
  64. return;
  65. }
  66. },
  67. fail: e => {
  68. uni.hideLoading();
  69. uni.getNetworkType({
  70. success: res => {
  71. if (res.networkType == 'none') {
  72. uni.showModal({
  73. content: '当前网络不可用,请检查网络稍后重试',
  74. showCancel: false
  75. });
  76. } else {
  77. uni.showModal({
  78. content: '服务异常,请稍后重试',
  79. showCancel: false
  80. })
  81. }
  82. }
  83. });
  84. }
  85. })
  86. }
  87. const getUser = () => {
  88. return uni.getStorageSync('user');
  89. }
  90. module.exports = {
  91. urls,
  92. request,
  93. getUser
  94. };