feat: 扩展知识库文档上传限制至 100 MB
- 上传前校验单文件大小并给出本地化提示 - 同步支持格式与中英文说明
This commit is contained in:
@@ -4,6 +4,7 @@ import type { UploadProps } from 'element-plus';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useAppConfig } from '@easyflow/hooks';
|
||||
import { $t } from '@easyflow/locales';
|
||||
import { useAccessStore } from '@easyflow/stores';
|
||||
|
||||
import { UploadFilled } from '@element-plus/icons-vue';
|
||||
@@ -26,6 +27,8 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const emit = defineEmits(['success', 'error', 'onChange']);
|
||||
const MAX_FILE_SIZE_BYTES = 100 * 1024 * 1024;
|
||||
const ACCEPTED_FILE_TYPES = '.txt,.pdf,.docx,.md,.pptx,.xlsx';
|
||||
const accessStore = useAccessStore();
|
||||
const headers = ref({
|
||||
'easyflow-token': accessStore.accessToken,
|
||||
@@ -51,6 +54,14 @@ const handleError: UploadProps['onError'] = (error) => {
|
||||
emit('error', normalizedError);
|
||||
};
|
||||
|
||||
const beforeUpload: UploadProps['beforeUpload'] = (rawFile) => {
|
||||
if (rawFile.size <= MAX_FILE_SIZE_BYTES) {
|
||||
return true;
|
||||
}
|
||||
ElMessage.warning($t('message.upload.fileTooLarge'));
|
||||
return false;
|
||||
};
|
||||
|
||||
// 文件状态变化回调
|
||||
const handleChange: UploadProps['onChange'] = (file, fileList) => {
|
||||
emit('onChange', file, fileList);
|
||||
@@ -86,6 +97,8 @@ defineExpose({
|
||||
drag
|
||||
:headers="headers"
|
||||
:action="`${apiURL}${props.action}`"
|
||||
:accept="ACCEPTED_FILE_TYPES"
|
||||
:before-upload="beforeUpload"
|
||||
:on-success="handleSuccess"
|
||||
:on-error="handleError"
|
||||
:on-change="handleChange"
|
||||
@@ -97,7 +110,7 @@ defineExpose({
|
||||
</ElIcon>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-base">{{ $t('message.upload.title') }}</span>
|
||||
<span class="text-sm text-[#75808d]">{{
|
||||
<span class="text-muted-foreground text-sm">{{
|
||||
$t('message.upload.description')
|
||||
}}</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user