|
|
|
@ -142,7 +142,6 @@ |
|
|
|
backgroundImg: '', |
|
|
|
goodShare: '', |
|
|
|
s_id: '', |
|
|
|
isShowButtonCount: 0, |
|
|
|
userInfo: {} |
|
|
|
} |
|
|
|
}, |
|
|
|
@ -169,12 +168,11 @@ |
|
|
|
}).then(res => { |
|
|
|
let img = res.data.img_url |
|
|
|
if (img) { |
|
|
|
wx.getImageInfo({ |
|
|
|
uni.getImageInfo({ |
|
|
|
src: img, |
|
|
|
success: function(sres) { |
|
|
|
uni.showLoading({title:'生成海报中...'}) |
|
|
|
_this.backgroundImg = sres.path; |
|
|
|
_this.isShowButtonCount++; |
|
|
|
resolve(); // 成功回调 |
|
|
|
} |
|
|
|
}) |
|
|
|
@ -187,7 +185,7 @@ |
|
|
|
let _this = this |
|
|
|
let goods = _this.goods_detail; |
|
|
|
let imageUrl = goods.share_cover || goods.cover; |
|
|
|
wx.getImageInfo({ |
|
|
|
uni.getImageInfo({ |
|
|
|
src: imageUrl, |
|
|
|
success: function(sres) { |
|
|
|
_this.goodShare = sres.path |
|
|
|
@ -255,21 +253,21 @@ |
|
|
|
}) |
|
|
|
}, |
|
|
|
//海报开始 |
|
|
|
//保存头像 |
|
|
|
//保存二维码 |
|
|
|
getwxCodeImg(resolve, reject) { |
|
|
|
var imgSrc = this.wxCode; //base64编码 |
|
|
|
var save = wx.getFileSystemManager(); |
|
|
|
var save = uni.getFileSystemManager(); |
|
|
|
var number = Math.random(); |
|
|
|
uni.showLoading({ |
|
|
|
title: '生成海报中...' |
|
|
|
}) |
|
|
|
var filePath = wx.env.USER_DATA_PATH + '/pic' + number + '.jpg'; |
|
|
|
save.writeFile({ |
|
|
|
filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.jpg', |
|
|
|
filePath: filePath, |
|
|
|
data: imgSrc, |
|
|
|
encoding: 'base64', |
|
|
|
success: res => { |
|
|
|
this.onceCode = wx.env.USER_DATA_PATH + '/pic' + number + '.jpg'; |
|
|
|
this.isShowButtonCount++; |
|
|
|
this.onceCode = filePath; |
|
|
|
resolve(); // 成功回调 |
|
|
|
console.log('二维码临时路径',this.onceCode) |
|
|
|
}, |
|
|
|
@ -281,7 +279,7 @@ |
|
|
|
}, |
|
|
|
createNewImg() { |
|
|
|
var that = this; |
|
|
|
var context = wx.createCanvasContext('mycanvas'); |
|
|
|
var context = uni.createCanvasContext('mycanvas'); |
|
|
|
let goods = that.goods_detail; |
|
|
|
let title = goods.name; |
|
|
|
let price = '¥'+goods.specs[0].selling_price; |
|
|
|
@ -332,6 +330,7 @@ |
|
|
|
context.draw(); |
|
|
|
//将生成好的图片保存到本地,需要延迟一会,绘制期间耗时 |
|
|
|
setTimeout(function() { |
|
|
|
|
|
|
|
wx.canvasToTempFilePath({ |
|
|
|
canvasId: 'mycanvas', |
|
|
|
success: function(res) { |
|
|
|
@ -341,6 +340,7 @@ |
|
|
|
that.maskHidden = true |
|
|
|
} |
|
|
|
uni.hideLoading() |
|
|
|
|
|
|
|
console.log('海报生成成功') |
|
|
|
console.log(res) |
|
|
|
console.log('图片链接', that.imagePath) |
|
|
|
@ -353,10 +353,10 @@ |
|
|
|
}, |
|
|
|
saveBill() { |
|
|
|
var that = this |
|
|
|
wx.saveImageToPhotosAlbum({ |
|
|
|
uni.saveImageToPhotosAlbum({ |
|
|
|
filePath: that.imagePath, |
|
|
|
success(res) { |
|
|
|
wx.showModal({ |
|
|
|
uni.showModal({ |
|
|
|
content: '图片已保存到相册,赶紧晒一下吧~', |
|
|
|
showCancel: false, |
|
|
|
confirmText: '好的', |
|
|
|
@ -378,7 +378,7 @@ |
|
|
|
var that = this; |
|
|
|
uni.showLoading({ |
|
|
|
title: '生成海报中...' |
|
|
|
}) |
|
|
|
}); |
|
|
|
if(that.backgroundImg && that.onceCode){ |
|
|
|
that.createNewImg(); |
|
|
|
}else { |
|
|
|
|