1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

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

Refs https://github.com/1Panel-dev/1Panel/issues/1833
This commit is contained in:
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>
import { reactive, ref } from 'vue';
import { computeSize } from '@/utils/util';
import { checkFileType, computeSize } from '@/utils/util';
import { useDeleteData } from '@/hooks/use-delete-data';
import { handleRecoverByUpload } from '@/api/modules/setting';
import i18n from '@/lang';
@ -184,7 +184,9 @@ const beforeAvatarUpload = (rawFile) => {
};
const fileOnChange = (_uploadFile: UploadFile, uploadFiles: UploadFiles) => {
uploaderFiles.value = uploadFiles;
if (checkFileType(_uploadFile, uploadFiles)) {
uploaderFiles.value = uploadFiles;
}
};
const handleClose = () => {

View File

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

View File

@ -865,6 +865,7 @@ const message = {
uploadFailed: '{0} 文件上傳失敗',
fileUploadStart: '正在上傳{0}....',
currentSelect: '當前選中: ',
unsupportType: '不支持的文件類型',
},
ssh: {
sshAlert: '列表數據根據登錄時間排序但請註意切換時區或其他操作可能導致登錄日誌的時間出現偏差',

View File

@ -865,6 +865,7 @@ const message = {
uploadFailed: '{0} 文件上传失败',
fileUploadStart: '正在上传{0}....',
currentSelect: '当前选中: ',
unsupportType: '不支持的文件类型',
},
ssh: {
sshAlert: '列表数据根据登录时间排序但请注意切换时区或其他操作可能导致登录日志的时间出现偏差',

View File

@ -1,4 +1,6 @@
import i18n from '@/lang';
import { UploadFile, UploadFiles } from 'element-plus';
import { MsgWarning } from './message';
export function deepCopy<T>(obj: any): T {
let newObj: any;
@ -305,3 +307,15 @@ export function downloadWithContent(content: string, fileName: string) {
const event = new MouseEvent('click');
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 DrawerHeader from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
import { checkFileType } from '@/utils/util';
interface UploadFileProps {
path: string;
@ -70,7 +71,9 @@ const handleClose = () => {
const uploaderFiles = ref<UploadFiles>([]);
const fileOnChange = (_uploadFile: UploadFile, uploadFiles: UploadFiles) => {
uploaderFiles.value = uploadFiles;
if (checkFileType(_uploadFile, uploadFiles)) {
uploaderFiles.value = uploadFiles;
}
};
const handleExceed: UploadProps['onExceed'] = (files) => {