Commit e1b64306 by 李伟康

修改画布&生成海报

1 parent cacdcfc2
...@@ -52,7 +52,7 @@ Component({ ...@@ -52,7 +52,7 @@ Component({
/** /**
* 禁止滑动 * 禁止滑动
*/ */
noScroll: wx.$util.noScroll(), noScroll(){},
cancel(e) { cancel(e) {
let { confirm } = e.currentTarget.dataset let { confirm } = e.currentTarget.dataset
let { buttonType, title } = this.data let { buttonType, title } = this.data
......
...@@ -44,13 +44,13 @@ Component({ ...@@ -44,13 +44,13 @@ Component({
height: 66, height: 66,
url: 'https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/output/poster-bg.png' url: 'https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/output/poster-bg.png'
}, },
{ // {
x: 16, // x: 16,
y: 70, // y: 70,
width: 247, // width: 247,
height: 472, // height: 472,
url: n.posterUrl // url: n.posterUrl
} // }
], ],
textList: [{ textList: [{
x: 12, x: 12,
...@@ -71,17 +71,15 @@ Component({ ...@@ -71,17 +71,15 @@ Component({
}, },
{ {
x: 14 + drawfun.getTextWidth(n.activityName, 14) + 9, x: 14 + drawfun.getTextWidth(n.activityName, 14) + 9,
y: 37, y: 39,
fontSize: 10, fontSize: 10,
color: '#4466F0', color: '#4466F0',
text: '众筹', text: '众筹',
textBaseline: 'top',
border: { border: {
width: 1, width: 1,
color: '#4466F0', color: '#8FA5FF',
radius: 2, radius: 2,
padding: [2, 5], padding: [5, 5]
opacity: 0.5
} }
} }
], ],
...@@ -89,22 +87,34 @@ Component({ ...@@ -89,22 +87,34 @@ Component({
console.log(res) console.log(res)
wx.hideLoading() wx.hideLoading()
this.setData({ this.setData({
poster: res.path, poster: res.path
show: true
}) })
}, },
download() { download() {
const filePath = this.data.poster const filePath = this.data.poster,
_this = this
wx.saveImageToPhotosAlbum({ wx.saveImageToPhotosAlbum({
filePath filePath,
}) success(){
wx.$api.showToast('保存成功')
},
fail(err) {
const auth = _this.selectComponent('#auth')
auth.check()
}
}
)
}, },
hide() { hide() {
this.setData({ this.setData({
show: false,
poster: '' poster: ''
}) })
}, },
noScroll() {} noScroll() {},
authFail(e) {
this.setData({
showAuth: true
})
}
} }
}) })
\ No newline at end of file \ No newline at end of file
{ {
"component": true, "component": true,
"usingComponents": {} "usingComponents": {
"authorize":"/components/Authorize/Authorize"
}
} }
\ No newline at end of file \ No newline at end of file
<block wx:if="{{show}}"> <block wx:if="{{poster}}">
<view class="layout" catchtouchmove="noScroll"> <view class="layout" catchtouchmove="noScroll">
<view class="bg" bindtap="hide"></view> <view class="bg" bindtap="hide"></view>
<image src="{{poster}}" class="poster" mode="aspectFit"></image> <image src="{{poster}}" class="poster" mode="aspectFit"></image>
...@@ -8,3 +8,4 @@ ...@@ -8,3 +8,4 @@
</view> </view>
</view> </view>
</block> </block>
<authorize scopeType="writePhotosAlbum" bindfail="authFail" show="{{showAuth}}" id="auth"></authorize>
\ No newline at end of file \ No newline at end of file
...@@ -140,18 +140,10 @@ class Draw { ...@@ -140,18 +140,10 @@ class Draw {
this[_ctx_].globalAlpha = opacity this[_ctx_].globalAlpha = opacity
this[_ctx_].font = `${fontWeight || 400} ${fontSize}px${font}` this[_ctx_].font = `${fontWeight || 400} ${fontSize}px${font}`
this[_ctx_].fillStyle = color || '#000' this[_ctx_].fillStyle = color || '#000'
this[_ctx_].strokeStyle = color || '#000'
this[_ctx_].textBaseline = textBaseline this[_ctx_].textBaseline = textBaseline
this[_ctx_].textAlign = textAlign this[_ctx_].textAlign = textAlign
this[_ctx_].lineWidth = this.toRpx(2) this[_ctx_].lineWidth = this.toRpx(2)
let text_width = this.getTextWidth(text) let text_width = this.getTextWidth(text)
if (textParams.border) this.drawBorder({
text,
x: textParams.x,
y: textParams.y,
fontSize: textParams.fontSize || 12,
...textParams.border
})
const drawOneLineText = () => { const drawOneLineText = () => {
let textArr = text.toString().split(''), let textArr = text.toString().split(''),
newText = '', newText = '',
...@@ -230,6 +222,14 @@ class Draw { ...@@ -230,6 +222,14 @@ class Draw {
drawOneLineText() drawOneLineText()
} }
} else drawOneLineText() } else drawOneLineText()
if (textParams.border) this.drawBorder({
text,
x: textParams.x,
y: textParams.y,
fontSize: textParams.fontSize || 12,
...textParams.border
})
this[_ctx_].stroke() this[_ctx_].stroke()
} }
drawBorder(params) { drawBorder(params) {
...@@ -243,18 +243,91 @@ class Draw { ...@@ -243,18 +243,91 @@ class Draw {
opacity, opacity,
padding, padding,
fontSize fontSize
} = params } = params,
console.log(params) paddingX = 0,
let topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY, paddingX, paddingY paddingY = 0
// if(padding && padding.length>1) if (padding && padding.length) {
paddingX = this.toRpx(padding[0])
paddingY = this.toRpx(padding[0])
if (padding.length > 1) paddingX = this.toRpx(padding[1])
}
let startX = this.toRpx(x) - paddingX,
endX = this.toRpx(x) + this.getTextWidth(text) + paddingX,
startY = this.toRpx(y) - paddingY,
endY = this.toRpx(y + fontSize) + paddingY / 2,
arr = [{
x: startX,
y: startY,
width: endX
},
{
x: endX,
y: startY,
height: endY
},
{
x: startX,
y: endY,
width: endX
},
{
x: startX,
y: startY,
height: endY
}
]
console.log(this.toRpx(y) , paddingY)
this[_ctx_].beginPath()
this[_ctx_].globalAlpha = typeof opacity === 'number' ? opacity : 1
this[_ctx_].lineWidth = width || this.toRpx(1)
if (radius) { if (radius) {
radius = this.toRpx(radius)
let arcArr = [{
moveTo: [startX, startY + radius],
arcTo: [startX, startY, startX + radius, startY],
}, {
moveTo: [endX - radius, startY],
arcTo: [endX, startY, endX, startY + radius],
},
{
moveTo: [startX, endY - radius],
arcTo: [startX, endY, startX + radius, endY],
},
{
moveTo: [endX, endY - radius],
arcTo: [endX, endY, endX - radius, endY],
}
]
arr.map((e,index) =>{
if(index == 0 || index == 2) {
e.x += radius
e.width -= radius
} else{
e.y += radius
e.height -= radius
} }
})
arcArr.map((e, index) => {
this[_ctx_].moveTo(...e.moveTo)
this[_ctx_].arcTo(...e.arcTo, radius)
this[_ctx_].stroke()
this[_ctx_].restore()
this[_ctx_].save()
})
}
arr.map((e, index) => {
this[_ctx_].moveTo(e.x, e.y)
this[_ctx_].lineTo(e.width ? e.width : e.x, e.height ? e.height : e.y)
this[_ctx_].stroke()
this[_ctx_].restore()
this[_ctx_].strokeStyle = color || '#000'
this[_ctx_].save()
})
} }
drawLine(lineParams, callback) { drawLine(lineParams, callback) {
this[_ctx_].beginPath() this[_ctx_].beginPath()
let { let {
noTransition,
opacity, opacity,
startX, startX,
startY, startY,
...@@ -263,18 +336,20 @@ class Draw { ...@@ -263,18 +336,20 @@ class Draw {
endX, endX,
endY endY
} = lineParams } = lineParams
if (!noTransition) {
startX = this.toRpx(startX) startX = this.toRpx(startX)
startY = this.toRpx(startY) startY = this.toRpx(startY)
width = this.toRpx(width) width = this.toRpx(width)
endX = this.toRpx(endX) endX = this.toRpx(endX)
endY = this.toRpx(endY) endY = this.toRpx(endY)
}
this[_ctx_].globalAlpha = typeof opacity === 'number' ? opacity : 1 this[_ctx_].globalAlpha = typeof opacity === 'number' ? opacity : 1
this[_ctx_].strokeStyle = color || '#000'
this[_ctx_].lineWidth = width || this.toRpx(1) this[_ctx_].lineWidth = width || this.toRpx(1)
this[_ctx_].moveTo(startX, startY) this[_ctx_].moveTo(startX, startY)
this[_ctx_].lineTo(endX, endY) this[_ctx_].lineTo(endX, endY)
this[_ctx_].stroke() this[_ctx_].stroke()
this[_ctx_].restore() this[_ctx_].restore()
this[_ctx_].strokeStyle = color || '#000'
this[_ctx_].save() this[_ctx_].save()
if (callback) callback() if (callback) callback()
} }
...@@ -412,7 +487,7 @@ class Draw { ...@@ -412,7 +487,7 @@ class Draw {
if (index == data.imageList.length - 1) drawFun() if (index == data.imageList.length - 1) drawFun()
} }
else drawFun() else drawFun()
} } else drawFun()
}) })
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!