景徳镇旅游微信小程序
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.

191 lines
3.4 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 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: {
  11. // url: '/api/getConfig',
  12. // method: 'GET',
  13. // limit: 500
  14. // },
  15. // 微信登录接口
  16. wxLogin: {
  17. url: '/login/login',
  18. method: 'GET',
  19. limit: 500,
  20. showLoading: true,
  21. },
  22. // 修改个人信息接口
  23. updateInfo: {
  24. url: '/info/updateInfo',
  25. method: 'POST',
  26. auth: true,
  27. limit: 500,
  28. showLoading: true,
  29. },
  30. //隐私政策
  31. getPrivacyPolicy: {
  32. url: '/login/getPrivacyPolicy',
  33. method: 'GET',
  34. },
  35. //用户协议
  36. getUserAgreement: {
  37. url: '/login/getUserAgreement',
  38. method: 'GET',
  39. },
  40. /**
  41. * 首页相关接口
  42. */
  43. // 添加建议
  44. addAdvice: {
  45. url: '/info/addAdvice',
  46. method: 'POST',
  47. limit: 500,
  48. showLoading: true,
  49. },
  50. // 添加志愿者
  51. addVolunteer: {
  52. url: '/info/addVolunteer',
  53. method: 'POST',
  54. limit: 500,
  55. showLoading: true,
  56. },
  57. // 获取景区列表
  58. queryAreaList: {
  59. url: '/info/queryAreaList',
  60. method: 'GET',
  61. showLoading: true,
  62. },
  63. // 根据id获取文章详情
  64. queryArticleById: {
  65. url: '/info/queryArticleById',
  66. method: 'GET',
  67. showLoading: true,
  68. },
  69. // 获取文章列表
  70. queryArticleList: {
  71. url: '/info/queryArticleList',
  72. method: 'GET',
  73. showLoading: true,
  74. },
  75. // 根据分类获取文章列表
  76. queryArticleListByType: {
  77. url: '/info/queryArticleListByType',
  78. method: 'GET',
  79. showLoading: true,
  80. },
  81. // 获取banner图列表
  82. queryBannerList: {
  83. url: '/info/queryBannerList',
  84. method: 'GET',
  85. showLoading: true,
  86. },
  87. // 根据角色Id获取角色信息详情
  88. queryRoleInfoById: {
  89. url: '/info/queryRoleInfoById',
  90. method: 'GET',
  91. showLoading: true,
  92. },
  93. // 根据角色类型获取角色信息列表-讲解员-达人-摄影师
  94. queryRoleInfoList: {
  95. url: '/info/queryRoleInfoList',
  96. method: 'GET',
  97. showLoading: true,
  98. },
  99. // 根据景区id获取该景区下的地点列表:景点-厕所-美食店铺-民宿
  100. querySpotList: {
  101. url: '/info/querySpotList',
  102. method: 'GET',
  103. showLoading: true,
  104. },
  105. // 获取视频列表
  106. queryVedioById: {
  107. url: '/info/queryVedioById',
  108. method: 'GET',
  109. showLoading: true,
  110. },
  111. }
  112. export function api(key, data, callback, loadingTitle) {
  113. let req = config[key]
  114. if (!req) {
  115. console.error('无效key' + key);
  116. return
  117. }
  118. if (typeof callback == 'string') {
  119. loadingTitle = callback
  120. }
  121. if (typeof data == 'function') {
  122. callback = data
  123. data = {}
  124. }
  125. // 接口限流
  126. if (req.limit) {
  127. let storageKey = req.url
  128. let storage = limit[storageKey]
  129. if (storage && new Date().getTime() - storage < req.limit) {
  130. return
  131. }
  132. limit[storageKey] = new Date().getTime()
  133. }
  134. //必须登录
  135. if (req.auth) {
  136. if (!uni.getStorageSync('token')) {
  137. uni.navigateTo({
  138. url: '/pages_order/auth/wxLogin'
  139. })
  140. console.error('需要登录')
  141. return
  142. }
  143. }
  144. // 接口防抖
  145. if(req.debounce){
  146. let storageKey = req.url
  147. let storage = debounce[storageKey]
  148. if (storage) {
  149. clearTimeout(storage)
  150. }
  151. debounce[storageKey] = setTimeout(() => {
  152. clearTimeout(storage)
  153. delete debounce[storageKey]
  154. http.http(req.url, data, callback, req.method,
  155. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  156. }, req.debounce)
  157. return
  158. }
  159. http.http(req.url, data, callback, req.method,
  160. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  161. }
  162. export default api