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

fix: 去掉上传图片比例限制

wuguojie 11 месяцев назад
Родитель
Сommit
c925289cf5
2 измененных файлов с 37 добавлено и 37 удалено
  1. 35 35
      src/components/UploadToCos.vue
  2. 2 2
      src/views/application/form/add.vue

+ 35 - 35
src/components/UploadToCos.vue

@@ -46,10 +46,10 @@
         type: Array,
         default: null // () => [100, 100]
       },
-      imgRadio: {
-          type: Boolean,
-          default: false
-      },
+      // imgRadio: {
+      //     type: Boolean,
+      //     default: false
+      // },
       // 允许上传的文件格式后缀名 eg:["jpg", "png"],['*']为不限制,各类型有默认限制 参见: formatDefault
       format: {
         type: Array,
@@ -429,37 +429,37 @@
           // 图片
           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(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) => {

+ 2 - 2
src/views/application/form/add.vue

@@ -32,8 +32,8 @@
                     </div>
                 </el-form-item>
                 <el-form-item label="活动图片" prop="fileUrl">
-                    <UploadToCos :fileUrl.sync="addForm.fileUrl" type="0" :imgRadio="true" >
-                        <div slot="tip">支持jpg/jpeg/png格式,上传图片为16:9</div>
+                    <UploadToCos :fileUrl.sync="addForm.fileUrl" type="0" >
+                        <div slot="tip">支持jpg/jpeg/png格式,建议采用‌750x1000px‌</div>
                     </UploadToCos>
                 </el-form-item>
             </el-form>