From 98f7c9924a4724d7149c7facdf4082cb2caee0df Mon Sep 17 00:00:00 2001
From: du <13220750630.163.com>
Date: 星期三, 09 四月 2025 16:48:51 +0800
Subject: [PATCH] 字幕查看

---
 easegen-front/src/views/myCourse/index.vue |  130 ++++++++++++++++++++++++++++++++++++++++--
 easegen-front/src/api/pptTemplate/index.ts |    4 +
 2 files changed, 126 insertions(+), 8 deletions(-)

diff --git a/easegen-front/src/api/pptTemplate/index.ts b/easegen-front/src/api/pptTemplate/index.ts
index 2977174..8b2d2da 100644
--- a/easegen-front/src/api/pptTemplate/index.ts
+++ b/easegen-front/src/api/pptTemplate/index.ts
@@ -98,3 +98,7 @@
 export const saveSubtitles = async(data) => {
   return await request.put({ url: '/digitalcourse/course-media/updateSubtitles', data })
 }
+// 瑙嗛鍚堟垚
+export const videoMeger = async(data) => {
+  return await request.post({ url: '/digitalcourse/course-media/createSubtitlesVideo', data })
+}
diff --git a/easegen-front/src/views/myCourse/index.vue b/easegen-front/src/views/myCourse/index.vue
index 0977127..323b4ba 100644
--- a/easegen-front/src/views/myCourse/index.vue
+++ b/easegen-front/src/views/myCourse/index.vue
@@ -145,7 +145,7 @@
   <!-- 瀛楀箷鐢熸垚寮规 -->
   <el-dialog
     v-model="subtitleDialogVisible"
-    title="瀛楀箷鐢熸垚"
+    title="瀛楀箷鏌ョ湅淇敼"
     width="60%"
     @closed="resetSubtitleForm"
   >
@@ -176,7 +176,7 @@
               @click="generateSubtitles"
               :loading="generating || polling"
             >
-              鐢熸垚瀛楀箷
+              鏌ョ湅瀛楀箷
             </el-button>
             <el-button
               type="primary"
@@ -190,6 +190,12 @@
                 style="display: none"
                 @change="handleFileUpload"
               />
+            </el-button>
+            <el-button
+              type="primary"
+              @click="downloadSubtitles"
+            >
+              瀛楀箷瑙嗛鍚堟垚
             </el-button>
           </el-form-item>
         </el-col>
@@ -205,7 +211,11 @@
           resize="none"
         />
       </el-form-item>
+      <el-form-item label="棰勮瑙嗛" v-if="subtitleForm.subtitlesAddStatus==2">
+        <video width="100%" :src="subtitleForm.videoUrl" controls></video>
+      </el-form-item>
     </el-form>
+
 
     <template #footer>
       <div class="dialog-footer">
@@ -232,6 +242,7 @@
 import { getAccessToken, getTenantId } from "@/utils/auth"
 import axios from 'axios'
 import { config } from '@/config/axios/config'
+import {videoMeger} from "@/api/pptTemplate";
 const router = useRouter()
 const message = useMessage()
 const { t } = useI18n()
@@ -377,9 +388,48 @@
 }
 
 // 鎵撳紑瀛楀箷寮规
