|
@@ -5,6 +5,7 @@
|
|
|
:list-type="type == 'image' ? 'picture-card' : 'picture'"
|
|
|
:show-upload-list="false"
|
|
|
:headers="headers"
|
|
|
+ accept=".image/jpeg,.image/png,.image/jpg"
|
|
|
:before-upload="beforeUpload"
|
|
|
:disabled="disabled"
|
|
|
@change="handleChange"
|
|
@@ -52,10 +53,10 @@ export default {
|
|
|
title: {
|
|
|
type: String,
|
|
|
},
|
|
|
- disabled:{
|
|
|
- type:Boolean,
|
|
|
- default: false
|
|
|
- }
|
|
|
+ disabled: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false,
|
|
|
+ },
|
|
|
},
|
|
|
components: {},
|
|
|
// watch: {
|
|
@@ -100,11 +101,27 @@ export default {
|
|
|
},
|
|
|
beforeUpload(file) {
|
|
|
// 文件类型(file.type)、大小限制(file.size)
|
|
|
- const isLt2M = file.size / 1024 / 1024 < 20
|
|
|
- if (!isLt2M) {
|
|
|
- this.$message.error('图片大小限制 20MB!')
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 100
|
|
|
+ if (this.type == 'image') {
|
|
|
+ if (!isLt2M) {
|
|
|
+ return this.$message.error('图片大小限制 100M!')
|
|
|
+ }
|
|
|
+ let isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/jpg'
|
|
|
+ if (!isJpgOrPng) {
|
|
|
+ this.$message.error('格式错误,只能上传jpg、jpeg、png')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }else if(this.type == 'file'){
|
|
|
+ if (!isLt2M) {
|
|
|
+ return this.$message.error('文件大小限制 100M!')
|
|
|
+ }
|
|
|
+ let isJpgOrPng = file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || file.type === 'application/msword' || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'||file.type==='application/vnd.ms-excel'||file.type==='application/vnd.ms-powerpoint'||file.type==='application/pdf'
|
|
|
+ if (!isJpgOrPng) {
|
|
|
+ this.$message.error('格式错误,只能上传docx、doc、xls、pdf、ppt')
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
- return isLt2M
|
|
|
+ return true
|
|
|
},
|
|
|
},
|
|
|
}
|