Selaa lähdekoodia

fix: 尝试解决背景图片无法截图的问题

奔跑的面条 3 vuotta sitten
vanhempi
sitoutus
da809f13b3
2 muutettua tiedostoa jossa 6 lisäystä ja 2 poistoa
  1. 3 1
      src/utils/utils.ts
  2. 3 1
      src/views/chart/hooks/useSync.hook.ts

+ 3 - 1
src/utils/utils.ts

@@ -154,7 +154,9 @@ export const canvasCut = (html: HTMLElement | null, callback?: Function) => {
   }
 
   html2canvas(html, {
-    backgroundColor: null
+    backgroundColor: null,
+    allowTaint: true,
+    useCORS: true
   }).then((canvas: HTMLCanvasElement) => {
     window['$message'].success('导出成功!')
     downloadByA(canvas.toDataURL(), undefined, 'png')

+ 3 - 1
src/views/chart/hooks/useSync.hook.ts

@@ -179,7 +179,9 @@ export const useSync = () => {
     const range = document.querySelector('.go-edit-range') as HTMLElement
     // 生成图片
     const canvasImage: HTMLCanvasElement = await html2canvas(range, {
-      backgroundColor: null
+      backgroundColor: null,
+      allowTaint: true,
+      useCORS: true
     })
     
     // 上传预览图