-const openSubtitleDialog = (videoId: number) => {
-  subtitleForm.videoId = videoId
-  subtitleDialogVisible.value = true
+const openSubtitleDialog = async (videoId: number) => {
+  try {
+
+    subtitleDialogVisible.value = true
+    subtitleForm.videoId = videoId
+    const videoDetail = await pptTemplateApi.myCourseDetail(videoId)
+    console.log('瑙嗛璇︽儏:', videoDetail)
+    // 绔嬪嵆鑾峰彇瑙嗛璇︽儏妫�鏌ュ瓧骞曠姸鎬�
+    subtitleForm.subtitlesAddStatus=videoDetail.subtitlesAddStatus
+    if (videoDetail.subtitlesAddStatus === 2) {
+      subtitleForm.videoUrl = videoDetail.videoUrl || ''
+
+    }
+    if (videoDetail.subtitlesStatus === 2) { // 2 琛ㄧず瀛楀箷宸茬敓鎴�
+      if (videoDetail.subtitlesUrl) {
+        try {
+          // 灏濊瘯浠嶶RL鑾峰彇瀛楀箷鍐呭
+          const response = await fetch(videoDetail.subtitlesUrl)
+          if (response.ok) {
+            const srtContent = await response.text()
+            subtitleForm.content = srtContent
+          } else {
+            // 濡傛灉URL涓嶅彲鐢紝妫�鏌ユ槸鍚︽湁鐩存帴鐨勫瓧骞曞唴瀹�
+            subtitleForm.content = videoDetail.subtitlesContent || ''
+          }
+        } catch (error) {
+          console.error('鑾峰彇瀛楀箷鍐呭澶辫触:', error)
+          subtitleForm.content = videoDetail.subtitlesContent || ''
+        }
+      } else if (videoDetail.subtitlesContent) {
+        // 鐩存帴浣跨敤瀛楀箷鍐呭
+        subtitleForm.content = videoDetail.subtitlesContent
+      }
+    } else {
+      // 瀛楀箷鏈敓鎴愭垨鐢熸垚澶辫触锛屾竻绌哄唴瀹�
+      subtitleForm.content = ''
+    }
+  } catch (error) {
+    console.error('鑾峰彇瑙嗛璇︽儏澶辫触:', error)
+    message.error('鑾峰彇瑙嗛璇︽儏澶辫触锛岃閲嶈瘯')
+    subtitleDialogVisible.value = false
+  }
 }
 
 // 閲嶇疆瀛楀箷琛ㄥ崟
@@ -440,9 +490,9 @@
     generating.value = true
 
     const params = {
-      videoId: subtitleForm.videoId,
-      timeThreshold: parseFloat(subtitleForm.timeThreshold),
-      language: subtitleForm.language
+      id: subtitleForm.videoId,
+      sentenceGap: parseFloat(subtitleForm.timeThreshold),
+      lang: subtitleForm.language
     }
     await pptTemplateApi.generateSubtitles(params)
     message.success('瀛楀箷鐢熸垚浠诲姟宸插紑濮�')
@@ -576,7 +626,71 @@
   }
   polling.value = false
 }
+//瀛楀箷瑙嗛鍚堟垚
+const downloadSubtitles = async () => {
+  try {
+    // 鍒ゆ柇瀛楀箷鍐呭鏄惁涓虹┖
+    if (!subtitleForm.content.trim()) {
+      message.warning('璇峰厛鐢熸垚鎴栦笂浼犲瓧骞曞唴瀹�')
+      return
+    }
 
+    generating.value = true
+    const obj = {
+      id: subtitleForm.videoId
+    }
+    await pptTemplateApi.videoMeger(obj)
+    message.success('瀛楀箷瑙嗛鍚堟垚浠诲姟宸插紑濮�')
+
+    const maxAttempts = 20
+    const interval = 3000
+    let attempts = 0
+
+    const poll = async () => {
+      polling.value = true
+      attempts++
+
+      try {
+        const videoDetail = await pptTemplateApi.myCourseDetail(subtitleForm.videoId!)
+        console.log('杞瀛楀箷瑙嗛鍚堟垚缁撴灉:', videoDetail)
+
+        if (videoDetail.subtitlesAddStatus === 2) {
+          message.success('瀛楀箷瑙嗛鍚堟垚鎴愬姛')
+          if (videoDetail.previewUrl) {
+            subtitleForm.content = '' // 娓呯┖褰撳墠瀛楀箷鍐呭
+            stopPolling()
+            subtitleDialogVisible.value = false
+            getList() // 鍒锋柊鍒楄〃
+          }
+        } else if (videoDetail.subtitlesAddStatus === 3) {
+          message.error(`瀛楀箷瑙嗛鍚堟垚澶辫触: ${videoDetail.errorReason || '鏈煡鍘熷洜'}`)
+          stopPolling()
+        } else if (attempts >= maxAttempts) {
+          message.warning('瀛楀箷瑙嗛鍚堟垚瓒呮椂锛岃绋嶅悗鎵嬪姩妫�鏌�')
+          stopPolling()
+        } else {
+          pollingTimer = window.setTimeout(poll, interval)
+        }
+      } catch (error) {
+        console.error('杞瀛楀箷瑙嗛鍚堟垚鐘舵�佸嚭閿�:', error)
+        if (attempts >= maxAttempts) {
+          message.error('瀛楀箷瑙嗛鍚堟垚鐘舵�佹鏌ヨ秴鏃�')
+          stopPolling()
+        } else {
+          pollingTimer = window.setTimeout(poll, interval)
+        }
+      }
+    }
+
+    poll()
+  } catch (error) {
+    console.error('瀛楀箷瑙嗛鍚堟垚澶辫触:', error)
+    message.error(`瀛楀箷瑙嗛鍚堟垚澶辫触: ${error.message || '鏈煡閿欒'}`)
+    stopPolling()
+  } finally {
+    generating.value = false
+  }
+}
 // 娓呯悊瀹氭椂鍣�
 onBeforeUnmount(() => {
   stopPolling()

--
Gitblit v1.9.3