予ヾ
2023-03-14 3b0077dc73772a460684b5ae5807c5bf511bd757
fix: 修复水印重复叠加问题 (#2622)

Co-authored-by: whong <whif@foxmail.com>
1个文件已修改
6 ■■■■■ 已修改文件
src/hooks/web/useWatermark.ts 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/hooks/web/useWatermark.ts
@@ -4,10 +4,15 @@
import { isDef } from '/@/utils/is';
const domSymbol = Symbol('watermark-dom');
const sourceMap = new WeakMap<HTMLElement, {}>();
export function useWatermark(
  appendEl: Ref<HTMLElement | null> = ref(document.body) as Ref<HTMLElement>,
) {
  const appendElRaw = unref(appendEl);
  if (appendElRaw && sourceMap.has(appendElRaw)) {
    return sourceMap.get(appendElRaw);
  }
  const func = useRafThrottle(function () {
    const el = unref(appendEl);
    if (!el) return;
@@ -82,6 +87,7 @@
    const { clientHeight: height, clientWidth: width } = el;
    updateWatermark({ str, width, height });
    el.appendChild(div);
    sourceMap.set(el, { setWatermark, clear });
    return id;
  };