绚火健康
This commit is contained in:
172
pages/user/code/code.js
Normal file
172
pages/user/code/code.js
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 手太欠
|
||||
* 愿这世界都如故事里一样 美好而动人~
|
||||
*/
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
barHeight : getApp().globalData.barHeight, // 状态栏高度
|
||||
shareSee : false, //分享弹出
|
||||
inviteText : '', //邀请码
|
||||
inviteCode : '', //二维码
|
||||
|
||||
//海报
|
||||
canvas : ''
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
// 初始化画布
|
||||
wx.createSelectorQuery().select('#coverCanvas').fields({node: true, size: true}).exec(canvasNode => {
|
||||
const canvas = canvasNode[0].node
|
||||
canvas.width = 375
|
||||
canvas.height = 800
|
||||
this.setData({
|
||||
canvas
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
// 小程序码
|
||||
// this.ShareInfo();
|
||||
},
|
||||
|
||||
/**
|
||||
* 小程序码
|
||||
*/
|
||||
ShareInfo() {
|
||||
wx.$api.user.miniShare({
|
||||
url: '/pages/mall/index'
|
||||
}).then(res => {
|
||||
this.setData({
|
||||
inviteCode: res.data.qrcode
|
||||
})
|
||||
}).catch(err => {})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生成海报
|
||||
*/
|
||||
onCanvas(){
|
||||
wx.showLoading({
|
||||
title: '生成图片中...',
|
||||
mask : true
|
||||
})
|
||||
const canvas = this.data.canvas
|
||||
const ctx = canvas.getContext('2d')
|
||||
const codeImgEl = canvas.createImage()
|
||||
const backBackEl = canvas.createImage()
|
||||
|
||||
// codeImgEl.src = this.data.inviteCode //二维码
|
||||
codeImgEl.src = '/static/imgs/userHead.png' //二维码
|
||||
backBackEl.src = 'https://cdn.douhuofalv.com/images/2023/08/11/cd8093d6ab1a248e5154be48b0ddcaac.jpg' //背景素材
|
||||
const codeImgLoding = new Promise((resolve, reason) => {
|
||||
codeImgEl.onload = () => {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
const backBackLoding = new Promise((resolve, reason) => {
|
||||
backBackEl.onload = () => {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
Promise.all([codeImgLoding, backBackLoding]).then(() => {
|
||||
ctx.drawImage(backBackEl, 0, 0, 375, 800)
|
||||
// 绘制[二维码-白色背景]
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.fillRect(140, 610, 130, 130);
|
||||
|
||||
// 绘制[二维码-白色背景黑框]
|
||||
ctx.strokeStyle = "#da2b54";
|
||||
ctx.lineWidth = 2
|
||||
ctx.strokeRect(140, 610, 132, 132);
|
||||
|
||||
// 绘制[二维码]
|
||||
ctx.drawImage(codeImgEl, 150, 620, 110, 110)
|
||||
|
||||
// 文字
|
||||
ctx.font = "bold 14px Arial"; //字体大小
|
||||
ctx.fillStyle = "#ffffff"; //字体颜色
|
||||
ctx.textAlign = "center"
|
||||
ctx.fillText('保存并分享二维码', 208, 770);
|
||||
|
||||
wx.hideLoading()
|
||||
wx.canvasToTempFilePath({
|
||||
canvas: this.data.canvas,
|
||||
success : res => {
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath: res.tempFilePath,
|
||||
success: saveRes => {
|
||||
wx.showToast({
|
||||
title: '海报已保存至您的相册',
|
||||
icon : 'none'
|
||||
})
|
||||
this.setData({
|
||||
shareSee: false
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading()
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '暂未授权小程序写入您的相册,无法存储海报',
|
||||
confirmColor: '#e50d01',
|
||||
confirmText: '去设置',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
wx.openSetting()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
})
|
||||
}).catch(err => {
|
||||
wx.showToast({
|
||||
title: '图片加载失败',
|
||||
icon : 'none'
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享弹出
|
||||
*/
|
||||
shareTap() {
|
||||
this.setData({
|
||||
shareSee: !this.data.shareSee
|
||||
})
|
||||
},
|
||||
|
||||
// 返回上一页
|
||||
returnGo() {
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 微信分享
|
||||
*/
|
||||
onShareAppMessage(){
|
||||
this.setData({
|
||||
shareSee: false
|
||||
})
|
||||
return {
|
||||
title : '水感应修复、紧致、舒缓喷雾',
|
||||
path : "/pages/index/index?invite=" + wx.getStorageSync("invite"),
|
||||
imageUrl: "https://cdn.shuiganying.com/images/2023/04/04/9cd9968136e7efd85028fba69e4c587a.jpg"
|
||||
}
|
||||
}
|
||||
})
|
||||
4
pages/user/code/code.json
Normal file
4
pages/user/code/code.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
35
pages/user/code/code.wxml
Normal file
35
pages/user/code/code.wxml
Normal file
@@ -0,0 +1,35 @@
|
||||
<view class="navigation {{isFixedTop > 0 ? 'active' : ''}}" style="padding-top:{{barHeight}}px;">
|
||||
<image bindtap="returnGo" class="navigation-arrow" src="{{isFixedTop > 0 ? '/static/icons/arrowBlack.png' : '/static/icons/arrowWrite.png'}}"></image>
|
||||
</view>
|
||||
|
||||
<view class="code">
|
||||
<image src="https://cdn.douhuofalv.com/images/2023/08/11/cd8093d6ab1a248e5154be48b0ddcaac.jpg" class="code-back"></image>
|
||||
<view class="code-cont">
|
||||
<view class="code-img">
|
||||
<image src="{{inviteCode}}" mode="widthFix"></image>
|
||||
</view>
|
||||
<view class="code-text"><text>保存并分享二维码</text></view>
|
||||
</view>
|
||||
<view class="code-share" bindtap="shareTap">
|
||||
<image src="https://cdn.douhuofalv.com/images/2023/08/11/063dc9fe75abe56e9c654b65c3bfc771.png"></image>
|
||||
<view class="code-share-name">分享</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 海报canvas -->
|
||||
<canvas type="2d" style="width: 375px; height: 800px;" id="coverCanvas" class="canvas-img" />
|
||||
|
||||
<!-- 分享弹出 -->
|
||||
<view class="sharePop {{shareSee ? 'active' : ''}}">
|
||||
<view class="shareCont">
|
||||
<button class="shareCont-label codeShare-button" open-type="share" hover-class="none">
|
||||
<image src="https://cdn.shuiganying.com/images/2023/03/28/f8b773edc2fe6db8e45f96773b9a8dc4.png"></image>
|
||||
微信好友
|
||||
</button>
|
||||
<view class="shareCont-label" bindtap="onCanvas">
|
||||
<image src="https://cdn.shuiganying.com/images/2023/03/28/cfe0efbb53eaf7911ea5211923859c65.png"></image>
|
||||
保存二维码
|
||||
</view>
|
||||
</view>
|
||||
<view class="shareCancel" bindtap="shareTap">取消</view>
|
||||
</view>
|
||||
148
pages/user/code/code.wxss
Normal file
148
pages/user/code/code.wxss
Normal file
@@ -0,0 +1,148 @@
|
||||
/* 返回上一页 */
|
||||
.navigation{
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 99;
|
||||
width: 100%;
|
||||
height: 90rpx;
|
||||
background-color: transparent;
|
||||
transition: .2s;
|
||||
}
|
||||
|
||||
.navigation.active {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.navigation-arrow {
|
||||
width: 44rpx;
|
||||
height: 44rpx;
|
||||
margin: 20rpx 15rpx 0 20rpx;
|
||||
}
|
||||
|
||||
|
||||
/* 二维码 */
|
||||
.code {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.code-back {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.code-cont {
|
||||
width: 400rpx;
|
||||
position: absolute;
|
||||
z-index: 9;
|
||||
text-align: center;
|
||||
left: calc(50% - 200rpx);
|
||||
bottom: 5%;
|
||||
}
|
||||
|
||||
.code-img{
|
||||
margin: 0 auto 20rpx;
|
||||
overflow: hidden;
|
||||
width: 260rpx;
|
||||
height: 260rpx;
|
||||
border: 4rpx solid #ff4f64;
|
||||
background-color: #ffffff;
|
||||
padding: 10rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.code-img image {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.code-text {
|
||||
color: #ffffff;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.code-share {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
right: 0;
|
||||
bottom: 15%;
|
||||
background: linear-gradient(to right, #fffafb, #ffd4dd);
|
||||
width: 50rpx;
|
||||
text-align: center;
|
||||
border-radius: 26rpx 0 0 26rpx;
|
||||
padding: 30rpx 10rpx 30rpx 15rpx;
|
||||
box-shadow: 0 0 0 6rpx rgba(249, 96, 116, .8);
|
||||
}
|
||||
|
||||
.code-share-name {
|
||||
writing-mode:vertical-rl;
|
||||
font-size: 30rpx;
|
||||
padding-left: 4rpx;
|
||||
color: #da2b54;
|
||||
}
|
||||
|
||||
.code-share image {
|
||||
width: 36rpx;
|
||||
height: 36rpx;
|
||||
margin-bottom: 5rpx;
|
||||
}
|
||||
|
||||
.sharePop {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
z-index: 99;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
background-color: #ffffff;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sharePop.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.shareCont-label image {
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
display: block;
|
||||
margin: 0 auto 10rpx;
|
||||
}
|
||||
|
||||
.shareCancel {
|
||||
border-top: 2rpx solid #ebebeb;
|
||||
color: #000000;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
line-height: 100rpx;
|
||||
}
|
||||
|
||||
.shareCont{
|
||||
display: flex;
|
||||
padding: 30rpx 0;
|
||||
}
|
||||
|
||||
.shareCont-label {
|
||||
color: #000000;
|
||||
flex: 2;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.codeShare-button {
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
/* canvas */
|
||||
.canvas-img {
|
||||
position: fixed;
|
||||
left: 0%;
|
||||
/* left: -10000%; */
|
||||
top: 0;
|
||||
z-index: 99;
|
||||
}
|
||||
Reference in New Issue
Block a user