Browse Source

提交1

1
mo 2 years ago
parent
commit
d7fbb69777
2 changed files with 11 additions and 7 deletions
  1. 10 7
      src/helpers/imageFunction.ts
  2. 1 0
      src/views/muiscDetial/index.tsx

+ 10 - 7
src/helpers/imageFunction.ts

@@ -1,10 +1,11 @@
 import imgList from './images/logoWatermark.png'
 export const imgToCanvas = async (url: string) => {
+  console.log('imgToCanvas',url)
   const img = document.createElement('img')
+  img.setAttribute('crossOrigin', 'anonymous')
+  img.src = url+`?${new Date().getTime()}`
 
-  img.src = url
-
-  img.setAttribute('crossOrigin', 'anonymous') // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
+ // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
 
   await new Promise(resolve => (img.onload = resolve))
 
@@ -32,15 +33,16 @@ export const imgToCanvas = async (url: string) => {
 */
 
 export const addWatermark = async (canvas, text) => {
+  console.log('addWatermark')
   try {
     const ctx = canvas.getContext('2d')
     // ctx.fillStyle = '#fff'
     const img = document.createElement('img')
+    img.setAttribute('crossOrigin', 'anonymous')
 
-    img.src = imgList
-
-    // img.setAttribute('crossOrigin', 'anonymous') // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
+    img.src = imgList+`?${new Date().getTime()}`
 
+   // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
     await new Promise(resolve => (img.onload = resolve))
 
     // 创建canvas DOM元素,并设置其宽高和图片一样
@@ -66,9 +68,10 @@ export const addWatermark = async (canvas, text) => {
     const pat = ctx.createPattern(water, 'repeat')
     ctx.fillStyle = pat
     ctx.fillRect(0, 0, canvas.width, canvas.height)
-    console.log('加水印',canvas)
+
     return canvas
   } catch (e) {
+
     console.log(e)
   }
 }

+ 1 - 0
src/views/muiscDetial/index.tsx

@@ -319,6 +319,7 @@ export default defineComponent({
         const ress = await request.post('/api-website/open/music/sheet/img', {
           data: {musicSheetId:state.musicDetail.id,musicImg:imgurl}
         })
+        console.log('赋值')
         state.showImg = imgurl
       } catch (e) {
         console.log(e)