axiosNotice.ts 701 B

12345678910111213141516171819202122232425262728
  1. import Vue from "vue";
  2. import { throttle } from "lodash-es";
  3. import { message } from "ant-design-vue";
  4. import { logout } from "@/api/loginPage";
  5. import router, { routeLogout } from "@/router";
  6. export const notifyInvalidTokenThrottled = throttle(
  7. () => {
  8. if (router.currentRoute.value.name === "Login") {
  9. return;
  10. }
  11. message.error({
  12. content: "登录失效,请重新登录!",
  13. duration: 10,
  14. });
  15. setTimeout(() => {
  16. logout().finally(() =>
  17. routeLogout({
  18. cause: "登录失效",
  19. redirectTo: router.currentRoute.value.fullPath,
  20. })
  21. );
  22. }, 3000);
  23. console.log("登录失效");
  24. },
  25. 5000,
  26. { trailing: false }
  27. );