Browse Source

增加图片上传限制
Signed-off-by: Caner <5658514@qq.com>

Caner 4 years ago
parent
commit
29c7ec5efe
1 changed files with 8 additions and 2 deletions
  1. 8 2
      web/src/pages/index/views/index.vue

+ 8 - 2
web/src/pages/index/views/index.vue

@@ -58,7 +58,12 @@ export default {
       }
       }
       for (let j = 0; j < file.length; j++) {
       for (let j = 0; j < file.length; j++) {
         const el = file[j];
         const el = file[j];
-        if (el.size > size) {
+        if (el.size >= size) {
+          Notice.warning({
+            desc: el.name + "大小超过2M限制请重新上传",
+          });
+          break;
+        } else if (el.size >= size * 0.5) {
           Notice.warning({
           Notice.warning({
             desc: el.name + "大小超过限制将被压缩",
             desc: el.name + "大小超过限制将被压缩",
           });
           });
@@ -88,6 +93,7 @@ export default {
         }
         }
       }
       }
       this.newImg = newArr;
       this.newImg = newArr;
+      document.getElementById("psd").reset();
     },
     },
     // 图片临时路径
     // 图片临时路径
     getObjectURL(file) {
     getObjectURL(file) {
@@ -105,12 +111,12 @@ export default {
     async save() {
     async save() {
       if (!this.newImg.length) return;
       if (!this.newImg.length) return;
       try {
       try {
+        console.log(this.newImg[0].data)
         this.show = true;
         this.show = true;
         const formData = new FormData();
         const formData = new FormData();
         formData.append("pic", this.newImg[0].data);
         formData.append("pic", this.newImg[0].data);
         const res = await axios.post("/uploadOneInvoicePic", formData);
         const res = await axios.post("/uploadOneInvoicePic", formData);
         this.table = this.setData(res.data.invoice_data.words_result[0].result);
         this.table = this.setData(res.data.invoice_data.words_result[0].result);
-        document.getElementById("psd").reset();
       } catch (error) {
       } catch (error) {
         Notice.warning({
         Notice.warning({
           desc: error,
           desc: error,