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 [collectionOptions, setCollectionOptions] = useState([]);
|
||||||
const [importConfig, setImportConfig] = useState<any>({
|
const [importConfig, setImportConfig] = useState<any>({
|
||||||
source: DataSource.UPLOAD,
|
source: DataSource.UPLOAD,
|
||||||
|
hasArchive: true,
|
||||||
|
splitByLine: false,
|
||||||
});
|
});
|
||||||
const [currentPrefix, setCurrentPrefix] = useState<string>("");
|
const [currentPrefix, setCurrentPrefix] = useState<string>("");
|
||||||
|
|
||||||
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
|
||||||
|
|
||||||
// 本地上传文件相关逻辑
|
// 本地上传文件相关逻辑
|
||||||
|
|
||||||
const resetFiles = () => {
|
|
||||||
setFileList([]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUpload = async (dataset: Dataset) => {
|
const handleUpload = async (dataset: Dataset) => {
|
||||||
let filesToUpload = fileList;
|
let filesToUpload = form.getFieldValue("files") || [];
|
||||||
|
|
||||||
// 如果启用分行分割,处理文件
|
// 如果启用分行分割,处理文件
|
||||||
if (importConfig.splitByLine) {
|
if (importConfig.splitByLine) {
|
||||||
const splitResults = await Promise.all(
|
const splitResults = await Promise.all(
|
||||||
fileList.map((file) => splitFileByLines(file))
|
filesToUpload.map((file) => splitFileByLines(file))
|
||||||
);
|
);
|
||||||
filesToUpload = splitResults.flat();
|
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 () => {
|
const fetchCollectionTasks = async () => {
|
||||||
@@ -138,9 +124,12 @@ export default function ImportConfiguration({
|
|||||||
const resetState = () => {
|
const resetState = () => {
|
||||||
console.log('[ImportConfiguration] resetState called, preserving currentPrefix:', currentPrefix);
|
console.log('[ImportConfiguration] resetState called, preserving currentPrefix:', currentPrefix);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
setFileList([]);
|
|
||||||
form.setFieldsValue({ files: null });
|
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);
|
console.log('[ImportConfiguration] resetState done, currentPrefix still:', currentPrefix);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,7 +177,7 @@ export default function ImportConfiguration({
|
|||||||
<Button onClick={onClose}>取消</Button>
|
<Button onClick={onClose}>取消</Button>
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
disabled={!fileList?.length && !importConfig.dataSource}
|
disabled={!importConfig?.files?.length && !importConfig.dataSource}
|
||||||
onClick={handleImportData}
|
onClick={handleImportData}
|
||||||
>
|
>
|
||||||
确定
|
确定
|
||||||
@@ -267,7 +256,6 @@ export default function ImportConfiguration({
|
|||||||
label="自动解压上传的压缩包"
|
label="自动解压上传的压缩包"
|
||||||
name="hasArchive"
|
name="hasArchive"
|
||||||
valuePropName="checked"
|
valuePropName="checked"
|
||||||
initialValue={true}
|
|
||||||
>
|
>
|
||||||
<Switch />
|
<Switch />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -282,13 +270,19 @@ export default function ImportConfiguration({
|
|||||||
}
|
}
|
||||||
name="splitByLine"
|
name="splitByLine"
|
||||||
valuePropName="checked"
|
valuePropName="checked"
|
||||||
initialValue={false}
|
|
||||||
>
|
>
|
||||||
<Switch />
|
<Switch />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="上传文件"
|
label="上传文件"
|
||||||
name="files"
|
name="files"
|
||||||
|
valuePropName="fileList"
|
||||||
|
getValueFromEvent={(e: any) => {
|
||||||
|
if (Array.isArray(e)) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
return e && e.fileList;
|
||||||
|
}}
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
@@ -298,8 +292,7 @@ export default function ImportConfiguration({
|
|||||||
>
|
>
|
||||||
<Dragger
|
<Dragger
|
||||||
className="w-full"
|
className="w-full"
|
||||||
onRemove={handleRemoveFile}
|
beforeUpload={() => false}
|
||||||
beforeUpload={handleBeforeUpload}
|
|
||||||
multiple
|
multiple
|
||||||
>
|
>
|
||||||
<p className="ant-upload-drag-icon">
|
<p className="ant-upload-drag-icon">
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ const AsiderAndHeaderLayout = () => {
|
|||||||
<div className="p-4 border-t border-gray-200">
|
<div className="p-4 border-t border-gray-200">
|
||||||
{sidebarOpen ? (
|
{sidebarOpen ? (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{/* <Popover
|
<Popover
|
||||||
forceRender
|
forceRender
|
||||||
title={
|
title={
|
||||||
<div className="flex items-center justify-between gap-2 border-b border-gray-200 pb-2 mb-2">
|
<div className="flex items-center justify-between gap-2 border-b border-gray-200 pb-2 mb-2">
|
||||||
@@ -136,7 +136,7 @@ const AsiderAndHeaderLayout = () => {
|
|||||||
<Button block onClick={() => setTaskCenterVisible(true)}>
|
<Button block onClick={() => setTaskCenterVisible(true)}>
|
||||||
任务中心
|
任务中心
|
||||||
</Button>
|
</Button>
|
||||||
</Popover> */}
|
</Popover>
|
||||||
<Button
|
<Button
|
||||||
block
|
block
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -148,7 +148,7 @@ const AsiderAndHeaderLayout = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{/* <div className="relative">
|
<div className="relative">
|
||||||
<Popover
|
<Popover
|
||||||
forceRender
|
forceRender
|
||||||
title="任务中心"
|
title="任务中心"
|
||||||
@@ -163,7 +163,7 @@ const AsiderAndHeaderLayout = () => {
|
|||||||
icon={<ClipboardList className="w-4 h-4" />}
|
icon={<ClipboardList className="w-4 h-4" />}
|
||||||
></Button>
|
></Button>
|
||||||
</Popover>
|
</Popover>
|
||||||
</div> */}
|
</div>
|
||||||
<Button
|
<Button
|
||||||
block
|
block
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user