|
|
@ -172,6 +172,7 @@ |
|
|
wx.getImageInfo({ |
|
|
wx.getImageInfo({ |
|
|
src: img, |
|
|
src: img, |
|
|
success: function(sres) { |
|
|
success: function(sres) { |
|
|
|
|
|
uni.showLoading({title:'生成海报中...'}) |
|
|
_this.backgroundImg = sres.path; |
|
|
_this.backgroundImg = sres.path; |
|
|
_this.isShowButtonCount++; |
|
|
_this.isShowButtonCount++; |
|
|
resolve(); // 成功回调 |
|
|
resolve(); // 成功回调 |
|
|
@ -224,6 +225,9 @@ |
|
|
}, |
|
|
}, |
|
|
getWxCode() { |
|
|
getWxCode() { |
|
|
let that = this; |
|
|
let that = this; |
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
title: '生成海报中...' |
|
|
|
|
|
}) |
|
|
return new Promise((resolve, reject) => { |
|
|
return new Promise((resolve, reject) => { |
|
|
const token = that.$shared.createToken({ |
|
|
const token = that.$shared.createToken({ |
|
|
user_id: that.userInfo.id, |
|
|
user_id: that.userInfo.id, |
|
|
@ -256,6 +260,9 @@ |
|
|
var imgSrc = this.wxCode; //base64编码 |
|
|
var imgSrc = this.wxCode; //base64编码 |
|
|
var save = wx.getFileSystemManager(); |
|
|
var save = wx.getFileSystemManager(); |
|
|
var number = Math.random(); |
|
|
var number = Math.random(); |
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
title: '生成海报中...' |
|
|
|
|
|
}) |
|
|
save.writeFile({ |
|
|
save.writeFile({ |
|
|
filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.jpg', |
|
|
filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.jpg', |
|
|
data: imgSrc, |
|
|
data: imgSrc, |
|
|
@ -325,7 +332,6 @@ |
|
|
context.draw(); |
|
|
context.draw(); |
|
|
//将生成好的图片保存到本地,需要延迟一会,绘制期间耗时 |
|
|
//将生成好的图片保存到本地,需要延迟一会,绘制期间耗时 |
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
uni.hideLoading(); // 关闭loading |
|
|
|
|
|
wx.canvasToTempFilePath({ |
|
|
wx.canvasToTempFilePath({ |
|
|
canvasId: 'mycanvas', |
|
|
canvasId: 'mycanvas', |
|
|
success: function(res) { |
|
|
success: function(res) { |
|
|
@ -334,7 +340,7 @@ |
|
|
that.canvasHidden = true |
|
|
that.canvasHidden = true |
|
|
that.maskHidden = true |
|
|
that.maskHidden = true |
|
|
} |
|
|
} |
|
|
wx.hideToast() |
|
|
|
|
|
|
|
|
uni.hideLoading() |
|
|
console.log('海报生成成功') |
|
|
console.log('海报生成成功') |
|
|
console.log(res) |
|
|
console.log(res) |
|
|
console.log('图片链接', that.imagePath) |
|
|
console.log('图片链接', that.imagePath) |
|
|
@ -370,16 +376,19 @@ |
|
|
}, |
|
|
}, |
|
|
formSubmit() { |
|
|
formSubmit() { |
|
|
var that = this; |
|
|
var that = this; |
|
|
wx.showToast({ |
|
|
|
|
|
title: '生成海报中...', |
|
|
|
|
|
icon: 'loading', |
|
|
|
|
|
duration: 100000 |
|
|
|
|
|
}); |
|
|
|
|
|
Promise.all([that.getWxCode(), that.getBackground()]).then(res => { |
|
|
|
|
|
that.createNewImg(); |
|
|
|
|
|
}).catch(err => { |
|
|
|
|
|
this.$msg('生成失败,请稍后重试!'); |
|
|
|
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
title: '生成海报中...' |
|
|
}) |
|
|
}) |
|
|
|
|
|
if(that.backgroundImg && that.onceCode){ |
|
|
|
|
|
that.createNewImg(); |
|
|
|
|
|
}else { |
|
|
|
|
|
Promise.all([that.getWxCode(), that.getBackground()]).then(res => { |
|
|
|
|
|
that.createNewImg(); |
|
|
|
|
|
}).catch(err => { |
|
|
|
|
|
this.$msg('生成失败,请稍后重试!'); |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
//海报结束 |
|
|
//海报结束 |
|
|
getGoodsDetail() { |
|
|
getGoodsDetail() { |
|
|
|