Browse Source
fix: 修复水印重复叠加问题 (#2622)
Co-authored-by: whong <whif@foxmail.com>
pull/2628/head
予ヾ
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
6 additions and
0 deletions
-
src/hooks/web/useWatermark.ts
|
|
|
@ -4,10 +4,15 @@ import { addResizeListener, removeResizeListener } from '/@/utils/event'; |
|
|
|
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 @@ export function useWatermark( |
|
|
|
const { clientHeight: height, clientWidth: width } = el; |
|
|
|
updateWatermark({ str, width, height }); |
|
|
|
el.appendChild(div); |
|
|
|
sourceMap.set(el, { setWatermark, clear }); |
|
|
|
return id; |
|
|
|
}; |
|
|
|
|
|
|
|
|