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 5129117a
authored
Nov 07, 2022
by
李伟康
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
图片增加缓存
1 parent
3cf2b0b1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
208 additions
and
59 deletions
components/CrowdfundPoster/CrowdfundPoster.js
packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.js
packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.wxml
utils/Draw.js
utils/constantData.js
components/CrowdfundPoster/CrowdfundPoster.js
View file @
5129117
...
...
@@ -9,8 +9,13 @@ Component({
item
:
{
type
:
Object
,
observer
(
n
)
{
console
.
log
(
n
,
'================='
)
n
.
posterUrl
&&
this
.
getImageInfo
(
n
)
this
.
check
(
n
).
then
(
res
=>
{
if
(
res
)
this
.
setData
({
poster
:
res
,
show
:
true
})
else
this
.
begin
()
}).
catch
(()
=>
this
.
begin
())
}
}
},
...
...
@@ -24,6 +29,45 @@ Component({
* 组件的方法列表
*/
methods
:
{
begin
()
{
let
{
item
}
=
this
.
data
item
.
posterUrl
&&
this
.
getImageInfo
(
item
)
},
check
(
n
)
{
const
fileList
=
wx
.
$storage
.
get
(
'fileList'
)
||
[],
fn
=
wx
.
getFileSystemManager
()
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
fileList
.
length
)
{
fn
.
readdir
({
dirPath
:
wx
.
env
.
USER_DATA_PATH
,
success
({
files
})
{
console
.
log
(
files
,
'文件列表'
)
if
(
files
.
length
<
21
)
{
let
item
=
fileList
.
find
(
e
=>
e
.
activityId
===
n
.
activityId
)
if
(
item
)
{
const
poster
=
files
.
find
(
s
=>
s
.
includes
(
item
.
fileId
))
wx
.
hideLoading
()
if
(
poster
)
resolve
(
`
${
wx
.
env
.
USER_DATA_PATH
}
/
${
poster
}
`
)
else
reject
()
}
else
reject
()
}
else
{
wx
.
$storage
.
rm
(
'fileList'
)
files
.
map
(
e
=>
{
fn
.
unlink
({
filePath
:
`
${
wx
.
env
.
USER_DATA_PATH
}
/
${
e
}
`
})
})
reject
()
}
}
})
}
else
reject
()
})
},
getImageInfo
(
n
,
width
,
height
)
{
wx
.
$api
.
showLoading
(
'处理中'
)
let
that
=
this
...
...
@@ -46,19 +90,19 @@ Component({
let
actualHeight
=
ImgHeight
/
proportion
console
.
log
(
actualHeight
)
n
.
activityName
=
n
.
activityName
.
length
>
12
?
`
${
n
.
activityName
.
substring
(
0
,
12
)}
...`
:
n
.
activityName
const
drawfun
=
new
Draw
(
{
const
drawfun
=
new
Draw
({
width
:
279
,
// height: 554
height
:
82
+
actualHeight
},
this
),
{
userInfo
}
=
wx
.
$storage
.
get
(),
merchantName
=
userInfo
.
merchantName
.
length
>
12
?
`
${
userInfo
.
merchantName
.
substring
(
0
,
12
)}
...`
:
userInfo
.
merchantName
,
{
userInfo
}
=
wx
.
$storage
.
get
(),
merchantName
=
userInfo
.
merchantName
.
length
>
12
?
`
${
userInfo
.
merchantName
.
substring
(
0
,
12
)}
...`
:
userInfo
.
merchantName
,
res
=
await
drawfun
.
begin
({
imageList
:
[
{
imageList
:
[{
x
:
0
,
y
:
0
,
width
:
279
,
...
...
@@ -73,8 +117,7 @@ Component({
url
:
n
.
posterUrl
}
],
textList
:
[
{
textList
:
[{
x
:
12
,
y
:
14
,
fontSize
:
14
,
...
...
@@ -114,6 +157,13 @@ Component({
poster
:
res
.
path
,
show
:
true
})
let
fileList
=
wx
.
$storage
.
get
(
'fileList'
)
||
[]
fileList
.
push
({
fileId
:
res
.
fileId
,
path
:
res
.
path
,
activityId
:
n
.
activityId
})
wx
.
$storage
.
set
(
'fileList'
,
fileList
)
},
download
()
{
const
filePath
=
this
.
data
.
poster
,
...
...
@@ -142,4 +192,4 @@ Component({
})
}
}
})
})
\ No newline at end of file
packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.js
View file @
5129117
// packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.js
import
wxqrcode
from
'~/utils/lib/wxqrcode'
import
{
IMG_URL
}
from
'~/utils/constantData'
import
{
IMG_URL
}
from
'~/utils/constantData'
import
outputApi
from
'~/api/outputApi/index'
const
IMAGES
=
Object
.
freeze
({
download
:
`
${
IMG_URL
}
/output/download.webp`
...
...
@@ -30,8 +32,7 @@ Component({
IMGURL
:
IMG_URL
,
IMAGES
,
isShowTip
:
true
,
orderFormList
:
[
{
orderFormList
:
[{
label
:
'总场次'
,
name
:
'totalNum'
},
...
...
@@ -45,8 +46,7 @@ Component({
prefix
:
'¥'
}
],
merchantFormList
:
[
{
merchantFormList
:
[{
label
:
'活动时间'
,
name
:
'time'
},
...
...
@@ -66,8 +66,7 @@ Component({
prefix
:
'¥'
}
],
tableHeadList
:
[
{
tableHeadList
:
[{
label
:
''
,
width
:
''
,
width
:
'28rpx'
...
...
@@ -115,7 +114,9 @@ Component({
})
},
handleMore
(
e
)
{
var
{
idx
}
=
e
.
currentTarget
.
dataset
var
{
idx
}
=
e
.
currentTarget
.
dataset
var
list
=
this
.
data
.
orderObj
var
item
=
list
.
activityList
[
idx
]
list
.
activityList
[
idx
].
showStaffList
=
list
.
activityList
[
idx
].
showStaffList
.
concat
(
item
.
staffList
.
length
>
10
?
item
.
staffList
.
slice
(
0
,
10
)
:
item
.
staffList
)
...
...
@@ -125,7 +126,9 @@ Component({
})
},
handleCopy
(
e
)
{
var
{
idx
}
=
e
.
currentTarget
.
dataset
var
{
idx
}
=
e
.
currentTarget
.
dataset
var
currentItem
=
this
.
data
.
orderObj
.
activityList
[
idx
]
var
qr
=
wxqrcode
.
createQrCodeImg
(
currentItem
.
activityUrl
)
const
base64src
=
function
(
base64data
)
{
...
...
@@ -163,16 +166,31 @@ Component({
// const { item } = e.currentTarget.dataset
// wx.$router.jumpH5(item.activityUrl)
},
download
(
e
)
{
const
{
item
}
=
e
.
currentTarget
.
dataset
wx
.
$api
.
showLoading
(
'加载中...'
)
outputApi
.
getPosterUrl
({
id
:
item
.
activityId
}).
then
(
res
=>
{
item
.
posterUrl
=
res
this
.
setData
({
posterItem
:
item
,
isShowTip
:
false
async
download
(
e
)
{
const
{
item
}
=
e
.
currentTarget
.
dataset
,
posterObj
=
this
.
selectComponent
(
'#poster'
)
try
{
let
flag
=
await
posterObj
.
check
(
item
)
posterObj
.
setData
({
poster
:
flag
,
show
:
true
})
})
}
catch
(
error
)
{
wx
.
$api
.
showLoading
(
'加载中...'
)
outputApi
.
getPosterUrl
({
id
:
item
.
activityId
}).
then
(
res
=>
{
item
.
posterUrl
=
res
this
.
setData
({
posterItem
:
item
,
isShowTip
:
false
})
}).
catch
(()
=>
{
wx
.
$api
.
showToast
(
'下载海报失败'
)
})
}
}
}
})
})
\ No newline at end of file
packageOutput/pages/summary/components/outputCrowdfund/outputCrowdfund.wxml
View file @
5129117
...
...
@@ -115,5 +115,5 @@
</view>
</view>
</view>
<crowdfund-poster item="{{posterItem}}" />
<crowdfund-poster item="{{posterItem}}"
id="poster"
/>
utils/Draw.js
View file @
5129117
...
...
@@ -34,7 +34,14 @@ class Draw {
async
drawImages
(
imageParams
,
callback
)
{
this
[
_ctx_
].
beginPath
()
this
[
_ctx_
].
save
()
let
{
borderRadius
,
height
,
width
,
url
,
x
,
y
}
=
imageParams
let
{
borderRadius
,
height
,
width
,
url
,
x
,
y
}
=
imageParams
height
=
this
.
toRpx
(
height
)
width
=
this
.
toRpx
(
width
)
x
=
this
.
toRpx
(
x
)
...
...
@@ -76,7 +83,13 @@ class Draw {
return
this
[
_ctx_
].
measureText
(
text
).
width
}
// 画块形状
drawFill
({
x
,
y
,
width
,
height
,
color
})
{
drawFill
({
x
,
y
,
width
,
height
,
color
})
{
height
=
this
.
toRpx
(
height
)
width
=
this
.
toRpx
(
width
)
x
=
this
.
toRpx
(
x
)
...
...
@@ -89,8 +102,25 @@ class Draw {
this
[
_ctx_
].
save
()
}
drawText
(
textParams
)
{
let
{
textDecoration
,
textBaseline
,
lineHeight
,
fontWeight
,
textAlign
,
textWidth
,
maxWidth
,
fontSize
,
lastFont
,
opacity
,
lineNum
,
width
,
color
,
text
,
x
,
y
}
=
textParams
,
font
=
this
[
_ctx_
].
font
.
split
(
'px'
)[
1
]
let
{
textDecoration
,
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'
textBaseline
=
textBaseline
||
'normal'
opacity
=
typeof
opacity
===
'number'
?
opacity
:
1
...
...
@@ -189,9 +219,7 @@ class Draw {
})
}
})
}
else
{
drawOneLineText
()
}
}
else
drawOneLineText
()
}
else
drawOneLineText
()
if
(
textParams
.
border
)
this
.
drawBorder
({
...
...
@@ -205,8 +233,18 @@ class Draw {
this
[
_ctx_
].
stroke
()
}
drawBorder
(
params
)
{
let
{
x
,
y
,
text
,
color
,
width
,
radius
,
opacity
,
padding
,
fontSize
}
=
params
,
paddingX
=
0
,
let
{
x
,
y
,
text
,
color
,
width
,
radius
,
opacity
,
padding
,
fontSize
}
=
params
,
paddingX
=
0
,
paddingY
=
0
if
(
padding
&&
padding
.
length
)
{
paddingX
=
this
.
toRpx
(
padding
[
0
])
...
...
@@ -217,8 +255,7 @@ class Draw {
endX
=
this
.
toRpx
(
x
)
+
this
.
getTextWidth
(
text
)
+
paddingX
,
startY
=
this
.
toRpx
(
y
)
-
paddingY
,
endY
=
this
.
toRpx
(
y
+
fontSize
)
+
paddingY
/
2
,
arr
=
[
{
arr
=
[{
x
:
startX
,
y
:
startY
,
width
:
endX
...
...
@@ -245,8 +282,7 @@ class Draw {
this
[
_ctx_
].
lineWidth
=
width
||
this
.
toRpx
(
1
)
if
(
radius
)
{
radius
=
this
.
toRpx
(
radius
)
let
arcArr
=
[
{
let
arcArr
=
[{
moveTo
:
[
startX
,
startY
+
radius
],
arcTo
:
[
startX
,
startY
,
startX
+
radius
,
startY
]
},
...
...
@@ -291,7 +327,16 @@ class Draw {
}
drawLine
(
lineParams
,
callback
)
{
this
[
_ctx_
].
beginPath
()
let
{
noTransition
,
opacity
,
startX
,
startY
,
width
,
color
,
endX
,
endY
}
=
lineParams
let
{
noTransition
,
opacity
,
startX
,
startY
,
width
,
color
,
endX
,
endY
}
=
lineParams
if
(
!
noTransition
)
{
startX
=
this
.
toRpx
(
startX
)
startY
=
this
.
toRpx
(
startY
)
...
...
@@ -310,7 +355,12 @@ class Draw {
if
(
callback
)
callback
()
}
setLineY
=
params
=>
{
let
{
textDecoration
,
textBaseline
,
fontSize
,
y
}
=
params
let
{
textDecoration
,
textBaseline
,
fontSize
,
y
}
=
params
let
type
=
{
underline
:
{
top
:
y
+
fontSize
,
...
...
@@ -333,7 +383,11 @@ class Draw {
}
return
type
[
textDecoration
][
textBaseline
]
}
setLineX
({
textAlign
,
text
,
x
})
{
setLineX
({
textAlign
,
text
,
x
})
{
let
textWidth
=
this
.
getTextWidth
(
text
)
let
type
=
{
left
:
x
,
...
...
@@ -342,7 +396,13 @@ class Draw {
}
return
type
[
textAlign
]
}
drawRadiusRect
({
borderRadius
,
height
,
width
,
x
,
y
},
callBack
)
{
drawRadiusRect
({
borderRadius
,
height
,
width
,
x
,
y
},
callBack
)
{
let
radius
=
typeof
borderRadius
===
'string'
?
((
Number
(
borderRadius
.
split
(
'%'
)[
0
])
/
100
)
*
width
)
/
2
:
borderRadius
/
2
radius
=
radius
||
0
this
[
_ctx_
].
beginPath
()
...
...
@@ -353,7 +413,12 @@ class Draw {
}
if
(
callBack
)
callBack
()
}
getFontWidth
({
textAlign
,
fontSize
,
text
,
x
})
{
getFontWidth
({
textAlign
,
fontSize
,
text
,
x
})
{
let
type
=
{
left
:
x
,
center
:
x
-
(
fontSize
*
text
.
length
)
/
2
,
...
...
@@ -363,7 +428,12 @@ class Draw {
}
drawDecoration
(
params
)
{
let
{
newText
,
opacity
,
y
,
x
}
=
params
let
{
newText
,
opacity
,
y
,
x
}
=
params
let
lineX
=
x
let
lineY
=
y
lineX
=
this
.
setLineX
(
params
)
...
...
@@ -376,16 +446,20 @@ class Draw {
let
url
=
this
[
_canvas_
].
toDataURL
(
'image/png'
)
const
base64src
=
function
(
base64data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
[
a
,
format
,
bodyData
]
=
/data:image
\/(\w
+
)
;base64,
(
.*
)
/
.
exec
(
base64data
)
||
[]
const
[,
format
,
bodyData
]
=
/data:image
\/(\w
+
)
;base64,
(
.*
)
/
.
exec
(
base64data
)
||
[]
if
(
!
format
)
reject
(
new
Error
(
'ERROR_BASE64SRC_PARSE'
))
const
filePath
=
`
${
wx
.
env
.
USER_DATA_PATH
}
/tmp_base64src
${
Date
.
now
()}
.
${
format
}
`
const
fileId
=
Date
.
now
()
const
filePath
=
`
${
wx
.
env
.
USER_DATA_PATH
}
/tmp_base64src_
${
fileId
}
.
${
format
}
`
const
buffer
=
wx
.
base64ToArrayBuffer
(
bodyData
)
wx
.
getFileSystemManager
().
writeFile
({
filePath
,
data
:
buffer
,
encoding
:
'binary'
,
success
()
{
resolve
(
filePath
)
resolve
({
filePath
,
fileId
})
},
fail
()
{
reject
(
new
Error
(
'ERROR_BASE64SRC_WRITE'
))
...
...
@@ -431,11 +505,17 @@ const checkTextDecoration = textDecoration => {
}
/**网络图片转成本地资源 */
const
createLocalImg
=
(
url
,
callBack
)
=>
{
const
createLocalImg
=
({
filePath
,
fileId
},
callBack
)
=>
{
wx
.
getImageInfo
({
src
:
url
,
src
:
filePath
,
success
(
res
)
{
callBack
(
res
)
callBack
({
...
res
,
fileId
})
},
fail
()
{
wx
.
showToast
({
...
...
@@ -447,4 +527,4 @@ const createLocalImg = (url, callBack) => {
}
})
}
export
default
Draw
export
default
Draw
\ No newline at end of file
utils/constantData.js
View file @
5129117
...
...
@@ -16,10 +16,11 @@ export const STORAGE_OBJECTkEY = {
firstLogin
:
'firstLogin'
,
authphone
:
'authphone'
,
posterTimer
:
'posterTimer'
,
disLikeRecordFlag
:
'disLikeRecordFlag'
disLikeRecordFlag
:
'disLikeRecordFlag'
,
fileList
:
'fileList'
}
export
const
IMG_VERSION
=
()
=>
{
const
accountInfo
=
wx
.
getAccountInfoSync
()
return
accountInfo
.
miniProgram
.
version
||
'1.0.0'
}
}
\ No newline at end of file
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