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'
6566import type { FormField } from ' @/components/dynamics-form/type'
6667import { MsgError } from ' @/utils/message'
6768import type { UploadFiles } from ' element-plus'
68- import { filesize , getImgUrl } from ' @/utils/common'
69+ import { filesize , getImgUrl , fileType } from ' @/utils/common'
6970import { t } from ' @/locales'
7071const upload = inject (' upload' ) as any
7172const attrs = useAttrs () as any
@@ -82,6 +83,7 @@ const onExceed = () => {
8283const emit = defineEmits ([' update:modelValue' ])
8384const fileArray = ref <any >([])
8485const loading = ref <boolean >(false )
86+ const UploadRef = ref ()
8587// 上传on-change事件
8688const 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}
107116function 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
114120const handlePreview = (bool : boolean ) => {
@@ -123,7 +129,9 @@ const handlePreview = (bool: boolean) => {
123129const 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+ })
127135const formats = computed (() => {
128136 return (attrs .file_type_list || []).map ((item : any ) => item .toUpperCase ()).join (' 、' )
129137})
0 commit comments