http.js 3.6 KB

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