Bläddra i källkod

上传图片尺寸兼容倍数

DESKTOP-SVI9JE1\muzen 1 år sedan
förälder
incheckning
eb35c56c92
1 ändrade filer med 4 tillägg och 2 borttagningar
  1. 4 2
      src/components/Upload/index.vue

+ 4 - 2
src/components/Upload/index.vue

@@ -139,8 +139,10 @@ export default {
     async beforeUpload(file) {
       if (this.width && this.height) {
         const data = await this.readerImg(file)
-        if (data.width !== this.width || data.height !== this.height) {
-          this.$message.error(`请上传${this.width}x${this.height}尺寸的图片`)
+        let _width = data.width % this.width === 0 || this.width % data.width === 0 ? true : false
+        let _height = data.height % this.height === 0 || this.height % data.height === 0 ? true : false
+        if (!_width || !_height) {
+          this.$message.error(`请上传${this.width}x${this.height}尺寸或同比例倍数的图片`)
           return Promise.reject(false)
         }
       }