完成评查点分组的增删改
This commit is contained in:
+72
-40
@@ -31,10 +31,10 @@ export const meta: MetaFunction = () => {
|
||||
|
||||
// 文件类型定义
|
||||
export enum FileType {
|
||||
CONTRACT = "contract",
|
||||
LICENSE = "license",
|
||||
PUNISHMENT = "punishment",
|
||||
OTHER = "other"
|
||||
CONTRACT = "1",
|
||||
LICENSE = "2",
|
||||
PUNISHMENT = "3",
|
||||
OTHER = "4"
|
||||
}
|
||||
|
||||
// 文件类型标签映射
|
||||
@@ -59,6 +59,13 @@ export const PRIORITY_LABELS: Record<Priority, string> = {
|
||||
[Priority.URGENT]: "紧急"
|
||||
};
|
||||
|
||||
// 优先级中文映射
|
||||
const PRIORITY_TO_CHINESE: Record<Priority, string> = {
|
||||
[Priority.NORMAL]: "普通",
|
||||
[Priority.HIGH]: "优先",
|
||||
[Priority.URGENT]: "紧急"
|
||||
};
|
||||
|
||||
// 处理状态定义
|
||||
export enum ProcessingStatus {
|
||||
WAITING = "waiting",
|
||||
@@ -128,46 +135,62 @@ async function uploadFileToServer(
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
try {
|
||||
// 创建HTTP请求的参数(实际环境中会使用这些参数发送请求)
|
||||
// 创建FormData对象,将文件和其他信息一起提交
|
||||
const formData = new FormData();
|
||||
|
||||
// 将二进制数据转换为Blob并添加到FormData
|
||||
const blob = new Blob([binaryData], { type: fileType });
|
||||
formData.append('file', blob, fileName);
|
||||
|
||||
// 将 type_id 和 priority 添加到一个JSON对象中
|
||||
const uploadInfo = {
|
||||
type_id: Number(documentType), // 确保 type_id 是数字值
|
||||
evaluation_level: PRIORITY_TO_CHINESE[priority] // 转换为中文优先级
|
||||
};
|
||||
|
||||
// 添加 JSON 字符串到 FormData
|
||||
formData.append('upload_info', JSON.stringify(uploadInfo));
|
||||
|
||||
// 创建HTTP请求的参数
|
||||
const requestParams = {
|
||||
method: 'POST',
|
||||
url: 'http://172.16.0.55:8000/admin/documents/upload',
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'X-File-Name': encodeURIComponent(fileName),
|
||||
'X-File-Type': fileType,
|
||||
'X-Document-Type': documentType,
|
||||
'X-Priority': priority
|
||||
// FormData会自动设置Content-Type为multipart/form-data
|
||||
'X-File-Name': encodeURIComponent(fileName)
|
||||
},
|
||||
body: binaryData // 二进制数据作为请求体
|
||||
body: formData
|
||||
};
|
||||
|
||||
// 打印 FormData 内容的正确方式
|
||||
console.log('[模拟API] 请求参数:', {
|
||||
url: requestParams.url,
|
||||
headers: requestParams.headers,
|
||||
bodySize: binaryData.byteLength
|
||||
uploadInfo, // 直接打印原始对象更有帮助
|
||||
formDataEntries: Array.from(formData.entries()).map(([key, value]) => {
|
||||
if (!(value instanceof Blob)) {
|
||||
return { key, value };
|
||||
}
|
||||
}),
|
||||
fileName
|
||||
});
|
||||
|
||||
// 实际API调用 - 在生产环境中实现
|
||||
const response = await fetch(requestParams.url, {
|
||||
method: requestParams.method,
|
||||
headers: requestParams.headers,
|
||||
body: binaryData
|
||||
body: requestParams.body
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// 获取更多错误信息
|
||||
const errorText = await response.text();
|
||||
console.error(`上传失败 (${response.status}): ${errorText}`);
|
||||
throw new Error(`上传失败: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
|
||||
// 模拟成功响应 (实际应用中这是服务器返回的)
|
||||
return {
|
||||
success: true,
|
||||
fileId: `file_${Date.now()}`,
|
||||
message: '文件上传成功'
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('[模拟API] 上传错误:', error);
|
||||
return {
|
||||
@@ -344,7 +367,8 @@ export default function FilesUpload() {
|
||||
}
|
||||
|
||||
setCurrentFile(selectedFiles[0]);
|
||||
// 不再立即上传,而是等待表单提交
|
||||
// 立即开始上传
|
||||
startUpload(selectedFiles[0]);
|
||||
}, [fileType]);
|
||||
|
||||
// 开始上传文件
|
||||
@@ -410,6 +434,25 @@ export default function FilesUpload() {
|
||||
setUploadProgress(100);
|
||||
setUploadSpeed("完成");
|
||||
|
||||
// 创建新的文件对象并添加到队列
|
||||
const newFile: UploadedFile = {
|
||||
id: `file_${Date.now()}`,
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
type: file.type,
|
||||
fileType: fileType as FileType,
|
||||
priority,
|
||||
status: ProcessingStatus.PROCESSING,
|
||||
uploadTime: getCurrentTime(),
|
||||
processingInfo: {
|
||||
progress: 0,
|
||||
currentStep: 0
|
||||
}
|
||||
};
|
||||
|
||||
// 添加到队列中
|
||||
setQueueFiles(prev => [newFile, ...prev]);
|
||||
|
||||
// 完成上传后开始处理流程
|
||||
startProcessing(file);
|
||||
} catch (error) {
|
||||
@@ -699,10 +742,10 @@ export default function FilesUpload() {
|
||||
disabled={uploadStage !== "idle"}
|
||||
>
|
||||
<option value="">请选择文件类型</option>
|
||||
<option value={FileType.CONTRACT}>合同文档</option>
|
||||
<option value={FileType.LICENSE}>专卖许可证</option>
|
||||
<option value={FileType.PUNISHMENT}>行政处罚决定书</option>
|
||||
<option value={FileType.OTHER}>其他文档</option>
|
||||
<option value={FileType.CONTRACT}>{FILE_TYPE_LABELS[FileType.CONTRACT]}</option>
|
||||
<option value={FileType.LICENSE}>{FILE_TYPE_LABELS[FileType.LICENSE]}</option>
|
||||
<option value={FileType.PUNISHMENT}>{FILE_TYPE_LABELS[FileType.PUNISHMENT]}</option>
|
||||
<option value={FileType.OTHER}>{FILE_TYPE_LABELS[FileType.OTHER]}</option>
|
||||
</select>
|
||||
<div className="form-tip">不同类型的文档将应用不同的审核规则</div>
|
||||
</div>
|
||||
@@ -716,9 +759,9 @@ export default function FilesUpload() {
|
||||
onChange={(e) => setPriority(e.target.value as Priority)}
|
||||
disabled={uploadStage !== "idle"}
|
||||
>
|
||||
<option value={Priority.NORMAL}>普通</option>
|
||||
<option value={Priority.HIGH}>优先</option>
|
||||
<option value={Priority.URGENT}>紧急</option>
|
||||
<option value={Priority.NORMAL}>{PRIORITY_LABELS[Priority.NORMAL]}</option>
|
||||
<option value={Priority.HIGH}>{PRIORITY_LABELS[Priority.HIGH]}</option>
|
||||
<option value={Priority.URGENT}>{PRIORITY_LABELS[Priority.URGENT]}</option>
|
||||
</select>
|
||||
<div className="form-tip">优先级影响文档在队列中的处理顺序</div>
|
||||
</div>
|
||||
@@ -736,19 +779,8 @@ export default function FilesUpload() {
|
||||
multiple={false}
|
||||
accept=".pdf,.doc,.docx,.xls,.xlsx,.jpg,.jpeg,.png"
|
||||
tipText="支持单个或批量上传,文件格式:PDF、Word、Excel、图片"
|
||||
shouldPreventFileSelect={!fileType}
|
||||
/>
|
||||
|
||||
{currentFile && (
|
||||
<div className="mt-4 flex justify-end">
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!currentFile || !fileType}
|
||||
onClick={() => formRef.current?.requestSubmit()}
|
||||
>
|
||||
开始上传
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user