services.js 5.4 KB

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