This commit is contained in:
helloDy
2024-03-22 10:27:57 +08:00
parent e211e585af
commit 99fd016703
20 changed files with 417 additions and 212 deletions

View File

@@ -94,7 +94,7 @@
:show-file-list="false"
icon="el-icon-upload2"
:disabled="disabled"
:before-upload="beforeUpload"
:before-upload="col.uploadTips ? beforeUploadPic : beforeUpload"
:on-success="
(response, file, fileList) => {
handleUploadSuccess(response, file, col.prop);
@@ -110,7 +110,7 @@
上传文件
</el-button>
<div class="el-upload__tip" slot="tip" v-if="col.uploadTips">
{{ col.uploadTips || '只能上传jpg/png文件, 大小不超过2MB' }}
{{ '只能上传jpg/png文件, 大小不超过2MB' }}
</div>
</el-upload>
@@ -416,6 +416,26 @@ export default {
// 上传成功的特殊处理
beforeUpload(file) {
const checkFileSize = () => {
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
this.$modal.msgError('上传文件大小不能超过 2MB!');
}
return isLt2M;
};
// const checkFileType = () => {
// const isJPG =
// file.type === 'image/jpeg' ||
// file.type === 'image/png' ||
// file.type === 'image/jpg';
// return isJPG;
// };
// return checkFileSize() && checkFileType();
return checkFileSize();
},
// 上传成功的特殊处理----图片
beforeUploadPic(file) {
const checkFileSize = () => {
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
@@ -428,6 +448,9 @@ export default {
file.type === 'image/jpeg' ||
file.type === 'image/png' ||
file.type === 'image/jpg';
if (!isJPG) {
this.$modal.msgError('只能上传jpg/png文件!');
}
return isJPG;
};
return checkFileSize() && checkFileType();