services.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. const {
  2. Toast
  3. } = require('./util');
  4. const serverName = 'https://www.4dmuseum.cn/2.0'; // 正式
  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. offlineRecommend: '/wx/api/exhibition/offlineRecommend'
  56. };
  57. // 上传路径
  58. const uploadUrls = {};
  59. const requestFns = {};
  60. Object.keys(urls).forEach(function(key) {
  61. // console.log(token)
  62. requestFns[key] = function(
  63. data = {},
  64. method = "",
  65. success = () => {},
  66. fail = () => {},
  67. complete = () => {}
  68. ) {
  69. console.log(`request ${urls[key]}`);
  70. let commonData = {
  71. loginSessionKey: wx.getStorageSync('token') || ""
  72. };
  73. const url = `${serverName}${urls[key]}`;
  74. return wx.request({
  75. method: method || 'get',
  76. url,
  77. data: {
  78. ...data,
  79. ...commonData
  80. },
  81. header: {
  82. 'content-type': 'application/x-www-form-urlencoded'
  83. },
  84. success: function(res) {
  85. if (res.data.code == 0) {
  86. // console.log(`request ${urls[key]}, success:`, res);
  87. success(res);
  88. } else if (res.data.code == 102) {
  89. // 未登录
  90. // Toast.showToast('warn', '请登录后进行下一步操作');
  91. wx.showModal({
  92. title: '提示',
  93. content: '登录才能进行以上操作,确定登录吗?',
  94. confirmColor: '#e83828',
  95. success: function (res) {
  96. if (res.confirm) {
  97. wx.navigateTo({
  98. url: '/pages/login_page/index',
  99. success: function (res) { },
  100. fail: function (res) { },
  101. complete: function (res) { },
  102. })
  103. } else if (res.cancel) {
  104. console.log('用户点击取消')
  105. }
  106. }
  107. })
  108. // Toast.showToast('tip', "登录才能进行以上操作", success => {
  109. // })
  110. fail(res);
  111. } else if (res.data.code == 11) {
  112. Toast.showToast('warn', '提交信息不完整');
  113. fail(res);
  114. } else if (res.data.code == 14) {
  115. Toast.showToast('warn', '该展会异常,请联系管理员');
  116. fail(res);
  117. } else if (res.data.code == 15) {
  118. Toast.showToast('warn', '该展会不需要支付');
  119. fail(res);
  120. } else if (res.data.code == 16) {
  121. Toast.showToast('warn', '金额有误');
  122. fail(res);
  123. } else if (res.data.code == 101) {
  124. Toast.showToast('warn', '网络超时,请重新登录');
  125. fail(res);
  126. } else if (res.data.code == 103) {
  127. Toast.showToast('warn', '微信统一下单异常');
  128. fail(res);
  129. } else if (res.data.code == 104) {
  130. Toast.showToast('warn', '获取参数失败,请重新下单');
  131. fail(res);
  132. } else if (res.data.code == 106) {
  133. Toast.showToast('warn', '您已下单,请前往【我的-我的订单】完成支付');
  134. fail(res);
  135. } else if (res.data.code == 105) {
  136. Toast.showToast('warn', '您已经发表过评论,不能重复评论');
  137. fail(res);
  138. } else if (res.data.code == 107) {
  139. Toast.showToast('warn', '账号异常,请重新登录');
  140. fail(res);
  141. } else if (res.data.code == -1) {
  142. Toast.showToast('warn', '请求发送失败');
  143. fail(res);
  144. } else {
  145. Toast.showToast('warn', res.data.msg || '网络超时,请检查网络');
  146. fail(res);
  147. }
  148. },
  149. fail: function(res) {
  150. fail(res);
  151. },
  152. complete: function() {
  153. complete()
  154. }
  155. });
  156. };
  157. });
  158. module.exports.request = requestFns;
  159. module.exports.serverName = serverName;
  160. module.exports.imgServer = imgServer;