mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-09-28 01:28:45 +00:00
136 lines
3.1 KiB
TypeScript
136 lines
3.1 KiB
TypeScript
![]() |
import { useTranslate } from '@/hooks/commonHooks';
|
||
|
import { IModalProps } from '@/interfaces/common';
|
||
|
import { InboxOutlined } from '@ant-design/icons';
|
||
|
import {
|
||
|
Flex,
|
||
|
Modal,
|
||
|
Segmented,
|
||
|
Tabs,
|
||
|
TabsProps,
|
||
|
Upload,
|
||
|
UploadFile,
|
||
|
UploadProps,
|
||
|
} from 'antd';
|
||
|
import { Dispatch, SetStateAction, useState } from 'react';
|
||
|
|
||
|
import styles from './index.less';
|
||
|
|
||
|
const { Dragger } = Upload;
|
||
|
|
||
|
const FileUpload = ({
|
||
|
directory,
|
||
|
fileList,
|
||
|
setFileList,
|
||
|
}: {
|
||
|
directory: boolean;
|
||
|
fileList: UploadFile[];
|
||
|
setFileList: Dispatch<SetStateAction<UploadFile[]>>;
|
||
|
}) => {
|
||
|
const { t } = useTranslate('fileManager');
|
||
|
const props: UploadProps = {
|
||
|
multiple: true,
|
||
|
onRemove: (file) => {
|
||
|
const index = fileList.indexOf(file);
|
||
|
const newFileList = fileList.slice();
|
||
|
newFileList.splice(index, 1);
|
||
|
setFileList(newFileList);
|
||
|
},
|
||
|
beforeUpload: (file) => {
|
||
|
setFileList((pre) => {
|
||
|
return [...pre, file];
|
||
|
});
|
||
|
|
||
|
return false;
|
||
|
},
|
||
|
directory,
|
||
|
fileList,
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<Dragger {...props} className={styles.uploader}>
|
||
|
<p className="ant-upload-drag-icon">
|
||
|
<InboxOutlined />
|
||
|
</p>
|
||
|
<p className="ant-upload-text">{t('uploadTitle')}</p>
|
||
|
<p className="ant-upload-hint">{t('uploadDescription')}</p>
|
||
|
</Dragger>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
const FileUploadModal = ({
|
||
|
visible,
|
||
|
hideModal,
|
||
|
loading,
|
||
|
onOk: onFileUploadOk,
|
||
|
}: IModalProps<UploadFile[]>) => {
|
||
|
const { t } = useTranslate('fileManager');
|
||
|
const [value, setValue] = useState<string | number>('local');
|
||
|
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
||
|
const [directoryFileList, setDirectoryFileList] = useState<UploadFile[]>([]);
|
||
|
|
||
|
const onOk = async () => {
|
||
|
const ret = await onFileUploadOk?.([...fileList, ...directoryFileList]);
|
||
|
if (ret !== undefined && ret === 0) {
|
||
|
setFileList([]);
|
||
|
setDirectoryFileList([]);
|
||
|
}
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
const items: TabsProps['items'] = [
|
||
|
{
|
||
|
key: '1',
|
||
|
label: t('file'),
|
||
|
children: (
|
||
|
<FileUpload
|
||
|
directory={false}
|
||
|
fileList={fileList}
|
||
|
setFileList={setFileList}
|
||
|
></FileUpload>
|
||
|
),
|
||
|
},
|
||
|
{
|
||
|
key: '2',
|
||
|
label: t('directory'),
|
||
|
children: (
|
||
|
<FileUpload
|
||
|
directory
|
||
|
fileList={directoryFileList}
|
||
|
setFileList={setDirectoryFileList}
|
||
|
></FileUpload>
|
||
|
),
|
||
|
},
|
||
|
];
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
<Modal
|
||
|
title={t('uploadFile')}
|
||
|
open={visible}
|
||
|
onOk={onOk}
|
||
|
onCancel={hideModal}
|
||
|
confirmLoading={loading}
|
||
|
>
|
||
|
<Flex gap={'large'} vertical>
|
||
|
<Segmented
|
||
|
options={[
|
||
|
{ label: t('local'), value: 'local' },
|
||
|
{ label: t('s3'), value: 's3' },
|
||
|
]}
|
||
|
block
|
||
|
value={value}
|
||
|
onChange={setValue}
|
||
|
/>
|
||
|
{value === 'local' ? (
|
||
|
<Tabs defaultActiveKey="1" items={items} />
|
||
|
) : (
|
||
|
t('comingSoon', { keyPrefix: 'common' })
|
||
|
)}
|
||
|
</Flex>
|
||
|
</Modal>
|
||
|
</>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default FileUploadModal;
|