fix: align login and home routing with leaudit backend

This commit is contained in:
wren
2026-04-29 18:02:31 +08:00
parent 7dbeaac5f8
commit 3d3d8d6e6b
7 changed files with 636 additions and 724 deletions
+65 -81
View File
@@ -1,11 +1,12 @@
import React, { useState, useEffect } from 'react';
import { useNavigate, Form, useLoaderData } from '@remix-run/react';
import { type MetaFunction, type ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import styles from "~/styles/pages/home.css?url";
import dayjs from 'dayjs';
import { getUserSession, logout } from "~/api/login/auth.server";
import { toastService } from '~/components/ui';
import { DOCUMENT_URL, CROSS_CHECKING_ONLY_MODE, CROSS_CHECKING_ONLY_PORT, getCurrentPort } from '~/config/api-config';
import { useNavigate, Form, useLoaderData } from '@remix-run/react';
import { type MetaFunction, type ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import styles from "~/styles/pages/home.css?url";
import dayjs from 'dayjs';
import type { EntryModule } from '~/api/home/home';
import { getUserSession, logout } from "~/api/login/auth.server";
import { toastService } from '~/components/ui';
import { DOCUMENT_URL, CROSS_CHECKING_ONLY_MODE, CROSS_CHECKING_ONLY_PORT, getCurrentPort } from '~/config/api-config';
export const links = () => [
{ rel: "stylesheet", href: styles }
@@ -37,18 +38,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
const { userRole, userInfo, frontendJWT } = await getUserSession(request);
// 🔑 获取用户地区并查询入口模块
const userArea = userInfo?.area || null;
// console.log('🔍 [Index Loader] 用户地区:', userArea);
// console.log('🔍 [Index Loader] 用户角色:', userRole);
let entryModules = [];
if (userRole && frontendJWT) {
const { getEntryModules } = await import('~/api/home/home');
entryModules = await getEntryModules(userRole,userArea, frontendJWT);
console.log(`📦 [Index Loader] 获取到 ${entryModules.length} 个入口模块`);
} else {
console.warn('⚠️ [Index Loader] 用户角色为空,返回空模块列表');
}
let entryModules: EntryModule[] = [];
if (frontendJWT) {
const { getEntryModules } = await import('~/api/home/home');
entryModules = await getEntryModules(frontendJWT);
console.log(`📦 [Index Loader] 获取到 ${entryModules.length} 个入口模块`);
} else {
console.warn('⚠️ [Index Loader] 缺少 JWT,返回空模块列表');
}
// 🔑 检查用户是否有系统设置权限
let hasSettingsAccess = false;
@@ -200,18 +197,17 @@ export default function Index() {
}, []);
// 处理模块点击
const handleModuleClick = (module: typeof loaderData.entryModules[0]) => {
// 提取文档类型 IDs
const typeIds = module.document_types?.map(dt => dt.id) || [];
// 🔑 验证文档类型(智慧法务助手除外)
if (module.name !== '智慧法务助手' && typeIds.length === 0) {
toastService.error('该入口尚未关联文档类型,无法进入');
console.warn('⚠️ [Index] 模块未关联文档类型:', module.name);
return; // 阻止进入
}
if (typeof window !== 'undefined') {
const handleModuleClick = (module: EntryModule) => {
// 提取文档类型 IDs
const typeIds = module.documentTypes.map((dt) => dt.id) || [];
if (module.requiresDocumentTypes && typeIds.length === 0) {
toastService.error('该入口尚未关联文档类型,无法进入');
console.warn('⚠️ [Index] 模块未关联文档类型:', module.name);
return;
}
if (typeof window !== 'undefined') {
// 🔑 清除各页面的筛选条件缓存(切换入口模块时重置)
sessionStorage.removeItem('rules.searchParams');
@@ -225,54 +221,36 @@ export default function Index() {
sessionStorage.removeItem('documentTypeIds');
}
// 存储模块信息
sessionStorage.setItem('selectedModuleId', String(module.id));
sessionStorage.setItem('selectedModuleName', module.name);
sessionStorage.setItem('selectedModulePicPath', module.path)
}
// 🔑 根据模块名称决定跳转路径
let targetPath = '/home'; // 默认跳转到首页
if (module.name.includes('合同')) {
// 合同相关模块 → 跳转到合同模板搜索
targetPath = '/contract-template/search';
// console.log('📌 [Index] 合同模块,跳转到:', targetPath);
} else if (module.name === '智慧法务助手') {
// 智慧法务助手 → 跳转到 AI 对话
targetPath = '/chat-with-llm/chat';
sessionStorage.setItem('selectedModulePicPath', '/images/icon_assistant.png')
// console.log('📌 [Index] 智慧法务助手,跳转到:', targetPath);
} else {
// console.log('📌 [Index] 其他模块,跳转到:', targetPath);
}
navigate(targetPath);
};
// 存储模块信息
sessionStorage.setItem('selectedModuleId', String(module.id));
sessionStorage.setItem('selectedModuleName', module.name);
sessionStorage.setItem('selectedModulePicPath', module.iconPath || '')
}
const targetPath = module.targetPath || '/home';
if (targetPath === '/chat-with-llm/chat' && typeof window !== 'undefined') {
sessionStorage.setItem('selectedModulePicPath', module.iconPath || '/images/icon_assistant.png');
}
navigate(targetPath);
};
// 处理键盘事件
const handleKeyDown = (module: typeof loaderData.entryModules[0], e: React.KeyboardEvent<HTMLDivElement>) => {
const handleKeyDown = (module: EntryModule, e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Enter' || e.key === ' ') {
handleModuleClick(module);
}
};
// 获取模块图标(根据模块 path 或 id)
const getModuleIcon = (module: typeof loaderData.entryModules[0]) => {
// 根据 path 判断图标
// if (module.path?.includes('ht')) {
// return '/images/icon_hetong.png';
// } else if (module.path?.includes('aj')) {
// return '/images/icon_anjuan.png';
// } else if (module.path?.includes('nw')) {
// return '/images/icon_assistant.png';
// }
// 默认图标
if (module.path){
return `${DOCUMENT_URL}${module.path}`
}
return '/images/icon_assistant.png';
};
const getModuleIcon = (module: EntryModule) => {
if (module.iconPath){
if (module.iconPath.startsWith('/images/')) {
return module.iconPath;
}
return `${DOCUMENT_URL}${module.iconPath}`;
}
return '/images/icon_assistant.png';
};
// 处理登出
const handleLogout = () => {
@@ -439,15 +417,21 @@ export default function Index() {
/* 正常模式:显示所有入口模块 */
loaderData.entryModules && loaderData.entryModules.length > 0 ? (
<>
{loaderData.entryModules.map((module) => {
const isLLMModule = module.name === '智慧法务助手';
// 🔑 如果是智慧法务助手且用户没有访问权限,则不渲染该模块
if (isLLMModule && !loaderData.hasChatLLMAccess) {
return null;
}
return (
{loaderData.entryModules.map((module: EntryModule) => {
const isLLMModule = module.targetPath === '/chat-with-llm/chat';
const isCrossCheckingModule = module.targetPath === '/cross-checking';
// 🔑 如果是智慧法务助手且用户没有访问权限,则不渲染该模块
if (isLLMModule && !loaderData.hasChatLLMAccess) {
return null;
}
// 交叉评查已在下面独立渲染,避免首页重复出现两张卡片
if (isCrossCheckingModule) {
return null;
}
return (
<div
key={module.id}
className="module-card"
@@ -512,4 +496,4 @@ export default function Index() {
</main>
</div>
);
}
}