Browse Source

fix: 上传同样文件时没有提示

chris 3 years ago
parent
commit
318e6d2159
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/views/modules/common/upload-component.vue

+ 8 - 0
src/views/modules/common/upload-component.vue

@@ -82,9 +82,17 @@
     methods: {
       // 上传
       submitUpload () {
+        // 判断是否有文件
         if (this.fileList.length === 0) {
           return this.$message.warning('请选取文件后再上传')
         }
+        // 判断是否有重复文件
+        let arr1 = this.fileList.map(i => i.name)
+        let arr2 = [...new Set(arr1)]
+        if (arr1.length !== arr2.length) {
+          return this.$message.warning('请去掉重复文件后再上传')
+        }
+        // 开始上传
         const formData = new FormData()
         this.fileList.forEach((file) => {
           formData.append('file', file.raw)