indexRx.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import axios from 'axios'
  2. import { Sequelize, EventBus } from 'base-core-lib'
  3. const ignoreUrl = ['notice-se/notice/query/noticeNumber', 'purchase-se/supplySparepartStoreInfo/query/getPageHisBy', '/pbHelpQuestionBank/query/getNoviceGuideData']
  4. const instance = axios.create({
  5. baseURL: process.env.VUE_APP_BASE_API,
  6. withCredentials: process.env.VUE_APP_WITHCREDENTIALS,
  7. timeout: process.env.VUE_APP_AJAX_TIMEOUT
  8. })
  9. console.log(process.env,1234455)
  10. instance.interceptors.request.use(
  11. (config) => {
  12. if(config.params){
  13. if(config.params.loadingstatus){
  14. // EventBus.$emit('hideLoading')
  15. }else{
  16. if (ignoreUrl.indexOf(config.url) === -1) {
  17. EventBus.$emit('showLoading')
  18. }
  19. }
  20. }else{
  21. if (ignoreUrl.indexOf(config.url) === -1) {
  22. EventBus.$emit('showLoading')
  23. }
  24. }
  25. // console.info(config.url, 'config.url')
  26. console.log(config, 'config.url')
  27. return config
  28. },
  29. (error) => {
  30. console.log(error) // for debug
  31. return Promise.reject(error)
  32. },
  33. )
  34. // 添加一个响应拦截器
  35. instance.interceptors.response.use(
  36. (response) => {
  37. // Do something with response data
  38. // console.log('response->', response)
  39. closeLoading()
  40. return response
  41. },
  42. (error) => {
  43. console.log(error, 'error')
  44. // Do something with response error
  45. closeLoading()
  46. return Promise.reject(error)
  47. },
  48. )
  49. function closeLoading () {
  50. setTimeout(() => {
  51. EventBus.$emit('hideLoading')
  52. }, 200)
  53. }
  54. export const appRx = new Sequelize({}, instance)