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

241 lines
5.3 KiB

11 months ago
11 months ago
11 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
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 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: {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. limit : 1000,
  57. },
  58. // ========================产品报价===============================
  59. // 清关申请
  60. addCustoms: {
  61. url: '/product/addCustoms',
  62. method: 'POST',
  63. limit : 1000,
  64. },
  65. // 产品报价
  66. addProduct: {
  67. url: '/product/addProduct',
  68. method: 'POST',
  69. },
  70. // 下订单
  71. addProductOrder: {
  72. url: '/product/addProductOrder',
  73. method: 'POST',
  74. },
  75. // 确认-取消订单
  76. updateOrder: {
  77. url: '/product/updateOrder',
  78. method: 'POST',
  79. },
  80. // 我的挂单列表
  81. getMyProductlist: {
  82. url: '/product/myProductlist',
  83. method: 'GET',
  84. },
  85. // 撤单
  86. noShow: {
  87. url: '/product/noShow',
  88. method: 'GET',
  89. },
  90. // 现货/期货列表
  91. productList: {
  92. url: '/product/productList',
  93. method: 'GET',
  94. },
  95. // 交易平台挂单列表
  96. productlist: {
  97. url: '/product/productlist',
  98. method: 'GET',
  99. },
  100. // ========================用户地址===============================
  101. // 用户地址表-添加
  102. addAddress: {
  103. url: '/address/add',
  104. method: 'POST',
  105. },
  106. // 用户地址表-编辑
  107. editAddress: {
  108. url: '/address/edit',
  109. method: 'POST',
  110. },
  111. // 用户地址表-删除
  112. deleteAddress: {
  113. url: '/address/edit',
  114. method: 'PUT',
  115. },
  116. // 用户地址表-分页列表查询
  117. addressList: {
  118. url: '/address/list',
  119. method: 'GET',
  120. },
  121. // ========================首页等展示接口===============================
  122. // 帮助与反馈
  123. addSuggest: {
  124. url: '/index/addSuggest',
  125. method: 'POST',
  126. },
  127. // 铝价接口
  128. getAlPrice: {
  129. url: '/index/alprice',
  130. method: 'POST',
  131. },
  132. // 我的头像昵称,平台客户电话等信息
  133. getImagePhoneOther: {
  134. url: '/index/index',
  135. method: 'POST',
  136. limit: 500,
  137. },
  138. // 我的订单列表
  139. myOrderlist: {
  140. url: '/product/myOrderlist',
  141. method: 'GET',
  142. limit: 500,
  143. },
  144. // 采购商根据订单id查询订单信息
  145. getMyOrderInfo: {
  146. url: '/product/myOrderlist',
  147. method: 'GET',
  148. limit: 500,
  149. },
  150. // 供应商根据挂单id查询挂单详情的接口
  151. getProductInfo: {
  152. url: '/product/myOrderlist',
  153. method: 'GET',
  154. limit: 500,
  155. },
  156. // 获取banner列表
  157. bannerList: {
  158. url: '/index/bannerList',
  159. method: 'POST',
  160. limit: 500,
  161. },
  162. }
  163. export function api(key, data, callback, loadingTitle) {
  164. let req = config[key]
  165. if (!req) {
  166. console.error('无效key' + key);
  167. return
  168. }
  169. if (typeof callback == 'string') {
  170. loadingTitle = callback
  171. }
  172. if (typeof data == 'function') {
  173. callback = data
  174. data = {}
  175. }
  176. // 接口限流
  177. if (req.limit) {
  178. let storageKey = req.url
  179. let storage = limit[storageKey]
  180. if (storage && new Date().getTime() - storage < req.limit) {
  181. return
  182. }
  183. limit[storageKey] = new Date().getTime()
  184. }
  185. //必须登录
  186. if (req.auth) {
  187. if (!uni.getStorageSync('token')) {
  188. uni.navigateTo({
  189. url: '/pages_order/auth/loginAndRegisterAndForgetPassword'
  190. })
  191. console.error('需要登录')
  192. return
  193. }
  194. }
  195. // 接口防抖
  196. if (req.debounce) {
  197. let storageKey = req.url
  198. let storage = debounce[storageKey]
  199. if (storage) {
  200. clearTimeout(storage)
  201. }
  202. debounce[storageKey] = setTimeout(() => {
  203. clearTimeout(storage)
  204. delete debounce[storageKey]
  205. http.http(req.url, data, callback, req.method,
  206. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  207. }, req.debounce)
  208. return
  209. }
  210. http.http(req.url, data, callback, req.method,
  211. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  212. }
  213. export default api