فهرست منبع

判断文件类型

lex 2 سال پیش
والد
کامیت
fb512f365c
1فایلهای تغییر یافته به همراه12 افزوده شده و 1 حذف شده
  1. 12 1
      src/views/massMessage/operation.vue

+ 12 - 1
src/views/massMessage/operation.vue

@@ -71,8 +71,9 @@
               :before-delete="beforDelete"
               :after-read="afterRead"
               :max-count="1"
-              accept="image/*, .pdf"
+              accept="*.*"
             >
+              <!-- accept="image/*, .pdf" -->
               <!-- <div class="file">
                 <img src="./images/icon_url.png" class="icon_url" />
                 <div class="uploder-txt">
@@ -158,11 +159,21 @@ export default {
     };
   },
   methods: {
+    checkFileType(type) {
+      if (type.indexOf("pdf") != -1 || type.indexOf("image") != -1) {
+        return true;
+      } else {
+        return false;
+      }
+    },
     beforeRead(file) {
       const isLt2M = file.size / 1000 / 1000 < 5;
       if (!isLt2M) {
         this.$toast("上传文件大小不能超过 5MB");
         return false;
+      } else if (!this.checkFileType(file.type)) {
+        this.$toast("上传文件类型不支持");
+        return false;
       }
       return true;
     },