|
@@ -2,8 +2,10 @@ import React, { useState, useCallback } from 'react';
|
|
|
import { Upload, Progress, message, Tag, Space, Typography, Button } from 'antd';
|
|
import { Upload, Progress, message, Tag, Space, Typography, Button } from 'antd';
|
|
|
import { UploadOutlined, CloseOutlined, CheckCircleOutlined, SyncOutlined } from '@ant-design/icons';
|
|
import { UploadOutlined, CloseOutlined, CheckCircleOutlined, SyncOutlined } from '@ant-design/icons';
|
|
|
import { App } from 'antd';
|
|
import { App } from 'antd';
|
|
|
-import type { UploadFile , UploadProps} from 'antd';
|
|
|
|
|
|
|
+import type { UploadFile, UploadProps } from 'antd';
|
|
|
|
|
+import type { RcFile } from 'rc-upload/lib/interface';
|
|
|
import type { UploadFileStatus } from 'antd/es/upload/interface';
|
|
import type { UploadFileStatus } from 'antd/es/upload/interface';
|
|
|
|
|
+import type { UploadRequestOption } from 'rc-upload/lib/interface';
|
|
|
import { uploadMinIOWithPolicy, MinioProgressEvent } from '@/client/utils/minio';
|
|
import { uploadMinIOWithPolicy, MinioProgressEvent } from '@/client/utils/minio';
|
|
|
|
|
|
|
|
interface MinioUploaderProps {
|
|
interface MinioUploaderProps {
|
|
@@ -111,25 +113,21 @@ const MinioUploader: React.FC<MinioUploaderProps> = ({
|
|
|
}, [antdMessage, onUploadError]);
|
|
}, [antdMessage, onUploadError]);
|
|
|
|
|
|
|
|
// 自定义上传逻辑
|
|
// 自定义上传逻辑
|
|
|
- const customRequest = async (options: {
|
|
|
|
|
- file: UploadFile,
|
|
|
|
|
- onSuccess: () => void,
|
|
|
|
|
- onError: (error: Error) => void
|
|
|
|
|
- }) => {
|
|
|
|
|
|
|
+ const customRequest = async (options: UploadRequestOption) => {
|
|
|
const { file, onSuccess, onError } = options;
|
|
const { file, onSuccess, onError } = options;
|
|
|
- const uid = file.uid;
|
|
|
|
|
|
|
+ const rcFile = file as RcFile;
|
|
|
|
|
+ const uid = rcFile.uid;
|
|
|
|
|
|
|
|
// 添加到文件列表
|
|
// 添加到文件列表
|
|
|
setFileList(prev => [
|
|
setFileList(prev => [
|
|
|
...prev.filter(item => item.uid !== uid),
|
|
...prev.filter(item => item.uid !== uid),
|
|
|
{
|
|
{
|
|
|
uid,
|
|
uid,
|
|
|
- name: file.name,
|
|
|
|
|
- size: file.size,
|
|
|
|
|
- type: file.type,
|
|
|
|
|
- lastModified: file.lastModified,
|
|
|
|
|
- lastModifiedDate: file.lastModifiedDate,
|
|
|
|
|
- originFileObj: file.originFileObj,
|
|
|
|
|
|
|
+ name: rcFile.name,
|
|
|
|
|
+ size: rcFile.size,
|
|
|
|
|
+ type: rcFile.type,
|
|
|
|
|
+ lastModified: rcFile.lastModified,
|
|
|
|
|
+ lastModifiedDate: new Date(rcFile.lastModified),
|
|
|
status: 'uploading' as UploadFileStatus,
|
|
status: 'uploading' as UploadFileStatus,
|
|
|
percent: 0,
|
|
percent: 0,
|
|
|
}
|
|
}
|
|
@@ -142,19 +140,19 @@ const MinioUploader: React.FC<MinioUploaderProps> = ({
|
|
|
// 调用minio上传方法
|
|
// 调用minio上传方法
|
|
|
const result = await uploadMinIOWithPolicy(
|
|
const result = await uploadMinIOWithPolicy(
|
|
|
uploadPath,
|
|
uploadPath,
|
|
|
- file.originFileObj as File,
|
|
|
|
|
- file.name,
|
|
|
|
|
|
|
+ options.file as unknown as File,
|
|
|
|
|
+ rcFile.name,
|
|
|
{
|
|
{
|
|
|
onProgress: (event) => handleProgress(uid, event),
|
|
onProgress: (event) => handleProgress(uid, event),
|
|
|
signal: new AbortController().signal
|
|
signal: new AbortController().signal
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- handleComplete(uid, result, file.originFileObj as File);
|
|
|
|
|
- onSuccess();
|
|
|
|
|
|
|
+ handleComplete(uid, result, rcFile as unknown as File);
|
|
|
|
|
+ onSuccess?.({}, rcFile);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- handleError(uid, error instanceof Error ? error : new Error('未知错误'), file.originFileObj as File);
|
|
|
|
|
- onError(error instanceof Error ? error : new Error('未知错误'));
|
|
|
|
|
|
|
+ handleError(uid, error instanceof Error ? error : new Error('未知错误'), rcFile as unknown as File);
|
|
|
|
|
+ onError?.(error instanceof Error ? error : new Error('未知错误'));
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|