Skip to content

Commit bc1f15e

Browse files
authored
fix: Local file import, drag and drop upload method to upload files in formats other than allowed (#4449)
1 parent 6c1451f commit bc1f15e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ui/src/components/dynamics-form/items/upload/LocalFileUpload.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div v-loading="loading" class="w-full">
33
<el-upload
4+
ref="UploadRef"
45
:webkitdirectory="false"
56
class="w-full"
67
drag
@@ -65,7 +66,7 @@ import { computed, useAttrs, nextTick, inject, ref } from 'vue'
6566
import type { FormField } from '@/components/dynamics-form/type'
6667
import { MsgError } from '@/utils/message'
6768
import type { UploadFiles } from 'element-plus'
68-
import { filesize, getImgUrl } from '@/utils/common'
69+
import { filesize, getImgUrl, fileType } from '@/utils/common'
6970
import { t } from '@/locales'
7071
const upload = inject('upload') as any
7172
const attrs = useAttrs() as any
@@ -82,6 +83,7 @@ const onExceed = () => {
8283
const emit = defineEmits(['update:modelValue'])
8384
const fileArray = ref<any>([])
8485
const loading = ref<boolean>(false)
86+
const UploadRef = ref()
8587
// 上传on-change事件
8688
const fileHandleChange = (file: any, fileList: UploadFiles) => {
8789
//1、判断文件大小是否合法,文件限制不能大于100M
@@ -91,6 +93,13 @@ const fileHandleChange = (file: any, fileList: UploadFiles) => {
9193
fileList.splice(-1, 1) //移除当前超出大小的文件
9294
return false
9395
}
96+
if (!file_type_list.value.includes(fileType(file.name).toLocaleUpperCase())) {
97+
if (file?.name !== '.DS_Store') {
98+
MsgError(t('views.document.upload.errorMessage2'))
99+
}
100+
fileList.splice(-1, 1)
101+
return false
102+
}
94103
95104
if (file?.size === 0) {
96105
MsgError(t('views.document.upload.errorMessage3'))
@@ -105,10 +114,7 @@ const fileHandleChange = (file: any, fileList: UploadFiles) => {
105114
})
106115
}
107116
function deleteFile(index: number) {
108-
emit(
109-
'update:modelValue',
110-
props.modelValue.filter((item: any, i: number) => index != i),
111-
)
117+
props.modelValue.splice(index, 1)
112118
}
113119
114120
const handlePreview = (bool: boolean) => {
@@ -123,7 +129,9 @@ const handlePreview = (bool: boolean) => {
123129
const accept = computed(() => {
124130
return (attrs.file_type_list || []).map((item: any) => '.' + item.toLowerCase()).join(',')
125131
})
126-
132+
const file_type_list = computed(() => {
133+
return attrs.file_type_list || []
134+
})
127135
const formats = computed(() => {
128136
return (attrs.file_type_list || []).map((item: any) => item.toUpperCase()).join('')
129137
})

0 commit comments

Comments
 (0)