@@ -4,7 +4,7 @@ import type { GetProp, UploadFile, UploadProps } from 'antd'
44import { Form , Modal , Upload } from 'antd'
55import { addFile } from '@/infrastructure/api/knowledgeBase' // , uploadData
66import { API_PREFIX } from '@/app-specs'
7- import Toast from '@/app/components/base/flash-notice'
7+ import Toast , { ToastTypeEnum } from '@/app/components/base/flash-notice'
88import { useModalContext } from '@/shared/hooks/modal-context'
99import Iconfont from '@/app/components/base/iconFont'
1010
@@ -19,7 +19,6 @@ const UploadModal = (props: any) => {
1919 const selfRef = useRef ( { uploadTasks : { } } )
2020 const [ form ] = Form . useForm ( )
2121 const [ fileList , setFileList ] = useState < UploadFile [ ] > ( [ ] )
22- const [ confirmLoading , setConfirmLoading ] = useState ( false )
2322
2423 const requestEvent = ( { formData, options, onSuccess, onFail, onProgress } ) => {
2524 const xhr = new XMLHttpRequest ( )
@@ -66,18 +65,17 @@ const UploadModal = (props: any) => {
6665 if ( ! nextFileData ) {
6766 const file_ids = Object . values ( selfRef . current . uploadTasks ) . map ( ( item : any ) => item . serverId ) || [ ]
6867 Promise . resolve ( addFile ( { url : '/kb/file/add' , body : { knowledge_base_id : id , file_ids } } ) ) . then ( ( ) => {
69- Toast . notify ( { type : 'success' , message : '上传成功' } )
68+ Toast . notify ( { type : ToastTypeEnum . Success , message : '上传成功' } )
7069 successEvent ( )
7170 setFileList ( [ ] )
7271 form . setFieldValue ( 'file' , [ ] )
73- // setConfirmLoading(false)
7472 } )
7573 }
7674 else {
7775 startUpload ( nextFileData )
7876 }
7977 } ,
80- onFail : ( { uid, name } ) => {
78+ onFail : ( { uid } ) => {
8179 const { uploadTasks } = selfRef . current
8280 const failTasks = uploadTasks [ uid ]
8381 if ( failTasks ) {
@@ -116,8 +114,7 @@ const UploadModal = (props: any) => {
116114 name : 'file' ,
117115 accept : allowedTypes . join ( ',' ) ,
118116 multiple : true ,
119- maxCount : 1 ,
120- onDelete : ( file ) => {
117+ onRemove : ( file ) => {
121118 const index = fileList . indexOf ( file )
122119 const newFileList = fileList . slice ( )
123120 newFileList . splice ( index , 1 )
@@ -127,18 +124,18 @@ const UploadModal = (props: any) => {
127124 beforeUpload : ( file ) => {
128125 const isAllowedType = allowedTypes . some ( type => file . name . endsWith ( type ) )
129126 if ( ! isAllowedType ) {
130- Toast . notify ( { type : 'error' , message : '不支持该类型文件' } )
127+ Toast . notify ( { type : ToastTypeEnum . Error , message : '不支持该类型文件' } )
131128 return false
132129 }
133130 if ( ( file . type === 'application/zip' || file . type === 'application/x-zip-compressed' ) && file . size > 500 * 1024 * 1024 ) {
134- Toast . notify ( { type : 'error' , message : '压缩包文件大小不能超过500MB' } )
131+ Toast . notify ( { type : ToastTypeEnum . Error , message : '压缩包文件大小不能超过500MB' } )
135132 return false
136133 }
137134 if ( file . type !== 'application/zip' && file . type !== 'application/x-zip-compressed' && file . size > 50 * 1024 * 1024 ) {
138- Toast . notify ( { type : 'error' , message : '文件大小不能超过50MB' } )
135+ Toast . notify ( { type : ToastTypeEnum . Error , message : '文件大小不能超过50MB' } )
139136 return false
140137 }
141- const currentFiles = [ file ]
138+ const currentFiles = [ ... fileList , file ]
142139 setFileList ( currentFiles )
143140 selfRef . current . uploadTasks = Object . fromEntries ( currentFiles . map ( item => ( [ item . uid , {
144141 progress : 0 ,
@@ -160,7 +157,7 @@ const UploadModal = (props: any) => {
160157 filesName . push ( file . name )
161158 }
162159 if ( filesName . length > 0 )
163- Toast . notify ( { type : 'error' , message : `不支持的文件上传: ${ filesName . join ( ', ' ) } ` } )
160+ Toast . notify ( { type : ToastTypeEnum . Error , message : `不支持的文件上传: ${ filesName . join ( ', ' ) } ` } )
164161 } ,
165162 fileList,
166163 }
@@ -173,7 +170,7 @@ const UploadModal = (props: any) => {
173170 }
174171
175172 return (
176- < Modal title = "上传知识库文件" destroyOnClose open = { visible } onOk = { handleOk } onCancel = { handleCancel } confirmLoading = { confirmLoading } cancelText = '取消' okText = '下一步' >
173+ < Modal title = "上传知识库文件" destroyOnClose open = { visible } onOk = { handleOk } onCancel = { handleCancel } cancelText = '取消' okText = '下一步' >
177174 < Form
178175 form = { form }
179176 layout = "vertical"
@@ -188,9 +185,9 @@ const UploadModal = (props: any) => {
188185 < p className = "ant-upload-drag-icon" >
189186 < InboxOutlined />
190187 </ p >
191- < p className = "ant-upload-text" > 将文件拖拽至此区域或选择文件上传</ p >
188+ < p className = "ant-upload-text" > 将文件拖拽至此区域或选择文件上传(支持多文件上传) </ p >
192189 < p className = "ant-upload-hint" >
193- 支持使用 pdf、word、ppt、excel、csv、 txt、json、html、markdown、latex,编码格式为utf-8,导入的数据要求单个大小50MB以内 。
190+ 支持使用 pdf、word、ppt、excel、csv、 txt、json、html、markdown、latex,编码格式为utf-8,可一次上传多个文件,每个文件大小50MB以内 。
194191 </ p >
195192 </ Dragger >
196193
0 commit comments