-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
127 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Router } from 'vue-router'; | ||
import { useProjectSetting } from '/@/hooks/setting'; | ||
import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel'; | ||
|
||
export function createHttpGuard(router: Router) { | ||
const { removeAllHttpPending } = useProjectSetting(); | ||
let axiosCanceler: Nullable<AxiosCanceler>; | ||
if (removeAllHttpPending) { | ||
axiosCanceler = new AxiosCanceler(); | ||
} | ||
router.beforeEach(async () => { | ||
// Switching the route will delete the previous request | ||
removeAllHttpPending && axiosCanceler?.removeAllPending(); | ||
return true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Router } from 'vue-router'; | ||
import { useProjectSetting } from '/@/hooks/setting'; | ||
import { Modal, notification } from 'ant-design-vue'; | ||
|
||
import { warn } from '/@/utils/log'; | ||
|
||
export function createMessageGuard(router: Router) { | ||
const { closeMessageOnSwitch } = useProjectSetting(); | ||
|
||
router.beforeEach(async () => { | ||
try { | ||
if (closeMessageOnSwitch) { | ||
Modal.destroyAll(); | ||
notification.destroy(); | ||
} | ||
} catch (error) { | ||
warn('message guard error:' + error); | ||
} | ||
return true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Router } from 'vue-router'; | ||
import { setLastChangeTab } from '/@/logics/mitt/tabChange'; | ||
|
||
export function createPageGuard(router: Router) { | ||
const loadedPageMap = new Map<string, boolean>(); | ||
|
||
router.beforeEach(async (to) => { | ||
to.meta.loaded = !!loadedPageMap.get(to.path); | ||
// Notify routing changes | ||
setLastChangeTab(to); | ||
|
||
return true; | ||
}); | ||
|
||
router.afterEach((to) => { | ||
loadedPageMap.set(to.path, true); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { RouteLocationNormalized, Router } from 'vue-router'; | ||
|
||
const isHash = (href: string) => { | ||
return /^#/.test(href); | ||
}; | ||
|
||
export function createScrollGuard(router: Router) { | ||
const body = document.body; | ||
|
||
router.afterEach(async (to) => { | ||
// scroll top | ||
isHash((to as RouteLocationNormalized & { href: string })?.href) && body.scrollTo(0, 0); | ||
return true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Router } from 'vue-router'; | ||
|
||
import { useGlobSetting } from '/@/hooks/setting'; | ||
|
||
import { setTitle } from '/@/utils/browser'; | ||
import { useI18n } from '/@/hooks/web/useI18n'; | ||
|
||
import { REDIRECT_NAME } from '/@/router/constant'; | ||
|
||
const globSetting = useGlobSetting(); | ||
|
||
export function createTitleGuard(router: Router) { | ||
router.afterEach(async (to) => { | ||
const { t } = useI18n(); | ||
to.name !== REDIRECT_NAME && setTitle(t(to.meta.title), globSetting.title); | ||
return true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters