浏览代码

图片上传限制

cuixq 3 年之前
父节点
当前提交
f9ab33a386
共有 2 个文件被更改,包括 36 次插入31 次删除
  1. 21 19
      front-vue/src/views/system/company/certification.vue
  2. 15 12
      front-vue/src/views/system/fundSide/fundSide.vue

+ 21 - 19
front-vue/src/views/system/company/certification.vue

@@ -69,6 +69,7 @@
                 :on-preview="handlePictureCardPreview"
                 :on-remove="beforeRemove"
                 :on-change="dealImgChange"
+                :before-upload="beforeAvatarUpload"
                 multiple
                 :limit="1"
                 :on-exceed="handleExceed"
@@ -253,6 +254,7 @@
                   :http-request="fsfzzRequest"
                   :on-preview="fsfzzPictureCardPreview"
                   :on-remove="fsfzzRemove"
+                  :before-upload="beforeAvatarUpload"
                   multiple
                   :limit="1"
                   :on-exceed="fsfzzExceed"
@@ -287,6 +289,7 @@
                   :http-request="fsfzfRequest"
                   :on-preview="fsfzfPictureCardPreview"
                   :on-remove="fsfzfRemove"
+                  :before-upload="beforeAvatarUpload"
                   multiple
                   :limit="1"
                   :on-exceed="fsfzfExceed"
@@ -362,6 +365,7 @@
                   :http-request="jsfzzRequest"
                   :on-preview="jsfzzPictureCardPreview"
                   :on-remove="jsfzzRemove"
+                  :before-upload="beforeAvatarUpload"
                   multiple
                   :limit="1"
                   :on-exceed="jsfzzExceed"
@@ -396,6 +400,7 @@
                   :http-request="jsfzfRequest"
                   :on-preview="jsfzfPictureCardPreview"
                   :on-remove="jsfzfRemove"
+                  :before-upload="beforeAvatarUpload"
                   multiple
                   :limit="1"
                   :on-exceed="jsfzfExceed"
@@ -523,6 +528,7 @@
               :http-request="frsqsRequest"
               :on-preview="frsqsPictureCardPreview"
               :on-remove="frsqsRemove"
+              :before-upload="beforeAvatarUpload"
               multiple
               :limit="1"
               :on-exceed="frsqsExceed"
@@ -561,6 +567,7 @@
               :http-request="szzssqRequest"
               :on-preview="szzssqPictureCardPreview"
               :on-remove="szzssqRemove"
+              :before-upload="beforeAvatarUpload"
               multiple
               :limit="1"
               :on-exceed="szzssqExceed"
@@ -597,6 +604,7 @@
                 :http-request="qtfjRequest"
                 :on-preview="qtfjPictureCardPreview"
                 :on-remove="qtfjRemove"
+                :before-upload="beforeAvatarUpload"
                 multiple
                 :limit="1"
                 :on-exceed="qtfjExceed"
@@ -1365,19 +1373,23 @@ export default {
     qtfjUpload() {
       this.$refs.qtfjload.submit();
     },
+         //上传前校验
+    beforeAvatarUpload(file) {
+      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
+      const isLt2M = file.size / 1024 / 1024 < 2;
+
+      if (!isJPG) {
+        this.$message.error('上传图片只能是 JPG/PNG 格式');
+      }
+      if (!isLt2M) {
+        this.$message.error('上传图片大小不能超过 2MB');
+      }
+      return isJPG && isLt2M;
+    },
 
     //营业执照上传
     yyzzRequest(param) {
       let fileObj = param.file; // 相当于input里取得的files
-      const isLt2M = fileObj.size / 1024 / 1024 < 2;
-      if (!isLt2M) {
-        this.$message.error("上传图片大小不能超过 2MB!");
-        loading.close();
-      }
-      const isJPG = fileObj.type === "image/jpeg";
-      if (!isJPG) {
-        this.$message.error("上传头像图片只能是 JPG 格式!");
-      }
       let fd = new FormData(); // FormData 对象
       fd.append("file", fileObj); // 文件对象
       const loading = this.$loading({
@@ -1421,11 +1433,6 @@ export default {
     //法人身份证正面ocr识别
     fsfzzRequest(param) {
       let fileObj = param.file; // 相当于input里取得的files
-      const isLt2M = fileObj.size / 1024 / 1024 < 2;
-      if (!isLt2M) {
-        this.$message.error("上传图片大小不能超过 2MB!");
-        loading.close();
-      }
       let fd = new FormData(); // FormData 对象
       fd.append("file", fileObj); // 文件对象
       fd.append("fileType", "00"); // 文件类型
@@ -1477,11 +1484,6 @@ export default {
     //经办人身份证正面
     jsfzzRequest(param) {
       let fileObj = param.file; // 相当于input里取得的files
-      const isLt2M = fileObj.size / 1024 / 1024 < 2;
-      if (!isLt2M) {
-        this.$message.error("上传图片大小不能超过 2MB!");
-        loading.close();
-      }
       let fd = new FormData(); // FormData 对象
       fd.append("file", fileObj); // 文件对象
       fd.append("fileType", "01"); // 文件类型

+ 15 - 12
front-vue/src/views/system/fundSide/fundSide.vue

@@ -286,6 +286,7 @@
             :on-preview="handlePictureCardPreview"
             :on-remove="beforeRemove"
             :on-change="dealImgChange"
+            :before-upload="beforeAvatarUpload"
             multiple
             :limit="20"
             :on-exceed="handleExceed"
@@ -342,7 +343,7 @@ export default {
       sfzVisible: false,
       showBtnImg: false,
       noneBtnImg: false,
-      limitCountImg: 1,
+      limitCountImg: 20,
       // id隐藏
       isShow: false,
       // 遮罩层
@@ -645,6 +646,19 @@ export default {
         }
       });
     },
+     //上传前校验
+    beforeAvatarUpload(file) {
+      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png';
+      const isLt2M = file.size / 1024 / 1024 < 2;
+
+      if (!isJPG) {
+        this.$message.error('上传图片只能是 JPG/PNG 格式');
+      }
+      if (!isLt2M) {
+        this.$message.error('上传图片大小不能超过 2MB');
+      }
+      return isJPG && isLt2M;
+    },
     //状态变更
     handleStatusChange(row) {
       let text = row.scyStatus === "00" ? "启用" : "停用";
@@ -691,17 +705,6 @@ export default {
     //手动上传文件触发
     sfzRequest(param) {
       let fileObj = param.file; // 相当于input里取得的files
-        const isLt2M = fileObj.size / 1024 / 1024 < 2;
-      if (!isLt2M) {
-        this.$message.error("上传图片大小不能超过 2MB!");
-        loading.close();
-      }
-      const isJPG = fileObj.type === "image/jpeg"||
-      fileObj.type === "image/png";
-      if (!isJPG) {
-        this.$message.error("上传头像图片只能是 JPG ,PNG格式!");
-         loading.close();
-      }
       let fd = new FormData(); // FormData 对象
       fd.append("file", fileObj); // 文件对象
       fd.append("fileType", "00"); //文件类型