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