268 lines
8.4 KiB
JavaScript
268 lines
8.4 KiB
JavaScript
/*
|
||
* 手太欠
|
||
* 愿这世界都如故事里一样 美好而动人~
|
||
*/
|
||
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
shareSee : false, //分享弹出
|
||
identity : 1, //1为普通,2为上师版, 3为何院士
|
||
userInfo : '', //用户信息
|
||
inviteText: '', //邀请码
|
||
invite : '' //二维码
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
// 获取推广码
|
||
this.inviteInfo();
|
||
|
||
// 获取小程序码
|
||
this.ShareInfo();
|
||
},
|
||
|
||
/**
|
||
* 推广码
|
||
*/
|
||
inviteInfo() {
|
||
wx.$api.user.invite().then(res => {
|
||
this.setData({
|
||
identity : res.data.user_info.tag,
|
||
userInfo : res.data.user_info,
|
||
inviteText : res.data.invite
|
||
})
|
||
}).catch(err => {})
|
||
},
|
||
|
||
/**
|
||
* 小程序码
|
||
*/
|
||
ShareInfo() {
|
||
wx.$api.user.miniShare({
|
||
url: '/pages/login/index'
|
||
}).then(res => {
|
||
this.setData({
|
||
invite: res.data.qrcode
|
||
})
|
||
}).catch(err => {})
|
||
},
|
||
|
||
/**
|
||
* 分享弹出
|
||
*/
|
||
shareTap() {
|
||
this.setData({
|
||
shareSee: !this.data.shareSee
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 第一种海报样式 保存图片到本地
|
||
*/
|
||
saveImg(){
|
||
this.dowImg();
|
||
this.setData({
|
||
shareSee: false
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 第二种海报样式 保存图片到本地
|
||
*/
|
||
TwoImg(){
|
||
this.TwoSaveImg();
|
||
this.setData({
|
||
shareSee: false
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 第一种海报样式
|
||
*/
|
||
dowImg(){
|
||
wx.showLoading({
|
||
title: '生成中',
|
||
mask : true
|
||
})
|
||
|
||
// 下载背景素材
|
||
let codeImg = new Promise(success => {
|
||
wx.getImageInfo({
|
||
src : this.data.invite,
|
||
success : res => {
|
||
success(res.path)
|
||
}
|
||
})
|
||
})
|
||
|
||
// 下载背景素材
|
||
let backUrl
|
||
if (this.data.identity == 1) {
|
||
backUrl = "https://api.siyuankunlun.com/storage/materials/2022/09/14/code.jpg"
|
||
} else if (this.data.identity == 2) {
|
||
backUrl = "https://api.siyuankunlun.com/storage/materials/2022/09/14/code_01.png"
|
||
}
|
||
|
||
Promise.all([codeImg]).then(res => {
|
||
wx.getImageInfo({
|
||
src : backUrl,
|
||
success : networkImg => {
|
||
// 绘制海报
|
||
const ctx = wx.createCanvasContext('qrcodeCard')
|
||
ctx.save()
|
||
|
||
// 绘制背景
|
||
ctx.drawImage(networkImg.path, 0, 0, 375, 800)
|
||
|
||
// 绘制二维码背景
|
||
ctx.drawImage("/static/imgs/codeshart_back.png", 137, 532, 100, 100)
|
||
|
||
// 绘制二维码
|
||
ctx.drawImage(res[0], 145, 540, 85, 85)
|
||
|
||
// 文字
|
||
ctx.setFontSize(12)
|
||
ctx.setFillStyle("#eadbc8")
|
||
ctx.setTextAlign('center')
|
||
ctx.fillText("扫描二维码了解更多", 188, 650 , 270)
|
||
|
||
// 保存图片
|
||
ctx.draw(true, () => {
|
||
wx.hideLoading()
|
||
wx.canvasToTempFilePath({
|
||
canvasId: 'qrcodeCard',
|
||
x: 0,
|
||
y: 0,
|
||
success: keepRes => {
|
||
wx.saveImageToPhotosAlbum({
|
||
filePath: keepRes.tempFilePath,
|
||
success : ()=>{
|
||
wx.showToast({
|
||
title: '分享海报已保存至相册',
|
||
icon : 'none'
|
||
})
|
||
},
|
||
fail : err=>{
|
||
wx.showModal({
|
||
title : '提示',
|
||
content : '暂未授权小程序写入您的相册,无法存储二维码海报',
|
||
confirmColor: '#d82526',
|
||
confirmText : '去设置',
|
||
success : info=>{
|
||
if (info.confirm){
|
||
wx.openSetting()
|
||
}
|
||
}
|
||
})
|
||
},
|
||
complete: e => {}
|
||
})
|
||
}
|
||
})
|
||
})
|
||
}
|
||
})
|
||
}).catch(err=>{})
|
||
},
|
||
|
||
/**
|
||
* 第二种海报样式
|
||
*/
|
||
TwoSaveImg() {
|
||
wx.showLoading({
|
||
title: '加载中',
|
||
})
|
||
|
||
// 下载背景素材
|
||
let codeImg = new Promise(success => {
|
||
wx.getImageInfo({
|
||
src : this.data.invite,
|
||
success : res => {
|
||
success(res.path)
|
||
}
|
||
})
|
||
})
|
||
|
||
Promise.all([codeImg]).then(res => {
|
||
wx.getImageInfo({
|
||
src: "https://api.siyuankunlun.com/storage/materials/2022/09/14/code_02.png",
|
||
success : networkImg => {
|
||
// 绘制海报
|
||
const ctx = wx.createCanvasContext('qrcodeCard')
|
||
ctx.save()
|
||
|
||
// 绘制背景
|
||
ctx.drawImage(networkImg.path, 0, 0, 375, 800)
|
||
|
||
// 绘制二维码背景
|
||
ctx.drawImage("/static/imgs/codeshart_back_02.png", 60, 550, 246, 94)
|
||
|
||
// 绘制二维码
|
||
ctx.drawImage(res[0], 215, 562, 70, 70)
|
||
|
||
// 绘制标题
|
||
ctx.drawImage("/static/imgs/codeShart_title1.png", 80, 570, 120, 56)
|
||
|
||
// 保存图片
|
||
ctx.draw(true, () => {
|
||
wx.hideLoading()
|
||
wx.canvasToTempFilePath({
|
||
canvasId: 'qrcodeCard',
|
||
x: 0,
|
||
y: 0,
|
||
success: keepRes => {
|
||
wx.saveImageToPhotosAlbum({
|
||
filePath: keepRes.tempFilePath,
|
||
success : ()=>{
|
||
wx.showToast({
|
||
title: '分享海报已保存至相册',
|
||
icon : 'none'
|
||
})
|
||
},
|
||
fail : err=>{
|
||
wx.showModal({
|
||
title : '提示',
|
||
content : '暂未授权小程序写入您的相册,无法存储二维码海报',
|
||
confirmColor: '#d82526',
|
||
confirmText : '去设置',
|
||
success : info=>{
|
||
if (info.confirm){
|
||
wx.openSetting()
|
||
}
|
||
}
|
||
})
|
||
},
|
||
complete: e => {}
|
||
})
|
||
}
|
||
})
|
||
})
|
||
}
|
||
})
|
||
}).catch(err=>{})
|
||
},
|
||
|
||
/**
|
||
* 微信分享
|
||
*/
|
||
onShareAppMessage(){
|
||
return {
|
||
title : this.data.userInfo.nickname + '邀请您了解锶源昆仑',
|
||
path : "/pages/login/index?invite=" + this.data.inviteText,
|
||
imageUrl: "https://api.siyuankunlun.com/storage/materials/2022/09/14/code.jpg"
|
||
}
|
||
}
|
||
}) |