feat: 运营平台基建 搭建

This commit is contained in:
2026-07-23 15:00:19 +08:00
parent 3b5a908ee4
commit 5523695518
11 changed files with 1096 additions and 130 deletions
+1 -32
View File
@@ -3,7 +3,7 @@ import { useState } from './useState';
import { watch } from 'vue';
import { useMenuStore } from '@/stores/menuStore';
import { usePermissionStore } from '@/stores/permissionStore';
import router, { WHITE_LIST } from '@/router';
import router from '@/router';
const TOKEN_KEY = 'MY_APP_AUTH_TOKEN';
@@ -60,34 +60,3 @@ function createAuth() {
}
export const auth = createAuth();
/**
* 路由守卫逻辑(由 router/guard.ts 使用)
* 判断逻辑:
* 1. 白名单路径 → 直接放行
* 2. 已登录但菜单未加载 → 加载菜单后放行
* 3. 已登录且菜单已加载 → 直接放行
* 4. 未登录 → 跳转 /login
*/
export async function handleRouteGuard(
toPath: string,
): Promise<{ allow: boolean; redirect?: string }> {
// 白名单直接放行
if (WHITE_LIST.includes(toPath) || toPath.match(/^\/:pathMatch/)) {
return { allow: true };
}
// 未登录
if (!auth.isLoggedIn()) {
return { allow: false, redirect: '/login' };
}
// 已登录但菜单未加载 → 先加载
const { loadMenu, loaded } = useMenuStore();
if (!loaded.value) {
const { loadPermissions } = usePermissionStore();
await Promise.all([loadMenu(), loadPermissions()]);
}
return { allow: true };
}