瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
3.5 KiB

8 months ago
7 months ago
8 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
7 months ago
8 months ago
  1. import http from './http.js'
  2. let limit = {}
  3. let debounce = {}
  4. const config = {
  5. // 示例
  6. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  7. // auth : false, showLoading : true, loadingTitle : '加载中...',
  8. // limit : 1000
  9. // },
  10. getConfig : {url : '/api/getConfig', method : 'GET', limit : 500},
  11. // 微信登录接口
  12. wxLogin: {
  13. url: '/login/login',
  14. method: 'GET',
  15. limit : 500,
  16. showLoading : true,
  17. },
  18. // 修改个人信息接口
  19. updateInfo: {
  20. url: '/info/updateInfo',
  21. method: 'POST',
  22. auth: true,
  23. limit : 500,
  24. showLoading : true,
  25. },
  26. //隐私政策
  27. getPrivacyPolicy: {
  28. url: '/login/getPrivacyPolicy',
  29. method: 'GET',
  30. },
  31. //用户协议
  32. getUserAgreement: {
  33. url: '/login/getUserAgreement',
  34. method: 'GET',
  35. },
  36. // 不需要登录的接口
  37. //获取分类
  38. getClassInfo: {
  39. url: '/city/getClassInfo',
  40. method: 'GET',
  41. },
  42. //获取首页头部信息
  43. getIndexHeaderInfo: {
  44. url: '/city/getIndexHeaderInfo',
  45. method: 'GET',
  46. },
  47. //获取banner列表
  48. getBannerList: {
  49. url: '/city/getBannerList',
  50. method: 'GET',
  51. },
  52. //获取分类类型列表
  53. getClassifyList: {
  54. url: '/city/getClassifyList',
  55. method: 'GET',
  56. },
  57. //获取工作信息列表
  58. getJobPage: {
  59. url: '/city/getJobPage',
  60. method: 'GET',
  61. },
  62. //获取工作详情
  63. getJobDetail: {
  64. url: '/city/getJobDetail',
  65. method: 'GET',
  66. },
  67. //根据分类获取租房信息列表
  68. getRentPage: {
  69. url: '/city/getRentPage',
  70. method: 'GET',
  71. },
  72. //获取租房详情
  73. getRentDetail: {
  74. url: '/city/getRentDetail',
  75. method: 'GET',
  76. },
  77. //根据分类获取动态帖子列表带分页
  78. getPostPage: {
  79. url: '/city/getPostPage',
  80. method: 'GET',
  81. },
  82. //获取活动列表信息
  83. getActivityPage: {
  84. url: '/city/getActivityPage',
  85. method: 'GET',
  86. },
  87. //获取活动详情
  88. getActivityDetail: {
  89. url: '/city/getActivityDetail',
  90. method: 'GET',
  91. },
  92. //根据分类获取门店信息列表(美食)
  93. getStorePage: {
  94. url: '/city/getStorePage',
  95. method: 'GET',
  96. },
  97. //发布按钮列表
  98. getPublishList: {
  99. url: '/city/getPublishList',
  100. method: 'GET',
  101. },
  102. //获取城市列表服务区域
  103. getCityList: {
  104. url: '/city/getCityList',
  105. method: 'GET',
  106. },
  107. //发布帖子\动态
  108. publishPost: {
  109. url: '/token/publishPost',
  110. method: 'POST',
  111. limit : 1000,
  112. },
  113. }
  114. export function api(key, data, callback, loadingTitle) {
  115. let req = config[key]
  116. if (!req) {
  117. console.error('无效key--------' + key);
  118. return
  119. }
  120. if (typeof callback == 'string') {
  121. loadingTitle = callback
  122. }
  123. if (typeof data == 'function') {
  124. callback = data
  125. data = {}
  126. }
  127. // 接口限流
  128. if (req.limit) {
  129. let storageKey = req.url
  130. let storage = limit[storageKey]
  131. if (storage && new Date().getTime() - storage < req.limit) {
  132. return
  133. }
  134. limit[storageKey] = new Date().getTime()
  135. }
  136. //必须登录
  137. if (req.auth) {
  138. if (!uni.getStorageSync('token')) {
  139. uni.navigateTo({
  140. url: '/pages_order/auth/wxLogin'
  141. })
  142. console.error('需要登录')
  143. return
  144. }
  145. }
  146. // 接口防抖
  147. if(req.debounce){
  148. let storageKey = req.url
  149. let storage = debounce[storageKey]
  150. if (storage) {
  151. clearTimeout(storage)
  152. }
  153. debounce[storageKey] = setTimeout(() => {
  154. clearTimeout(storage)
  155. delete debounce[storageKey]
  156. http.http(req.url, data, callback, req.method,
  157. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  158. }, req.debounce)
  159. return
  160. }
  161. http.http(req.url, data, callback, req.method,
  162. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  163. }
  164. export default api