This commit is contained in:
白了个白 2024-12-10 10:16:07 +08:00
parent 464f39dac8
commit c78233a2f4
1 changed files with 21 additions and 7 deletions

View File

@ -106,6 +106,7 @@
<script setup> <script setup>
import { Search } from '@element-plus/icons-vue' import { Search } from '@element-plus/icons-vue'
import html2canvas from 'html2canvas'; import html2canvas from 'html2canvas';
import { toPng } from 'html-to-image';
import { onMounted, ref,watch, reactive, getCurrentInstance,nextTick } from 'vue' import { onMounted, ref,watch, reactive, getCurrentInstance,nextTick } from 'vue'
import {listEntpcoursework, listEntpcourseworkNew, getEntpcoursework} from '@/api/education/entpCourseWork' import {listEntpcoursework, listEntpcourseworkNew, getEntpcoursework} from '@/api/education/entpCourseWork'
@ -438,12 +439,25 @@ const getPaginationList = ( page, limit ) => {
*/ */
const captureScreenshot = (id) => { const captureScreenshot = (id) => {
const targetElement = document.getElementById('screenshot-target-' + id); const targetElement = document.getElementById('screenshot-target-' + id);
html2canvas(targetElement).then(canvas => { // html2canvas(targetElement).then(canvas => {
// canvasURL // console.log(canvas);
const screenshotUrl = canvas.toDataURL('image/png'); // // canvasURL
// // const screenshotUrl = canvas.toDataURL('image/png');
// console.log(screenshotUrl); // //
emit('addQuizImgBs64', screenshotUrl); // // console.log(screenshotUrl);
// emit('addQuizImgBs64', screenshotUrl);
// });
// const node = document.querySelector('#img')
console.log(targetElement)
toPng(targetElement).then((dataUrl) => {
// 使URL
console.log(dataUrl);
// this.imgUrl = dataUrl
// console.log(this.imgUrl)
emit('addQuizImgBs64', dataUrl);
})
.catch(function (error) {
console.error('转换错误:', error);
}); });
} }