Просмотр исходного кода

feat: 上传的壁纸分辨率为做限制大小

332777428@qq.com 6 месяцев назад
Родитель
Сommit
d14214d696
2 измененных файлов с 12 добавлено и 11 удалено
  1. 10 11
      src/components/Upload/index.vue
  2. 2 0
      src/views/operation/piano/index.vue

+ 10 - 11
src/components/Upload/index.vue

@@ -18,6 +18,8 @@
       :on-progress="onProgress"
       :on-success="onSuccess"
       :on-error="onError"
+      :width="width"
+      :height="height"
     >
       <!-- <el-button v-if="listType !== 'picture-card'" :type="type" ref="upload"> -->
       <el-button
@@ -104,11 +106,11 @@ export default {
     },
     // 图片尺寸
     width: {
-      type: Number,
+      type: String,
       default: null,
     },
     height: {
-      type: Number,
+      type: String,
       default: null,
     },
     // 文件大小
@@ -179,20 +181,17 @@ export default {
       var platformId = this.$props.platformId;
       this.form.platformId = platformId;
       this.data.platformId = platformId;
+
       if (this.width && this.height) {
+        var w = Number(this.width);
+        var h = Number(this.height);
         const data = await this.readerImg(file);
         let _width =
-          data.width % this.width === 0 || this.width % data.width === 0
-            ? true
-            : false;
+          data.width % w === 0 || w % data.width === 0 ? true : false;
         let _height =
-          data.height % this.height === 0 || this.height % data.height === 0
-            ? true
-            : false;
+          data.height % h === 0 || h % data.height === 0 ? true : false;
         if (!_width || !_height) {
-          this.$message.error(
-            `请上传${this.width}x${this.height}尺寸或同比例倍数的图片`
-          );
+          this.$message.error(`请上传${w}x${h}尺寸或同比例倍数的图片`);
           return Promise.reject(false);
         }
       }

+ 2 - 0
src/views/operation/piano/index.vue

@@ -70,6 +70,8 @@
         <el-form-item label="上传:" prop="pic">
           <Upload
             listType="picture-card"
+            width="480"
+            height="480"
             :url="dialogData.pic"
             @upload="uploadCode($event, 'pic')"
           />