铝交易,微信公众号
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.

203 lines
4.5 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 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: 'POST',
  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. loginUser: {
  39. url: '/alUser/login',
  40. method: 'POST',
  41. },
  42. //用户注册
  43. registerUser: {
  44. url: '/alUser/regUesr',
  45. method: 'POST',
  46. },
  47. // 发送短信接口
  48. sendSms: {
  49. url: '/alUser/sendSms',
  50. method: 'POST',
  51. },
  52. // 选择身份
  53. roleOption: {
  54. url: '/alUser/role',
  55. method: 'POST',
  56. },
  57. // ========================产品报价===============================
  58. // 清关申请
  59. addCustoms: {
  60. url: '/product/addCustoms',
  61. method: 'POST',
  62. },
  63. // 产品报价
  64. addProduct: {
  65. url: '/product/addProduct',
  66. method: 'POST',
  67. },
  68. // 下订单
  69. addProductOrder: {
  70. url: '/product/addProductOrder',
  71. method: 'POST',
  72. },
  73. // 我的挂单列表
  74. getMyProductlist: {
  75. url: '/product/myProductlist',
  76. method: 'GET',
  77. },
  78. // 撤单
  79. noShow: {
  80. url: '/product/noShow',
  81. method: 'GET',
  82. },
  83. // 产品报价分页列表
  84. productList: {
  85. url: '/product/productList',
  86. method: 'GET',
  87. },
  88. // 交易平台挂单列表
  89. productlist: {
  90. url: '/product/productList',
  91. method: 'GET',
  92. },
  93. // ========================用户地址===============================
  94. // 用户地址表-添加
  95. addAddress: {
  96. url: '/address/add',
  97. method: 'POST',
  98. },
  99. // 用户地址表-编辑
  100. editAddress: {
  101. url: '/address/add',
  102. method: 'POST',
  103. },
  104. // 用户地址表-分页列表查询
  105. addressList: {
  106. url: '/address/list',
  107. method: 'GET',
  108. },
  109. // ========================首页等展示接口===============================
  110. // 帮助与反馈
  111. addSuggest: {
  112. url: '/index/addSuggest',
  113. method: 'POST',
  114. },
  115. // 铝价接口
  116. getAlPrice: {
  117. url: '/index/alprice',
  118. method: 'POST',
  119. },
  120. // 我的头像昵称,平台客户电话等信息
  121. getImagePhoneOther: {
  122. url: '/index/index',
  123. method: 'POST',
  124. },
  125. }
  126. export function api(key, data, callback, loadingTitle) {
  127. let req = config[key]
  128. if (!req) {
  129. console.error('无效key' + key);
  130. return
  131. }
  132. if (typeof callback == 'string') {
  133. loadingTitle = callback
  134. }
  135. if (typeof data == 'function') {
  136. callback = data
  137. data = {}
  138. }
  139. // 接口限流
  140. if (req.limit) {
  141. let storageKey = req.url
  142. let storage = limit[storageKey]
  143. if (storage && new Date().getTime() - storage < req.limit) {
  144. return
  145. }
  146. limit[storageKey] = new Date().getTime()
  147. }
  148. //必须登录
  149. if (req.auth) {
  150. if (!uni.getStorageSync('token')) {
  151. uni.navigateTo({
  152. url: '/pages_order/auth/wxLogin'
  153. })
  154. console.error('需要登录')
  155. return
  156. }
  157. }
  158. // 接口防抖
  159. if (req.debounce) {
  160. let storageKey = req.url
  161. let storage = debounce[storageKey]
  162. if (storage) {
  163. clearTimeout(storage)
  164. }
  165. debounce[storageKey] = setTimeout(() => {
  166. clearTimeout(storage)
  167. delete debounce[storageKey]
  168. http.http(req.url, data, callback, req.method,
  169. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  170. }, req.debounce)
  171. return
  172. }
  173. http.http(req.url, data, callback, req.method,
  174. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  175. }
  176. export default api