You've already forked DataMate
fix(import): 修复文件上传配置和表单状态管理问题
- 移除手动fileList状态管理,改用Form组件内置字段 - 修复重置状态时的初始值设置,确保hasArchive和splitByLine默认值正确 - 更新文件上传验证逻辑,使用form.getFieldValue获取文件列表 - 修改拖拽上传组件配置,移除不必要的回调函数 - 修复按钮禁用条件判断,使用正确的字段路径检查文件长度 - 移除表单项的initialValue配置,统一在state初始化时设置默认值 - 调整Sidebar组件中的注释标记,修复任务中心弹窗显示逻辑
This commit is contained in:
@@ -63,24 +63,20 @@ export default function ImportConfiguration({
|
||||
const [collectionOptions, setCollectionOptions] = useState([]);
|
||||
const [importConfig, setImportConfig] = useState<any>({
|
||||
source: DataSource.UPLOAD,
|
||||
hasArchive: true,
|
||||
splitByLine: false,
|
||||
});
|
||||
const [currentPrefix, setCurrentPrefix] = useState<string>("");
|
||||
|
||||
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
||||
|
||||
// 本地上传文件相关逻辑
|
||||
|
||||
const resetFiles = () => {
|
||||
setFileList([]);
|
||||
};
|
||||
|
||||
const handleUpload = async (dataset: Dataset) => {
|
||||
let filesToUpload = fileList;
|
||||
let filesToUpload = form.getFieldValue("files") || [];
|
||||
|
||||
// 如果启用分行分割,处理文件
|
||||
if (importConfig.splitByLine) {
|
||||
const splitResults = await Promise.all(
|
||||
fileList.map((file) => splitFileByLines(file))
|
||||
filesToUpload.map((file) => splitFileByLines(file))
|
||||
);
|
||||
filesToUpload = splitResults.flat();
|
||||
}
|
||||
@@ -109,16 +105,6 @@ export default function ImportConfiguration({
|
||||
},
|
||||
})
|
||||
);
|
||||
resetFiles();
|
||||
};
|
||||
|
||||
const handleBeforeUpload = (_, files: UploadFile[]) => {
|
||||
setFileList([...fileList, ...files]);
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleRemoveFile = (file: UploadFile) => {
|
||||
setFileList((prev) => prev.filter((f) => f.uid !== file.uid));
|
||||
};
|
||||
|
||||
const fetchCollectionTasks = async () => {
|
||||
@@ -138,9 +124,12 @@ export default function ImportConfiguration({
|
||||
const resetState = () => {
|
||||
console.log('[ImportConfiguration] resetState called, preserving currentPrefix:', currentPrefix);
|
||||
form.resetFields();
|
||||
setFileList([]);
|
||||
form.setFieldsValue({ files: null });
|
||||
setImportConfig({ source: importConfig.source ? importConfig.source : DataSource.UPLOAD });
|
||||
setImportConfig({
|
||||
source: importConfig.source ? importConfig.source : DataSource.UPLOAD,
|
||||
hasArchive: true,
|
||||
splitByLine: false,
|
||||
});
|
||||
console.log('[ImportConfiguration] resetState done, currentPrefix still:', currentPrefix);
|
||||
};
|
||||
|
||||
@@ -188,7 +177,7 @@ export default function ImportConfiguration({
|
||||
<Button onClick={onClose}>取消</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!fileList?.length && !importConfig.dataSource}
|
||||
disabled={!importConfig?.files?.length && !importConfig.dataSource}
|
||||
onClick={handleImportData}
|
||||
>
|
||||
确定
|
||||
@@ -267,7 +256,6 @@ export default function ImportConfiguration({
|
||||
label="自动解压上传的压缩包"
|
||||
name="hasArchive"
|
||||
valuePropName="checked"
|
||||
initialValue={true}
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
@@ -282,13 +270,19 @@ export default function ImportConfiguration({
|
||||
}
|
||||
name="splitByLine"
|
||||
valuePropName="checked"
|
||||
initialValue={false}
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="上传文件"
|
||||
name="files"
|
||||
valuePropName="fileList"
|
||||
getValueFromEvent={(e: any) => {
|
||||
if (Array.isArray(e)) {
|
||||
return e;
|
||||
}
|
||||
return e && e.fileList;
|
||||
}}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
@@ -298,8 +292,7 @@ export default function ImportConfiguration({
|
||||
>
|
||||
<Dragger
|
||||
className="w-full"
|
||||
onRemove={handleRemoveFile}
|
||||
beforeUpload={handleBeforeUpload}
|
||||
beforeUpload={() => false}
|
||||
multiple
|
||||
>
|
||||
<p className="ant-upload-drag-icon">
|
||||
|
||||
Reference in New Issue
Block a user