Browse Source

1. 代码调整
2. 增加上传文件类型过滤

梁展鹏 3 years ago
parent
commit
89dfde5e73
1 changed files with 20 additions and 20 deletions
  1. 20 20
      src/views/photographerManagement/photoVerify/modal/ali-oss-multi.vue

+ 20 - 20
src/views/photographerManagement/photoVerify/modal/ali-oss-multi.vue

@@ -28,16 +28,18 @@
           <el-upload
             action
             :http-request="upload"
-            :before-upload="beforeAvatarUpload"
             :on-preview="handlePreview"
-            :before-remove="beforeRemove"
             :on-remove="handleRemove"
             :on-success="handleSuccess"
-            :on-exceed="handleExceed"
-            drag
+            :on-change="handleChange"
+            :before-upload="beforeUpload"
+            :before-remove="beforeRemove"
             multiple
-            :limit="limit"
+            drag
+            accept="image/*"
             :file-list="fileList"
+            :limit="limit"
+            :on-exceed="handleExceed"
           >
             <i class="el-icon-upload"></i>
             <div class="el-upload__text">
@@ -104,18 +106,8 @@ export default {
     };
   },
   methods: {
-    // 文件超出个数限制时的钩子
-    handleExceed(files, fileList) {
-      this.$message.warning(`每次只能上传 ${this.limit} 张照片`);
-    },
     // 点击文件列表中已上传的文件时的钩子
     handlePreview(file) {},
-    // 删除文件之前的钩子
-    beforeRemove(file, fileList) {
-      if (file && file.status==="success") {
-        return this.$confirm(`确定移除 ${file.name}?`);
-      }
-    },
     // 文件列表移除文件时的钩子
     handleRemove(file, fileList) {
       if (file && file.status==="success") {}
@@ -127,12 +119,10 @@ export default {
       //   this.saveData(response.name);
       // }
     },
+    handleChange(file, fileList) {
+    },
     // 文件上传前的校验
-    beforeAvatarUpload(file) {
-      // if (["video/mp4"].indexOf(file.type) == -1) {
-      //   this.$message.error("请上传正确的视频格式");
-      //   return false;
-      // }
+    beforeUpload(file) {
       const isLt100M = file.size / 1024 / 1024 > 1 && file.size / 1024 / 1024 < 100;
       if (!isLt100M) {
         this.$message.error("上传照片大小要在1MB ~ 100MB之间哦!");
@@ -144,6 +134,16 @@ export default {
         return false;
       }
     },
+    // 删除文件之前的钩子
+    beforeRemove(file, fileList) {
+      if (file && file.status==="success") {
+        return this.$confirm(`确定移除 ${file.name}?`);
+      }
+    },
+    // 文件超出个数限制时的钩子
+    handleExceed(files, fileList) {
+      this.$message.warning(`每次只能上传 ${this.limit} 张照片`);
+    },
     // http-request属性来覆盖默认的上传行为(即action="url"),自定义上传的实现
     upload(file) {
       const _that = this;