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

208 lines
4.6 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 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/edit',
  102. method: 'POST',
  103. },
  104. // 用户地址表-删除
  105. deleteAddress: {
  106. url: '/address/edit',
  107. method: 'PUT',
  108. },
  109. // 用户地址表-分页列表查询
  110. addressList: {
  111. url: '/address/list',
  112. method: 'GET',
  113. },
  114. // ========================首页等展示接口===============================
  115. // 帮助与反馈
  116. addSuggest: {
  117. url: '/index/addSuggest',
  118. method: 'POST',
  119. },
  120. // 铝价接口
  121. getAlPrice: {
  122. url: '/index/alprice',
  123. method: 'POST',
  124. },
  125. // 我的头像昵称,平台客户电话等信息
  126. getImagePhoneOther: {
  127. url: '/index/index',
  128. method: 'POST',
  129. },
  130. }
  131. export function api(key, data, callback, loadingTitle) {
  132. let req = config[key]
  133. if (!req) {
  134. console.error('无效key' + key);
  135. return
  136. }
  137. if (typeof callback == 'string') {
  138. loadingTitle = callback
  139. }
  140. if (typeof data == 'function') {
  141. callback = data
  142. data = {}
  143. }
  144. // 接口限流
  145. if (req.limit) {
  146. let storageKey = req.url
  147. let storage = limit[storageKey]
  148. if (storage && new Date().getTime() - storage < req.limit) {
  149. return
  150. }
  151. limit[storageKey] = new Date().getTime()
  152. }
  153. //必须登录
  154. if (req.auth) {
  155. if (!uni.getStorageSync('token')) {
  156. uni.navigateTo({
  157. url: '/pages_order/auth/loginAndRegisterAndForgetPassword'
  158. })
  159. console.error('需要登录')
  160. return
  161. }
  162. }
  163. // 接口防抖
  164. if (req.debounce) {
  165. let storageKey = req.url
  166. let storage = debounce[storageKey]
  167. if (storage) {
  168. clearTimeout(storage)
  169. }
  170. debounce[storageKey] = setTimeout(() => {
  171. clearTimeout(storage)
  172. delete debounce[storageKey]
  173. http.http(req.url, data, callback, req.method,
  174. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  175. }, req.debounce)
  176. return
  177. }
  178. http.http(req.url, data, callback, req.method,
  179. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  180. }
  181. export default api