services.js 5.3 KB

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