// pages/share/shareQrcode.js
|
var utils = require("../../utils/util.js");
|
var app = getApp();
|
|
let avatarFilePath,logoFilePath,qrCodeImgFilePath,bgImgFilePath;
|
let imgDownloadObj={
|
// 9:{
|
// isComplete:false
|
// }
|
}
|
let abc = 'd';
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
// setTimeout(() => {
|
// abc = app.globalData.cardUserData.Avatar
|
// }, 6000);
|
wx.showLoading();
|
wx.request({
|
url: utils.getUrl( '/shopping/getMiniAppQrCode.do?userid='+app.globalData.FromUserId),
|
//'/shopping/getMiniAppQrCode.do?userid='+app.globalData.FromUserId
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
this.setData({
|
Qrcode: res.data.imgurl
|
})
|
// this.downloadFile();
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/share.do');
|
}
|
})
|
|
wx.request({
|
url: utils.getUrl('/shopping/getSettingEntity.do'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
if(!utils.requestError(res)){
|
return false;
|
}
|
console.log('设置数据',res)
|
this.setData({
|
logo: res.data.logoUrl||res.data.imageUrl||res.data.iconUrl,
|
name: res.data.name,
|
})
|
// this.downloadIdCardImg();
|
},
|
fail: function(errmsg) {
|
utils.requestFail(errmsg, '/shopping/getSettingEntity.do');
|
}
|
})
|
|
wx.request({
|
url: utils.getUrl('/wx/getCardUserInfo.do?FromUserId=' + app.globalData.FromUserId),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
if(!utils.requestError(res)){
|
return false;
|
}
|
this.setData({
|
cardName: res.data.Name,
|
Company: res.data.CompanyName,
|
})
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/wx/getCardUserInfo.do');
|
}
|
})
|
|
},
|
|
downloadIdCardImg(){
|
console.log(app.globalData.cardUserData)
|
console.log('头像',app.globalData.cardUserData.Avatar)
|
console.log('logo',app.globalData.logoUrl)
|
console.log('二维码',this.data.Qrcode)
|
// console.log('商品',this.data.goodsItem.PhotoPath)
|
avatarFilePath = wx.pro.downloadFile({
|
url: app.globalData.cardUserData.Avatar
|
}).then((res)=>{
|
if (res.statusCode === 200) {
|
console.log('......头像',res.tempFilePath)
|
this.setData({
|
avatarUrl: res.tempFilePath
|
})
|
}
|
})
|
|
logoFilePath = wx.pro.downloadFile({
|
url: this.data.logo
|
}).then((res)=>{
|
if (res.statusCode === 200) {
|
console.log('......logo图',res.tempFilePath)
|
this.setData({
|
logoImg: res.tempFilePath
|
})
|
}
|
})
|
|
},
|
|
downloadFile(){
|
this.downloadIdCardImg();
|
qrCodeImgFilePath = wx.pro.downloadFile({
|
url: this.data.Qrcode
|
}).then((res)=>{
|
if (res.statusCode === 200) {
|
console.log('......二维码',res.tempFilePath)
|
this.setData({
|
qrCodeImg: res.tempFilePath
|
})
|
}
|
})
|
Promise.all([avatarFilePath,logoFilePath,qrCodeImgFilePath]).then((res)=>{
|
imgDownloadObj.isComplete = true;
|
// setTimeout(()=>{
|
|
// },5000)
|
|
})
|
.catch((err)=>{
|
console.log('请检查名片头像、公司logo等图片是否已经配置',err)
|
wx.hideToast()
|
wx.showModal({
|
title:'提示',
|
content:`${err.errMsg}`,
|
showCancel:false,
|
success:(res)=>{
|
// if (res.confirm) {
|
// console.log('用户点击确定')
|
// wx.showLoading()
|
// this.downloadFile()
|
// } else if (res.cancel) {
|
// console.log('用户点击取消')
|
// }
|
|
}
|
})
|
})
|
},
|
|
createCanvas(e){
|
wx.showToast({
|
title: '生成中...',
|
icon: 'loading',
|
mask:true,
|
duration: 10000
|
});
|
if (imgDownloadObj.isComplete) {
|
|
|
this.sendCommand(e);
|
} else {
|
// 下载图片到本地
|
this.downloadFile();
|
utils.watchObj(imgDownloadObj,'isComplete',(val)=>{
|
console.log(JSON.stringify(imgDownloadObj)+'isComplete值变化!!!','新值为'+val)
|
if (imgDownloadObj.isComplete) {
|
this.sendCommand(e);
|
}
|
})
|
}
|
},
|
|
sendCommand(e){
|
wx.hideToast()
|
let posterCreate = this.selectComponent('#posterCreate');
|
posterCreate.formSubmit(e);
|
},
|
|
createNewImg (e) {
|
console.log(e);
|
let posterCreate = this.selectComponent('#posterCreate');
|
// let goodsItem = this.data.goodsItem;
|
let context = e.detail.context;
|
// let childComp = e.detail.childComp;
|
// let context = wx.createCanvasContext('mycanvas');
|
// context.draw();
|
context.clearRect(0, 0, 375, 667);
|
context.setFillStyle("#fff");
|
context.fillRect(0, 0, 375, 667);
|
|
let avatarImg = this.data.avatarUrl;
|
console.log(avatarImg,"avatarImg")
|
// let path2 = "../../imgs/chengzhong.png";
|
let logoImg = this.data.logoImg;
|
let qrCodeImg = this.data.qrCodeImg;
|
|
|
// 绘制背景图
|
// let posterBg = this.data.bgImg;
|
// context.drawImage(posterBg, 0, 0, 375, 667);
|
|
console.log('将生成好的图片保存到本地',avatarImg,logoImg,qrCodeImg)
|
//绘制文字
|
context.beginPath()
|
context.setFontSize(36);
|
context.setFillStyle('#333');
|
context.setTextAlign('center');
|
context.fillText(this.data.cardName, 187.5, 65);
|
context.stroke();
|
|
context.setFontSize(16);
|
context.setFillStyle('#333');
|
context.setTextAlign('center');
|
context.fillText(this.data.Company||'公司名称', 187.5, 100);
|
context.stroke();
|
context.closePath();
|
//绘制名片二维码
|
// context.drawImage(goodsImg, 48, 125, 280, 280);
|
context.drawImage(qrCodeImg, 38, 135, 300, 300);
|
|
|
//绘制公司logo
|
context.drawImage(logoImg, 150, 465, 80, 80);
|
|
//绘制门店名称
|
// context.drawImage(path5, 248, 578, 90, 25);
|
context.setFontSize(18);
|
context.setFillStyle('#333');
|
context.setTextAlign('center');
|
context.fillText(this.data.name,187.5, 565);
|
// context.strokeText("长按识别小程序码 即可查看~",150, 600);
|
context.stroke();
|
|
context.draw();
|
//将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
|
setTimeout(()=> {
|
posterCreate.createPoster();
|
|
// console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
|
}, 300);
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload: function () {
|
imgDownloadObj = {
|
isComplete:false
|
};
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh: function () {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom: function () {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
// onShareAppMessage: function () {
|
|
// }
|
})
|