index.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import type { Router } from 'vue-router';
  2. import { Modal, notification } from 'ant-design-vue';
  3. import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
  4. import { createPageTitleGuard } from './pageTitleGuard';
  5. import { createProgressGuard } from './progressGuard';
  6. import { createPermissionGuard } from './permissionGuard';
  7. import { createPageLoadingGuard } from './pageLoadingGuard';
  8. import { useSetting } from '/@/hooks/core/useSetting';
  9. import { getIsOpenTab } from '/@/utils/helper/routeHelper';
  10. const { projectSetting } = useSetting();
  11. export function createGuard(router: Router) {
  12. const axiosCanceler = new AxiosCanceler();
  13. router.beforeEach(async (to) => {
  14. const isOpen = getIsOpenTab(to.path);
  15. to.meta.inTab = isOpen;
  16. try {
  17. Modal.destroyAll();
  18. notification.destroy();
  19. // TODO Some special interfaces require long connections
  20. // Switching the route will delete the previous request
  21. axiosCanceler.removeAllPending();
  22. } catch (error) {
  23. console.warn('basic guard error:' + error);
  24. }
  25. });
  26. projectSetting.openNProgress && createProgressGuard(router);
  27. createPermissionGuard(router);
  28. createPageTitleGuard(router);
  29. createPageLoadingGuard(router);
  30. }