upload.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import axios from 'axios';
  2. import { Message, MessageBox } from 'element-ui';
  3. import { delItem } from '@/utils/storage';
  4. axios.defaults.baseURL = process.env.BASE_API
  5. // axios.defaults.baseURL = 'http://10.108.12.23:8080' // 德明本地
  6. // axios.defaults.baseURL = "http://haitongnla.test.anji-plus.com"
  7. // axios.defaults.baseURL = "http://10.108.26.163:8080"
  8. const service = axios.create({
  9. withCredentials: true,
  10. timeout: 60000,
  11. headers: {
  12. 'Content-Type': 'multipart/form-data'
  13. }
  14. })
  15. // response interceptor
  16. service.interceptors.response.use(
  17. response => {
  18. const res = response.data;
  19. if (res.repCode == '0000') {
  20. return res
  21. }
  22. else if (res.repCode == '0024') {
  23. //登录超时或被登出,弹确认框,用户确认后,跳转到登录页面
  24. MessageBox({
  25. message: "当前登录已失效或异地登录,请重新登录",
  26. type: 'error',
  27. duration: 3 * 1000,
  28. }).then(() => {
  29. console.log(1)
  30. sessionStorage.clear();
  31. localStorage.clear();
  32. // location.reload();
  33. window.location.href = "/";
  34. }).catch(err => {
  35. console.log(2)
  36. })
  37. }else if(res.repCode == "3100" || res.repCode == "3101"){
  38. return res;
  39. }
  40. else {
  41. Message({
  42. message: res.repMsg,
  43. type: 'error',
  44. duration: 3 * 1000
  45. })
  46. return res;
  47. }
  48. },
  49. error => {
  50. var errorStatus = error.response.status;
  51. var errorData = error.response.data;
  52. var messageTxt = "";
  53. if (errorStatus != 200) {
  54. messageTxt = "服务器内部错误,请联系管理员";
  55. } else {
  56. messageTxt = '失败原因:' + errorData.repCode + '--' + errorData.repMsg;
  57. }
  58. Message({
  59. message: messageTxt,
  60. type: 'error',
  61. duration: 5 * 1000
  62. })
  63. }
  64. )
  65. export default service