services.js 5.5 KB

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