Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pro-layout
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
packages
pro-layout
Commits
0ad2871f
Commit
0ad2871f
authored
Nov 18, 2021
by
章启成
Committed by
言肆
Nov 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(watermark): 绘制背景需要的 props 全在 watchEffect 内解构
parent
2c038ef5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
index.tsx
src/WaterMark/index.tsx
+20
-15
No files found.
src/WaterMark/index.tsx
View file @
0ad2871f
import
type
{
CSSProperties
,
PropType
,
ExtractPropTypes
}
from
'vue'
import
{
defineComponent
,
computed
,
ref
,
watchEffect
,
toRef
}
from
'vue'
import
{
defineComponent
,
computed
,
ref
,
watchEffect
}
from
'vue'
import
{
useRouteContext
}
from
'../RouteContext'
export
type
FontStyle
=
'none'
|
'normal'
|
'italic'
|
'oblique'
...
...
@@ -77,22 +77,10 @@ const WaterMark = defineComponent({
// antd 内容层 zIndex 基本上在 10 以下 https://github.com/ant-design/ant-design/blob/6192403b2ce517c017f9e58a32d58774921c10cd/components/style/themes/default.less#L335
zIndex
=
9
,
gapX
=
212
,
gapY
=
222
,
width
=
120
,
height
=
64
,
rotate
=
-
22
,
// 默认旋转 -22 度
image
,
offsetLeft
,
offsetTop
,
fontStyle
=
'normal'
,
fontWeight
=
'normal'
,
fontColor
=
'rgba(0,0,0,.15)'
,
fontSize
=
16
,
fontFamily
=
'sans-serif'
,
prefixCls
:
customizePrefixCls
,
}
=
props
const
content
=
toRef
(
props
,
'content'
)
const
{
getPrefixCls
}
=
useRouteContext
()
const
prefixCls
=
getPrefixCls
(
'pro-layout-watermark'
,
customizePrefixCls
)
const
wrapperCls
=
computed
(()
=>
`
${
prefixCls
}
-wrapper`
)
...
...
@@ -105,6 +93,23 @@ const WaterMark = defineComponent({
const
base64Url
=
ref
(
''
)
watchEffect
(()
=>
{
const
{
gapX
=
212
,
gapY
=
222
,
width
=
120
,
height
=
64
,
rotate
=
-
22
,
// 默认旋转 -22 度
image
,
content
,
offsetLeft
,
offsetTop
,
fontStyle
=
'normal'
,
fontWeight
=
'normal'
,
fontColor
=
'rgba(0,0,0,.15)'
,
fontSize
=
16
,
fontFamily
=
'sans-serif'
,
}
=
props
const
canvas
=
document
.
createElement
(
'canvas'
)
const
ctx
=
canvas
.
getContext
(
'2d'
)
const
ratio
=
getPixelRatio
(
ctx
)
...
...
@@ -133,11 +138,11 @@ const WaterMark = defineComponent({
ctx
.
drawImage
(
img
,
0
,
0
,
markWidth
,
markHeight
)
base64Url
.
value
=
canvas
.
toDataURL
()
}
}
else
if
(
content
.
value
)
{
}
else
if
(
content
)
{
const
markSize
=
Number
(
fontSize
)
*
ratio
ctx
.
font
=
`
${
fontStyle
}
normal
${
fontWeight
}
${
markSize
}
px/
${
markHeight
}
px
${
fontFamily
}
`
ctx
.
fillStyle
=
fontColor
ctx
.
fillText
(
content
.
value
,
0
,
0
)
ctx
.
fillText
(
content
,
0
,
0
)
base64Url
.
value
=
canvas
.
toDataURL
()
}
}
else
{
...
...
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