http.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //const ip = 'http://127.0.0.1:8080';
  2. //const ip = 'https://qfnj.gaswkj.com/prod-api';
  3. //const ip = 'http://192.168.0.100:8080';
  4. const ip = 'https://xdmly.qiyiiot.com/prod-api';
  5. /**
  6. * 全部接口(集中管理)
  7. */
  8. const urls = {
  9. ip: ip,
  10. home: ip + '/api/index/home', //首页数据
  11. feedback: ip + '/api/index/feedback', //投诉建议
  12. wxLogin: ip + '/api/login/wxLogin/', //游客微信小程序登录
  13. bindWxMobile: ip + '/api/index/bindWxMobile', //绑定会员微信手机号
  14. getPageContent: ip + '/api/index/getPageContent', //分页获取主要内容信息
  15. getContentInfo: ip + '/api/index/getContentInfo/', //获取主要内容详细信息
  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. shopManage: ip + '/api/index/shopManage', //店铺管理
  27. hotelBook: ip + '/api/index/hotelBook', //酒店房间预订
  28. hotelEnable: ip + '/api/index/hotelEnable', //是否开启酒店预订
  29. hotelDelete: ip + '/api/index/hotelDelete', //注销并且关闭店铺
  30. order: ip + '/api/index/order', //预订房间订单
  31. orderDeal: ip + '/api/index/orderDeal', //商家订单处理
  32. orderDelete: ip + '/api/index/orderDelete', //商家订单删除
  33. roomDel: ip + '/api/index/roomDel', //商家删除酒店房间
  34. uploadImg: ip + '/api/index/uploadImg', //图片上传请求
  35. }
  36. /**
  37. * 封装的http请求
  38. */
  39. const request = (opt) => {
  40. opt = opt || {};
  41. opt.url = opt.url || '';
  42. opt.data = opt.data || null;
  43. opt.method = opt.method || 'GET';
  44. opt.header = opt.header || {
  45. "Content-Type": "application/json;charset=UTF-8",
  46. "apiToken": getUser().apiToken || ''
  47. };
  48. opt.loading = opt.loading || 'true';
  49. opt.success = opt.success || function() {};
  50. console.log("**************************************参数调式***************************************************");
  51. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  52. console.log("************************************************************************************************");
  53. if (opt.loading == 'true') {
  54. uni.showLoading({
  55. title: '正在加载',
  56. mask: true
  57. });
  58. }
  59. uni.request({
  60. url: opt.url,
  61. data: opt.data,
  62. method: opt.method,
  63. header: opt.header,
  64. dataType: 'json',
  65. success: res => {
  66. setTimeout(() => {
  67. uni.hideLoading();
  68. }, 500)
  69. if (res.data.code == 200) {
  70. opt.success(res);
  71. return;
  72. }
  73. if (res.data.code == 500) {
  74. uni.showModal({
  75. content: res.data.msg,
  76. showCancel: false
  77. });
  78. return;
  79. }
  80. if (res.data.code == 401) {
  81. uni.removeStorageSync('user');
  82. uni.showModal({
  83. title: '提示',
  84. content: '您还未登陆,请先登陆!',
  85. success: res => {
  86. if (res.confirm) {
  87. uni.navigateTo({
  88. url: '/pages/user/login'
  89. })
  90. }
  91. }
  92. });
  93. return;
  94. }
  95. },
  96. fail: e => {
  97. uni.hideLoading();
  98. uni.getNetworkType({
  99. success: res => {
  100. if (res.networkType == 'none') {
  101. uni.showModal({
  102. content: '当前网络不可用,请检查网络稍后重试',
  103. showCancel: false
  104. });
  105. } else {
  106. uni.showModal({
  107. content: '服务异常,请稍后重试',
  108. showCancel: false
  109. })
  110. }
  111. }
  112. });
  113. }
  114. })
  115. }
  116. const getUser = () => {
  117. return uni.getStorageSync('user');
  118. }
  119. module.exports = {
  120. urls,
  121. request,
  122. getUser
  123. };