|
|
|
|
|
|
|
|
windowScale:0,//屏幕缩放比 |
|
|
windowScale:0,//屏幕缩放比 |
|
|
windowW: 0,//屏幕宽度 |
|
|
windowW: 0,//屏幕宽度 |
|
|
windowH: 0,//屏幕高度 |
|
|
windowH: 0,//屏幕高度 |
|
|
posterUrl:null,//海报图片 |
|
|
|
|
|
|
|
|
posterUrl:[],//海报图片 |
|
|
|
|
|
canvasShow: true,//是否渲染canvas |
|
|
|
|
|
swiperCurrent: 0,//swiper选中的元素下标 |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
|
|
|
this.data.windowScale = res.windowWidth / 750; |
|
|
this.data.windowScale = res.windowWidth / 750; |
|
|
this.data.windowW = res.windowWidth; |
|
|
this.data.windowW = res.windowWidth; |
|
|
this.data.windowH = res.windowHeight; |
|
|
this.data.windowH = res.windowHeight; |
|
|
this.posterDrawing(); |
|
|
|
|
|
|
|
|
this.posterDrawing(1); |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
saveImg:function(){//保存到手机 |
|
|
saveImg:function(){//保存到手机 |
|
|
wx.chooseImage({ |
|
|
|
|
|
success: function (res) { |
|
|
|
|
|
console.log(res); |
|
|
|
|
|
const tempFilePaths = res.tempFilePaths |
|
|
|
|
|
wx.saveFile({ |
|
|
|
|
|
tempFilePath: tempFilePaths[0], |
|
|
|
|
|
success(res) { |
|
|
|
|
|
console.log(res); |
|
|
|
|
|
const savedFilePath = res.savedFilePath |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
wx.saveFile({ |
|
|
|
|
|
tempFilePath: this.data.posterUrl[this.data.swiperCurrent], |
|
|
|
|
|
success(res) { |
|
|
|
|
|
if (res.errMsg== "saveFile:ok"){ |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '保存成功' |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
posterDrawing: function () {//海报绘制 |
|
|
|
|
|
var ctx = this.data.canvasContron; |
|
|
|
|
|
var scale = this.data.windowScale; |
|
|
|
|
|
console.log(scale); |
|
|
|
|
|
|
|
|
posterDrawing: function (e) {//海报绘制 |
|
|
|
|
|
var ctx = this.data.canvasContron;//canvas对象 |
|
|
|
|
|
var scale = this.data.windowScale;//屏幕缩放比 |
|
|
//背景 |
|
|
//背景 |
|
|
ctx.drawImage(this.data.imgUrl + '/images/tempImg1.jpg', 0, 0, scale * 444, scale * 817);//defaultHead |
|
|
|
|
|
|
|
|
ctx.drawImage(this.data.imgUrl + '/images/tempImg'+e+'.jpg', 0, 0, scale * 444, scale * 817);//defaultHead |
|
|
ctx.setFillStyle("#FFFFFF"); |
|
|
ctx.setFillStyle("#FFFFFF"); |
|
|
ctx.save(); |
|
|
ctx.save(); |
|
|
ctx.beginPath(); //开始绘制 |
|
|
ctx.beginPath(); //开始绘制 |
|
|
|
|
|
|
|
|
ctx.fillText("啦啦啦", scale * 102, scale *572); |
|
|
ctx.fillText("啦啦啦", scale * 102, scale *572); |
|
|
//我是第XXX星探 |
|
|
//我是第XXX星探 |
|
|
ctx.drawImage(this.data.imgUrl + '/images/posterNum.png', scale * 50, scale * 598, scale * 333, scale * 74); |
|
|
ctx.drawImage(this.data.imgUrl + '/images/posterNum.png', scale * 50, scale * 598, scale * 333, scale * 74); |
|
|
|
|
|
//排名数字 |
|
|
|
|
|
ctx.drawImage(this.data.imgUrl + '/images/nums/8.png', scale * 168, scale * 602, scale * 32, scale * 40); |
|
|
|
|
|
ctx.drawImage(this.data.imgUrl + '/images/nums/9.png', scale * 202, scale * 602, scale * 32, scale * 40); |
|
|
|
|
|
ctx.drawImage(this.data.imgUrl + '/images/nums/0.png', scale * 236, scale * 602, scale * 32, scale * 40); |
|
|
|
|
|
ctx.drawImage(this.data.imgUrl + '/images/nums/8.png', scale * 270, scale * 602, scale * 32, scale * 40); |
|
|
//二维码 |
|
|
//二维码 |
|
|
ctx.drawImage(this.data.qrCodeUrl, scale * 282, scale * 672, scale * 105, scale* 106); |
|
|
ctx.drawImage(this.data.qrCodeUrl, scale * 282, scale * 672, scale * 105, scale* 106); |
|
|
//绘制 |
|
|
//绘制 |
|
|
ctx.draw(); |
|
|
|
|
|
|
|
|
ctx.draw(false, setTimeout(() => { |
|
|
|
|
|
wx.canvasToTempFilePath({ |
|
|
|
|
|
canvasId: 'myCanvas', |
|
|
|
|
|
success: res => { |
|
|
|
|
|
this.data.posterUrl.push(res.tempFilePath); |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
posterUrl: this.data.posterUrl |
|
|
|
|
|
}) |
|
|
|
|
|
if (e < 3) { |
|
|
|
|
|
this.posterDrawing(e+1); |
|
|
|
|
|
}else{ |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
canvasShow:false |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}, 300)); |
|
|
}, |
|
|
}, |
|
|
savePoster:function(){//生成海报 |
|
|
|
|
|
wx.canvasToTempFilePath({ |
|
|
|
|
|
width: 443 * this.windowScale, |
|
|
|
|
|
height: 817 * this.windowScale, |
|
|
|
|
|
destWidth: 443 * this.windowScale *this.data.windowW*3, |
|
|
|
|
|
destHeight: 817 * this.windowScale * this.data.windowH*3, |
|
|
|
|
|
canvasId: 'myCanvas', |
|
|
|
|
|
success: res => { |
|
|
|
|
|
wx.previewImage({ |
|
|
|
|
|
urls: [res.tempFilePath] // 需要预览的图片http链接列表 |
|
|
|
|
|
}) |
|
|
|
|
|
// this.data.posterUrl = res.tempFilePath; |
|
|
|
|
|
// console.log(this.data.posterUrl); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
savePoster:function(){//预览海报 |
|
|
|
|
|
wx.previewImage({ |
|
|
|
|
|
current: this.data.posterUrl[this.data.swiperCurrent], |
|
|
|
|
|
urls: this.data.posterUrl // 需要预览的图片http链接列表 |
|
|
}) |
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
prevImg() {//上一张图片 |
|
|
|
|
|
if (this.data.swiperCurrent > 0) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
swiperCurrent: this.data.swiperCurrent -= 1, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
nextImg() {//下一张图片 |
|
|
|
|
|
if (this.data.swiperCurrent < this.data.posterUrl.length - 1) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
swiperCurrent: this.data.swiperCurrent += 1, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
swiperChange(e) {//通过鼠标滑动改变swiper时 |
|
|
|
|
|
if (e.detail.source == "touch") { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
swiperCurrent: e.detail.current, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |