http.js 3.7 KB

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