lsc 6 dní pred
rodič
commit
5df9941ec2
1 zmenil súbory, kde vykonal 47 pridanie a 5 odobranie
  1. 47 5
      src/views/Student/index.vue

+ 47 - 5
src/views/Student/index.vue

@@ -337,6 +337,40 @@ const toggleLaserPen = () => {
 // 获取导入导出功能
 const { readJSON, exportJSON2 } = useImport()
 
+// 根据iframe的URL查找对应的幻灯片索引
+const findSlideIndexByIframeUrl = (iframeUrl: string): number => {
+  try {
+    console.log('查找iframe对应的幻灯片索引,iframe URL:', iframeUrl)
+    
+    // 遍历所有幻灯片,查找包含该iframe URL的幻灯片
+    for (let i = 0; i < slides.value.length; i++) {
+      const slide = slides.value[i]
+      
+      // 检查幻灯片的元素中是否有iframe
+      if (slide.elements && slide.elements.length > 0) {
+        for (const element of slide.elements) {
+          // 检查是否是iframe元素
+          if (element.type === ElementTypes.FRAME) {
+            // 检查iframe的src是否匹配
+            if (element.url === iframeUrl) {
+              console.log(`找到匹配的幻灯片,索引: ${i}, 幻灯片ID: ${slide.id}`)
+              return i
+            }
+          }
+        }
+      }
+    }
+    
+    // 如果没有找到匹配的幻灯片,返回当前幻灯片索引
+    console.log('未找到匹配的幻灯片,使用当前幻灯片索引:', slideIndex.value)
+    return slideIndex.value
+  }
+  catch (error) {
+    console.error('查找幻灯片索引时出错:', error)
+    return slideIndex.value
+  }
+}
+
 // 处理iframe链接,为包含workPage的iframe添加必要参数
 const processIframeLinks = () => {
   try {
@@ -344,7 +378,7 @@ const processIframeLinks = () => {
     console.log('当前props:', { courseid: props.courseid, userid: props.userid })
     
     // 获取所有iframe元素
-    const iframes = document.querySelectorAll('iframe')
+    const iframes = document.querySelectorAll('.viewer-canvas iframe')
     console.log('找到iframe元素数量:', iframes.length)
     
     if (iframes.length === 0) {
@@ -359,6 +393,10 @@ const processIframeLinks = () => {
         console.log(`处理iframe ${index + 1}:`, iframeSrc)
         
         try {
+          // 查找iframe对应的幻灯片索引
+          const slideIndex = findSlideIndexByIframeUrl(iframeSrc)
+          console.log(`iframe ${index + 1} 对应的幻灯片索引:`, slideIndex)
+          
           // 解析URL,处理hash部分
           let baseUrl = iframeSrc
           let hashPart = ''
@@ -371,15 +409,15 @@ const processIframeLinks = () => {
           }
           
           // 构建新的hash部分,添加参数
-          // 为iframe设置固定的task值,避免每次切换都刷新
+          // 使用找到的幻灯片索引作为task参数
           let newHash = hashPart
           if (newHash.includes('?')) {
             // 如果hash中已经有查询参数,添加&
-            newHash += `&courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=0&tool=0`
+            newHash += `&courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=${slideIndex}&tool=0`
           }
           else {
             // 如果hash中没有查询参数,添加?
-            newHash += `?courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=0&tool=0`
+            newHash += `?courseid=${props.courseid || ''}&userid=${props.userid || ''}&stage=0&task=${slideIndex}&tool=0`
           }
           
           // 构建新的URL
@@ -500,7 +538,11 @@ const handleHomeworkSubmit = () => {
           if (iframeWindow && typeof iframeWindow.submitWork === 'function') {
             // 如果存在submitWork方法,执行它,参数可变
             console.log('执行iframe中的submitWork方法,参数可变')
-            const submitArgs = [slideIndex.value]
+            
+            // 查找iframe对应的幻灯片索引
+            const iframeSlideIndex = findSlideIndexByIframeUrl(iframeSrc)
+            const submitArgs = [iframeSlideIndex]
+            
             iframeWindow.submitWork(...submitArgs)
             message.success('作业提交成功')
             return