|
@@ -142,47 +142,35 @@
|
|
|
this.$forceUpdate()
|
|
|
},
|
|
|
beforeAvatarUpload(file,type) {
|
|
|
- if (file.type == 'image/png') {
|
|
|
- this.asyncImgChecked(file,type).then(data => {
|
|
|
- if (data.code == 200) {
|
|
|
- return true;
|
|
|
- } else if(data.code == 201){
|
|
|
- this.$message.error('尺寸限制为200*200px,支持PNG格式')
|
|
|
- return false;
|
|
|
- } else if(data.code == 202){
|
|
|
- this.$message.error('尺寸限制为110*500px,支持PNG格式')
|
|
|
- return false;
|
|
|
- }
|
|
|
- })
|
|
|
- }else{
|
|
|
- this.$message.error('请上传PNG格式');
|
|
|
- return false;
|
|
|
- }
|
|
|
- },
|
|
|
- // 计算图片尺寸
|
|
|
- asyncImgChecked (file,type) {
|
|
|
- return new Promise((resolve) => {
|
|
|
- let reader = new FileReader()
|
|
|
- reader.readAsDataURL(file) // 必须用file.raw
|
|
|
- reader.onload = e => { // 让页面中的img标签的src指向读取的路径
|
|
|
- let img = e.target.result;
|
|
|
- const image = new Image()
|
|
|
- image.src=img
|
|
|
- image.onload = _=>{
|
|
|
- if(type == '1'){
|
|
|
- if(image.width == 200 && image.height == 200){
|
|
|
- resolve({code:200})
|
|
|
- }else{
|
|
|
- resolve({code:201})
|
|
|
- }
|
|
|
- }else if(type == '2'){
|
|
|
- if(image.width == 500 && image.height == 110){
|
|
|
- resolve({code:200})
|
|
|
- }else{
|
|
|
- resolve({code:202})
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (file.type == 'image/png') {
|
|
|
+ let reader = new FileReader()
|
|
|
+ reader.readAsDataURL(file) // 必须用file.raw
|
|
|
+ reader.onload = e => { // 让页面中的img标签的src指向读取的路径
|
|
|
+ let img = e.target.result;
|
|
|
+ const image = new Image()
|
|
|
+ image.src=img
|
|
|
+ image.onload = _=>{
|
|
|
+ if(type == '1'){
|
|
|
+ if(image.width == 200 && image.height == 200){
|
|
|
+ resolve()
|
|
|
+ }else{
|
|
|
+ this.$message.error('尺寸限制为200*200px,支持PNG格式')
|
|
|
+ reject();
|
|
|
+ }
|
|
|
+ }else if(type == '2'){
|
|
|
+ if(image.width == 500 && image.height == 110){
|
|
|
+ resolve()
|
|
|
+ }else{
|
|
|
+ this.$message.error('尺寸限制为110*500px,支持PNG格式')
|
|
|
+ reject();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ this.$message.error('请上传PNG格式');
|
|
|
+ reject();
|
|
|
}
|
|
|
})
|
|
|
},
|