messageGuard.ts 542 B

123456789101112131415161718192021
  1. import type { Router } from 'vue-router';
  2. import { useProjectSetting } from '/@/hooks/setting';
  3. import { Modal, notification } from 'ant-design-vue';
  4. import { warn } from '/@/utils/log';
  5. export function createMessageGuard(router: Router) {
  6. const { closeMessageOnSwitch } = useProjectSetting();
  7. router.beforeEach(async () => {
  8. try {
  9. if (closeMessageOnSwitch) {
  10. Modal.destroyAll();
  11. notification.destroy();
  12. }
  13. } catch (error) {
  14. warn('message guard error:' + error);
  15. }
  16. return true;
  17. });
  18. }