酒店桌布为微信小程序
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.

245 lines
3.9 KiB

11 months ago
10 months ago
11 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
11 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
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 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. },
  14. // banner列表
  15. bannerList: {
  16. url: '/banner/list',
  17. method: 'GET',
  18. showLoading : true,
  19. },
  20. // 公告列表
  21. noticeList: {
  22. url: '/notice/list',
  23. method: 'GET',
  24. showLoading : true,
  25. },
  26. // 公告详情
  27. noticeOne: {
  28. url: '/notice/one',
  29. method: 'GET',
  30. showLoading : true,
  31. },
  32. // 商品列表
  33. goodsPage: {
  34. url: '/goods/page',
  35. method: 'GET',
  36. showLoading : true,
  37. },
  38. // 商品详情
  39. goodsOne: {
  40. url: '/goods/one',
  41. method: 'GET',
  42. showLoading : true,
  43. },
  44. // 购物车分页
  45. cartPage: {
  46. url: '/goods/shopping/cart/page',
  47. method: 'GET',
  48. showLoading : true,
  49. auth : true,
  50. },
  51. // 加入购物车
  52. cartAdd: {
  53. url: '/goods/join/shopping/cart',
  54. method: 'POST',
  55. showLoading : true,
  56. auth : true,
  57. },
  58. // 删除购物车
  59. cartDel: {
  60. url: '/goods/shopping/cart/delete',
  61. method: 'POST',
  62. showLoading : true,
  63. auth : true,
  64. },
  65. // 修改购物车数量
  66. cartNum: {
  67. url: '/goods/shopping/cart/add/or/delete',
  68. method: 'POST',
  69. auth : true,
  70. debounce : 1000,
  71. },
  72. //分类列表
  73. categoryList: {
  74. url: '/category/list',
  75. method: 'GET',
  76. showLoading : true,
  77. },
  78. //新增地址
  79. addressAdd: {
  80. url: '/address/add',
  81. method: 'POST',
  82. limit: 500,
  83. auth : true,
  84. showLoading : true,
  85. },
  86. //修改默认地址
  87. addressDefault: {
  88. url: '/address/default',
  89. method: 'POST',
  90. auth : true,
  91. showLoading : true,
  92. },
  93. //删除地址
  94. addressDelete: {
  95. url: '/address/delete',
  96. method: 'POST',
  97. auth : true,
  98. showLoading : true,
  99. },
  100. //修改地址
  101. addressEdit: {
  102. url: '/address/edit',
  103. method: 'POST',
  104. limit: 500,
  105. auth : true,
  106. showLoading : true,
  107. },
  108. //分页查询地址
  109. addressPage: {
  110. url: '/address/page',
  111. method: 'GET',
  112. auth : true,
  113. showLoading : true,
  114. },
  115. //分页查询订单
  116. orderPage: {
  117. url: '/order/page',
  118. method: 'GET',
  119. auth : true,
  120. showLoading : true,
  121. },
  122. //查询订单详情
  123. orderOne: {
  124. url: '/order/one',
  125. method: 'GET',
  126. auth : true,
  127. showLoading : true,
  128. },
  129. // 微信登录接口
  130. wxLogin: {
  131. url: '/login/login',
  132. method: 'POST',
  133. limit : 500,
  134. showLoading : true,
  135. },
  136. // 修改个人信息接口
  137. updateInfo: {
  138. url: '/user/edit',
  139. method: 'POST',
  140. auth: true,
  141. limit : 500,
  142. showLoading : true,
  143. },
  144. // 获取用户信息
  145. getInfo: {
  146. url: '/user/info',
  147. method: 'GET',
  148. auth: true,
  149. showLoading : true,
  150. },
  151. // 获取我的租赁
  152. getLeasePage: {
  153. url: '/user/lease/page',
  154. method: 'POST',
  155. showLoading : true,
  156. },
  157. }
  158. export function api(key, data, callback, loadingTitle) {
  159. let req = config[key]
  160. if (!req) {
  161. console.error('无效key' + key);
  162. return
  163. }
  164. if (typeof callback == 'string') {
  165. loadingTitle = callback
  166. }
  167. if (typeof data == 'function') {
  168. callback = data
  169. data = {}
  170. }
  171. // 接口限流
  172. if (req.limit) {
  173. let storageKey = req.url
  174. let storage = limit[storageKey]
  175. if (storage && new Date().getTime() - storage < req.limit) {
  176. return
  177. }
  178. limit[storageKey] = new Date().getTime()
  179. }
  180. //必须登录
  181. if (req.auth) {
  182. if (!uni.getStorageSync('token')) {
  183. uni.navigateTo({
  184. url: '/pages_order/auth/wxLogin'
  185. })
  186. console.error('需要登录')
  187. return
  188. }
  189. }
  190. // 接口防抖
  191. if(req.debounce){
  192. let storageKey = req.url
  193. let storage = debounce[storageKey]
  194. if (storage) {
  195. clearTimeout(storage)
  196. }
  197. debounce[storageKey] = setTimeout(() => {
  198. clearTimeout(storage)
  199. delete debounce[storageKey]
  200. http.http(req.url, data, callback, req.method,
  201. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  202. }, req.debounce)
  203. return
  204. }
  205. http.http(req.url, data, callback, req.method,
  206. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  207. }
  208. export default api