http.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //const ip = 'http://127.0.0.1:8080';
  2. //const ip = 'http://192.168.2.102:8080';
  3. const ip = 'https://xtmly.zhongchuang-tech.com/prod-api';
  4. /**
  5. * 全部接口(集中管理)
  6. */
  7. const urls = {
  8. ip: ip,
  9. home: ip + '/api/index/home', //首页数据
  10. feedback: ip + '/api/index/feedback', //投诉建议
  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. weather: 'https://www.tianqiapi.com/free/day?appid=46884165&appsecret=b7oFR7GK&unescape=1&cityid=101140214'
  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 === 500) {
  70. uni.showModal({
  71. content: res.data.msg,
  72. showCancel: false
  73. });
  74. return;
  75. }
  76. if (res.data.code === 401) {
  77. uni.removeStorageSync('user');
  78. uni.showModal({
  79. title: '提示',
  80. content: '您还未登陆,请先登陆!',
  81. success: res => {
  82. if (res.confirm) {
  83. uni.navigateTo({
  84. url: '/pages/user/login'
  85. })
  86. }
  87. }
  88. });
  89. return;
  90. }
  91. opt.success(res);
  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 getParam = (url, parameter) => {
  114. let index = url.lastIndexOf(parameter);
  115. url = url.substring(index + 4, url.length);
  116. return url;
  117. }
  118. const getUser = () => {
  119. return uni.getStorageSync('user');
  120. }
  121. //拨打救援电话
  122. const call = (aboutUs) => {
  123. //获取拨打人位置
  124. uni.authorize({
  125. scope: 'scope.userLocation',
  126. success: s => {
  127. uni.getLocation({
  128. type: 'wgs84',
  129. success: res => {
  130. //上传拨打救援记录
  131. request({
  132. method: 'POST',
  133. url: urls.pushHelp,
  134. data: {
  135. memberId: getUser().memberId,
  136. lat: res.latitude,
  137. lng: res.longitude,
  138. phone: aboutUs.helpPhone,
  139. memberPhone: getUser().mobile
  140. },
  141. success: r => {
  142. uni.makePhoneCall({
  143. phoneNumber: aboutUs
  144. .helpPhone
  145. });
  146. }
  147. });
  148. }
  149. });
  150. },
  151. fail(res) {
  152. //1.2 拒绝授权
  153. console.log(JSON.stringify(res));
  154. }
  155. });
  156. }
  157. module.exports = {
  158. urls,
  159. request,
  160. getUser,
  161. call,
  162. getParam,
  163. };