feat: sync rule management and review ui fixes
This commit is contained in:
+18
-2
@@ -69,9 +69,21 @@ export type { UserRole };
|
||||
// 辅助函数:从 MenuItem 数组中提取所有路径(包括子路由)
|
||||
interface MenuItem {
|
||||
path: string;
|
||||
title?: string;
|
||||
hideBreadcrumb?: boolean;
|
||||
children?: MenuItem[];
|
||||
}
|
||||
|
||||
|
||||
function filterVisibleMenuItems(menuItems: MenuItem[]): MenuItem[] {
|
||||
return menuItems
|
||||
.filter((item) => !item.hideBreadcrumb)
|
||||
.map((item) => ({
|
||||
...item,
|
||||
children: item.children ? filterVisibleMenuItems(item.children) : undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
function extractAllPaths(menuItems: MenuItem[]): string[] {
|
||||
const paths: string[] = [];
|
||||
|
||||
@@ -208,6 +220,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
let userInfo: any = null;
|
||||
let allowedPaths: string[] = []; // 用户允许访问的路由列表
|
||||
let permissionMap: Record<string, string[]> = {}; // ✅ 权限映射表
|
||||
let menuItems: MenuItem[] = [];
|
||||
|
||||
if (!isPublicPath) {
|
||||
try {
|
||||
@@ -252,6 +265,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
allowedPaths = extractAllPaths(routesResult.data);
|
||||
// console.log("🔑 [Root Loader] 用户允许的路由:", allowedPaths);
|
||||
|
||||
menuItems = filterVisibleMenuItems(routesResult.data as MenuItem[]);
|
||||
|
||||
// ✅ 保存权限映射表
|
||||
if (routesResult.permissionMap) {
|
||||
permissionMap = routesResult.permissionMap;
|
||||
@@ -366,6 +381,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
isPublicPath, // 传递给客户端,用于判断是否需要认证
|
||||
isMobile, // 🔒 传递移动端标识
|
||||
permissionMap, // ✅ 传递权限映射表
|
||||
menuItems,
|
||||
ENV: {
|
||||
// 客户端不再需要直接调用 Dify API
|
||||
},
|
||||
@@ -401,7 +417,7 @@ export function links() {
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const { userRole, ENV, frontendJWT, userInfo, isPublicPath, isMobile } = useLoaderData<typeof loader>();
|
||||
const { userRole, ENV, frontendJWT, userInfo, isPublicPath, isMobile, menuItems } = useLoaderData<typeof loader>();
|
||||
|
||||
|
||||
return (
|
||||
@@ -441,7 +457,7 @@ export default function App() {
|
||||
{isPublicPath ? (
|
||||
<Outlet />
|
||||
) : (
|
||||
<Layout userRole={userRole} frontendJWT={frontendJWT} isMobile={isMobile}>
|
||||
<Layout userRole={userRole} frontendJWT={frontendJWT} isMobile={isMobile} menuItems={menuItems}>
|
||||
<Outlet />
|
||||
</Layout>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user