lsc 2 days ago
parent
commit
87c93f37ef
1 changed files with 7 additions and 21 deletions
  1. 7 21
      src/components/CreateCourseDialog.vue

+ 7 - 21
src/components/CreateCourseDialog.vue

@@ -143,22 +143,7 @@ const handleFileUpload = async (files: FileList) => {
     // 调用importPPTXFile并传入signal
     await importPPTXFile(files, { signal, onclose: () => {
       emit('setTitle', file.name.replace(/\.[^/.]+$/, ''), 2) 
-      emit('close')
-      // showConfirmDialog({
-      //   title: lang.ssUploadSuccess,
-      //   content: lang.ssBatchInteractiveWebConfirm,
-      //   confirmText: lang.ssBatchInteractiveWebConfirmDesc,
-      //   cancelText: lang.ssBatchInteractiveWebConfirmDesc2,
-      //   width: 400,
-      //   onConfirm: () => {
-      //     setRunningState(true)
-      //   },
-      //   onCancel: () => {
-      //     console.log('取消删除')
-      //   },
-      // })
-      // 等图片上传完毕(imgExporting === false)后触发保存
-      console.log('等图片上传完毕(imgExporting === false)后触发保存')
+      // ★ save 逻辑必须在 emit('close') 之前,否则 Modal 隐藏后组件卸载,watch 会自动 dispose
       const trySave = () => {
         const parentWindow = window.parent as any
         parentWindow?.save?.(3)
@@ -168,14 +153,15 @@ const handleFileUpload = async (files: FileList) => {
         trySave()
       }
       else {
-        // 有图片正在上传,等上传完毕再保存
-        const stopWatch = watch(imgExporting, (val) => {
-          if (val === false) {
-            stopWatch()
+        // 有图片正在上传,用 setInterval 轮询(不依赖组件生命周期,emit close 后也能继续跑)
+        const timer = setInterval(() => {
+          if (imgExporting.value === false) {
+            clearInterval(timer)
             trySave()
           }
-        })
+        }, 300)
       }
+      emit('close')
     } })
   }
   catch (error) {