lsc 3 주 전
부모
커밋
b34b1d9789
2개의 변경된 파일71개의 추가작업 그리고 13개의 파일을 삭제
  1. 69 1
      src/views/Student/index.vue
  2. 2 12
      src/views/components/element/FrameElement/jietu.js

+ 69 - 1
src/views/Student/index.vue

@@ -1093,7 +1093,7 @@ const handleHomeworkSubmit = async () => {
           })
         }
       }
-      else {
+      else if (slides.value[slideIndex.value].elements.some((element: any) => element.isHTML)) {
         // message.warning('当前页面暂不支持作业提交')
         console.log('尝试截图当前页面并提交')
         // return
@@ -1295,6 +1295,74 @@ const handleHomeworkSubmit = async () => {
           message.error('截图提交失败')
         }
       }
+      else {
+        const screenSlides = document.querySelectorAll('.viewer-canvas .screen-slide')
+        let iframeElement: HTMLIFrameElement | null = null
+
+        // 获取iframe元素
+        if (
+          screenSlides &&
+            screenSlides[slideIndex.value] &&
+            screenSlides[slideIndex.value].querySelector('iframe')
+        ) {
+          iframeElement = screenSlides[slideIndex.value].querySelector('iframe') as HTMLIFrameElement
+        }
+        else {
+          throw new Error('未能获取到iframe元素,无法截图')
+        }
+
+
+
+        // 获取iframe内部的body元素(同源)
+        if (
+          iframeElement.contentWindow &&
+            iframeElement.contentWindow.document &&
+            iframeElement.contentWindow.document.body
+        ) {
+
+          const _ajs = iframeElement.contentWindow.document.createElement('script')
+          _ajs.type = 'text/javascript'
+          _ajs.innerHTML =
+        'var _js = document.createElement("script");\n' +
+        '_js.type="text/javascript";\n' +
+        '_js.src="https://html2canvas.hertzen.com/dist/html2canvas.min.js";\n' +
+        '_js.onload = function(){\n' +
+        ' var a = document.getElementsByTagName("img")\n' +
+        ' for(var i = 0;i<a.length;i++){a[i].crossOrigin="anonymous"}\n' +
+        ' html2canvas(document.body).then(canvas => {\n' +
+        '  var base64Url = canvas.toDataURL("image/png");\n' +
+        'var base64 = "<img src=" + base64Url + " />"\n' +
+        'var file = dataURLtoFile_shishi(base64Url, "截图")\n' +
+        'beforeUpload_shishi(file,' +
+        "'" +
+        props.userid +
+        "'" +
+        ', ' +
+        "'" +
+        props.courseid +
+        "'" +
+        ', ' +
+        "'" +
+        slideIndex.value +
+        "'" +
+        ', ' +
+        "'0'" +
+        ', ' +
+        "'73'" +
+        ', ' +
+        "'1'" +
+        ')\n' +
+        ' });\n' +
+        '}\n' +
+        'document.head.appendChild(_js);\n'
+          iframeElement.contentWindow.document.head.appendChild(_ajs)
+          
+        }
+        else {
+          throw new Error('未能获取到iframe的body元素,无法截图')
+        }
+       
+      }
     }
 
     if (!hasSubmitWork) {

+ 2 - 12
src/views/components/element/FrameElement/jietu.js

@@ -92,18 +92,8 @@ function addSWork_shishi(uid, cid, a, task, tool, atool, type) {
       for (let i = 0; i < _a.length; i++) {
         _a[i].removeAttribute('crossorigin')
       }
-      parent.document.getElementById('shishi_loading').style.display = 'none'
-      const _div = document.createElement('div')
-      _div.style = 'width:100%;height:100%;background:#0000008f;position:fixed;top:0;left:0;z-index:99999999999999;display: flex;justify-content: center;align-items: center;'
-      const _inner = document.createElement('div')
-      _inner.style = 'color: #fff;padding: 15px;background: #00000070;border-radius: 5px;font-size: 18px;'
-      _inner.innerHTML = '截图上传成功'
-      _div.appendChild(_inner)
-      document.body.appendChild(_div)
-      setTimeout(() => {
-        //  document.body.removeChild(_loading)
-        document.body.removeChild(_div)
-      }, 2000)
+      // parent.document.getElementById('shishi_loading').style.display = 'none'
+
       console.log('截图上传成功')
     }
   })