Commit 61423087 by 张立顺

海报部分机型缓存问题

1 parent deb73f35
......@@ -25,14 +25,19 @@ Component({
*/
methods: {
getImageInfo(n, width, height) {
wx.$api.showLoading('战报生成中')
let that = this
wx.getImageInfo({
src: n.posterUrl,
src: `${n.posterUrl}?v=${Date.now()}`,
success: function (res) {
console.log(res)
// w = res.width
// h = res.height
that.init(n, res.width, res.height)
},
fail: function (res) {
console.log(res);
wx.$api.showToast('生成失败')
}
})
},
......@@ -40,8 +45,6 @@ Component({
let proportion = ImgWidth / 247
let actualHeight = ImgHeight / proportion
console.log(actualHeight)
wx.$api.showLoading()
const drawfun = new Draw(
{
width: 279,
......
......@@ -113,6 +113,7 @@
</block>
</swiper>
<navigator
class="navOhterApp"
target="miniProgram"
open-type="navigate"
......
......@@ -34,14 +34,7 @@ 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)
......@@ -82,13 +75,7 @@ class Draw {
if (fontSize) this[_ctx_].font = `${fontSize}px${font}`
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)
......@@ -101,25 +88,8 @@ 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
......@@ -222,29 +192,20 @@ class Draw {
drawOneLineText()
}
} else drawOneLineText()
if (textParams.border) this.drawBorder({
text,
x: textParams.x,
y: textParams.y,
fontSize: textParams.fontSize || 12,
...textParams.border
})
if (textParams.border)
this.drawBorder({
text,
x: textParams.x,
y: textParams.y,
fontSize: textParams.fontSize || 12,
...textParams.border
})
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])
......@@ -255,7 +216,8 @@ 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
......@@ -276,33 +238,35 @@ class Draw {
height: endY
}
]
console.log(this.toRpx(y) , paddingY)
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) {
radius = this.toRpx(radius)
let arcArr = [{
let arcArr = [
{
moveTo: [startX, startY + radius],
arcTo: [startX, startY, startX + radius, startY],
}, {
arcTo: [startX, startY, startX + radius, startY]
},
{
moveTo: [endX - radius, startY],
arcTo: [endX, startY, endX, startY + radius],
arcTo: [endX, startY, endX, startY + radius]
},
{
moveTo: [startX, endY - radius],
arcTo: [startX, endY, startX + radius, endY],
arcTo: [startX, endY, startX + radius, endY]
},
{
moveTo: [endX, endY - radius],
arcTo: [endX, endY, endX - radius, endY],
arcTo: [endX, endY, endX - radius, endY]
}
]
arr.map((e,index) =>{
if(index == 0 || index == 2) {
arr.map((e, index) => {
if (index == 0 || index == 2) {
e.x += radius
e.width -= radius
} else{
} else {
e.y += radius
e.height -= radius
}
......@@ -326,16 +290,7 @@ 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)
......@@ -354,12 +309,7 @@ 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,
......@@ -382,11 +332,7 @@ class Draw {
}
return type[textDecoration][textBaseline]
}
setLineX({
textAlign,
text,
x
}) {
setLineX({ textAlign, text, x }) {
let textWidth = this.getTextWidth(text)
let type = {
left: x,
......@@ -395,13 +341,7 @@ 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()
......@@ -412,12 +352,7 @@ 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,
......@@ -427,12 +362,7 @@ 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)
......@@ -447,7 +377,7 @@ class Draw {
return new Promise((resolve, reject) => {
const [a, 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.${format}`
const filePath = `${wx.env.USER_DATA_PATH}/tmp_base64src${Date.now()}.${format}`
const buffer = wx.base64ToArrayBuffer(bodyData)
wx.getFileSystemManager().writeFile({
filePath,
......@@ -469,12 +399,16 @@ class Draw {
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)
})
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))
})
......@@ -512,4 +446,4 @@ const createLocalImg = (url, callBack) => {
}
})
}
export default Draw
\ No newline at end of file
export default Draw
......@@ -69,8 +69,8 @@ const domain = {
/**登录: 192.168.2.3:8315
商城: 192.168.2.3:8558 */
dev: 'https://scrm.dev.glsx.com.cn',
// uat: 'https://scrm.test.glsx.com.cn',
uat: 'https://scrm.beta.glsx.com.cn',
uat: 'https://scrm.test.glsx.com.cn',
// uat: 'https://scrm.beta.glsx.com.cn',
prod: 'https://scrm.cgacar.com'
}[target[index]]
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!