feat:增加文件上传数量判断

This commit is contained in:
wuyx
2022-10-27 18:33:14 +08:00
parent 8fbd7c6cb1
commit a9e7489d9f

View File

@@ -150,12 +150,13 @@
</div> </div>
<div class="filebox"> <div class="filebox">
<div> <div>
<img class="fileimg" src="../../assets/images/projectadd/enclosure.png" /> <img v-if="fileList1.length < 6" class="fileimg" src="../../assets/images/projectadd/enclosure.png" />
<a-upload v-model:file-list="fileList1" name="file" action="/api/file/upload" :headers="headers" <a-upload :disabled="fileList1.length > 5" :before-upload="beforeUpload1" v-model:file-list="fileList1"
@change="handleChange1"> name="file" action="/api/file/upload" :headers="headers" @change="handleChange1">
<!-- <a-button> --> <!-- <a-button> -->
<!-- <upload-outlined></upload-outlined> --> <!-- <upload-outlined></upload-outlined> -->
<span class="filetext">上传附件</span> <span v-if="fileList1.length > 5" class="filetext">上传数量已经达到最大值</span>
<span v-else class="filetext">上传附件</span>
<!-- </a-button> --> <!-- </a-button> -->
</a-upload> </a-upload>
</div> </div>
@@ -243,14 +244,20 @@ export default {
} }
}; };
let uplodaFileCount = false;
const handleChange1 = (info) => { const handleChange1 = (info) => {
if (info.file.status === 'uploading') { if (info.file.status === 'uploading') {
loading.value = true; loading.value = true;
return; return;
} }
if (info.file.status === 'done') { if (info.file.status === 'done') {
console.log('上传附件返回的信息 %o', info) console.log('上传附件返回的信息 %o', info, info.fileList.length, uplodaFileCount)
if (info.fileList.length > 5) {
uplodaFileCount = true;
} else {
uplodaFileCount = false;
}
} }
if (info.file.status === 'error') { if (info.file.status === 'error') {
loading.value = false; loading.value = false;
@@ -270,6 +277,16 @@ export default {
return isJpgOrPng && isLt2M; return isJpgOrPng && isLt2M;
}; };
const beforeUpload1 = () => {
return new Promise((resovle, reject) => {
if (uplodaFileCount) {
message.info("上传文件数量已达最大数量")
return reject(false);
}
return resovle(true);
})
};
const onRangeChange = (value, dateString) => { const onRangeChange = (value, dateString) => {
console.log('Selected Time: ', value); console.log('Selected Time: ', value);
// 项目时间选择函数 // 项目时间选择函数
@@ -344,7 +361,7 @@ export default {
console.log(obj[i]) console.log(obj[i])
if (obj[i] === "") { if (obj[i] === "") {
message.destroy() message.destroy()
message.info(errorMsgs[i]) message.warning(errorMsgs[i])
return return
} }
} }
@@ -368,11 +385,13 @@ export default {
handleChange, handleChange,
handleChange1, handleChange1,
beforeUpload, beforeUpload,
beforeUpload1,
onRangeChange, onRangeChange,
classifyList1, classifyList1,
remark, remark,
changeChecked, changeChecked,
changeChecked1, changeChecked1,
uplodaFileCount,
createProject createProject
}; };
} }