|
@@ -2,60 +2,70 @@ import { Input, Modal } from 'antd'
|
|
|
import { useEffect, useRef, useState } from 'react'
|
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
|
import style from './style.module.scss'
|
|
|
-import html2canvas from 'html2canvas'
|
|
|
+// import html2canvas from 'html2canvas'
|
|
|
import { SceneType, SceneTypeDomain, SceneTypePaths } from 'constant';
|
|
|
import { getHref } from 'utils';
|
|
|
import { asyncLoading } from 'components/loading';
|
|
|
|
|
|
|
|
|
const domScreenshot = async (dom: HTMLElement, foreignObjectRendering: boolean) => {
|
|
|
- const imgs = Array.from(dom.querySelectorAll('img'))
|
|
|
- try {
|
|
|
- await Promise.all(
|
|
|
- imgs.map(img => {
|
|
|
- if (!img.src) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- const req = fetch(img.src, {
|
|
|
- method: 'get'
|
|
|
- })
|
|
|
- return req
|
|
|
- .then(res => res.blob())
|
|
|
- .then(blob => {
|
|
|
- const render = new FileReader()
|
|
|
- return new Promise<void>(resolve => {
|
|
|
- render.onload = e => {
|
|
|
- if (e.target?.result) {
|
|
|
- img.src = e.target?.result as string
|
|
|
- }
|
|
|
- resolve()
|
|
|
- }
|
|
|
- render.readAsDataURL(blob)
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
- )
|
|
|
- } catch {
|
|
|
- }
|
|
|
-
|
|
|
- const canvas = await html2canvas(dom, {
|
|
|
- allowTaint: true,
|
|
|
- useCORS: true,
|
|
|
- imageTimeout: 0,
|
|
|
- removeContainer: false,
|
|
|
- foreignObjectRendering,
|
|
|
- width: dom.offsetWidth,
|
|
|
- height: dom.offsetHeight
|
|
|
- })
|
|
|
-
|
|
|
- await new Promise(resolve => setTimeout(resolve, 3000))
|
|
|
-
|
|
|
+ const canvas = (dom.tagName.toUpperCase() === 'CANVAS' ? dom : dom.querySelector('canvas')) as HTMLCanvasElement
|
|
|
return new Promise<Blob | null>(resolve => {
|
|
|
+ if (!canvas) {
|
|
|
+ resolve(null)
|
|
|
+ }
|
|
|
canvas.toBlob((blob) => {
|
|
|
- console.error('=====>aaa', blob, dom)
|
|
|
+ console.log(blob)
|
|
|
+ if (blob) {
|
|
|
+ window.open(URL.createObjectURL(blob))
|
|
|
+ }
|
|
|
resolve(blob)
|
|
|
})
|
|
|
})
|
|
|
+ // const imgs = Array.from(dom.querySelectorAll('img'))
|
|
|
+ // try {
|
|
|
+ // await Promise.all(
|
|
|
+ // imgs.map(img => {
|
|
|
+ // if (!img.src) {
|
|
|
+ // return null;
|
|
|
+ // }
|
|
|
+ // const req = fetch(img.src, {
|
|
|
+ // method: 'get'
|
|
|
+ // })
|
|
|
+ // return req
|
|
|
+ // .then(res => res.blob())
|
|
|
+ // .then(blob => {
|
|
|
+ // const render = new FileReader()
|
|
|
+ // return new Promise<void>(resolve => {
|
|
|
+ // render.onload = e => {
|
|
|
+ // if (e.target?.result) {
|
|
|
+ // img.src = e.target?.result as string
|
|
|
+ // }
|
|
|
+ // resolve()
|
|
|
+ // }
|
|
|
+ // render.readAsDataURL(blob)
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // )
|
|
|
+ // } catch {
|
|
|
+ // }
|
|
|
+
|
|
|
+ // const canvas = await html2canvas(dom, {
|
|
|
+ // allowTaint: true,
|
|
|
+ // useCORS: true,
|
|
|
+ // imageTimeout: 0,
|
|
|
+ // removeContainer: false,
|
|
|
+ // foreignObjectRendering,
|
|
|
+ // width: dom.offsetWidth,
|
|
|
+ // height: dom.offsetHeight
|
|
|
+ // })
|
|
|
+
|
|
|
+ // return new Promise<Blob | null>(resolve => {
|
|
|
+ // canvas.toBlob((blob) => {
|
|
|
+ // resolve(blob)
|
|
|
+ // })
|
|
|
+ // })
|
|
|
}
|
|
|
|
|
|
|
|
@@ -177,15 +187,22 @@ export const SelectFuse = (props: SelectImageProps & {caseId: number}) => {
|
|
|
|
|
|
const onSubmit = async () => {
|
|
|
if (iframeRef.current?.contentWindow) {
|
|
|
+ const iframeElement = iframeRef.current.contentWindow.document.documentElement
|
|
|
+
|
|
|
let fuseBody: Element | null = null
|
|
|
if (!fuseBody) {
|
|
|
- const iframe = iframeRef.current.contentWindow.document.documentElement.querySelector('.external') as HTMLIFrameElement
|
|
|
- fuseBody = iframe?.contentWindow?.document.documentElement || null
|
|
|
+ const iframe = iframeElement.querySelector('.external') as HTMLIFrameElement
|
|
|
+ const childElement = iframe?.contentWindow?.document.documentElement
|
|
|
+ if (childElement) {
|
|
|
+ fuseBody = childElement.querySelector('.scene-canvas > canvas') ||
|
|
|
+ childElement.querySelector('.player[name="main"] > canvas') ||
|
|
|
+ childElement
|
|
|
+ }
|
|
|
+ console.log(fuseBody)
|
|
|
}
|
|
|
if (!fuseBody) {
|
|
|
- fuseBody = iframeRef.current.contentWindow.document.documentElement.querySelector('.scene-canvas')
|
|
|
+ fuseBody = iframeElement.querySelector('.scene-canvas > canvas')
|
|
|
}
|
|
|
- console.log(fuseBody)
|
|
|
if (fuseBody) {
|
|
|
const blob = await domScreenshot(fuseBody as HTMLElement, true)
|
|
|
if (blob) {
|