发布 v1.10 #5
@@ -4,6 +4,7 @@ import type { UploadProps } from 'element-plus';
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { useAppConfig } from '@easyflow/hooks';
|
import { useAppConfig } from '@easyflow/hooks';
|
||||||
|
import { $t } from '@easyflow/locales';
|
||||||
import { useAccessStore } from '@easyflow/stores';
|
import { useAccessStore } from '@easyflow/stores';
|
||||||
|
|
||||||
import { UploadFilled } from '@element-plus/icons-vue';
|
import { UploadFilled } from '@element-plus/icons-vue';
|
||||||
@@ -26,6 +27,8 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['success', 'error', 'onChange']);
|
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 accessStore = useAccessStore();
|
||||||
const headers = ref({
|
const headers = ref({
|
||||||
'easyflow-token': accessStore.accessToken,
|
'easyflow-token': accessStore.accessToken,
|
||||||
@@ -51,6 +54,14 @@ const handleError: UploadProps['onError'] = (error) => {
|
|||||||
emit('error', normalizedError);
|
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) => {
|
const handleChange: UploadProps['onChange'] = (file, fileList) => {
|
||||||
emit('onChange', file, fileList);
|
emit('onChange', file, fileList);
|
||||||
@@ -86,6 +97,8 @@ defineExpose({
|
|||||||
drag
|
drag
|
||||||
:headers="headers"
|
:headers="headers"
|
||||||
:action="`${apiURL}${props.action}`"
|
:action="`${apiURL}${props.action}`"
|
||||||
|
:accept="ACCEPTED_FILE_TYPES"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
:on-success="handleSuccess"
|
:on-success="handleSuccess"
|
||||||
:on-error="handleError"
|
:on-error="handleError"
|
||||||
:on-change="handleChange"
|
:on-change="handleChange"
|
||||||
@@ -97,7 +110,7 @@ defineExpose({
|
|||||||
</ElIcon>
|
</ElIcon>
|
||||||
<div class="flex flex-col gap-1">
|
<div class="flex flex-col gap-1">
|
||||||
<span class="text-base">{{ $t('message.upload.title') }}</span>
|
<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')
|
$t('message.upload.description')
|
||||||
}}</span>
|
}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -27,7 +27,8 @@
|
|||||||
"copyFail": "Copy fail",
|
"copyFail": "Copy fail",
|
||||||
"upload": {
|
"upload": {
|
||||||
"title": "Click or drag and drop files here to upload",
|
"title": "Click or drag and drop files here to upload",
|
||||||
"description": "TXT, PDF, DOCX, MD, PPT, PPTX files are supported. Each upload allows one file only, with a maximum size of 20M per file."
|
"description": "TXT, PDF, DOCX, MD, PPTX, and XLSX files are supported, up to 100 MB each.",
|
||||||
|
"fileTooLarge": "Each file must not exceed 100 MB"
|
||||||
},
|
},
|
||||||
"uploadFileFirst": "Please upload the file first",
|
"uploadFileFirst": "Please upload the file first",
|
||||||
"deleteModelAlert": "This operation will delete the large model. Are you sure to delete it?",
|
"deleteModelAlert": "This operation will delete the large model. Are you sure to delete it?",
|
||||||
|
|||||||
@@ -27,7 +27,8 @@
|
|||||||
"copyFail": "复制失败",
|
"copyFail": "复制失败",
|
||||||
"upload": {
|
"upload": {
|
||||||
"title": "点击或将文件拖拽到这里上传",
|
"title": "点击或将文件拖拽到这里上传",
|
||||||
"description": "TXT, PDF, DOCX, MD, PPT, PPTX 格式文件,单个大小不超过20M。"
|
"description": "支持 TXT、PDF、DOCX、MD、PPTX、XLSX,单个文件不超过 100 MB。",
|
||||||
|
"fileTooLarge": "单个文件大小不能超过 100 MB"
|
||||||
},
|
},
|
||||||
"uploadFileFirst": "请先上传文件",
|
"uploadFileFirst": "请先上传文件",
|
||||||
"deleteModelAlert": "该操作会删除大模型,确定删除吗?",
|
"deleteModelAlert": "该操作会删除大模型,确定删除吗?",
|
||||||
|
|||||||
Reference in New Issue
Block a user