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.

41 lines
791 B

  1. import Request from '@/common/libs/luch-request/index.js'
  2. import App from '@/app.config.js'
  3. const http = new Request()
  4. http.setConfig(config => {
  5. config.baseURL = App.BASE_URL
  6. return config
  7. })
  8. function Token () {
  9. return uni.getStorageSync('token') || ''
  10. }
  11. http.interceptors.request.use(config => {
  12. config.header = {
  13. ...config.header,
  14. token: Token
  15. }
  16. return config
  17. }, config => {
  18. return Promise.reject(config)
  19. })
  20. http.interceptors.response.use((response) => {
  21. const data = response.data
  22. if(/([1345]\d*)/.test(data.code)) {
  23. uni.showToast({
  24. icon: 'none',
  25. title: data.msg
  26. })
  27. return Promise.reject(response)
  28. }
  29. return response
  30. }, (response) => {
  31. return Promise.reject(response)
  32. })
  33. export default http