From 165ce58abbd0f79bea6657520079f8bdb5744618 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 30 Apr 2025 19:13:03 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=B0=B4=E5=8D=B0=E9=92=88?= =?UTF-8?q?=E5=AF=B9=E9=BB=91=E7=99=BD=E4=B8=BB=E9=A2=98=E7=9A=84=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/web/useWatermark.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/hooks/web/useWatermark.ts b/src/hooks/web/useWatermark.ts index 4a313594..028926b4 100644 --- a/src/hooks/web/useWatermark.ts +++ b/src/hooks/web/useWatermark.ts @@ -1,8 +1,14 @@ +import { useAppStore } from '@/store/modules/app' +import { watch } from 'vue' + const domSymbol = Symbol('watermark-dom') export function useWatermark(appendEl: HTMLElement | null = document.body) { let func: Fn = () => {} const id = domSymbol.toString() + const appStore = useAppStore() + let watermarkStr = '' + const clear = () => { const domId = document.getElementById(id) if (domId) { @@ -22,7 +28,7 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) { if (cans) { cans.rotate((-20 * Math.PI) / 120) cans.font = '15px Vedana' - cans.fillStyle = 'rgba(0, 0, 0, 0.15)' + cans.fillStyle = appStore.getIsDark ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.15)' cans.textAlign = 'left' cans.textBaseline = 'middle' cans.fillText(str, can.width / 20, can.height) @@ -44,6 +50,7 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) { } function setWatermark(str: string) { + watermarkStr = str createWatermark(str) func = () => { createWatermark(str) @@ -51,5 +58,15 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) { window.addEventListener('resize', func) } + // 监听主题变化 + watch( + () => appStore.getIsDark, + () => { + if (watermarkStr) { + createWatermark(watermarkStr) + } + } + ) + return { setWatermark, clear } }