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