services.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. const {
  2. Toast
  3. } = require('./util');
  4. //const serverName = 'https://www.4dmuseum.cn'; // 正式
  5. const serverName = 'http://192.168.0.177:8081'; // 本地
  6. //const imgServer = 'https://www.4dmuseum.cn/'
  7. const imgServer = ''
  8. const urls = {
  9. //用户API
  10. getLoginSessionKey: '/wx/api/user/getLoginSessionKey',
  11. // checkPaySessionKey:'/wx/api/user/checkLoginSessionKey',
  12. checkLoginSessionKey: '/wx/api/user/getBrowsedExhibitions',
  13. logout: '/wx/api/user/logout',
  14. isCollect: '/wx/api/exhibition/like',
  15. collectExhibitions: "/wx/api/user/getExhibitions",
  16. getOrders: '/wx/api/user/getOrders',
  17. //轮播图
  18. getBannerList: '/wx/api/banner/list',
  19. //展会
  20. getExhibitionList: "/wx/api/exhibition/listByType",
  21. getExhibitionListOffline: "/wx/api/exhibition/offline",
  22. getExhibitionDetail: "/wx/api/exhibition/detail",
  23. getExhibitionSearch: "/wx/api/exhibition/search",
  24. getKeywordCode: "/wx/api/dataDictionary/keywordCode",
  25. //展馆
  26. getPavilionDetail: "/wx/api/pavilion/detail",
  27. getPavilionSearch: "/wx/api/pavilion/search",
  28. //同城
  29. getDomesticCity: '/wx/api/exhibition/domesticCity',
  30. getInternationalCity: '/wx/api/exhibition/internationalCity',
  31. getNearByList: '/wx/api/exhibition/nearByList',
  32. //支付
  33. orderPay: '/wx/api/order/pay',
  34. getPayParams: '/wx/api/order/getPayParams',
  35. getProduct: '/wx/api/exhibition/getProduct',
  36. //看过
  37. getExhibitionsByIds: '/wx/api/exhibition/getExhibitionsByIds',
  38. //评论
  39. getComments: '/wx/api/user/getComments',
  40. //保存浏览
  41. saveBrowsedExhibitions: '/wx/api/user/saveBrowsedExhibitions',
  42. //获取浏览记录id
  43. getBrowsedExhibitions: 'wx/api/user/getBrowsedExhibitions',
  44. //
  45. getCommentslist: '/wx/api/comment/list',
  46. //评论
  47. writtenComments: '/wx/api/comment/written',
  48. //点赞评论
  49. commentLike: '/wx/api/comment/like',
  50. //未读
  51. longPolling: '/wx/api/user/longPolling',
  52. //热门推荐
  53. recommend: '/wx/api/exhibition/recommend'
  54. };
  55. // 上传路径
  56. const uploadUrls = {};
  57. const requestFns = {};
  58. Object.keys(urls).forEach(function(key) {
  59. // console.log(token)
  60. requestFns[key] = function(
  61. data = {},
  62. method = "",
  63. success = () => {},
  64. fail = () => {},
  65. complete = () => {}
  66. ) {
  67. console.log(`request ${urls[key]}`);
  68. let commonData = {
  69. loginSessionKey: wx.getStorageSync('token') || ""
  70. };
  71. const url = `${serverName}${urls[key]}`;
  72. return wx.request({
  73. method: method || 'get',
  74. url,
  75. data: {
  76. ...data,
  77. ...commonData
  78. },
  79. header: {
  80. 'content-type': 'application/x-www-form-urlencoded'
  81. },
  82. success: function(res) {
  83. if (res.data.code == 0) {
  84. // console.log(`request ${urls[key]}, success:`, res);
  85. success(res);
  86. } else if (res.data.code == 102) {
  87. // 未登录
  88. // Toast.showToast('warn', '请登录后进行下一步操作');
  89. wx.showModal({
  90. title: '提示',
  91. content: '登录才能进行以上操作,确定登录吗?',
  92. confirmColor: '#e83828',
  93. success: function (res) {
  94. if (res.confirm) {
  95. wx.navigateTo({
  96. url: '/pages/login_page/index',
  97. success: function (res) { },
  98. fail: function (res) { },
  99. complete: function (res) { },
  100. })
  101. } else if (res.cancel) {
  102. console.log('用户点击取消')
  103. }
  104. }
  105. })
  106. // Toast.showToast('tip', "登录才能进行以上操作", success => {
  107. // })
  108. fail(res);
  109. } else if (res.data.code == 11) {
  110. Toast.showToast('warn', '提交信息不完整');
  111. fail(res);
  112. } else if (res.data.code == 14) {
  113. Toast.showToast('warn', '该展会异常,请联系管理员');
  114. fail(res);
  115. } else if (res.data.code == 15) {
  116. Toast.showToast('warn', '该展会不需要支付');
  117. fail(res);
  118. } else if (res.data.code == 16) {
  119. Toast.showToast('warn', '金额有误');
  120. fail(res);
  121. } else if (res.data.code == 101) {
  122. Toast.showToast('warn', '网络超时,请重新登录');
  123. fail(res);
  124. } else if (res.data.code == 103) {
  125. Toast.showToast('warn', '微信统一下单异常');
  126. fail(res);
  127. } else if (res.data.code == 104) {
  128. Toast.showToast('warn', '获取参数失败,请重新下单');
  129. fail(res);
  130. } else if (res.data.code == 106) {
  131. Toast.showToast('warn', '您已下单,请前往【我的-我的订单】完成支付');
  132. fail(res);
  133. } else if (res.data.code == 105) {
  134. Toast.showToast('warn', '您已经发表过评论,不能重复评论');
  135. fail(res);
  136. } else if (res.data.code == 107) {
  137. Toast.showToast('warn', '账号异常,请重新登录');
  138. fail(res);
  139. } else if (res.data.code == -1) {
  140. Toast.showToast('warn', '请求发送失败');
  141. fail(res);
  142. } else {
  143. Toast.showToast('warn', res.data.msg || '网络超时,请检查网络');
  144. fail(res);
  145. }
  146. },
  147. fail: function(res) {
  148. fail(res);
  149. },
  150. complete: function() {
  151. complete()
  152. }
  153. });
  154. };
  155. });
  156. module.exports.request = requestFns;
  157. module.exports.serverName = serverName;
  158. module.exports.imgServer = imgServer;