Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
165ce58a
authored
Apr 30, 2025
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:水印针对黑白主题的适配
parent
66a062cf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletions
+18
-1
src/hooks/web/useWatermark.ts
+18
-1
No files found.
src/hooks/web/useWatermark.ts
View file @
165ce58a
import
{
useAppStore
}
from
'@/store/modules/app'
import
{
watch
}
from
'vue'
const
domSymbol
=
Symbol
(
'watermark-dom'
)
const
domSymbol
=
Symbol
(
'watermark-dom'
)
export
function
useWatermark
(
appendEl
:
HTMLElement
|
null
=
document
.
body
)
{
export
function
useWatermark
(
appendEl
:
HTMLElement
|
null
=
document
.
body
)
{
let
func
:
Fn
=
()
=>
{}
let
func
:
Fn
=
()
=>
{}
const
id
=
domSymbol
.
toString
()
const
id
=
domSymbol
.
toString
()
const
appStore
=
useAppStore
()
let
watermarkStr
=
''
const
clear
=
()
=>
{
const
clear
=
()
=>
{
const
domId
=
document
.
getElementById
(
id
)
const
domId
=
document
.
getElementById
(
id
)
if
(
domId
)
{
if
(
domId
)
{
...
@@ -22,7 +28,7 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) {
...
@@ -22,7 +28,7 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) {
if
(
cans
)
{
if
(
cans
)
{
cans
.
rotate
((
-
20
*
Math
.
PI
)
/
120
)
cans
.
rotate
((
-
20
*
Math
.
PI
)
/
120
)
cans
.
font
=
'15px Vedana'
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
.
textAlign
=
'left'
cans
.
textBaseline
=
'middle'
cans
.
textBaseline
=
'middle'
cans
.
fillText
(
str
,
can
.
width
/
20
,
can
.
height
)
cans
.
fillText
(
str
,
can
.
width
/
20
,
can
.
height
)
...
@@ -44,6 +50,7 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) {
...
@@ -44,6 +50,7 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) {
}
}
function
setWatermark
(
str
:
string
)
{
function
setWatermark
(
str
:
string
)
{
watermarkStr
=
str
createWatermark
(
str
)
createWatermark
(
str
)
func
=
()
=>
{
func
=
()
=>
{
createWatermark
(
str
)
createWatermark
(
str
)
...
@@ -51,5 +58,15 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) {
...
@@ -51,5 +58,15 @@ export function useWatermark(appendEl: HTMLElement | null = document.body) {
window
.
addEventListener
(
'resize'
,
func
)
window
.
addEventListener
(
'resize'
,
func
)
}
}
// 监听主题变化
watch
(
()
=>
appStore
.
getIsDark
,
()
=>
{
if
(
watermarkStr
)
{
createWatermark
(
watermarkStr
)
}
}
)
return
{
setWatermark
,
clear
}
return
{
setWatermark
,
clear
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment