fix: 解决文件上传可以拖入文件夹的问题 (#1840)

Refs https://github.com/1Panel-dev/1Panel/issues/1833
pull/1854/head
zhengkunwang 2023-08-04 17:44:04 +08:00 committed by GitHub
parent aa1e548ddf
commit 5944f67823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 3 deletions

View File

@ -80,7 +80,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { computeSize } from '@/utils/util'; import { checkFileType, 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';
@ -184,7 +184,9 @@ const beforeAvatarUpload = (rawFile) => {
}; };
const fileOnChange = (_uploadFile: UploadFile, uploadFiles: UploadFiles) => { const fileOnChange = (_uploadFile: UploadFile, uploadFiles: UploadFiles) => {
uploaderFiles.value = uploadFiles; if (checkFileType(_uploadFile, uploadFiles)) {
uploaderFiles.value = uploadFiles;
}
}; };
const handleClose = () => { const handleClose = () => {

View File

@ -895,6 +895,7 @@ const message = {
uploadFailed: '[{0}] File Upload file', uploadFailed: '[{0}] File Upload file',
fileUploadStart: 'Uploading [{0}]....', fileUploadStart: 'Uploading [{0}]....',
currentSelect: 'Current Select: ', currentSelect: 'Current Select: ',
unsupportType: 'Unsupported file type',
}, },
ssh: { ssh: {
sshAlert: sshAlert:

View File

@ -865,6 +865,7 @@ const message = {
uploadFailed: '{0} ', uploadFailed: '{0} ',
fileUploadStart: '{0}....', fileUploadStart: '{0}....',
currentSelect: ': ', currentSelect: ': ',
unsupportType: '',
}, },
ssh: { ssh: {
sshAlert: '', sshAlert: '',

View File

@ -865,6 +865,7 @@ const message = {
uploadFailed: '{0} ', uploadFailed: '{0} ',
fileUploadStart: '{0}....', fileUploadStart: '{0}....',
currentSelect: ': ', currentSelect: ': ',
unsupportType: '',
}, },
ssh: { ssh: {
sshAlert: '', sshAlert: '',

View File

@ -1,4 +1,6 @@
import i18n from '@/lang'; import i18n from '@/lang';
import { UploadFile, UploadFiles } from 'element-plus';
import { MsgWarning } from './message';
export function deepCopy<T>(obj: any): T { export function deepCopy<T>(obj: any): T {
let newObj: any; let newObj: any;
@ -305,3 +307,15 @@ export function downloadWithContent(content: string, fileName: string) {
const event = new MouseEvent('click'); const event = new MouseEvent('click');
a.dispatchEvent(event); a.dispatchEvent(event);
} }
export function checkFileType(_uploadFile: UploadFile, uploadFiles: UploadFiles): boolean {
if (_uploadFile.raw?.type == '') {
const index = uploadFiles.findIndex((file) => file.name === _uploadFile.name && file.raw?.type === '');
if (index !== -1) {
uploadFiles.splice(index, 1);
}
MsgWarning(i18n.global.t('file.unsupportType'));
return false;
}
return true;
}

View File

@ -48,6 +48,7 @@ import { ChunkUploadFileData, UploadFileData } from '@/api/modules/files';
import i18n from '@/lang'; import i18n from '@/lang';
import DrawerHeader from '@/components/drawer-header/index.vue'; import DrawerHeader from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message'; import { MsgSuccess } from '@/utils/message';
import { checkFileType } from '@/utils/util';
interface UploadFileProps { interface UploadFileProps {
path: string; path: string;
@ -70,7 +71,9 @@ const handleClose = () => {
const uploaderFiles = ref<UploadFiles>([]); const uploaderFiles = ref<UploadFiles>([]);
const fileOnChange = (_uploadFile: UploadFile, uploadFiles: UploadFiles) => { const fileOnChange = (_uploadFile: UploadFile, uploadFiles: UploadFiles) => {
uploaderFiles.value = uploadFiles; if (checkFileType(_uploadFile, uploadFiles)) {
uploaderFiles.value = uploadFiles;
}
}; };
const handleExceed: UploadProps['onExceed'] = (files) => { const handleExceed: UploadProps['onExceed'] = (files) => {