http.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //const ip = 'http://127.0.0.1:8080';
  2. //const ip = 'https://qfnj.gaswkj.com/prod-api';
  3. const ip = 'http://192.168.2.101: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. roomList: ip + '/api/index/roomList', //酒店房间
  23. roomAdd: ip + '/api/index/roomAdd', //商家添加,编辑酒店房间
  24. hotelList: ip + '/api/index/hotelList', //酒店列表
  25. hotelDetail: ip + '/api/index/hotelDetail', //酒店详情
  26. hotelBook: ip + '/api/index/hotelBook', //酒店房间预订
  27. roomDel: ip + '/api/index/roomDel', //商家删除酒店房间
  28. uploadImg: ip + '/api/index/uploadImg', //图片上传请求
  29. }
  30. /**
  31. * 封装的http请求
  32. */
  33. const request = (opt) => {
  34. opt = opt || {};
  35. opt.url = opt.url || '';
  36. opt.data = opt.data || null;
  37. opt.method = opt.method || 'GET';
  38. opt.header = opt.header || {
  39. "Content-Type": "application/json;charset=UTF-8",
  40. "apiToken": getUser().apiToken || ''
  41. };
  42. opt.loading = opt.loading || 'true';
  43. opt.success = opt.success || function() {};
  44. console.log("**************************************参数调式***************************************************");
  45. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  46. console.log("************************************************************************************************");
  47. if (opt.loading == 'true') {
  48. uni.showLoading({
  49. title: '正在加载',
  50. mask: true
  51. });
  52. }
  53. uni.request({
  54. url: opt.url,
  55. data: opt.data,
  56. method: opt.method,
  57. header: opt.header,
  58. dataType: 'json',
  59. success: res => {
  60. setTimeout(() => {
  61. uni.hideLoading();
  62. }, 500)
  63. if (res.data.code == 200) {
  64. opt.success(res);
  65. return;
  66. }
  67. if (res.data.code == 500) {
  68. uni.showModal({
  69. content: res.data.msg,
  70. showCancel: false
  71. });
  72. return;
  73. }
  74. if (res.data.code == 401) {
  75. uni.removeStorageSync('user');
  76. uni.showModal({
  77. title: '提示',
  78. content: '您还未登陆,请先登陆!',
  79. success: res => {
  80. if (res.confirm) {
  81. uni.navigateTo({
  82. url: '/pages/user/login'
  83. })
  84. }
  85. }
  86. });
  87. return;
  88. }
  89. },
  90. fail: e => {
  91. uni.hideLoading();
  92. uni.getNetworkType({
  93. success: res => {
  94. if (res.networkType == 'none') {
  95. uni.showModal({
  96. content: '当前网络不可用,请检查网络稍后重试',
  97. showCancel: false
  98. });
  99. } else {
  100. uni.showModal({
  101. content: '服务异常,请稍后重试',
  102. showCancel: false
  103. })
  104. }
  105. }
  106. });
  107. }
  108. })
  109. }
  110. const getUser = () => {
  111. return uni.getStorageSync('user');
  112. }
  113. module.exports = {
  114. urls,
  115. request,
  116. getUser
  117. };