完成文档类型增删改查
This commit is contained in:
+52
-39
@@ -30,21 +30,11 @@ export const meta: MetaFunction = () => {
|
||||
];
|
||||
};
|
||||
|
||||
// 文件类型定义
|
||||
export enum FileType {
|
||||
CONTRACT = "1",
|
||||
LICENSE = "2",
|
||||
PUNISHMENT = "3",
|
||||
OTHER = "4"
|
||||
}
|
||||
// 文件类型定义为字符串类型,以适应从API动态获取的ID
|
||||
export type FileType = string;
|
||||
|
||||
// 文件类型标签映射
|
||||
export const FILE_TYPE_LABELS: Record<FileType, string> = {
|
||||
[FileType.CONTRACT]: "合同文档",
|
||||
[FileType.LICENSE]: "专卖许可证",
|
||||
[FileType.PUNISHMENT]: "行政处罚决定书",
|
||||
[FileType.OTHER]: "其他文档"
|
||||
};
|
||||
// 动态构建的文件类型标签映射
|
||||
export const FILE_TYPE_LABELS: Record<string, string> = {};
|
||||
|
||||
// 优先级定义
|
||||
export enum Priority {
|
||||
@@ -85,7 +75,7 @@ export enum StepStatus {
|
||||
|
||||
// 上传的文件信息接口
|
||||
export interface UploadedFile {
|
||||
id: string;
|
||||
id: number;
|
||||
name: string;
|
||||
size: number;
|
||||
type: string;
|
||||
@@ -346,6 +336,19 @@ export default function FilesUpload() {
|
||||
const [queueFiles, setQueueFiles] = useState<Document[]>(documents);
|
||||
const [documentTypesState] = useState<DocumentType[]>(documentTypes);
|
||||
|
||||
// 构建文件类型标签映射
|
||||
useEffect(() => {
|
||||
// 清空之前的映射
|
||||
Object.keys(FILE_TYPE_LABELS).forEach(key => {
|
||||
delete FILE_TYPE_LABELS[key];
|
||||
});
|
||||
|
||||
// 使用从API获取的文档类型构建新的映射
|
||||
documentTypes.forEach(type => {
|
||||
FILE_TYPE_LABELS[type.id.toString()] = type.name;
|
||||
});
|
||||
}, [documentTypes]);
|
||||
|
||||
// 上传完成后的文件信息列表
|
||||
const [completedFiles, setCompletedFiles] = useState<UploadedFile[]>([]);
|
||||
|
||||
@@ -388,7 +391,7 @@ export default function FilesUpload() {
|
||||
|
||||
// 获取所有未完成的文档ID
|
||||
const incompleteIds = queueFiles
|
||||
.filter(file => file.status !== DocumentStatus.COMPLETED)
|
||||
.filter(file => file.status !== DocumentStatus.COMPLETED && file.id)
|
||||
.map(file => file.id);
|
||||
|
||||
console.log('未完成的文档ID:', incompleteIds);
|
||||
@@ -435,12 +438,17 @@ export default function FilesUpload() {
|
||||
|
||||
// 处理文件类型变化
|
||||
const handleFileTypeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
const newFileType = e.target.value as FileType;
|
||||
setFileType(newFileType);
|
||||
|
||||
// 如果已经有选中的文件,且选择了文件类型,则开始上传
|
||||
if (currentFiles.length > 0 && newFileType) {
|
||||
startUpload(currentFiles);
|
||||
const value = e.target.value;
|
||||
// 确保只有选择了有效的文件类型才进行设置
|
||||
if (value) {
|
||||
setFileType(value as FileType);
|
||||
|
||||
// 如果已经有选中的文件,且选择了文件类型,则开始上传
|
||||
if (currentFiles.length > 0) {
|
||||
startUpload(currentFiles);
|
||||
}
|
||||
} else {
|
||||
setFileType("");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -510,7 +518,7 @@ export default function FilesUpload() {
|
||||
|
||||
// 创建新的文件对象
|
||||
const newFile: UploadedFile = {
|
||||
id: response.result.id.toString(),
|
||||
id: response.result.id,
|
||||
name: response.result.file_name,
|
||||
size: response.result.file_size,
|
||||
type: file.type,
|
||||
@@ -537,14 +545,18 @@ export default function FilesUpload() {
|
||||
setUploadSpeed("完成");
|
||||
|
||||
// 更新队列
|
||||
const newDocuments: Document[] = uploadedFiles.map(file => ({
|
||||
id: parseInt(file.id),
|
||||
name: file.name,
|
||||
type_id: parseInt(fileType),
|
||||
file_size: file.size,
|
||||
status: DocumentStatus.CUTTING,
|
||||
created_at: new Date().toISOString()
|
||||
}));
|
||||
const newDocuments: Document[] = uploadedFiles.map(file => {
|
||||
// 确保id能够被正确解析为数字
|
||||
const id = file.id;
|
||||
return {
|
||||
id,
|
||||
name: file.name,
|
||||
type_id: fileType ? parseInt(fileType) : 0,
|
||||
file_size: file.size,
|
||||
status: DocumentStatus.CUTTING,
|
||||
created_at: new Date().toISOString()
|
||||
};
|
||||
});
|
||||
|
||||
setQueueFiles(prev => [...newDocuments, ...prev]);
|
||||
|
||||
@@ -587,7 +599,7 @@ export default function FilesUpload() {
|
||||
setProcessingSteps(updatedSteps);
|
||||
|
||||
// 获取文件ID列表
|
||||
const fileIds = files.map(file => parseInt(file.id));
|
||||
const fileIds = files.map(file => file.id).filter(id => id > 0);
|
||||
|
||||
console.log('开始处理文件,设置文件处理进度定时器');
|
||||
|
||||
@@ -802,8 +814,8 @@ export default function FilesUpload() {
|
||||
};
|
||||
|
||||
// 获取文档类型名称
|
||||
const getDocumentTypeName = (typeId: number) => {
|
||||
const type = documentTypesState.find(t => t.id === typeId);
|
||||
const getDocumentTypeName = (codeId: number) => {
|
||||
const type = documentTypesState.find(t => t.id === codeId);
|
||||
return type ? type.name : '未知类型';
|
||||
};
|
||||
|
||||
@@ -920,10 +932,9 @@ export default function FilesUpload() {
|
||||
disabled={uploadStage !== "idle"}
|
||||
>
|
||||
<option value="">请选择文件类型</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>
|
||||
{documentTypes.map(type => (
|
||||
<option key={type.id} value={type.id}>{type.name}</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
{actionData?.errors?.fileType && (
|
||||
@@ -1007,7 +1018,9 @@ export default function FilesUpload() {
|
||||
</li>
|
||||
<li className="file-info-item">
|
||||
<span className="file-info-label">文件类型:</span>
|
||||
<span className="file-info-value">{FILE_TYPE_LABELS[file.fileType]}</span>
|
||||
<span className="file-info-value">
|
||||
{FILE_TYPE_LABELS[file.fileType] || getDocumentTypeName(parseInt(file.fileType))}
|
||||
</span>
|
||||
</li>
|
||||
<li className="file-info-item">
|
||||
<span className="file-info-label">审核规则:</span>
|
||||
|
||||
Reference in New Issue
Block a user