services.js 5.5 KB

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