文档列表documents添加用户id的限制,添加通过统一认证之后数据库中用户数据的添加和角色的添加,添加Sidebar菜单通过数据库请求获取
This commit is contained in:
@@ -516,14 +516,16 @@ export function ReviewPointsList({
|
||||
/**
|
||||
* 加载意见列表数据
|
||||
*/
|
||||
const loadOpinionListData = async (page: number = 1, pageSize: number = 10) => {
|
||||
console.log('加载意见列表数据', selectedReviewPoint);
|
||||
if (!selectedReviewPoint?.documentId) return;
|
||||
const loadOpinionListData = async (page: number = 1, pageSize: number = 10, documentId?: string | number) => {
|
||||
// 使用传入的documentId或者从selectedReviewPoint获取
|
||||
const targetDocumentId = documentId || selectedReviewPoint?.documentId;
|
||||
console.log('加载意见列表数据', targetDocumentId);
|
||||
if (!targetDocumentId) return;
|
||||
|
||||
setOpinionListLoading(true);
|
||||
try {
|
||||
console.log('加载意见列表数据', selectedReviewPoint.documentId, page, pageSize);
|
||||
const response = await getCrossCheckingOpinions(selectedReviewPoint.documentId, page, pageSize);
|
||||
console.log('加载意见列表数据', targetDocumentId, page, pageSize);
|
||||
const response = await getCrossCheckingOpinions(targetDocumentId, page, pageSize);
|
||||
|
||||
console.log('意见列表数据', response);
|
||||
if (response.error) {
|
||||
@@ -555,7 +557,8 @@ export function ReviewPointsList({
|
||||
setSelectedReviewPoint(reviewPoint);
|
||||
setIsOpinionListModalOpen(true);
|
||||
console.log('打开意见列表模态框');
|
||||
loadOpinionListData(1, 10);
|
||||
// 直接传递reviewPoint的documentId,避免依赖状态更新
|
||||
loadOpinionListData(1, 10, reviewPoint.documentId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2253,15 +2256,13 @@ export function ReviewPointsList({
|
||||
|
||||
{/* 悬浮状态:横向排列,显示图标,数字放大 */}
|
||||
<div className="absolute top-0 right-0 opacity-0 scale-0 group-hover:opacity-100 group-hover:scale-100 flex items-center bg-blue-50 px-3 py-2 rounded-lg border border-blue-200 shadow-lg transition-all duration-300 origin-top-right">
|
||||
<button className="flex items-center" aria-label="点击查看详情">
|
||||
<div className="flex flex-col">
|
||||
<i className="ri-chat-1-line text-blue-600 text-base"></i>
|
||||
<span className="text-xl text-blue-600 font-bold">{scoringProposals.length}</span>
|
||||
<span className="text-xs text-blue-500 leading-tight whitespace-wrap">条</span>
|
||||
<span className="text-xs text-blue-500 leading-tight whitespace-wrap">意</span>
|
||||
<span className="text-xs text-blue-500 leading-tight whitespace-wrap">见</span>
|
||||
</div>
|
||||
</button>
|
||||
<div className="flex flex-col">
|
||||
<i className="ri-chat-1-line text-blue-600 text-base"></i>
|
||||
<span className="text-xl text-blue-600 font-bold">{scoringProposals.length}</span>
|
||||
<span className="text-xs text-blue-500 leading-tight whitespace-wrap">条</span>
|
||||
<span className="text-xs text-blue-500 leading-tight whitespace-wrap">意</span>
|
||||
<span className="text-xs text-blue-500 leading-tight whitespace-wrap">见</span>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
@@ -2451,7 +2452,7 @@ export function ReviewPointsList({
|
||||
</Modal>
|
||||
|
||||
|
||||
{/* 意见列表模态框 */}
|
||||
{/* 意见列表模态框 */}
|
||||
<Modal
|
||||
isOpen={isOpinionListModalOpen}
|
||||
onClose={handleCloseOpinionListModal}
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link, useLocation, useNavigate } from '@remix-run/react';
|
||||
import type { UserRole } from '~/root';
|
||||
|
||||
interface MenuItem {
|
||||
id: string;
|
||||
title: string;
|
||||
path: string;
|
||||
icon: string;
|
||||
hideBreadcrumb?: boolean;
|
||||
requiredRole?: UserRole;
|
||||
children?: MenuItem[];
|
||||
}
|
||||
import { getUserRoutesByRole, mapUserRoleToRoleKey, type MenuItem } from '~/api/auth/user-routes';
|
||||
|
||||
interface SidebarProps {
|
||||
onToggle: () => void;
|
||||
@@ -21,8 +12,8 @@ interface SidebarProps {
|
||||
|
||||
// 定义不同应用模块下显示的菜单项ID
|
||||
const APP_MENU_MAP = {
|
||||
'contract': ['home', 'contract-template', 'file-management', 'rule-management', 'system-settings'],
|
||||
'record': ['home', 'file-management', 'rule-management', 'system-settings'],
|
||||
'contract': ['home', 'contract-template', 'file-management', 'rule-management', 'cross-checking', 'system-settings'],
|
||||
'record': ['home', 'file-management', 'rule-management', 'cross-checking', 'system-settings'],
|
||||
'model': ['chat-with-llm']
|
||||
};
|
||||
|
||||
@@ -45,8 +36,47 @@ export function Sidebar({ onToggle, collapsed, userRole, selectedApp = '' }: Sid
|
||||
const [expandedMenus, setExpandedMenus] = useState<Record<string, boolean>>({});
|
||||
const [currentApp, setCurrentApp] = useState<string>(''); // 初始设置为空字符串而不是selectedApp
|
||||
const [isLoading, setIsLoading] = useState<boolean>(true); // 添加加载状态
|
||||
const [menuItems, setMenuItems] = useState<MenuItem[]>([]); // 动态菜单项
|
||||
const [isLoadingRoutes, setIsLoadingRoutes] = useState<boolean>(true); // 路由加载状态
|
||||
const navigate = useNavigate();
|
||||
|
||||
// 获取用户路由权限
|
||||
useEffect(() => {
|
||||
const fetchUserRoutes = async () => {
|
||||
setIsLoadingRoutes(true);
|
||||
try {
|
||||
const roleKey = mapUserRoleToRoleKey(userRole);
|
||||
const result = await getUserRoutesByRole(roleKey);
|
||||
|
||||
if (result.success && result.data) {
|
||||
setMenuItems(result.data);
|
||||
console.log('用户路由权限加载成功:', result.data);
|
||||
} else {
|
||||
console.error('获取用户路由权限失败:', result.error);
|
||||
|
||||
// 如果需要重定向到首页
|
||||
if (result.shouldRedirectToHome) {
|
||||
console.log('重定向到首页');
|
||||
navigate('/');
|
||||
return;
|
||||
}
|
||||
|
||||
// 其他错误情况,使用空数组
|
||||
setMenuItems([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户路由权限时发生错误:', error);
|
||||
// 发生异常时也重定向到首页
|
||||
navigate('/');
|
||||
return;
|
||||
} finally {
|
||||
setIsLoadingRoutes(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUserRoutes();
|
||||
}, [userRole, navigate]);
|
||||
|
||||
// 组件挂载后从 sessionStorage 读取初始 reviewType
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
@@ -135,142 +165,6 @@ export function Sidebar({ onToggle, collapsed, userRole, selectedApp = '' }: Sid
|
||||
}
|
||||
}, [selectedApp, currentApp]);
|
||||
|
||||
const menuItems: MenuItem[] = [
|
||||
{
|
||||
id: 'home',
|
||||
title: '系统概览',
|
||||
path: '/home',
|
||||
icon: 'ri-home-line'
|
||||
},
|
||||
{
|
||||
id: 'chat-with-llm',
|
||||
title: 'AI对话',
|
||||
path: '/chat-with-llm',
|
||||
icon: 'ri-chat-smile-2-line'
|
||||
},
|
||||
{
|
||||
id: 'file-management',
|
||||
title: '文件管理',
|
||||
path: '/files',
|
||||
icon: 'ri-folder-line',
|
||||
children: [
|
||||
{
|
||||
id: 'file-upload',
|
||||
title: '文件上传',
|
||||
path: '/files/upload',
|
||||
icon: 'ri-upload-cloud-line'
|
||||
},
|
||||
{
|
||||
id: 'documents',
|
||||
title: '文档列表',
|
||||
path: '/documents',
|
||||
icon: 'ri-file-list-3-line'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'rule-management',
|
||||
title: '评查规则库',
|
||||
path: '/rules',
|
||||
icon: 'ri-book-3-line',
|
||||
children: [
|
||||
{
|
||||
id: 'rule-groups',
|
||||
title: '评查点分组',
|
||||
path: '/rule-groups',
|
||||
icon: 'ri-folder-open-line'
|
||||
},
|
||||
{
|
||||
id: 'rules-list',
|
||||
title: '评查点列表',
|
||||
path: '/rules',
|
||||
icon: 'ri-list-check-3'
|
||||
},
|
||||
{
|
||||
id: 'rules-file',
|
||||
title: '评查文件列表',
|
||||
path: '/rules-files',
|
||||
icon: 'ri-list-check-2'
|
||||
},
|
||||
{
|
||||
id: 'cross-checking',
|
||||
title: '交叉评查',
|
||||
path: '/cross-checking',
|
||||
icon: 'ri-color-filter-line'
|
||||
},
|
||||
// {
|
||||
// id: 'rule-new',
|
||||
// title: '新增评查点',
|
||||
// path: '/rules-new',
|
||||
// requiredRole: 'developer',
|
||||
// icon: 'ri-add-circle-line'
|
||||
// },
|
||||
// {
|
||||
// id: 'review-detail',
|
||||
// title: '评查详情',
|
||||
// path: '/reviews',
|
||||
// icon: 'ri-file-chart-line'
|
||||
// }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'contract-template',
|
||||
title: '合同模板',
|
||||
path: '/contract-template',
|
||||
icon: 'ri-file-search-line',
|
||||
children: [
|
||||
{
|
||||
id: 'contract-search-ai',
|
||||
title: '智能搜索',
|
||||
path: '/contract-template/search',
|
||||
icon: 'ri-search-line'
|
||||
},
|
||||
{
|
||||
id: 'contract-list',
|
||||
title: '合同列表',
|
||||
path: '/contract-template/list',
|
||||
icon: 'ri-folder-line'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'system-settings',
|
||||
title: '系统设置',
|
||||
path: '/settings',
|
||||
icon: 'ri-settings-4-line',
|
||||
requiredRole: 'developer',
|
||||
children: [
|
||||
{
|
||||
id: 'config-lists',
|
||||
title: '配置列表',
|
||||
path: '/config-lists',
|
||||
icon: 'ri-list-check-3',
|
||||
requiredRole: 'developer'
|
||||
},
|
||||
// {
|
||||
// id: 'basic-settings',
|
||||
// title: '基础设置',
|
||||
// path: '/settings',
|
||||
// icon: 'ri-equalizer-line'
|
||||
// },
|
||||
{
|
||||
id: 'document-types',
|
||||
title: '文档类型',
|
||||
path: '/document-types',
|
||||
icon: 'ri-file-list-line',
|
||||
requiredRole: 'developer'
|
||||
},
|
||||
{
|
||||
id: 'prompt-management',
|
||||
title: '提示词管理',
|
||||
path: '/prompts',
|
||||
icon: 'ri-chat-1-line',
|
||||
requiredRole: 'developer'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// 初始化展开状态,默认全部展开
|
||||
useEffect(() => {
|
||||
const initialExpandedState: Record<string, boolean> = {};
|
||||
@@ -280,7 +174,7 @@ export function Sidebar({ onToggle, collapsed, userRole, selectedApp = '' }: Sid
|
||||
}
|
||||
});
|
||||
setExpandedMenus(initialExpandedState);
|
||||
}, []);
|
||||
}, [menuItems]);
|
||||
|
||||
const toggleMenu = (id: string, e: React.MouseEvent) => {
|
||||
// 我们只防止事件冒泡,不阻止默认行为
|
||||
@@ -318,13 +212,8 @@ export function Sidebar({ onToggle, collapsed, userRole, selectedApp = '' }: Sid
|
||||
// const visibleMenuIds = APP_MENU_MAP[currentApp as keyof typeof APP_MENU_MAP]
|
||||
// console.log('当前应用模式:', currentApp, '可见菜单ID:', visibleMenuIds);
|
||||
|
||||
// 根据用户角色和当前应用模式过滤菜单项
|
||||
// 根据当前应用模式过滤菜单项
|
||||
const filteredMenuItems = menuItems.filter(item => {
|
||||
// 如果菜单项需要特定角色但用户没有
|
||||
if (item.requiredRole && item.requiredRole !== userRole) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查当前菜单是否在所选应用模式中显示
|
||||
if (!visibleMenuIds.includes(item.id)) {
|
||||
return false;
|
||||
@@ -382,7 +271,7 @@ export function Sidebar({ onToggle, collapsed, userRole, selectedApp = '' }: Sid
|
||||
)}
|
||||
|
||||
<div className="py-4 px-[10px]">
|
||||
{isLoading ? (
|
||||
{isLoading || isLoadingRoutes ? (
|
||||
// 加载中状态显示,保留菜单布局结构
|
||||
<div className="py-2">
|
||||
{Array(5).fill(0).map((_, index) => (
|
||||
@@ -444,19 +333,17 @@ export function Sidebar({ onToggle, collapsed, userRole, selectedApp = '' }: Sid
|
||||
className={`submenu-container ${collapsed ? 'border-l-0 pl-0' : 'border-l border-gray-100 ml-4 pl-3'} z-20`}
|
||||
id={`submenu-${item.id}`}
|
||||
>
|
||||
{item.children
|
||||
.filter(child => !child.requiredRole || child.requiredRole === userRole)
|
||||
.map((child) => (
|
||||
<Link
|
||||
key={child.id}
|
||||
to={child.path}
|
||||
className={`sidebar-menu-item ${isActive(child.path) ? 'active' : ''} flex items-center ${collapsed ? 'justify-center' : ''}`}
|
||||
onClick={(e) => handleSubMenuClick(child, e)}
|
||||
>
|
||||
<i className={`${child.icon} ${collapsed ? 'text-xl' : 'mr-3'}`}></i>
|
||||
{!collapsed && <span>{child.title}</span>}
|
||||
</Link>
|
||||
))}
|
||||
{item.children.map((child) => (
|
||||
<Link
|
||||
key={child.id}
|
||||
to={child.path}
|
||||
className={`sidebar-menu-item ${isActive(child.path) ? 'active' : ''} flex items-center ${collapsed ? 'justify-center' : ''}`}
|
||||
onClick={(e) => handleSubMenuClick(child, e)}
|
||||
>
|
||||
<i className={`${child.icon} ${collapsed ? 'text-xl' : 'mr-3'}`}></i>
|
||||
{!collapsed && <span>{child.title}</span>}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user