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.

88 lines
3.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import {
  2. baseUrl
  3. } from "./config"
  4. const {
  5. http
  6. } = uni.$u
  7. // 响应拦截
  8. http.interceptors.response.use((response) => {
  9. /* 对响应成功做点什么 可使用async await 做异步操作*/
  10. const data = response.data
  11. // 自定义参数
  12. const custom = response.config?.custom
  13. if (data.code !== 200) {
  14. // 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
  15. if (custom.toast !== false) {
  16. uni.$u.toast(data.msg)
  17. }
  18. // 如果需要catch返回,则进行reject
  19. if (custom?.catch) {
  20. return Promise.reject(data)
  21. } else {
  22. // 否则返回一个pending中的promise,请求不会进入catch中
  23. return new Promise(() => {})
  24. }
  25. }
  26. return data.data === undefined ? {} : data.data
  27. }, (response) => {
  28. // 对响应错误做点什么 (statusCode !== 200)
  29. return Promise.reject(response)
  30. })
  31. // 带上用户token
  32. const userConfig = function() {
  33. return {
  34. header: {
  35. 'User-Token': uni.getStorageSync('user_token')
  36. }
  37. }
  38. }
  39. export const userGetMerchantInfo = (params) => http.post(baseUrl + '/api/user/getMerchantInfo', params, userConfig())
  40. export const userCreateOrder = (params) => http.post(baseUrl + '/api/user/createOrder', params, userConfig())
  41. export const userAccountInfo = () => http.post(baseUrl + '/api/user/accountInfo', {}, userConfig())
  42. export const userQueueRebateList = (params) => http.post(baseUrl + '/api/user/queueRebateList', params, userConfig())
  43. export const userOrderList = (params) => http.post(baseUrl + '/api/user/orderList', params, userConfig())
  44. export const userFillAlipayAccount = (params) => http.post(baseUrl + '/api/user/fillAlipayAccount', params, userConfig())
  45. export const userWithdraw = (params) => http.post(baseUrl + '/api/user/withdraw', params, userConfig())
  46. export const userWithdrawList = (params) => http.post(baseUrl + '/api/user/withdrawList', params, userConfig())
  47. // 带上代理token
  48. const agentConfig = function() {
  49. return {
  50. header: {
  51. 'Agent-Token': uni.getStorageSync('agent_token')
  52. }
  53. }
  54. }
  55. export const agentSmsLogin = (params) => http.post(baseUrl + '/api/agent/smsLogin', params)
  56. export const agentAccountInfo = (params) => http.post(baseUrl + '/api/agent/accountInfo', params, agentConfig())
  57. export const agentMerchantList = (params) => http.post(baseUrl + '/api/agent/merchantList', params, agentConfig())
  58. export const agentOrderList = (params) => http.post(baseUrl + '/api/agent/orderList', params, agentConfig())
  59. export const agentFillAlipayAccount = (params) => http.post(baseUrl + '/api/agent/fillAlipayAccount', params, agentConfig())
  60. export const agentWithdraw = (params) => http.post(baseUrl + '/api/agent/withdraw', params, agentConfig())
  61. export const agentWithdrawList = (params) => http.post(baseUrl + '/api/agent/withdrawList', params, agentConfig())
  62. // 带上商户token
  63. const merchantConfig = function() {
  64. return {
  65. header: {
  66. 'Merchant-Token': uni.getStorageSync('merchant_token')
  67. }
  68. }
  69. }
  70. export const merchantSmsLogin = (params) => http.post(baseUrl + '/api/merchant/smsLogin', params)
  71. export const merchantAccountInfo = (params) => http.post(baseUrl + '/api/merchant/accountInfo', params, merchantConfig())
  72. export const merchantOrderList = (params) => http.post(baseUrl + '/api/merchant/orderList', params, merchantConfig())
  73. export const merchantOrderRefund = (params) => http.post(baseUrl + '/api/merchant/orderRefund', params, merchantConfig())
  74. export const publicSysConfig = (params) => http.post(baseUrl + '/api/public/sysConfig', params)
  75. export const publicSendSms = (params) => http.post(baseUrl + '/api/public/sendSms', params)