Просмотр исходного кода

Merge branch 'beta' of https://git.cocorobo.cn/jack/PPT into beta

jack 1 неделя назад
Родитель
Сommit
5991a4fe4d

+ 1 - 0
src/types/slides.ts

@@ -651,6 +651,7 @@ export interface PPTFrameElement extends PPTBaseElement {
   type: 'frame'
   type: 'frame'
   url: string
   url: string
   isHTML?: boolean,
   isHTML?: boolean,
+  curl?: string,
   toolType?: number,
   toolType?: number,
   isDone?: boolean,
   isDone?: boolean,
   webId?: string,
   webId?: string,

+ 4 - 2
src/views/Student/index.vue

@@ -1910,7 +1910,8 @@ const elementDone = async (element: any, slideIndex: number) => {
       _element = {
       _element = {
         ...element,
         ...element,
         isHTML: true,  
         isHTML: true,  
-        url: html
+        url: html,
+        curl: iframeSrc
       }
       }
     }
     }
   }
   }
@@ -2525,11 +2526,12 @@ const handleHomeworkSubmit = async () => {
       message.info(lang.ssHwNoFunc)
       message.info(lang.ssHwNoFunc)
     }
     }
     else {
     else {
+      const element = elementList.value.find((i:any) => i.type === 'frame')
       api.addPPTOp2({
       api.addPPTOp2({
         id: props.courseid,
         id: props.courseid,
         userid: props.userid || '',
         userid: props.userid || '',
         type: '3',
         type: '3',
-        index: currentSlide.value.id, // 获取当前ppt页面的id
+        index: (element as any).id, // 获取当前ppt页面iframe的id
         data: String(Math.max(0, Math.round((Date.now() - slideEnterTime.value) / 1000))), // 进入作业页面到提交的耗时(秒)
         data: String(Math.max(0, Math.round((Date.now() - slideEnterTime.value) / 1000))), // 进入作业页面到提交的耗时(秒)
       }).then(res => {
       }).then(res => {
         console.log('res', res)
         console.log('res', res)

+ 15 - 0
src/views/components/element/FrameElement/BaseFrameElement.vue

@@ -240,6 +240,21 @@ const processedSrcDoc = computed(() => {
   for (const [pattern, replacement] of CDN_RULES) {
   for (const [pattern, replacement] of CDN_RULES) {
     html = html.replace(pattern, replacement)
     html = html.replace(pattern, replacement)
   }
   }
+  // 注入 <base href>:srcdoc 内相对路径资源需要基于原始页面 URL 解析
+  const baseHref = props.elementInfo.curl
+  if (baseHref && !/<base\s/i.test(html)) {
+    const safeHref = baseHref.replace(/"/g, '&quot;')
+    const baseTag = `<base href="${safeHref}">`
+    if (/<head[^>]*>/i.test(html)) {
+      html = html.replace(/<head[^>]*>/i, match => `${match}${baseTag}`)
+    }
+    else if (/<html[^>]*>/i.test(html)) {
+      html = html.replace(/<html[^>]*>/i, match => `${match}<head>${baseTag}</head>`)
+    }
+    else {
+      html = `<head>${baseTag}</head>${html}`
+    }
+  }
   return html
   return html
 })
 })