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

173 lines
2.8 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. import http from './http.js'
  2. const config = {
  3. // 示例
  4. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  5. // auth : false, showLoading : true, loadingTitle : '加载中...',
  6. // limit : 1000
  7. // },
  8. getConfig: {
  9. url: '/api/getConfig',
  10. method: 'GET'
  11. },
  12. // banner列表
  13. bannerList: {
  14. url: '/banner/list',
  15. method: 'GET',
  16. showLoading : true,
  17. },
  18. // 公告列表
  19. noticeList: {
  20. url: '/notice/list',
  21. method: 'GET',
  22. showLoading : true,
  23. },
  24. // 公告详情
  25. noticeOne: {
  26. url: '/notice/one',
  27. method: 'GET',
  28. showLoading : true,
  29. },
  30. // 商品列表
  31. goodsPage: {
  32. url: '/goods/page',
  33. method: 'GET',
  34. showLoading : true,
  35. },
  36. // 商品详情
  37. goodsOne: {
  38. url: '/goods/one',
  39. method: 'GET',
  40. showLoading : true,
  41. },
  42. //分类列表
  43. categoryList: {
  44. url: '/category/list',
  45. method: 'GET',
  46. showLoading : true,
  47. },
  48. //新增地址
  49. addressAdd: {
  50. url: '/address/add',
  51. method: 'POST',
  52. limit: 500,
  53. // auth : true,
  54. showLoading : true,
  55. },
  56. //修改默认地址
  57. addressDefault: {
  58. url: '/address/default',
  59. method: 'POST',
  60. // auth : true,
  61. showLoading : true,
  62. },
  63. //删除地址
  64. addressDelete: {
  65. url: '/address/delete',
  66. method: 'POST',
  67. // auth : true,
  68. showLoading : true,
  69. },
  70. //修改地址
  71. addressEdit: {
  72. url: '/address/edit',
  73. method: 'POST',
  74. limit: 500,
  75. // auth : true,
  76. showLoading : true,
  77. },
  78. //分页查询地址
  79. addressPage: {
  80. url: '/address/page',
  81. method: 'GET',
  82. // auth : true,
  83. showLoading : true,
  84. },
  85. //分页查询订单
  86. orderPage: {
  87. url: '/order/page',
  88. method: 'GET',
  89. // auth : true,
  90. showLoading : true,
  91. },
  92. //查询订单详情
  93. orderOne: {
  94. url: '/order/one',
  95. method: 'GET',
  96. // auth : true,
  97. showLoading : true,
  98. },
  99. // 微信登录接口
  100. wxLogin: {
  101. url: '/login/login',
  102. method: 'POST',
  103. limit : 500,
  104. showLoading : true,
  105. },
  106. // 修改个人信息接口
  107. updateInfo: {
  108. url: '/info/updateInfo',
  109. method: 'POST',
  110. auth: true,
  111. limit : 500,
  112. showLoading : true,
  113. },
  114. }
  115. export function api(key, data, callback, loadingTitle) {
  116. let req = config[key]
  117. if (!req) {
  118. console.error('无效key' + key);
  119. return
  120. }
  121. if (typeof callback == 'string') {
  122. loadingTitle = callback
  123. }
  124. if (typeof data == 'function') {
  125. callback = data
  126. data = {}
  127. }
  128. // 接口限流
  129. if (req.limit) {
  130. let storageKey = 'limit:' + req.url
  131. let storage = uni.getStorageSync(storageKey)
  132. if (storage && new Date().getTime() - parseInt(storage) < req.limit) {
  133. return
  134. }
  135. uni.setStorageSync(storageKey, new Date().getTime())
  136. }
  137. //必须登录
  138. if (req.auth) {
  139. if (!uni.getStorageSync('token')) {
  140. uni.navigateTo({
  141. url: '/pages/login/mobile'
  142. })
  143. console.error('需要登录')
  144. return
  145. }
  146. }
  147. http.http(req.url, data, callback, req.method,
  148. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  149. }
  150. export default api