fix: 文件上传备份增加格式及大小限制

pull/185/head
ssongliu 2 years ago committed by ssongliu
parent a195b8b69f
commit 507dd44465

@ -5,14 +5,7 @@
<DrawerHeader :header="$t('commons.button.import')" :resource="title" :back="handleClose" /> <DrawerHeader :header="$t('commons.button.import')" :resource="title" :back="handleClose" />
</template> </template>
<div v-loading="loading"> <div v-loading="loading">
<el-upload <el-upload ref="uploadRef" drag :on-change="fileOnChange" class="upload-demo" :auto-upload="false">
ref="uploadRef"
drag
:on-change="fileOnChange"
:before-upload="beforeAvatarUpload"
class="upload-demo"
:auto-upload="false"
>
<el-icon class="el-icon--upload"><upload-filled /></el-icon> <el-icon class="el-icon--upload"><upload-filled /></el-icon>
<div class="el-upload__text"> <div class="el-upload__text">
{{ $t('database.dropHelper') }} {{ $t('database.dropHelper') }}
@ -81,7 +74,7 @@ import { computeSize } from '@/utils/util';
import { useDeleteData } from '@/hooks/use-delete-data'; import { useDeleteData } from '@/hooks/use-delete-data';
import { handleRecoverByUpload } from '@/api/modules/setting'; import { handleRecoverByUpload } from '@/api/modules/setting';
import i18n from '@/lang'; import i18n from '@/lang';
import { UploadFile, UploadFiles, UploadInstance, UploadProps } from 'element-plus'; import { UploadFile, UploadFiles, UploadInstance } from 'element-plus';
import { File } from '@/api/interface/file'; import { File } from '@/api/interface/file';
import DrawerHeader from '@/components/drawer-header/index.vue'; import DrawerHeader from '@/components/drawer-header/index.vue';
import { BatchDeleteFile, GetUploadList, UploadFileData } from '@/api/modules/files'; import { BatchDeleteFile, GetUploadList, UploadFileData } from '@/api/modules/files';
@ -159,9 +152,9 @@ const onRecover = async (row: File.File) => {
const uploaderFiles = ref<UploadFiles>([]); const uploaderFiles = ref<UploadFiles>([]);
const uploadRef = ref<UploadInstance>(); const uploadRef = ref<UploadInstance>();
const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => { const beforeAvatarUpload = (rawFile) => {
if (type.value === 'app' || type.value === 'website') { if (type.value === 'app' || type.value === 'website') {
if (rawFile.name.endsWith('.tar.gz')) { if (!rawFile.name.endsWith('.tar.gz')) {
MsgError(i18n.global.t('database.unSupportType')); MsgError(i18n.global.t('database.unSupportType'));
return false; return false;
} else if (rawFile.size / 1024 / 1024 > 50) { } else if (rawFile.size / 1024 / 1024 > 50) {
@ -171,10 +164,10 @@ const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {
return true; return true;
} }
if ( if (
rawFile.name.endsWith('.sql') || !rawFile.name.endsWith('.sql') ||
rawFile.name.endsWith('.gz') || !rawFile.name.endsWith('.gz') ||
rawFile.name.endsWith('.zip') || !rawFile.name.endsWith('.zip') ||
rawFile.name.endsWith('.tgz') !rawFile.name.endsWith('.tgz')
) { ) {
MsgError(i18n.global.t('database.unSupportType')); MsgError(i18n.global.t('database.unSupportType'));
return false; return false;
@ -203,6 +196,10 @@ const onSubmit = () => {
if (uploaderFiles.value[0]!.raw != undefined) { if (uploaderFiles.value[0]!.raw != undefined) {
formData.append('file', uploaderFiles.value[0]!.raw); formData.append('file', uploaderFiles.value[0]!.raw);
} }
let isOk = beforeAvatarUpload(uploaderFiles.value[0]!.raw);
if (!isOk) {
return;
}
formData.append('path', baseDir.value); formData.append('path', baseDir.value);
loading.value = true; loading.value = true;
UploadFileData(formData, {}) UploadFileData(formData, {})

Loading…
Cancel
Save