services.js 5.6 KB

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