diff --git a/app/api/files/files-upload.ts b/app/api/files/files-upload.ts index a55d535..ada0bf2 100644 --- a/app/api/files/files-upload.ts +++ b/app/api/files/files-upload.ts @@ -136,6 +136,90 @@ export async function uploadFileToBinary(file: File): Promise { * @param jwtToken JWT token * @returns 上传结果 */ +/** + * 合同文档追加附件并合并 + * @param documentId 合同文档ID + * @param files 附件文件列表 + * @param mergeMode 合并模式:'overwrite'(覆盖原文档)或 'new'(新建文档记录) + * @param isReprocess 是否触发重新处理 + * @param remark 备注 + * @param jwtToken JWT token + * @returns 上传结果 + */ +export async function appendContractAttachments( + documentId: number, + files: File[], + mergeMode: 'overwrite' | 'new' = 'overwrite', + isReprocess: boolean = true, + remark?: string, + jwtToken?: string +): Promise<{data: FileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> { + try { + console.log('【合同附件追加】开始追加附件:', { documentId, fileCount: files.length, mergeMode }); + + // 创建FormData对象 + const formData = new FormData(); + + // 添加多个文件 + files.forEach(file => { + formData.append('files', file); + }); + + // 添加其他参数 + formData.append('merge_mode', mergeMode); + formData.append('is_reprocess', isReprocess.toString()); + if (remark) { + formData.append('remark', remark); + } + + // 构建请求URL + const uploadUrl = `${UPLOAD_URL}/contracts/${documentId}/append_attachments`; + console.log('【合同附件追加】准备发送请求到服务器:', uploadUrl); + + // 设置请求头 + const headers: HeadersInit = { + 'Accept': 'application/json' + }; + + if (jwtToken) { + headers['Authorization'] = `Bearer ${jwtToken}`; + } + + // 发送请求 + const response = await fetch(uploadUrl, { + method: 'POST', + headers, + body: formData + }); + + console.log('【合同附件追加】服务器响应状态:', response.status); + + if (!response.ok) { + const errorText = await response.text(); + console.error('【合同附件追加】服务器返回错误:', errorText); + return { + error: `服务器错误: ${response.status} ${response.statusText}`, + status: response.status + }; + } + + const result = await response.json(); + console.log('【合同附件追加】服务器返回结果:', result); + + if (result.success) { + return { data: result.result }; + } else { + return { error: result.error || '附件追加失败' }; + } + + } catch (error) { + console.error('【合同附件追加】上传过程中发生错误:', error); + return { + error: error instanceof Error ? error.message : '附件追加过程中发生未知错误' + }; + } +} + export async function uploadDocumentToServer( binaryData: ArrayBuffer, fileName: string, diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 7251ea0..ebd317c 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -30,17 +30,17 @@ export async function action({ request }: ActionFunctionArgs) { // 验证用户登录状态 export async function loader({ request }: LoaderFunctionArgs) { - const { isAuthenticated, userRole } = await getUserSession(request); + const { isAuthenticated, userRole, userInfo } = await getUserSession(request); if (!isAuthenticated) { return redirect("/login"); } - return Response.json({ userRole }); + return Response.json({ userRole, userInfo }); } export default function Index() { const navigate = useNavigate(); - const { userRole } = useLoaderData(); + const { userRole, userInfo } = useLoaderData(); const [currentDateTime, setCurrentDateTime] = useState({ date: '', time: '' @@ -133,8 +133,18 @@ export default function Index() {
{currentDateTime.date} {currentDateTime.time}
- 用户头像 - {userRole === 'developer' ? '系统管理员' : '普通用户'} + {(() => { + const displayName = (userInfo?.nick_name || (userInfo as { nickname?: string })?.nickname || (userInfo as { name?: string })?.name || '') as string; + const lastChar = displayName ? displayName.charAt(displayName.length - 1) : '用'; + return ( + <> +
+ {lastChar} +
+ {displayName || '未知用户'} + + ); + })()} +
+ + {record.type_id === 1 && record.status === DocumentStatus.PROCESSED && ( + + )} +
) } ]; @@ -2065,6 +2176,140 @@ export default function FilesUpload() { emptyText="暂无上传文件" /> + + {/* 附件追加模态框 */} + {showAttachmentUpload && ( +
+
+
+

追加合同附件

+ +
+ +
+ {/* 文档信息 */} +
+

+ 目标文档ID: {selectedDocumentId} +

+

+ 支持PDF、Word、ZIP、RAR格式,ZIP/RAR内仅合并其中的PDF文件 +

+
+ + {/* 文件上传区域 */} +
+ + + {attachmentFiles.length > 0 && ( +
+

+ 已选择 {attachmentFiles.length} 个文件 +

+
+ {attachmentFiles.map((file, index) => ( +
+ + {file.name} ({formatFileSize(file.size)}) +
+ ))} +
+
+ )} +
+ + {/* 合并模式选择 */} +
+ +
+ + +
+
+ + {/* 备注 */} +
+ +