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

247 lines
5.4 KiB

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