-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: 支持上传mp3文件 #1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 支持上传mp3文件 #1787
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
<div | ||
class="p-8-12" | ||
v-loading="localLoading" | ||
v-if="uploadDocumentList.length || uploadImageList.length" | ||
v-if="uploadDocumentList.length || uploadImageList.length || uploadAudioList.length || uploadVideoList.length" | ||
> | ||
<el-space wrap> | ||
<template v-for="(item, index) in uploadDocumentList" :key="index"> | ||
|
@@ -53,6 +53,27 @@ | |
/> | ||
</div> | ||
</template> | ||
<template v-for="(item, index) in uploadAudioList" :key="index"> | ||
<el-card shadow="never" style="--el-card-padding: 8px" class="file cursor"> | ||
<div | ||
class="flex align-center" | ||
@mouseenter.stop="mouseenter(item)" | ||
@mouseleave.stop="mouseleave()" | ||
> | ||
<div | ||
@click="deleteFile(index, 'audio')" | ||
class="delete-icon color-secondary" | ||
v-if="showDelete === item.url" | ||
> | ||
<el-icon><CircleCloseFilled /></el-icon> | ||
</div> | ||
<img :src="getImgUrl(item && item?.name)" alt="" width="24" /> | ||
<div class="ml-4 ellipsis" style="max-width: 160px" :title="item && item?.name"> | ||
{{ item && item?.name }} | ||
</div> | ||
</div> | ||
</el-card> | ||
</template> | ||
</el-space> | ||
</div> | ||
</el-scrollbar> | ||
|
@@ -200,7 +221,7 @@ const localLoading = computed({ | |
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp'] | ||
const documentExtensions = ['pdf', 'docx', 'txt', 'xls', 'xlsx', 'md', 'html', 'csv'] | ||
const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'flv'] | ||
const audioExtensions = ['mp3', 'wav', 'aac', 'flac'] | ||
const audioExtensions = ['mp3'] | ||
|
||
const getAcceptList = () => { | ||
const { image, document, audio, video } = props.applicationDetails.file_upload_setting | ||
|
@@ -227,14 +248,14 @@ const getAcceptList = () => { | |
const checkMaxFilesLimit = () => { | ||
return ( | ||
props.applicationDetails.file_upload_setting.maxFiles <= | ||
uploadImageList.value.length + uploadDocumentList.value.length | ||
uploadImageList.value.length + uploadDocumentList.value.length + uploadAudioList.value.length + uploadVideoList.value.length | ||
) | ||
} | ||
|
||
const uploadFile = async (file: any, fileList: any) => { | ||
const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting | ||
// 单次上传文件数量限制 | ||
const file_limit_once = uploadImageList.value.length + uploadDocumentList.value.length | ||
const file_limit_once = uploadImageList.value.length + uploadDocumentList.value.length + uploadAudioList.value.length + uploadVideoList.value.length | ||
if (file_limit_once >= maxFiles) { | ||
MsgWarning('最多上传' + maxFiles + '个文件') | ||
fileList.splice(0, fileList.length) | ||
|
@@ -257,9 +278,9 @@ const uploadFile = async (file: any, fileList: any) => { | |
} else if (documentExtensions.includes(extension)) { | ||
uploadDocumentList.value.push(file) | ||
} else if (videoExtensions.includes(extension)) { | ||
// videos.push(file) | ||
uploadVideoList.value.push(file) | ||
} else if (audioExtensions.includes(extension)) { | ||
// audios.push(file) | ||
uploadAudioList.value.push(file) | ||
} | ||
|
||
|
||
|
@@ -297,7 +318,20 @@ const uploadFile = async (file: any, fileList: any) => { | |
file.file_id = f[0].file_id | ||
} | ||
}) | ||
console.log(uploadDocumentList.value, uploadImageList.value) | ||
uploadAudioList.value.forEach((file: any) => { | ||
const f = response.data.filter((f: any) => f.name === file.name) | ||
if (f.length > 0) { | ||
file.url = f[0].url | ||
file.file_id = f[0].file_id | ||
} | ||
}) | ||
uploadVideoList.value.forEach((file: any) => { | ||
const f = response.data.filter((f: any) => f.name === file.name) | ||
if (f.length > 0) { | ||
file.url = f[0].url | ||
file.file_id = f[0].file_id | ||
} | ||
}) | ||
}) | ||
} | ||
const recorderTime = ref(0) | ||
|
@@ -306,6 +340,8 @@ const recorderLoading = ref(false) | |
const inputValue = ref<string>('') | ||
const uploadImageList = ref<Array<any>>([]) | ||
const uploadDocumentList = ref<Array<any>>([]) | ||
const uploadVideoList = ref<Array<any>>([]) | ||
const uploadAudioList = ref<Array<any>>([]) | ||
const mediaRecorderStatus = ref(true) | ||
const showDelete = ref('') | ||
|
||
|
@@ -433,11 +469,15 @@ function sendChatHandle(event: any) { | |
if (inputValue.value.trim()) { | ||
props.sendMessage(inputValue.value, { | ||
image_list: uploadImageList.value, | ||
document_list: uploadDocumentList.value | ||
document_list: uploadDocumentList.value, | ||
audio_list: uploadAudioList.value, | ||
video_list: uploadVideoList.value, | ||
}) | ||
inputValue.value = '' | ||
uploadImageList.value = [] | ||
uploadDocumentList.value = [] | ||
uploadAudioList.value = [] | ||
uploadVideoList.value = [] | ||
quickInputRef.value.textareaStyle.height = '45px' | ||
} | ||
} | ||
|
@@ -452,6 +492,10 @@ function deleteFile(index: number, val: string) { | |
uploadImageList.value.splice(index, 1) | ||
} else if (val === 'document') { | ||
uploadDocumentList.value.splice(index, 1) | ||
} else if (val === 'video') { | ||
uploadVideoList.value.splice(index, 1) | ||
} else if (val === 'audio') { | ||
uploadAudioList.value.splice(index, 1) | ||
} | ||
} | ||
function mouseenter(row: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code for the File Upload component has two issues that need attention:
export default {
name: 'FileUpload',
data() {
return {}; I recommend fixing this before further implementation steps, such as refactoring and integrating with your existing application architecture and functionality. Consider revising how files actually come through in this context, especially regarding the maximum count of individual types of files. If you're aiming for a clean interface instead of keeping all lists synchronized, creating additional state might help separate concern levels without complicating things too much. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,23 @@ | |
<el-checkbox v-model="form_data.image" /> | ||
</div> | ||
</el-card> | ||
<el-card | ||
shadow="hover" | ||
class="card-checkbox cursor w-full mb-8" | ||
:class="form_data.audio ? 'active' : ''" | ||
style="--el-card-padding: 8px 16px" | ||
> | ||
<div class="flex-between"> | ||
<div class="flex align-center"> | ||
<img class="mr-12" src="@/assets/icon_file-image.svg" alt="" /> | ||
<div> | ||
<p class="line-height-22 mt-4">音频(MP3)</p> | ||
<el-text class="color-secondary">所选模型支持接收音频或与语音转文本节点配合使用</el-text> | ||
</div> | ||
</div> | ||
<el-checkbox v-model="form_data.audio" /> | ||
</div> | ||
</el-card> | ||
</el-form-item> | ||
</el-form> | ||
<template #footer> | ||
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段是Markdown格式的代码,它的整体结构和内容在不同的环境中可能会有一定的调整,请问您是要我帮忙分析哪一部分? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,12 @@ const refreshFileUploadConfig = () => { | |
if (form_data[0].image) { | ||
fileUploadFields.push({ label: '图片', value: 'image' }) | ||
} | ||
if (form_data[0].audio) { | ||
fileUploadFields.push({ label: '音频', value: 'audio' }) | ||
} | ||
if (form_data[0].video) { | ||
fileUploadFields.push({ label: '视频', value: 'video' }) | ||
} | ||
|
||
set(props.nodeModel.properties.config, 'fields', [...fields, ...fileUploadFields]) | ||
} | ||
liuruibin marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此代码没有语法错误或潜在问题。不过,如果您希望在代码中使用变量并为属性赋值,请确保您正在使用的变量名与之前设置的props.state.fieldss正确匹配。 示例: set(formData[0], { image: true });
for (var i = 0; i < formData.length; i++) {
var fieldObject = Object.assign({}, formData[i]);
} 这将使变量 但是,在考虑实际项目时,为了防止将来可能发生的逻辑冲突或其他异常情况,最好总是对函数定义明确一些(例如声明输入参数)。这可以大大提高代码可读性: 注意这里添加了自动生成的变量名称来提高代码的一致性和复用性,同时保持清晰的功能注释以指示功能的作用域。 |
||
|
Uh oh!
There was an error while loading. Please reload this page.