Przeglądaj źródła

fix(upload): 添加上传按钮的加载状态以防止重复提交,失败消息提醒

liujt 7 miesięcy temu
rodzic
commit
7f7dc63a6e
1 zmienionych plików z 21 dodań i 10 usunięć
  1. 21 10
      src/components/upload/import-dialogNew.vue

+ 21 - 10
src/components/upload/import-dialogNew.vue

@@ -37,7 +37,7 @@
     </el-form>
     <div slot="footer" class="dialog-footer">
       <el-button size="small" @click="dialogVisible = false">关 闭</el-button>
-      <el-button size="small" @click="upload" type="primary">上 传</el-button>
+      <el-button size="small" @click="upload" type="primary" :loading="loading">上 传</el-button>
     </div>
   </el-dialog>
 </template>
@@ -62,7 +62,8 @@
         uploadShow: false,
         module: '',
         attaments: [], //上传文件
-        file: ''
+        file: '',
+        loading: false
       };
     },
 
@@ -92,18 +93,28 @@
       },
       // 文件上传
       async upload() {
+        this.loading = true;
         if (this.attaments.length == 0) {
           return this.$message.warning('文件不能为空!');
         }
         this.module = this.$props.defModule;
-
-        await importBatch({
-          module: this.module,
-          multiPartFiles: this.attaments
-        });
-        this.$message.success('操作成功!');
-        this.dialogVisible = false;
-        this.$emit('success');
+        try {
+          await importBatch({
+            module: this.module,
+            multiPartFiles: this.attaments
+          });
+          this.$message.success('操作成功!');
+          this.loading = false;
+          this.dialogVisible = false;
+          this.$emit('success');
+        } catch (error) {
+          this.loading = false;
+          // this.$message.error(error.message);
+          // this.$alert(error.message, '导入失败', {
+          //   confirmButtonText: '确定',
+          //   type: 'error'
+          // });
+        }
       },
       //下载模板
       downLoadTemplate() {