mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-23 21:18:09 +00:00
- 提取应用引导逻辑至 useAppBootstrap 组合式函数 - 增强日期选择器组件,支持全类型与格式自动推导 - 修复资源泄漏:清理 RAF、定时器、事件与 mitt 监听 - 修复退出登录逻辑与异步导出流程 - 迁移 ::v-deep 至 Vue 3 标准 :deep 语法 - 移除调试日志并改进类型定义与注释文档
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
/**
|
|
* 路由后置守卫:滚动置顶、结束 NProgress、关闭 beforeEach 开启的全局 loading。
|
|
*/
|
|
import { nextTick } from "vue";
|
|
import { useSettingsStore } from "@stores/modules/setting.store";
|
|
import { Router } from "vue-router";
|
|
import { NProgress } from "@utils/ui";
|
|
import { useCommon } from "@/hooks/core/useCommon";
|
|
import { loadingService } from "@utils/ui";
|
|
|
|
/** 防止重复注册 afterEach(与 beforeEach 同理) */
|
|
let afterEachGuardRegistered = false;
|
|
|
|
export async function setupAfterEachGuard(router: Router) {
|
|
if (afterEachGuardRegistered) {
|
|
if (import.meta.env.DEV) {
|
|
console.warn("[Router] setupAfterEachGuard 已注册,跳过重复调用");
|
|
}
|
|
return;
|
|
}
|
|
afterEachGuardRegistered = true;
|
|
|
|
const { scrollToTop } = useCommon();
|
|
|
|
// 延迟加载 beforeEach 中导出的守卫状态函数,避免静态循环依赖
|
|
const { getPendingLoading, resetPendingLoading } = await import("./beforeEach");
|
|
|
|
router.afterEach(() => {
|
|
scrollToTop();
|
|
|
|
const settingStore = useSettingsStore();
|
|
if (settingStore.showNprogress) {
|
|
NProgress.done();
|
|
setTimeout(() => {
|
|
NProgress.remove();
|
|
}, 600);
|
|
}
|
|
|
|
if (getPendingLoading()) {
|
|
nextTick(() => {
|
|
loadingService.hideLoading();
|
|
resetPendingLoading();
|
|
});
|
|
}
|
|
});
|
|
}
|