chore: 清理冗余配置、优化代码结构
- 移除 SSE 独立代理(VITE_APP_SSE_URL)及相关配置 - 删除 CHANGELOG.md,清理 .env 多余注释 - 重构 permission.ts 路由守卫,用 return 替代 next() 调用 - 优化 useSse.ts:合并重复逻辑、增加中文注释、调整重连参数 - 简化 vite.config.ts 代理和注释
This commit is contained in:
@@ -14,7 +14,7 @@ import { addRecentMenu } from "@/composables/useRecentMenus";
|
||||
export function setupPermissionGuard() {
|
||||
const whiteList = ["/login"];
|
||||
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
router.beforeEach(async (to, _from) => {
|
||||
NProgress.start();
|
||||
|
||||
try {
|
||||
@@ -23,18 +23,15 @@ export function setupPermissionGuard() {
|
||||
// 未登录处理
|
||||
if (!isLoggedIn) {
|
||||
if (whiteList.includes(to.path)) {
|
||||
next();
|
||||
} else {
|
||||
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`);
|
||||
NProgress.done();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
NProgress.done();
|
||||
return `/login?redirect=${encodeURIComponent(to.fullPath)}`;
|
||||
}
|
||||
|
||||
// 已登录访问登录页,重定向到首页
|
||||
if (to.path === "/login") {
|
||||
next({ path: "/" });
|
||||
return;
|
||||
return { path: "/" };
|
||||
}
|
||||
|
||||
const permissionStore = usePermissionStore();
|
||||
@@ -54,14 +51,12 @@ export function setupPermissionGuard() {
|
||||
router.addRoute(route);
|
||||
});
|
||||
|
||||
next({ ...to, replace: true });
|
||||
return;
|
||||
return { ...to, replace: true };
|
||||
}
|
||||
|
||||
// 路由 404 检查
|
||||
if (to.matched.length === 0) {
|
||||
next("/404");
|
||||
return;
|
||||
return "/404";
|
||||
}
|
||||
|
||||
// 动态标题
|
||||
@@ -69,13 +64,11 @@ export function setupPermissionGuard() {
|
||||
if (title) {
|
||||
to.meta.title = title;
|
||||
}
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.error("Route guard error:", error);
|
||||
await useUserStore().resetAllState();
|
||||
next("/login");
|
||||
NProgress.done();
|
||||
return "/login";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user