|
|
@@ -46,6 +46,10 @@
|
|
|
type: Array,
|
|
|
default: null // () => [100, 100]
|
|
|
},
|
|
|
+ imgRadio: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
// 允许上传的文件格式后缀名 eg:["jpg", "png"],['*']为不限制,各类型有默认限制 参见: formatDefault
|
|
|
format: {
|
|
|
type: Array,
|
|
|
@@ -424,6 +428,38 @@
|
|
|
if (this.type === '0') {
|
|
|
// 图片
|
|
|
let maxImgPx = this.maxImgPx
|
|
|
+ let imgRadio = this.imgRadio
|
|
|
+ if(imgRadio) {
|
|
|
+ try {
|
|
|
+ await new Promise((resolve) => {
|
|
|
+ let width, height
|
|
|
+ let image = new Image()
|
|
|
+ image.onload = () => {
|
|
|
+ width = image.width
|
|
|
+ height = image.height
|
|
|
+ if((width / height).toFixed(2) !== (16/9).toFixed(2)) {
|
|
|
+ this.$message.error('上传图片比例必须为16:9')
|
|
|
+ validate = false
|
|
|
+ }
|
|
|
+ window.URL && window.URL.revokeObjectURL(image.src)
|
|
|
+ resolve()
|
|
|
+ }
|
|
|
+ if (window.URL) {
|
|
|
+ let url = window.URL.createObjectURL(file)
|
|
|
+ image.src = url
|
|
|
+ } else if (window.FileReader) {
|
|
|
+ let reader = new FileReader()
|
|
|
+ reader.onload = function (e) {
|
|
|
+ let data = e.target.result
|
|
|
+ image.src = data
|
|
|
+ }
|
|
|
+ reader.readAsDataURL(file)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e)
|
|
|
+ }
|
|
|
+ }
|
|
|
if (maxImgPx) {
|
|
|
try {
|
|
|
await new Promise((resolve) => {
|
|
|
@@ -433,6 +469,10 @@
|
|
|
image.onload = () => {
|
|
|
width = image.width
|
|
|
height = image.height
|
|
|
+ if(width / height !== 16/9) {
|
|
|
+ this.$message.error('上传图片比例必须为16:9')
|
|
|
+ validate = false
|
|
|
+ }
|
|
|
if (width > maxImgPx[0]) {
|
|
|
validate = false
|
|
|
this.$message.error(`图片“宽”度超过${maxImgPx[0]}像素,请重新选择`)
|