浏览代码

视频上传重复提交处理

Long 1 天之前
父节点
当前提交
7ac7255481
共有 1 个文件被更改,包括 31 次插入15 次删除
  1. 31 15
      src/views/course/videoResource/index.vue

+ 31 - 15
src/views/course/videoResource/index.vue

@@ -332,7 +332,7 @@
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button @click="cancel">取消</el-button>
-        <el-button type="primary" @click="submitForm" :disabled="isUploading">
+        <el-button type="primary" @click="submitForm" :loading="add" :disabled="isUploading || add">
           {{ isUploading ? '上传中...' : '保存' }}
         </el-button>
       </div>
@@ -522,7 +522,7 @@
 
       <div class="dialog-footer">
         <el-button @click="cancelBatch">取 消</el-button>
-        <el-button type="primary" @click="submitBatchAdd">保 存</el-button>
+        <el-button type="primary" :loading="add" :disabled="add || isUploading" @click="submitBatchAdd">保 存</el-button>
       </div>
       <!-- 批量上传视频弹窗 -->
       <el-dialog
@@ -1094,9 +1094,10 @@ export default {
       this.$refs["form"].validate(valid => {
         if (valid) {
           if (this.add){
-            this.$message.warning("文件上传中,请稍后再试")
+            this.$message.warning("请勿重复提交")
             return
           }
+          this.add = true
 
           const params = Object.assign({}, this.form);
           params.projectIds = this.form.projectIds.join(',');
@@ -1107,7 +1108,7 @@ export default {
                 this.open = false;
                 this.getList();
               }
-            });
+            })
           } else {
             addVideoResource(params).then(response => {
               if (response.code === 200) {
@@ -1115,7 +1116,7 @@ export default {
                 this.open = false;
                 this.getList();
               }
-            });
+            })
           }
         }
       });
@@ -1273,7 +1274,7 @@ export default {
             this.uploadCancellationTokens.set(form.tempId, tokens);
           }
         });
-        
+
         let line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
         form.fileKey = data.urlPath.substring(1);
         form.videoUrl = line_1;
@@ -1310,7 +1311,7 @@ export default {
             this.uploadCancellationTokens.set(form.tempId, tokens);
           }
         });
-        
+
         form.line2 = `${process.env.VUE_APP_VIDEO_LINE_2}/${data.urlPath}`;
 
         // 更新线路2状态为成功
@@ -1355,7 +1356,7 @@ export default {
       const file = options.file;
       this.getMediaDuration(file);
       this.currentUploadProgress = { total: 0, line1: 0, line2: 0, line1Status: 'pending', line2Status: 'pending' };
-      
+
       try {
         await this.getFirstThumbnail(file, this.form);
         const [line1Result, line2Result] = await Promise.allSettled([
@@ -1414,6 +1415,7 @@ export default {
     /** 批量新增 */
     handleBatchAdd() {
       this.batchAddVisible = true;
+      this.add =false
       this.videoList = []; // 清空之前的视频列表
     },
     /** 批量修改 */
@@ -1486,12 +1488,24 @@ export default {
     },
     /** 提交批量添加 */
     submitBatchAdd() {
+      if (this.videoList.length === 0) {
+        this.$message.warning("请选择视频");
+        return;
+      }
+
       // 检查是否所有选中的视频都已上传完成
       const incompleteVideos = this.videoList.filter(item => (item.progress || 0) < 100);
       if (incompleteVideos.length > 0) {
         this.$message.warning('有未完成上传的视频,请先完成上传');
         return;
       }
+
+      if (this.add){
+        this.$message.warning("请勿重复提交")
+        return
+      }
+      this.add = true
+
       // 调用批量添加API
       const videoList = JSON.parse(JSON.stringify(this.videoList));
       videoList.forEach(item => {
@@ -1503,7 +1517,7 @@ export default {
           this.batchAddVisible = false;
           this.getList();
         }
-      });
+      })
     },
     /** 获取分类名称 */
     getTypeName(typeId) {
@@ -1564,7 +1578,7 @@ export default {
             console.error('Error cancelling COS upload:', error);
           }
         }
-        
+
         // Cancel OBS upload if exists
         if (cancellationTokens.obs) {
           try {
@@ -1574,7 +1588,7 @@ export default {
             console.error('Error cancelling OBS upload:', error);
           }
         }
-        
+
         // Remove cancellation tokens
         this.uploadCancellationTokens.delete(row.tempId);
       }
@@ -1716,6 +1730,7 @@ export default {
         return;
       }
 
+      this.isUploading = true;
       this.isProcessingBatch = true;
 
       while (this.uploadQueue.length > 0) {
@@ -1750,6 +1765,7 @@ export default {
       }
 
       this.isProcessingBatch = false;
+      this.isUploading = false;
       this.$message.success('所有视频上传队列处理完成!');
     },
 
@@ -2082,7 +2098,7 @@ export default {
             console.error('Error cancelling COS upload:', error);
           }
         }
-        
+
         // Cancel OBS upload if exists
         if (cancellationTokens.obs) {
           try {
@@ -2092,7 +2108,7 @@ export default {
             console.error('Error cancelling OBS upload:', error);
           }
         }
-        
+
         // Remove cancellation tokens
         this.uploadCancellationTokens.delete(row.tempId);
       }
@@ -2176,7 +2192,7 @@ export default {
           tokens.cos = uploadInfo.cancel;
           this.uploadCancellationTokens.set(tempVideo.tempId, tokens);
         });
-        
+
         let line_1 = `${process.env.VUE_APP_VIDEO_LINE_1}${data.urlPath}`;
         tempVideo.fileKey = data.urlPath.substring(1);
         tempVideo.videoUrl = line_1;
@@ -2202,7 +2218,7 @@ export default {
           tokens.obs = uploadInfo.cancel;
           this.uploadCancellationTokens.set(tempVideo.tempId, tokens);
         });
-        
+
         tempVideo.line2 = `${process.env.VUE_APP_VIDEO_LINE_2}/${data.urlPath}`;
         return { success: true, url: tempVideo.line2 };
       } catch (error) {