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.

76 lines
2.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. //vxvdvdsvsdvvds3
  2. import router from "@/router";
  3. import axios from "axios";
  4. // import Promise from 'promise'
  5. import { yztoken } from "@/utlis/istoken";
  6. import mm from "@/utlis/mm";
  7. import { Message } from "element-ui";
  8. const instance = axios.create({
  9. baseURL: mm.apiurl,
  10. timeout: 500000,
  11. });
  12. //请求拦截
  13. instance.interceptors.request.use(
  14. async function (config) {
  15. //console.log('old token:',localStorage.getItem("token"))
  16. //console.log('old expires_in',localStorage.getItem("expires_in"))
  17. await yztoken();
  18. let token = localStorage.getItem("token");
  19. let tokentype = localStorage.getItem("tokentype");
  20. config.headers["Access-Control-Allow-Origin"] = "*";
  21. // config.headers.ContentType = 'application/x-www-form-urlencoded'
  22. config.headers.Authorization = `${tokentype} ${token}`;
  23. return config;
  24. },
  25. function (err) {
  26. console.log("666");
  27. return Promise.reject(err);
  28. }
  29. );
  30. //响应拦截
  31. instance.interceptors.response.use(
  32. (res) => {
  33. console.log(res);
  34. if (res.data.code == -1) {
  35. Message.error(res.data.message);
  36. }
  37. return res.data;
  38. },
  39. (err) => {
  40. // console.log(err);
  41. // if (response.data.code == -1) {
  42. // router.push({ path: '/login' })
  43. // // this.$router.push({path:'/login'})
  44. // // this.$message.success('状态失效')
  45. // Message.error('状态失效请重新登录')
  46. // console.log('token失效返回登录');
  47. // }
  48. // console.log(err);
  49. return Promise.reject(err);
  50. }
  51. // function (response) {
  52. // console.log(response,10010)
  53. // const {data} = response
  54. // if (data.status == 401) {
  55. // window.location.href = '#/login'
  56. // this.$message.error('状态失效');
  57. // }
  58. // return data
  59. // },
  60. // function (err) {
  61. // if (err.response.status === 401) {
  62. // window.location.href = '#/login'
  63. // this.$router.push({ path: '/login' })
  64. // this.$message.error('登录失效请重新登录');
  65. // }
  66. // return err
  67. // }
  68. );
  69. export default instance;