Commit 61423087 by 张立顺

海报部分机型缓存问题

1 parent deb73f35
...@@ -25,14 +25,19 @@ Component({ ...@@ -25,14 +25,19 @@ Component({
*/ */
methods: { methods: {
getImageInfo(n, width, height) { getImageInfo(n, width, height) {
wx.$api.showLoading('战报生成中')
let that = this let that = this
wx.getImageInfo({ wx.getImageInfo({
src: n.posterUrl, src: `${n.posterUrl}?v=${Date.now()}`,
success: function (res) { success: function (res) {
console.log(res) console.log(res)
// w = res.width // w = res.width
// h = res.height // h = res.height
that.init(n, res.width, res.height) that.init(n, res.width, res.height)
},
fail: function (res) {
console.log(res);
wx.$api.showToast('生成失败')
} }
}) })
}, },
...@@ -40,8 +45,6 @@ Component({ ...@@ -40,8 +45,6 @@ Component({
let proportion = ImgWidth / 247 let proportion = ImgWidth / 247
let actualHeight = ImgHeight / proportion let actualHeight = ImgHeight / proportion
console.log(actualHeight) console.log(actualHeight)
wx.$api.showLoading()
const drawfun = new Draw( const drawfun = new Draw(
{ {
width: 279, width: 279,
......
...@@ -113,6 +113,7 @@ ...@@ -113,6 +113,7 @@
</block> </block>
</swiper> </swiper>
<navigator <navigator
class="navOhterApp" class="navOhterApp"
target="miniProgram" target="miniProgram"
open-type="navigate" open-type="navigate"
......
...@@ -34,14 +34,7 @@ class Draw { ...@@ -34,14 +34,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)
...@@ -82,13 +75,7 @@ class Draw { ...@@ -82,13 +75,7 @@ class Draw {
if (fontSize) this[_ctx_].font = `${fontSize}px${font}` if (fontSize) this[_ctx_].font = `${fontSize}px${font}`
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)
...@@ -101,24 +88,7 @@ class Draw { ...@@ -101,24 +88,7 @@ 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,
textBaseline,
lineHeight,
fontWeight,
textAlign,
textWidth,
maxWidth,
fontSize,
lastFont,
opacity,
lineNum,
width,
color,
text,
x,
y
} = textParams,
font = this[_ctx_].font.split('px')[1] font = this[_ctx_].font.split('px')[1]
textAlign = textAlign || 'left' textAlign = textAlign || 'left'
textBaseline = textBaseline || 'normal' textBaseline = textBaseline || 'normal'
...@@ -222,7 +192,8 @@ class Draw { ...@@ -222,7 +192,8 @@ class Draw {
drawOneLineText() drawOneLineText()
} }
} else drawOneLineText() } else drawOneLineText()
if (textParams.border) this.drawBorder({ if (textParams.border)
this.drawBorder({
text, text,
x: textParams.x, x: textParams.x,
y: textParams.y, y: textParams.y,
...@@ -233,17 +204,7 @@ class Draw { ...@@ -233,17 +204,7 @@ 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,
y,
text,
color,
width,
radius,
opacity,
padding,
fontSize
} = params,
paddingX = 0, paddingX = 0,
paddingY = 0 paddingY = 0
if (padding && padding.length) { if (padding && padding.length) {
...@@ -255,7 +216,8 @@ class Draw { ...@@ -255,7 +216,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
...@@ -276,33 +238,35 @@ class Draw { ...@@ -276,33 +238,35 @@ class Draw {
height: endY height: endY
} }
] ]
console.log(this.toRpx(y) , paddingY) console.log(this.toRpx(y), paddingY)
this[_ctx_].beginPath() this[_ctx_].beginPath()
this[_ctx_].globalAlpha = typeof opacity === 'number' ? opacity : 1 this[_ctx_].globalAlpha = typeof opacity === 'number' ? opacity : 1
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]
}, { },
{
moveTo: [endX - radius, startY], moveTo: [endX - radius, startY],
arcTo: [endX, startY, endX, startY + radius], arcTo: [endX, startY, endX, startY + radius]
}, },
{ {
moveTo: [startX, endY - radius], moveTo: [startX, endY - radius],
arcTo: [startX, endY, startX + radius, endY], arcTo: [startX, endY, startX + radius, endY]
}, },
{ {
moveTo: [endX, endY - radius], moveTo: [endX, endY - radius],
arcTo: [endX, endY, endX - radius, endY], arcTo: [endX, endY, endX - radius, endY]
} }
] ]
arr.map((e,index) =>{ arr.map((e, index) => {
if(index == 0 || index == 2) { if (index == 0 || index == 2) {
e.x += radius e.x += radius
e.width -= radius e.width -= radius
} else{ } else {
e.y += radius e.y += radius
e.height -= radius e.height -= radius
} }
...@@ -326,16 +290,7 @@ class Draw { ...@@ -326,16 +290,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)
...@@ -354,12 +309,7 @@ class Draw { ...@@ -354,12 +309,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,
...@@ -382,11 +332,7 @@ class Draw { ...@@ -382,11 +332,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,
...@@ -395,13 +341,7 @@ class Draw { ...@@ -395,13 +341,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()
...@@ -412,12 +352,7 @@ class Draw { ...@@ -412,12 +352,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,
...@@ -427,12 +362,7 @@ class Draw { ...@@ -427,12 +362,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)
...@@ -447,7 +377,7 @@ class Draw { ...@@ -447,7 +377,7 @@ class Draw {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const [a, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [] const [a, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || []
if (!format) reject(new Error('ERROR_BASE64SRC_PARSE')) 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) const buffer = wx.base64ToArrayBuffer(bodyData)
wx.getFileSystemManager().writeFile({ wx.getFileSystemManager().writeFile({
filePath, filePath,
...@@ -469,10 +399,14 @@ class Draw { ...@@ -469,10 +399,14 @@ class Draw {
async begin(data = {}) { async begin(data = {}) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const drawFun = () => { const drawFun = () => {
data.textList && data.textList.length && data.textList.map(e => { data.textList &&
data.textList.length &&
data.textList.map(e => {
this.drawText(e) this.drawText(e)
}) })
data.lineList && data.lineList.length && data.lineList.map(e => { data.lineList &&
data.lineList.length &&
data.lineList.map(e => {
this.drawLine(e) this.drawLine(e)
}) })
wx.nextTick(() => { wx.nextTick(() => {
......
...@@ -69,8 +69,8 @@ const domain = { ...@@ -69,8 +69,8 @@ const domain = {
/**登录: 192.168.2.3:8315 /**登录: 192.168.2.3:8315
商城: 192.168.2.3:8558 */ 商城: 192.168.2.3:8558 */
dev: 'https://scrm.dev.glsx.com.cn', dev: 'https://scrm.dev.glsx.com.cn',
// uat: 'https://scrm.test.glsx.com.cn', uat: 'https://scrm.test.glsx.com.cn',
uat: 'https://scrm.beta.glsx.com.cn', // uat: 'https://scrm.beta.glsx.com.cn',
prod: 'https://scrm.cgacar.com' prod: 'https://scrm.cgacar.com'
}[target[index]] }[target[index]]
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!