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 {
...
@@ -8,33 +8,29 @@ class Draw {
[
_canvasObject_
]
=
null
;
[
_canvasObject_
]
=
null
;
[
_canvas_
]
=
null
[
_canvas_
]
=
null
constructor
(
canvasObject
)
{
constructor
(
canvasObject
)
{
wx
.
getSystemInfo
().
then
(({
this
[
_canvasObject_
]
=
canvasObject
pixelRatio
this
[
_pixelRatio_
]
=
canvasObject
.
pixelRatio
||
2
})
=>
{
const
height
=
this
.
toRpx
(
canvasObject
.
height
),
this
[
_canvasObject_
]
=
canvasObject
width
=
this
.
toRpx
(
canvasObject
.
width
),
this
[
_pixelRatio_
]
=
canvasObject
.
pixelRatio
||
pixelRatio
||
2
canvas
=
wx
.
createOffscreenCanvas
({
const
height
=
this
.
toRpx
(
canvasObject
.
height
),
type
:
'2d'
,
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
,
width
,
width
,
height
,
height
color
:
canvasObject
.
backgroundColor
||
'rgb(255, 255, 255)'
}),
})
ctx
=
canvas
.
getContext
(
'2d'
)
this
[
_ctx_
].
save
()
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_
].
beginPath
()
this
[
_ctx_
].
save
()
this
[
_ctx_
].
save
()
let
{
let
{
...
@@ -60,13 +56,14 @@ class Draw {
...
@@ -60,13 +56,14 @@ class Draw {
this
[
_ctx_
].
clip
()
this
[
_ctx_
].
clip
()
}
}
let
image
=
this
[
_canvas_
].
createImage
()
let
image
=
this
[
_canvas_
].
createImage
()
new
Promise
(
resolve
=>
{
image
.
src
=
`
${
url
}
?v=
${
Date
.
now
()}
`
image
.
onload
=
resolve
return
new
Promise
(
resolve
=>
{
image
.
src
=
`
${
url
}
?v=
${
Date
.
now
()}
`
image
.
onload
=
()
=>
{
}).
then
(()
=>
{
this
[
_ctx_
].
drawImage
(
image
,
x
,
y
,
width
,
height
)
this
[
_ctx_
].
drawImage
(
image
,
x
,
y
,
width
,
height
)
this
[
_ctx_
].
restore
()
this
[
_ctx_
].
restore
()
if
(
callback
)
callback
()
if
(
callback
)
callback
()
resolve
(
imageParams
)
}
})
})
}
}
toRpx
(
val
)
{
toRpx
(
val
)
{
...
@@ -171,6 +168,7 @@ class Draw {
...
@@ -171,6 +168,7 @@ class Draw {
height
:
boxHeight
,
height
:
boxHeight
,
color
:
textParams
.
background
color
:
textParams
.
background
})
})
}
}
const
drawOneLineText
=
()
=>
{
const
drawOneLineText
=
()
=>
{
let
textArr
=
text
.
toString
().
split
(
''
),
let
textArr
=
text
.
toString
().
split
(
''
),
...
@@ -249,10 +247,7 @@ class Draw {
...
@@ -249,10 +247,7 @@ class Draw {
}
else
{
}
else
{
drawOneLineText
()
drawOneLineText
()
}
}
}
else
{
}
else
drawOneLineText
()
drawOneLineText
()
}
this
[
_ctx_
].
stroke
()
this
[
_ctx_
].
stroke
()
}
}
drawLine
(
lineParams
,
callback
)
{
drawLine
(
lineParams
,
callback
)
{
...
@@ -391,10 +386,33 @@ class Draw {
...
@@ -391,10 +386,33 @@ class Draw {
})
})
}
}
base64src
(
url
).
then
(
img
=>
{
base64src
(
url
).
then
(
img
=>
{
console
.
log
(
'img'
,
img
)
createLocalImg
(
img
,
callBack
)
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
=>
{
const
checkTextDecoration
=
textDecoration
=>
{
return
textDecoration
&&
(
textDecoration
===
'underline'
||
textDecoration
===
'overline'
||
textDecoration
===
'line-through'
)
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