services.js 5.5 KB

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