|
@@ -36,7 +36,7 @@
|
|
<el-col :span="24">
|
|
<el-col :span="24">
|
|
<el-form-item label="选择文件" prop="files">
|
|
<el-form-item label="选择文件" prop="files">
|
|
<el-upload v-if="visible" action="#" :http-request="upload" :before-upload="handleBeforeUpload" :with-credentials="true"
|
|
<el-upload v-if="visible" action="#" :http-request="upload" :before-upload="handleBeforeUpload" :with-credentials="true"
|
|
- :before-remove="removeFile" v-model:file-list="fileList" :accept="acceptType"
|
|
|
|
|
|
+ :before-remove="removeFile" v-model:file-list="fileList" :on-exceed="onExceed" :on-error="onUploadError" :accept="acceptType"
|
|
:show-file-list="true" multiple :limit="5" drag style="width: 100%;">
|
|
:show-file-list="true" multiple :limit="5" drag style="width: 100%;">
|
|
<!-- <el-button size="small" type="primary" icon="Upload">上传文件</el-button> -->
|
|
<!-- <el-button size="small" type="primary" icon="Upload">上传文件</el-button> -->
|
|
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
|
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
|
@@ -184,6 +184,19 @@
|
|
acceptType
|
|
acceptType
|
|
} = toRefs(data);
|
|
} = toRefs(data);
|
|
|
|
|
|
|
|
+ function onUploadError(err) {
|
|
|
|
+ console.log('onUploadError', err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onExceed(files) {
|
|
|
|
+ console.log( fileList.value)
|
|
|
|
+ if(files.length + fileList.value.length> 5) {
|
|
|
|
+ proxy.$modal.msgError("单次最多上传5个文件")
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+
|
|
function validateFiles(rule, value, callback) {
|
|
function validateFiles(rule, value, callback) {
|
|
if (!form.value.files || form.value.files.length == 0) {
|
|
if (!form.value.files || form.value.files.length == 0) {
|
|
callback(new Error('请上传文件'))
|
|
callback(new Error('请上传文件'))
|
|
@@ -273,7 +286,9 @@
|
|
|
|
|
|
form.value.files.push(file)
|
|
form.value.files.push(file)
|
|
fileMap.value[param.file.uid] = file.fileUrl
|
|
fileMap.value[param.file.uid] = file.fileUrl
|
|
- if(fileList.value.findIndex(f => f.uid == param.file.uid) > 0) {
|
|
|
|
|
|
+ if(fileList.value.findIndex(f => f.uid == param.file.uid) < 0) {
|
|
|
|
+ console.log('fileList', fileList)
|
|
|
|
+ console.log('param.file.uid', param.file.uid)
|
|
fileList.value.push(param.file)
|
|
fileList.value.push(param.file)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -286,7 +301,15 @@
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const types = acceptType.value.split(',')
|
|
function handleBeforeUpload(file) {
|
|
function handleBeforeUpload(file) {
|
|
|
|
+ const fileExtension = file.name.split('.').pop().toLowerCase();
|
|
|
|
+ if(!types.includes('.'+fileExtension)) {
|
|
|
|
+ proxy.$modal.msgError("文件格式不正确");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ console.log('handleBeforeUpload',file)
|
|
if(file.size > 15 * 1024 * 1024) {
|
|
if(file.size > 15 * 1024 * 1024) {
|
|
proxy.$modal.msgError("文件大小不能超过15M");
|
|
proxy.$modal.msgError("文件大小不能超过15M");
|
|
return false;
|
|
return false;
|