2020-09-28 20:19:10 +08:00
|
|
|
import type { Router } from 'vue-router';
|
|
|
|
|
|
|
|
|
|
import { Modal, notification } from 'ant-design-vue';
|
|
|
|
|
import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
|
|
|
|
|
import { createPageTitleGuard } from './pageTitleGuard';
|
|
|
|
|
import { createProgressGuard } from './progressGuard';
|
|
|
|
|
import { createPermissionGuard } from './permissionGuard';
|
|
|
|
|
import { createPageLoadingGuard } from './pageLoadingGuard';
|
2020-10-08 01:38:41 +08:00
|
|
|
import { useSetting } from '/@/hooks/core/useSetting';
|
2020-10-11 11:11:05 +08:00
|
|
|
import { getIsOpenTab } from '/@/utils/helper/routeHelper';
|
2020-09-28 20:19:10 +08:00
|
|
|
|
2020-10-08 01:38:41 +08:00
|
|
|
const { projectSetting } = useSetting();
|
2020-09-28 20:19:10 +08:00
|
|
|
export function createGuard(router: Router) {
|
2020-10-08 01:38:41 +08:00
|
|
|
const axiosCanceler = new AxiosCanceler();
|
|
|
|
|
|
2020-10-11 11:11:05 +08:00
|
|
|
router.beforeEach(async (to) => {
|
|
|
|
|
const isOpen = getIsOpenTab(to.path);
|
|
|
|
|
to.meta.inTab = isOpen;
|
2020-09-28 20:19:10 +08:00
|
|
|
try {
|
|
|
|
|
Modal.destroyAll();
|
|
|
|
|
notification.destroy();
|
|
|
|
|
// TODO Some special interfaces require long connections
|
|
|
|
|
// Switching the route will delete the previous request
|
|
|
|
|
axiosCanceler.removeAllPending();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn('basic guard error:' + error);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-10-08 01:38:41 +08:00
|
|
|
projectSetting.openNProgress && createProgressGuard(router);
|
2020-09-28 20:19:10 +08:00
|
|
|
createPermissionGuard(router);
|
|
|
|
|
createPageTitleGuard(router);
|
|
|
|
|
createPageLoadingGuard(router);
|
|
|
|
|
}
|