添加上传图片文件验证

This commit is contained in:
熊丽君
2021-10-20 09:28:46 +08:00
parent 5836cbb07a
commit 5fc1a876aa
3 changed files with 21 additions and 1 deletions

View File

@ -80,6 +80,10 @@ export default {
this.dialogImageUrl = file.url;
},
beforeUpload(file) {
if (file.type.indexOf("image/") == -1) {
this.msgError("文件格式错误,请上传图片类型,如JPGPNG后缀的文件。");
return false
}
let _self = this;
if (!this.useOss) {
//不使用oss不需要获取策略

View File

@ -86,9 +86,11 @@
<el-input
placeholder="请输入"
v-model="ruleForm.address"
maxlength="25"
maxlength="80"
show-word-limit
:disabled="check"
type="textarea"
:autosize="{ minRows: 3, maxRows: 4 }"
></el-input>
</el-form-item>
<el-form-item label="登录手机号" prop="username">
@ -456,3 +458,8 @@ export default {
}
};
</script>
<style lang="scss" scoped>
/deep/.el-input__count {
background-color: unset;
}
</style>

View File

@ -131,6 +131,7 @@
:action="upload.url"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:before-upload="beforeUpload"
:on-success="handleFileSuccess"
:auto-upload="false"
drag
@ -265,6 +266,14 @@ export default {
// resetForm(formName) {
// this.$refs[formName].resetFields();
// }
beforeUpload(file){
const fileSuffix = file.name.substring(file.name.lastIndexOf(".") + 1);
const whiteList = ["pdf", "doc", "docx", "xls", "xlsx"];
if (whiteList.indexOf(fileSuffix.toLowerCase()) === -1) {
this.msgError("上传文件只能是 pdf、doc、docx、xls、xlsx格式。");
return false;
}
},
// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;