Quellcode durchsuchen

支持上传格式

gzb
guozhongbo vor 1 Jahr
Ursprung
Commit
cdec076644
2 geänderte Dateien mit 54 neuen und 32 gelöschten Zeilen
  1. 27
    16
      src/views/school/index.vue
  2. 27
    16
      src/views/service/index.vue

+ 27
- 16
src/views/school/index.vue Datei anzeigen

@@ -69,7 +69,9 @@
69 69
             <Upload
70 70
               action
71 71
               class="file_left_up"
72
-              accept=".jpg,.jpeg,.png"
72
+              :format="pictureFormat"
73
+              :max-size="10 * 1024"
74
+              :accept="getPictureAccept()"
73 75
               :before-upload="
74 76
                 (file) => {
75 77
                   handleUpload(file);
@@ -102,6 +104,10 @@
102 104
               </div>
103 105
             </Upload>
104 106
           </div>
107
+          <div class="uptype">
108
+            <p>支持上传格式(10MB以内):</p>
109
+            <p>jpg、jpeg、png、bmp、jfif、webp.</p>
110
+          </div>
105 111
         </div>
106 112
       </Form>
107 113
       <div slot="footer" style="text-align: right">
@@ -142,7 +148,9 @@
142 148
             <Upload
143 149
               action
144 150
               class="file_left_up"
145
-              accept=".jpg,.jpeg,.png"
151
+              :format="pictureFormat"
152
+              :max-size="10 * 1024"
153
+              :accept="getPictureAccept()"
146 154
               :before-upload="
147 155
                 (file) => {
148 156
                   handleUpload(file);
@@ -175,6 +183,10 @@
175 183
               </div>
176 184
             </Upload>
177 185
           </div>
186
+          <div class="uptype">
187
+            <p>支持修改格式(10MB以内):</p>
188
+            <p>jpg、jpeg、png、bmp、jfif、webp.</p>
189
+          </div>
178 190
         </div>
179 191
       </Form>
180 192
       <div slot="footer" style="text-align: right">
@@ -194,9 +206,11 @@
194 206
 import axios from "axios";
195 207
 import { sl_list, sl_save, sl_update, sl_del } from "@/api/index";
196 208
 import { dateFormat } from "@/utils/index";
209
+import { pictureFormat } from "@/utils/fileConfig";
197 210
 export default {
198 211
   data() {
199 212
     return {
213
+      pictureFormat,
200 214
       userInfo: {},
201 215
       showLoading: false,
202 216
       form_search: {
@@ -374,6 +388,13 @@ export default {
374 388
     this.init();
375 389
   },
376 390
   methods: {
391
+    getPictureAccept() {
392
+      return this.pictureFormat
393
+          .map((v) => {
394
+            return `.${v}`;
395
+          })
396
+          .join(",");
397
+    },
377 398
     seach() {
378 399
       this.form_search.page = 1;
379 400
       this.init();
@@ -454,6 +475,7 @@ export default {
454 475
               this.add_form.show = false;
455 476
               this.add_form.schoolname = "";
456 477
               this.add_form.schoollogo = "";
478
+              this.$Message.success(res.msg);
457 479
               this.init();
458 480
             } else {
459 481
               this.$Message.error(res.msg);
@@ -464,20 +486,6 @@ export default {
464 486
     },
465 487
     handleUpload(file) {
466 488
       let that = this;
467
-      let size = file.size / 1024 / 1024;
468
-      if (!file.name) {
469
-        return;
470
-      }
471
-      let str = file.name.split(".");
472
-      let suffix = str[str.length - 1];
473
-      if (suffix !== "png" && suffix !== "jpg" && suffix !== "jpeg") {
474
-        this.$Message.error("请上传png、jpg、jpeg类型的文件");
475
-        return false;
476
-      }
477
-      if (size > 10) {
478
-        this.$Message.error("图片太大,不能超过10M!");
479
-        return false;
480
-      }
481 489
       let formData = new FormData();
482 490
       formData.append("file", file);
483 491
       formData.append("savefolder", "schoollogo");
@@ -563,4 +571,7 @@ export default {
563 571
     padding-right: 10px;
564 572
   }
565 573
 }
574
+.uptype{
575
+  padding-left: 10px;
576
+}
566 577
 </style>

+ 27
- 16
src/views/service/index.vue Datei anzeigen

@@ -69,7 +69,9 @@
69 69
             <Upload
70 70
               action
71 71
               class="file_left_up"
72
-              accept=".jpg,.jpeg,.png"
72
+              :format="pictureFormat"
73
+              :max-size="10 * 1024"
74
+              :accept="getPictureAccept()"
73 75
               :before-upload="
74 76
                 (file) => {
75 77
                   handleUpload(file);
@@ -102,6 +104,10 @@
102 104
               </div>
103 105
             </Upload>
104 106
           </div>
107
+          <div class="uptype">
108
+            <p>支持上传格式(10MB以内):</p>
109
+            <p>jpg、jpeg、png、bmp、jfif、webp.</p>
110
+          </div>
105 111
         </div>
106 112
       </Form>
107 113
       <div slot="footer" style="text-align: right">
@@ -142,7 +148,9 @@
142 148
             <Upload
143 149
               action
144 150
               class="file_left_up"
145
-              accept=".jpg,.jpeg,.png"
151
+              :format="pictureFormat"
152
+              :max-size="10 * 1024"
153
+              :accept="getPictureAccept()"
146 154
               :before-upload="
147 155
                 (file) => {
148 156
                   handleUpload(file);
@@ -175,6 +183,10 @@
175 183
               </div>
176 184
             </Upload>
177 185
           </div>
186
+          <div class="uptype">
187
+            <p>支持修改格式(10MB以内):</p>
188
+            <p>jpg、jpeg、png、bmp、jfif、webp.</p>
189
+          </div>
178 190
         </div>
179 191
       </Form>
180 192
       <div slot="footer" style="text-align: right">
@@ -194,9 +206,11 @@
194 206
 import axios from "axios";
195 207
 import { sc_list, sc_save, sc_update, sc_remove } from "@/api/index";
196 208
 import { dateFormat } from "@/utils/index";
209
+import { pictureFormat } from "@/utils/fileConfig";
197 210
 export default {
198 211
   data() {
199 212
     return {
213
+      pictureFormat,
200 214
       userInfo: {},
201 215
       showLoading: false,
202 216
       form_search: {
@@ -374,6 +388,13 @@ export default {
374 388
     this.init();
375 389
   },
376 390
   methods: {
391
+    getPictureAccept() {
392
+      return this.pictureFormat
393
+        .map((v) => {
394
+          return `.${v}`;
395
+        })
396
+        .join(",");
397
+    },
377 398
     seach() {
378 399
       this.form_search.page = 1;
379 400
       this.init();
@@ -453,6 +474,7 @@ export default {
453 474
               this.add_form.show = false;
454 475
               this.add_form.scname = "";
455 476
               this.add_form.scpic = "";
477
+              this.$Message.success(res.msg);
456 478
               this.init();
457 479
             } else {
458 480
               this.$Message.error(res.msg);
@@ -463,20 +485,6 @@ export default {
463 485
     },
464 486
     handleUpload(file) {
465 487
       let that = this;
466
-      let size = file.size / 1024 / 1024;
467
-      if (!file.name) {
468
-        return;
469
-      }
470
-      let str = file.name.split(".");
471
-      let suffix = str[str.length - 1];
472
-      if (suffix !== "png" && suffix !== "jpg" && suffix !== "jpeg") {
473
-        this.$Message.error("请上传png、jpg、jpeg类型的文件");
474
-        return false;
475
-      }
476
-      if (size > 10) {
477
-        this.$Message.error("图片太大,不能超过10M!");
478
-        return false;
479
-      }
480 488
       let formData = new FormData();
481 489
       formData.append("file", file);
482 490
       formData.append("savefolder", "servicecase");
@@ -562,4 +570,7 @@ export default {
562 570
     padding-right: 10px;
563 571
   }
564 572
 }
573
+.uptype {
574
+  padding-left: 10px;
575
+}
565 576
 </style>

Laden…
Abbrechen
Speichern