Skip to content

Commit 5e2ac2a

Browse files
committed
refactor: 根据配置类型限制上传文件格式
1 parent 119bba0 commit 5e2ac2a

File tree

1 file changed

+19
-3
lines changed
  • ui/src/components/ai-chat/component/chat-input-operate

1 file changed

+19
-3
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@
8080
action="#"
8181
:auto-upload="false"
8282
:show-file-list="false"
83-
:accept="
84-
[...imageExtensions, ...documentExtensions].map((ext) => '.' + ext).join(',')
85-
"
83+
:accept="getAcceptList()"
8684
:on-change="(file: any, fileList: any) => uploadFile(file, fileList)"
8785
>
8886
<el-button text>
@@ -191,6 +189,24 @@ const documentExtensions = ['pdf', 'docx', 'txt', 'xls', 'xlsx', 'md', 'html', '
191189
const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'flv']
192190
const audioExtensions = ['mp3', 'wav', 'aac', 'flac']
193191
192+
const getAcceptList = () => {
193+
const { image, document, audio, video } = props.applicationDetails.file_upload_setting
194+
let accepts = ''
195+
if (image) {
196+
accepts += imageExtensions.map((ext) => '.' + ext).join(',')
197+
}
198+
if (document) {
199+
accepts += documentExtensions.map((ext) => '.' + ext).join(',')
200+
}
201+
if (audio) {
202+
accepts += audioExtensions.map((ext) => '.' + ext).join(',')
203+
}
204+
if (video) {
205+
accepts += videoExtensions.map((ext) => '.' + ext).join(',')
206+
}
207+
return accepts
208+
}
209+
194210
const uploadFile = async (file: any, fileList: any) => {
195211
const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting
196212
if (fileList.length > maxFiles) {

0 commit comments

Comments
 (0)