|
|
@@ -8,17 +8,18 @@ Page({ |
|
|
|
data: { |
|
|
|
imgUrl: app.globalData.urlStatic,//图片路径 |
|
|
|
canvasContron:null,//canvas |
|
|
|
posterBg:[],//海报背景 |
|
|
|
posterBg:[false,false,false],//海报背景 |
|
|
|
qrCodeUrl:"",//二维码图片 |
|
|
|
userHead: app.globalData.userInfoData ? app.globalData.userInfoData.avatarUrl : null,//用户头像 |
|
|
|
rankNum: '0000',//缓存数字 |
|
|
|
windowScale:0,//屏幕缩放比 |
|
|
|
windowW: 0,//屏幕宽度 |
|
|
|
windowH: 0,//屏幕高度 |
|
|
|
posterUrl:[],//海报图片 |
|
|
|
posterUrl:[false,false,false],//海报图片 |
|
|
|
canvasShow: true,//是否渲染canvas |
|
|
|
swiperCurrent: 0,//swiper选中的元素下标 |
|
|
|
userInfoData: app.globalData.userInfoData |
|
|
|
userInfoData: app.globalData.userInfoData, |
|
|
|
posterState:false,//海报是否合成完毕 |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
@@ -45,19 +46,18 @@ Page({ |
|
|
|
this.data.windowScale = option.windowWidth / 750; |
|
|
|
this.data.windowW = option.windowWidth; |
|
|
|
this.data.windowH = option.windowHeight; |
|
|
|
var countNum = 0; |
|
|
|
wx.getImageInfo({//缓存海报背景 |
|
|
|
src: this.data.imgUrl + '/images/tempImg1.jpg?v=006', |
|
|
|
success: res => { |
|
|
|
this.data.posterBg.push(res.path); |
|
|
|
countNum += 1; |
|
|
|
} |
|
|
|
}) |
|
|
|
for (let i = 0; i < 3; i++) { |
|
|
|
wx.getImageInfo({//缓存海报背景 |
|
|
|
src: this.data.imgUrl + '/images/tempImg'+(i+1)+'.jpg?v=006', |
|
|
|
success: res => { |
|
|
|
this.data.posterBg[i] = res.path; |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
wx.getImageInfo({//缓存二维码 |
|
|
|
src: this.data.qrCodeUrl, |
|
|
|
success: res => { |
|
|
|
this.data.qrCodeUrl = res.path; |
|
|
|
countNum += 1; |
|
|
|
} |
|
|
|
}) |
|
|
|
if (this.data.userHead) { |
|
|
@@ -65,7 +65,6 @@ Page({ |
|
|
|
src: this.data.userHead, |
|
|
|
success: res => { |
|
|
|
this.data.userHead = res.path; |
|
|
|
countNum += 1; |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
@@ -73,7 +72,6 @@ Page({ |
|
|
|
src: this.data.imgUrl + '/images/posterNum.png?v=004', |
|
|
|
success: res => { |
|
|
|
this.data.numBg = res.path; |
|
|
|
countNum += 1; |
|
|
|
} |
|
|
|
}) |
|
|
|
for (let i = 0; i < this.data.rankNum.length; i++) { |
|
|
@@ -81,16 +79,9 @@ Page({ |
|
|
|
src: this.data.imgUrl + '/images/nums/' + this.data.rankNum[i] + '.png', |
|
|
|
success: res => { |
|
|
|
this.data.rankNum[i] = res.path; |
|
|
|
countNum += 1; |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
let setInt = setInterval(() => { |
|
|
|
if (countNum >= 8) { |
|
|
|
this.posterDrawing(1); |
|
|
|
clearInterval(setInt); |
|
|
|
} |
|
|
|
}, 500); |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
@@ -139,7 +130,20 @@ Page({ |
|
|
|
path: "/pages/coupon/coupon?friendOpenid=" + app.globalData.openid |
|
|
|
} |
|
|
|
}, |
|
|
|
saveImg:function(){//保存到手机 |
|
|
|
saveImg: function () {//保存到手机 |
|
|
|
console.log(this.data.posterUrl); |
|
|
|
if (!this.data.posterUrl[this.data.swiperCurrent]){ |
|
|
|
wx.showLoading({ |
|
|
|
title: '海报合成中', |
|
|
|
mask:true |
|
|
|
}) |
|
|
|
this.posterDrawing(this.data.swiperCurrent + 1); |
|
|
|
}else{ |
|
|
|
this.savePic(); |
|
|
|
} |
|
|
|
}, |
|
|
|
savePic: function () { |
|
|
|
wx.hideLoading(); |
|
|
|
wx.saveImageToPhotosAlbum({ |
|
|
|
filePath: this.data.posterUrl[this.data.swiperCurrent], |
|
|
|
success(res) { |
|
|
@@ -147,13 +151,13 @@ Page({ |
|
|
|
title: '保存成功' |
|
|
|
}) |
|
|
|
}, |
|
|
|
fail:res=>{ |
|
|
|
fail: res => { |
|
|
|
wx.getSetting({ |
|
|
|
success: res => { |
|
|
|
if (res.authSetting['scope.writePhotosAlbum']) { |
|
|
|
wx.showToast({ |
|
|
|
title: '保存失败', |
|
|
|
icon:"none" |
|
|
|
icon: "none" |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.showModal({ |
|
|
@@ -162,7 +166,7 @@ Page({ |
|
|
|
success: (opt) => { |
|
|
|
if (opt.confirm) { |
|
|
|
wx.openSetting({ |
|
|
|
success:e=>{ |
|
|
|
success: e => { |
|
|
|
if (e.authSetting['scope.writePhotosAlbum']) { |
|
|
|
wx.saveImageToPhotosAlbum({ |
|
|
|
filePath: this.data.posterUrl[this.data.swiperCurrent], |
|
|
@@ -220,29 +224,13 @@ Page({ |
|
|
|
ctx.drawImage(this.data.qrCodeUrl, scale * 476, scale * 1134, scale * 176, scale * 176); |
|
|
|
//绘制 |
|
|
|
ctx.draw(false, setTimeout(() => { |
|
|
|
console.log(); |
|
|
|
wx.canvasToTempFilePath({ |
|
|
|
width:scale*750, |
|
|
|
height: scale * 1380, |
|
|
|
canvasId: 'myCanvas', |
|
|
|
success: res => { |
|
|
|
this.data.posterUrl.push(res.tempFilePath); |
|
|
|
this.setData({ |
|
|
|
posterUrl: this.data.posterUrl |
|
|
|
}) |
|
|
|
if (e < 3) { |
|
|
|
wx.getImageInfo({ |
|
|
|
src: this.data.imgUrl + '/images/tempImg'+(e+1)+'.jpg?v=006', |
|
|
|
success: res => { |
|
|
|
this.data.posterBg.push(res.path); |
|
|
|
this.posterDrawing(e + 1); |
|
|
|
} |
|
|
|
}) |
|
|
|
}else{ |
|
|
|
this.setData({ |
|
|
|
canvasShow:false |
|
|
|
}) |
|
|
|
} |
|
|
|
this.data.posterUrl[this.data.swiperCurrent] = res.tempFilePath; |
|
|
|
this.savePic(); |
|
|
|
} |
|
|
|
}) |
|
|
|
}, 300)); |
|
|
@@ -291,7 +279,6 @@ Page({ |
|
|
|
}else{ |
|
|
|
this.data.rankNum = "0000".split(""); |
|
|
|
} |
|
|
|
console.log(this.data.rankNum); |
|
|
|
this.setData({ |
|
|
|
rankNum: this.data.rankNum |
|
|
|
}) |