http.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //const ip = 'http://192.168.2.101: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. return;
  60. }
  61. if (res.data.code == 500) {
  62. uni.showModal({
  63. content: res.data.msg,
  64. showCancel: false
  65. });
  66. return;
  67. }
  68. if (res.data.code == 401) {
  69. uni.removeStorageSync('user');
  70. uni.showModal({
  71. title: '提示',
  72. content: '您还未登陆,请先登陆!',
  73. success: res => {
  74. if (res.confirm) {
  75. uni.navigateTo({
  76. url: '/pages/user/login'
  77. })
  78. }
  79. }
  80. });
  81. return;
  82. }
  83. },
  84. fail: e => {
  85. uni.hideLoading();
  86. uni.getNetworkType({
  87. success: res => {
  88. if (res.networkType == 'none') {
  89. uni.showModal({
  90. content: '当前网络不可用,请检查网络稍后重试',
  91. showCancel: false
  92. });
  93. } else {
  94. uni.showModal({
  95. content: '服务异常,请稍后重试',
  96. showCancel: false
  97. })
  98. }
  99. }
  100. });
  101. }
  102. })
  103. }
  104. const getUser = () => {
  105. return uni.getStorageSync('user');
  106. }
  107. module.exports = {
  108. urls,
  109. request,
  110. getUser
  111. };