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

282 lines
4.6 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
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. },
  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. getMyUserPage: {
  117. url: '/shop/user',
  118. method: 'GET',
  119. auth : true,
  120. showLoading : true,
  121. },
  122. //分页查询订单
  123. orderPage: {
  124. url: '/order/page',
  125. method: 'GET',
  126. auth : true,
  127. showLoading : true,
  128. },
  129. //查询订单详情
  130. orderOne: {
  131. url: '/order/one',
  132. method: 'GET',
  133. auth : true,
  134. showLoading : true,
  135. },
  136. // 微信登录接口
  137. wxLogin: {
  138. url: '/login/login',
  139. method: 'POST',
  140. limit : 500,
  141. showLoading : true,
  142. },
  143. // 修改个人信息接口
  144. updateInfo: {
  145. url: '/user/edit',
  146. method: 'POST',
  147. auth: true,
  148. limit : 500,
  149. showLoading : true,
  150. },
  151. // 获取用户信息
  152. getInfo: {
  153. url: '/user/info',
  154. method: 'GET',
  155. auth: true,
  156. showLoading : true,
  157. },
  158. // 获取我的租赁
  159. getLeasePage: {
  160. url: '/user/lease/page',
  161. method: 'POST',
  162. showLoading : true,
  163. },
  164. // 申请成为水洗店
  165. applyShopHotel: {
  166. url: '/shop/apply',
  167. method: 'POST',
  168. showLoading : true,
  169. auth : true,
  170. },
  171. // 店铺申请提现
  172. storeWithdrawalApplication: {
  173. url: '/shop/withdrawal/apply',
  174. method: 'POST',
  175. showLoading : true,
  176. auth : true,
  177. },
  178. // 提现日志
  179. withdrawalLog: {
  180. url: '/withdrawal/page',
  181. method: 'GET',
  182. showLoading : true,
  183. auth : true,
  184. },
  185. // 水洗店首页数据
  186. laundryStoreHomeData: {
  187. url: '/shop/index',
  188. method: 'GET',
  189. // showLoading : true,
  190. auth : true,
  191. },
  192. }
  193. export function api(key, data, callback, loadingTitle) {
  194. let req = config[key]
  195. if (!req) {
  196. console.error('无效key' + key);
  197. return
  198. }
  199. if (typeof callback == 'string') {
  200. loadingTitle = callback
  201. }
  202. if (typeof data == 'function') {
  203. callback = data
  204. data = {}
  205. }
  206. // 接口限流
  207. if (req.limit) {
  208. let storageKey = req.url
  209. let storage = limit[storageKey]
  210. if (storage && new Date().getTime() - storage < req.limit) {
  211. return
  212. }
  213. limit[storageKey] = new Date().getTime()
  214. }
  215. //必须登录
  216. if (req.auth) {
  217. if (!uni.getStorageSync('token')) {
  218. uni.navigateTo({
  219. url: '/pages_order/auth/wxLogin'
  220. })
  221. console.error('需要登录')
  222. return
  223. }
  224. }
  225. // 接口防抖
  226. if(req.debounce){
  227. let storageKey = req.url
  228. let storage = debounce[storageKey]
  229. if (storage) {
  230. clearTimeout(storage)
  231. }
  232. debounce[storageKey] = setTimeout(() => {
  233. clearTimeout(storage)
  234. delete debounce[storageKey]
  235. http.http(req.url, data, callback, req.method,
  236. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  237. }, req.debounce)
  238. return
  239. }
  240. http.http(req.url, data, callback, req.method,
  241. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  242. }
  243. export default api