添加jwt验证,添加交叉评查首页加载对接接口,评查任务文档列表对接接口,意见列表对接接口
This commit is contained in:
+44
-17
@@ -123,7 +123,8 @@ async function handleFileUpload(
|
||||
remark: string | null,
|
||||
isTestDocument: boolean,
|
||||
documentId?: number | null,
|
||||
isReupload: boolean = false
|
||||
isReupload: boolean = false,
|
||||
jwtToken?: string
|
||||
): Promise<FileUploadResponse> {
|
||||
const response = await uploadDocumentToServer(
|
||||
binaryData,
|
||||
@@ -135,7 +136,8 @@ async function handleFileUpload(
|
||||
remark,
|
||||
isTestDocument,
|
||||
documentId,
|
||||
isReupload
|
||||
isReupload,
|
||||
jwtToken
|
||||
);
|
||||
|
||||
if (response.error || !response.data) {
|
||||
@@ -220,6 +222,8 @@ type LoaderData = {
|
||||
nick_name?: string;
|
||||
[key: string]: unknown;
|
||||
} | null;
|
||||
frontendJWT?: string | null;
|
||||
userError?: string;
|
||||
};
|
||||
|
||||
// 添加 loader 函数
|
||||
@@ -227,7 +231,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
try {
|
||||
// 获取用户会话信息
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { userInfo } = await getUserSession(request);
|
||||
const { userInfo, frontendJWT } = await getUserSession(request);
|
||||
|
||||
// console.log('loader: 开始加载数据...');
|
||||
const url = new URL(request.url);
|
||||
@@ -236,7 +240,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
// 我们不能在服务器端访问 sessionStorage,所以在客户端组件中处理 reviewType 过滤
|
||||
// 并行加载文档和文档类型
|
||||
const [documentsResponse, typesResponse] = await Promise.all([
|
||||
getTodayDocuments(),
|
||||
getTodayDocuments(userInfo),
|
||||
getDocumentTypes()
|
||||
]);
|
||||
|
||||
@@ -244,6 +248,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
// console.log('loader: 文档类型加载结果:', typesResponse);
|
||||
|
||||
if (documentsResponse.error || typesResponse.error) {
|
||||
// 如果是用户信息错误,返回特殊的错误状态
|
||||
if (documentsResponse.error === '没有找到用户信息,请刷新重试') {
|
||||
return Response.json({
|
||||
documents: [],
|
||||
documentTypes: typesResponse.data || [],
|
||||
userInfo: null,
|
||||
frontendJWT: null,
|
||||
userError: documentsResponse.error
|
||||
});
|
||||
}
|
||||
throw new Error(documentsResponse.error || typesResponse.error);
|
||||
}
|
||||
|
||||
@@ -251,14 +265,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
mode,
|
||||
documents: documentsResponse.data || [],
|
||||
documentTypes: typesResponse.data || [],
|
||||
userInfo // 传递用户信息到客户端
|
||||
userInfo, // 传递用户信息到客户端
|
||||
frontendJWT // 传递JWT到客户端
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('loader: 加载数据失败:', error);
|
||||
return Response.json({
|
||||
documents: [],
|
||||
documentTypes: [],
|
||||
userInfo: null
|
||||
userInfo: null,
|
||||
frontendJWT: null,
|
||||
userError: undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -368,16 +385,17 @@ export default function FilesUpload() {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用 reviewType 获取过滤后的文档列表
|
||||
const response = await getTodayDocuments(reviewType);
|
||||
|
||||
if (response.error) {
|
||||
console.error('过滤文档列表失败:', response.error);
|
||||
// 失败时使用原始数据
|
||||
setQueueFiles(loaderData.documents);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 使用 reviewType 获取过滤后的文档列表
|
||||
const response = await getTodayDocuments(loaderData.userInfo || undefined, reviewType);
|
||||
|
||||
if (response.error) {
|
||||
console.error('过滤文档列表失败:', response.error);
|
||||
toastService.error(response.error);
|
||||
// 失败时使用原始数据
|
||||
setQueueFiles(loaderData.documents);
|
||||
return;
|
||||
}
|
||||
const documents = response.data || [];
|
||||
console.log('过滤文档列表成功:', documents);
|
||||
setQueueFiles(documents);
|
||||
@@ -386,6 +404,7 @@ export default function FilesUpload() {
|
||||
startStatusChecker(documents);
|
||||
} catch (error) {
|
||||
console.error('过滤文档列表失败:', error);
|
||||
toastService.error('获取文档列表失败:'+(error instanceof Error ? error.message : '未知错误'));
|
||||
// 出错时使用原始数据
|
||||
const documents = loaderData.documents;
|
||||
setQueueFiles(documents);
|
||||
@@ -439,6 +458,13 @@ export default function FilesUpload() {
|
||||
setFileTypeError(actionData.errors.fileType);
|
||||
}
|
||||
}, [actionData]);
|
||||
|
||||
// 检查用户错误并显示 toast 提示
|
||||
useEffect(() => {
|
||||
if (loaderData.userError) {
|
||||
toastService.error(loaderData.userError);
|
||||
}
|
||||
}, [loaderData.userError]);
|
||||
|
||||
// 添加组件挂载状态引用
|
||||
const isMountedRef = useRef<boolean>(true);
|
||||
@@ -982,7 +1008,8 @@ export default function FilesUpload() {
|
||||
remark || null,
|
||||
isTestDocument,
|
||||
temp_n > 1 ? firstFileDocumentId : null, // 第二个文件及以后使用第一个文件的document_id
|
||||
false
|
||||
false,
|
||||
loaderData.frontendJWT || undefined
|
||||
);
|
||||
|
||||
const timeoutPromise = new Promise<FileUploadResponse>((_, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user