Commit 3b0077dc73772a460684b5ae5807c5bf511bd757

Authored by 予ヾ
Committed by GitHub
1 parent 3de5b53b

fix: 修复水印重复叠加问题 (#2622)

Co-authored-by: whong <whif@foxmail.com>
Showing 1 changed file with 6 additions and 0 deletions
src/hooks/web/useWatermark.ts
... ... @@ -4,10 +4,15 @@ import { addResizeListener, removeResizeListener } from &#39;/@/utils/event&#39;;
4 4 import { isDef } from '/@/utils/is';
5 5  
6 6 const domSymbol = Symbol('watermark-dom');
  7 +const sourceMap = new WeakMap<HTMLElement, {}>();
7 8  
8 9 export function useWatermark(
9 10 appendEl: Ref<HTMLElement | null> = ref(document.body) as Ref<HTMLElement>,
10 11 ) {
  12 + const appendElRaw = unref(appendEl);
  13 + if (appendElRaw && sourceMap.has(appendElRaw)) {
  14 + return sourceMap.get(appendElRaw);
  15 + }
11 16 const func = useRafThrottle(function () {
12 17 const el = unref(appendEl);
13 18 if (!el) return;
... ... @@ -82,6 +87,7 @@ export function useWatermark(
82 87 const { clientHeight: height, clientWidth: width } = el;
83 88 updateWatermark({ str, width, height });
84 89 el.appendChild(div);
  90 + sourceMap.set(el, { setWatermark, clear });
85 91 return id;
86 92 };
87 93  
... ...