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 d242bd32
authored
Dec 01, 2022
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
冲突解决
1 parent
a04de189
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
96 deletions
utils/Draw.js
utils/Draw.js
View file @
d242bd3
...
@@ -38,14 +38,7 @@ class Draw {
...
@@ -38,14 +38,7 @@ class Draw {
async
drawImages
(
imageParams
,
callback
)
{
async
drawImages
(
imageParams
,
callback
)
{
this
[
_ctx_
].
beginPath
()
this
[
_ctx_
].
beginPath
()
this
[
_ctx_
].
save
()
this
[
_ctx_
].
save
()
let
{
let
{
borderRadius
,
height
,
width
,
url
,
x
,
y
}
=
imageParams
borderRadius
,
height
,
width
,
url
,
x
,
y
}
=
imageParams
height
=
this
.
toRpx
(
height
)
height
=
this
.
toRpx
(
height
)
width
=
this
.
toRpx
(
width
)
width
=
this
.
toRpx
(
width
)
x
=
this
.
toRpx
(
x
)
x
=
this
.
toRpx
(
x
)
...
@@ -87,13 +80,7 @@ class Draw {
...
@@ -87,13 +80,7 @@ class Draw {
return
this
[
_ctx_
].
measureText
(
text
).
width
return
this
[
_ctx_
].
measureText
(
text
).
width
}
}
// 画块形状
// 画块形状
drawFill
({
drawFill
({
x
,
y
,
width
,
height
,
color
})
{
x
,
y
,
width
,
height
,
color
})
{
height
=
this
.
toRpx
(
height
)
height
=
this
.
toRpx
(
height
)
width
=
this
.
toRpx
(
width
)
width
=
this
.
toRpx
(
width
)
x
=
this
.
toRpx
(
x
)
x
=
this
.
toRpx
(
x
)
...
@@ -106,25 +93,8 @@ class Draw {
...
@@ -106,25 +93,8 @@ class Draw {
this
[
_ctx_
].
save
()
this
[
_ctx_
].
save
()
}
}
drawText
(
textParams
)
{
drawText
(
textParams
)
{
let
{
let
{
textDecoration
,
textBaseline
,
lineHeight
,
fontWeight
,
textAlign
,
textWidth
,
maxWidth
,
fontSize
,
lastFont
,
opacity
,
lineNum
,
width
,
color
,
text
,
x
,
y
}
=
textParams
,
textDecoration
,
font
=
this
[
_ctx_
].
font
.
split
(
'px'
)[
1
]
textBaseline
,
lineHeight
,
fontWeight
,
textAlign
,
textWidth
,
maxWidth
,
fontSize
,
lastFont
,
opacity
,
lineNum
,
width
,
color
,
text
,
x
,
y
}
=
textParams
,
font
=
this
[
_ctx_
].
font
.
split
(
'px'
)[
1
]
textAlign
=
textAlign
||
'left'
textAlign
=
textAlign
||
'left'
textBaseline
=
textBaseline
||
'normal'
textBaseline
=
textBaseline
||
'normal'
opacity
=
typeof
opacity
===
'number'
?
opacity
:
1
opacity
=
typeof
opacity
===
'number'
?
opacity
:
1
...
@@ -237,18 +207,8 @@ class Draw {
...
@@ -237,18 +207,8 @@ class Draw {
this
[
_ctx_
].
stroke
()
this
[
_ctx_
].
stroke
()
}
}
drawBorder
(
params
)
{
drawBorder
(
params
)
{
let
{
let
{
x
,
y
,
text
,
color
,
width
,
radius
,
opacity
,
padding
,
fontSize
}
=
params
,
x
,
paddingX
=
0
,
y
,
text
,
color
,
width
,
radius
,
opacity
,
padding
,
fontSize
}
=
params
,
paddingX
=
0
,
paddingY
=
0
paddingY
=
0
if
(
padding
&&
padding
.
length
)
{
if
(
padding
&&
padding
.
length
)
{
paddingX
=
this
.
toRpx
(
padding
[
0
])
paddingX
=
this
.
toRpx
(
padding
[
0
])
...
@@ -259,7 +219,8 @@ class Draw {
...
@@ -259,7 +219,8 @@ class Draw {
endX
=
this
.
toRpx
(
x
)
+
this
.
getTextWidth
(
text
)
+
paddingX
,
endX
=
this
.
toRpx
(
x
)
+
this
.
getTextWidth
(
text
)
+
paddingX
,
startY
=
this
.
toRpx
(
y
)
-
paddingY
,
startY
=
this
.
toRpx
(
y
)
-
paddingY
,
endY
=
this
.
toRpx
(
y
+
fontSize
)
+
paddingY
/
2
,
endY
=
this
.
toRpx
(
y
+
fontSize
)
+
paddingY
/
2
,
arr
=
[{
arr
=
[
{
x
:
startX
,
x
:
startX
,
y
:
startY
,
y
:
startY
,
width
:
endX
width
:
endX
...
@@ -286,7 +247,8 @@ class Draw {
...
@@ -286,7 +247,8 @@ class Draw {
this
[
_ctx_
].
lineWidth
=
width
||
this
.
toRpx
(
1
)
this
[
_ctx_
].
lineWidth
=
width
||
this
.
toRpx
(
1
)
if
(
radius
)
{
if
(
radius
)
{
radius
=
this
.
toRpx
(
radius
)
radius
=
this
.
toRpx
(
radius
)
let
arcArr
=
[{
let
arcArr
=
[
{
moveTo
:
[
startX
,
startY
+
radius
],
moveTo
:
[
startX
,
startY
+
radius
],
arcTo
:
[
startX
,
startY
,
startX
+
radius
,
startY
]
arcTo
:
[
startX
,
startY
,
startX
+
radius
,
startY
]
},
},
...
@@ -331,16 +293,7 @@ class Draw {
...
@@ -331,16 +293,7 @@ class Draw {
}
}
drawLine
(
lineParams
,
callback
)
{
drawLine
(
lineParams
,
callback
)
{
this
[
_ctx_
].
beginPath
()
this
[
_ctx_
].
beginPath
()
let
{
let
{
noTransition
,
opacity
,
startX
,
startY
,
width
,
color
,
endX
,
endY
}
=
lineParams
noTransition
,
opacity
,
startX
,
startY
,
width
,
color
,
endX
,
endY
}
=
lineParams
if
(
!
noTransition
)
{
if
(
!
noTransition
)
{
startX
=
this
.
toRpx
(
startX
)
startX
=
this
.
toRpx
(
startX
)
startY
=
this
.
toRpx
(
startY
)
startY
=
this
.
toRpx
(
startY
)
...
@@ -359,12 +312,7 @@ class Draw {
...
@@ -359,12 +312,7 @@ class Draw {
if
(
callback
)
callback
()
if
(
callback
)
callback
()
}
}
setLineY
=
params
=>
{
setLineY
=
params
=>
{
let
{
let
{
textDecoration
,
textBaseline
,
fontSize
,
y
}
=
params
textDecoration
,
textBaseline
,
fontSize
,
y
}
=
params
let
type
=
{
let
type
=
{
underline
:
{
underline
:
{
top
:
y
+
fontSize
,
top
:
y
+
fontSize
,
...
@@ -387,11 +335,7 @@ class Draw {
...
@@ -387,11 +335,7 @@ class Draw {
}
}
return
type
[
textDecoration
][
textBaseline
]
return
type
[
textDecoration
][
textBaseline
]
}
}
setLineX
({
setLineX
({
textAlign
,
text
,
x
})
{
textAlign
,
text
,
x
})
{
let
textWidth
=
this
.
getTextWidth
(
text
)
let
textWidth
=
this
.
getTextWidth
(
text
)
let
type
=
{
let
type
=
{
left
:
x
,
left
:
x
,
...
@@ -400,13 +344,7 @@ class Draw {
...
@@ -400,13 +344,7 @@ class Draw {
}
}
return
type
[
textAlign
]
return
type
[
textAlign
]
}
}
drawRadiusRect
({
drawRadiusRect
({
borderRadius
,
height
,
width
,
x
,
y
},
callBack
)
{
borderRadius
,
height
,
width
,
x
,
y
},
callBack
)
{
let
radius
=
typeof
borderRadius
===
'string'
?
((
Number
(
borderRadius
.
split
(
'%'
)[
0
])
/
100
)
*
width
)
/
2
:
borderRadius
/
2
let
radius
=
typeof
borderRadius
===
'string'
?
((
Number
(
borderRadius
.
split
(
'%'
)[
0
])
/
100
)
*
width
)
/
2
:
borderRadius
/
2
radius
=
radius
||
0
radius
=
radius
||
0
this
[
_ctx_
].
beginPath
()
this
[
_ctx_
].
beginPath
()
...
@@ -417,12 +355,7 @@ class Draw {
...
@@ -417,12 +355,7 @@ class Draw {
}
}
if
(
callBack
)
callBack
()
if
(
callBack
)
callBack
()
}
}
getFontWidth
({
getFontWidth
({
textAlign
,
fontSize
,
text
,
x
})
{
textAlign
,
fontSize
,
text
,
x
})
{
let
type
=
{
let
type
=
{
left
:
x
,
left
:
x
,
center
:
x
-
(
fontSize
*
text
.
length
)
/
2
,
center
:
x
-
(
fontSize
*
text
.
length
)
/
2
,
...
@@ -432,12 +365,7 @@ class Draw {
...
@@ -432,12 +365,7 @@ class Draw {
}
}
drawDecoration
(
params
)
{
drawDecoration
(
params
)
{
let
{
let
{
newText
,
opacity
,
y
,
x
}
=
params
newText
,
opacity
,
y
,
x
}
=
params
let
lineX
=
x
let
lineX
=
x
let
lineY
=
y
let
lineY
=
y
lineX
=
this
.
setLineX
(
params
)
lineX
=
this
.
setLineX
(
params
)
...
@@ -509,14 +437,7 @@ const checkTextDecoration = textDecoration => {
...
@@ -509,14 +437,7 @@ const checkTextDecoration = textDecoration => {
}
}
/**网络图片转成本地资源 */
/**网络图片转成本地资源 */
<<<<<<<
HEAD
const
createLocalImg
=
({
filePath
,
fileId
},
callBack
)
=>
{
=======
const
createLocalImg
=
({
filePath
,
fileId
},
callBack
)
=>
{
const
createLocalImg
=
({
filePath
,
fileId
},
callBack
)
=>
{
>>>>>>>
dev_v3
.
1
wx
.
getImageInfo
({
wx
.
getImageInfo
({
src
:
filePath
,
src
:
filePath
,
success
(
res
)
{
success
(
res
)
{
...
@@ -535,4 +456,4 @@ const createLocalImg = ({ filePath, fileId }, callBack) => {
...
@@ -535,4 +456,4 @@ const createLocalImg = ({ filePath, fileId }, callBack) => {
}
}
})
})
}
}
export
default
Draw
\ No newline at end of file
\ No newline at end of file
export
default
Draw
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