Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
business-assistant
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 43f3af47
authored
Oct 17, 2022
by
李伟康
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
canvas增加批量
1 parent
81a805af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
36 deletions
utils/Draw.js
utils/Draw.js
View file @
43f3af4
...
...
@@ -8,33 +8,29 @@ class Draw {
[
_canvasObject_
]
=
null
;
[
_canvas_
]
=
null
constructor
(
canvasObject
)
{
wx
.
getSystemInfo
().
then
(({
pixelRatio
})
=>
{
this
[
_canvasObject_
]
=
canvasObject
this
[
_pixelRatio_
]
=
canvasObject
.
pixelRatio
||
pixelRatio
||
2
const
height
=
this
.
toRpx
(
canvasObject
.
height
),
width
=
this
.
toRpx
(
canvasObject
.
width
),
canvas
=
wx
.
createOffscreenCanvas
({
type
:
'2d'
,
width
,
height
}),
ctx
=
canvas
.
getContext
(
'2d'
)
this
[
_canvas_
]
=
canvas
this
[
_ctx_
]
=
ctx
this
[
_ctx_
].
clearRect
(
0
,
0
,
width
,
height
)
this
.
drawFill
({
x
:
0
,
y
:
0
,
this
[
_canvasObject_
]
=
canvasObject
this
[
_pixelRatio_
]
=
canvasObject
.
pixelRatio
||
2
const
height
=
this
.
toRpx
(
canvasObject
.
height
),
width
=
this
.
toRpx
(
canvasObject
.
width
),
canvas
=
wx
.
createOffscreenCanvas
({
type
:
'2d'
,
width
,
height
,
color
:
canvasObject
.
backgroundColor
||
'rgb(255, 255, 255)'
})
this
[
_ctx_
].
save
()
height
}),
ctx
=
canvas
.
getContext
(
'2d'
)
this
[
_canvas_
]
=
canvas
this
[
_ctx_
]
=
ctx
this
[
_ctx_
].
clearRect
(
0
,
0
,
width
,
height
)
this
.
drawFill
({
x
:
0
,
y
:
0
,
width
,
height
,
color
:
canvasObject
.
backgroundColor
||
'rgb(255, 255, 255)'
})
this
[
_ctx_
].
save
()
}
drawImages
(
imageParams
,
callback
)
{
async
drawImages
(
imageParams
,
callback
)
{
this
[
_ctx_
].
beginPath
()
this
[
_ctx_
].
save
()
let
{
...
...
@@ -60,13 +56,14 @@ class Draw {
this
[
_ctx_
].
clip
()
}
let
image
=
this
[
_canvas_
].
createImage
()
new
Promise
(
resolve
=>
{
image
.
onload
=
resolve
image
.
src
=
`
${
url
}
?v=
${
Date
.
now
()}
`
}).
then
(()
=>
{
this
[
_ctx_
].
drawImage
(
image
,
x
,
y
,
width
,
height
)
this
[
_ctx_
].
restore
()
if
(
callback
)
callback
()
image
.
src
=
`
${
url
}
?v=
${
Date
.
now
()}
`
return
new
Promise
(
resolve
=>
{
image
.
onload
=
()
=>
{
this
[
_ctx_
].
drawImage
(
image
,
x
,
y
,
width
,
height
)
this
[
_ctx_
].
restore
()
if
(
callback
)
callback
()
resolve
(
imageParams
)
}
})
}
toRpx
(
val
)
{
...
...
@@ -171,6 +168,7 @@ class Draw {
height
:
boxHeight
,
color
:
textParams
.
background
})
}
const
drawOneLineText
=
()
=>
{
let
textArr
=
text
.
toString
().
split
(
''
),
...
...
@@ -249,10 +247,7 @@ class Draw {
}
else
{
drawOneLineText
()
}
}
else
{
drawOneLineText
()
}
}
else
drawOneLineText
()
this
[
_ctx_
].
stroke
()
}
drawLine
(
lineParams
,
callback
)
{
...
...
@@ -391,10 +386,33 @@ class Draw {
})
}
base64src
(
url
).
then
(
img
=>
{
console
.
log
(
'img'
,
img
)
createLocalImg
(
img
,
callBack
)
})
}
async
begin
(
data
=
{})
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
const
drawFun
=
()
=>
{
data
.
textList
&&
data
.
textList
.
length
&&
data
.
textList
.
map
(
e
=>
{
this
.
drawText
(
e
)
})
data
.
lineList
&&
data
.
lineList
.
length
&&
data
.
lineList
.
map
(
e
=>
{
this
.
drawLine
(
e
)
})
wx
.
nextTick
(()
=>
{
this
.
toDataURL
(
res
=>
resolve
(
res
))
})
}
if
(
data
.
imageList
&&
data
.
imageList
.
length
)
{
await
this
.
drawImages
(
data
.
imageList
[
0
])
if
(
data
.
imageList
.
length
>
1
)
for
(
let
index
=
1
;
index
<
data
.
imageList
.
length
;
index
++
)
{
await
this
.
drawImages
(
data
.
imageList
[
index
])
if
(
index
==
data
.
imageList
.
length
-
1
)
drawFun
()
}
else
drawFun
()
}
})
}
}
const
checkTextDecoration
=
textDecoration
=>
{
return
textDecoration
&&
(
textDecoration
===
'underline'
||
textDecoration
===
'overline'
||
textDecoration
===
'line-through'
)
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment