http.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. wxLogin: ip + '/api/login/wxLogin/', //游客微信小程序登录
  12. bindWxMobile: ip + '/api/index/bindWxMobile', //绑定会员微信手机号
  13. getPageContent: ip + '/api/index/getPageContent', //分页获取主要内容信息
  14. getContentInfo: ip + '/api/index/getContentInfo/', //获取主要内容详细信息
  15. pushRecord: ip + '/api/index/pushRecord', //门店数据上报
  16. shopApply: ip + '/api/index/shopApply', //商铺开通申请
  17. getShopList: ip + '/api/index/getShopList', //获取商铺列表
  18. updateShop: ip + '/api/index/updateShop', //更新门店信息
  19. getMarkerList: ip + '/api/index/getMarkerList/', //根据景区id获取标记物
  20. pushHelp: ip + '/api/index/pushHelp', //上传会员拨打记录
  21. roomList: ip + '/api/index/roomList', //酒店房间
  22. roomAdd: ip + '/api/index/roomAdd', //商家添加,编辑酒店房间
  23. hotelList: ip + '/api/index/hotelList', //酒店列表
  24. hotelDetail: ip + '/api/index/hotelDetail', //酒店详情
  25. shopManage: ip + '/api/index/shopManage', //店铺管理
  26. hotelBook: ip + '/api/index/hotelBook', //酒店房间预订
  27. hotelEnable: ip + '/api/index/hotelEnable', //是否开启酒店预订
  28. hotelDelete: ip + '/api/index/hotelDelete', //注销并且关闭店铺
  29. order: ip + '/api/index/order', //预订房间订单
  30. orderDeal: ip + '/api/index/orderDeal', //商家订单处理
  31. orderDelete: ip + '/api/index/orderDelete', //商家订单删除
  32. roomDel: ip + '/api/index/roomDel', //商家删除酒店房间
  33. uploadImg: ip + '/api/index/uploadImg', //图片上传请求
  34. }
  35. /**
  36. * 封装的http请求
  37. */
  38. const request = (opt) => {
  39. opt = opt || {};
  40. opt.url = opt.url || '';
  41. opt.data = opt.data || null;
  42. opt.method = opt.method || 'GET';
  43. opt.header = opt.header || {
  44. "Content-Type": "application/json;charset=UTF-8",
  45. "apiToken": getUser().apiToken || ''
  46. };
  47. opt.loading = opt.loading || 'true';
  48. opt.success = opt.success || function() {};
  49. console.log("**************************************参数调式***************************************************");
  50. console.log("请求地址:" + opt.url + " 请求参数:" + JSON.stringify(opt.data));
  51. console.log("************************************************************************************************");
  52. if (opt.loading == 'true') {
  53. uni.showLoading({
  54. title: '正在加载',
  55. mask: true
  56. });
  57. }
  58. uni.request({
  59. url: opt.url,
  60. data: opt.data,
  61. method: opt.method,
  62. header: opt.header,
  63. dataType: 'json',
  64. success: res => {
  65. setTimeout(() => {
  66. uni.hideLoading();
  67. }, 500)
  68. if (res.data.code == 200) {
  69. opt.success(res);
  70. return;
  71. }
  72. if (res.data.code == 500) {
  73. uni.showModal({
  74. content: res.data.msg,
  75. showCancel: false
  76. });
  77. return;
  78. }
  79. if (res.data.code == 401) {
  80. uni.removeStorageSync('user');
  81. uni.showModal({
  82. title: '提示',
  83. content: '您还未登陆,请先登陆!',
  84. success: res => {
  85. if (res.confirm) {
  86. uni.navigateTo({
  87. url: '/pages/user/login'
  88. })
  89. }
  90. }
  91. });
  92. return;
  93. }
  94. },
  95. fail: e => {
  96. uni.hideLoading();
  97. uni.getNetworkType({
  98. success: res => {
  99. if (res.networkType == 'none') {
  100. uni.showModal({
  101. content: '当前网络不可用,请检查网络稍后重试',
  102. showCancel: false
  103. });
  104. } else {
  105. uni.showModal({
  106. content: '服务异常,请稍后重试',
  107. showCancel: false
  108. })
  109. }
  110. }
  111. });
  112. }
  113. })
  114. }
  115. const getUser = () => {
  116. return uni.getStorageSync('user');
  117. }
  118. module.exports = {
  119. urls,
  120. request,
  121. getUser
  122. };