锶源昆仑商城
This commit is contained in:
250
pages/user/code/code.js
Normal file
250
pages/user/code/code.js
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* 手太欠
|
||||
* 愿这世界都如故事里一样 美好而动人~
|
||||
*/
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
shareSee : false, //分享弹出
|
||||
identity : '', //1为普通
|
||||
userInfo : '', //用户信息
|
||||
inviteText : '', //邀请码
|
||||
inviteCode : '', //二维码
|
||||
|
||||
//海报
|
||||
posterDatas: {
|
||||
width : 375, //画布宽度
|
||||
height : 800, //画布高度
|
||||
// 缓冲区,无需手动设定
|
||||
pic : null,
|
||||
buttonType : 1,
|
||||
show : false, // 显示隐藏海报弹窗
|
||||
success : false, // 是否成功生成过海报
|
||||
canvas : null, // 画布的节点
|
||||
ctx : null, // 画布的上下文
|
||||
dpr : 1, // 设备的像素比
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
//生成海报初始化
|
||||
var that = this;
|
||||
var posterDatas = that.data.posterDatas
|
||||
const query = wx.createSelectorQuery()
|
||||
query.select('#firstCanvas').fields({
|
||||
node: true,
|
||||
size: true
|
||||
},
|
||||
function (res) {
|
||||
const canvas = res.node
|
||||
const ctx = canvas.getContext('2d')
|
||||
const dpr = wx.getSystemInfoSync().pixelRatio
|
||||
canvas.width = posterDatas.width * dpr
|
||||
canvas.height = posterDatas.height * dpr
|
||||
ctx.scale(dpr, dpr)
|
||||
posterDatas.canvas = canvas
|
||||
posterDatas.ctx = ctx
|
||||
posterDatas.dpr = dpr
|
||||
//存储
|
||||
that.setData({
|
||||
posterDatas
|
||||
})
|
||||
}).exec()
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
// 获取推广码
|
||||
this.inviteInfo();
|
||||
|
||||
// 小程序码
|
||||
this.ShareInfo();
|
||||
},
|
||||
|
||||
/**
|
||||
* 推广码
|
||||
*/
|
||||
inviteInfo() {
|
||||
wx.$api.user.invite().then(res => {
|
||||
this.setData({
|
||||
identity : res.data.code,
|
||||
userInfo : res.data.user_info,
|
||||
inviteText : res.data.invite
|
||||
})
|
||||
}).catch(err => {})
|
||||
},
|
||||
|
||||
/**
|
||||
* 小程序码
|
||||
*/
|
||||
ShareInfo() {
|
||||
wx.$api.user.miniShare({
|
||||
url: '/pages/login/index'
|
||||
}).then(res => {
|
||||
this.setData({
|
||||
inviteCode: res.data.qrcode
|
||||
})
|
||||
}).catch(err => {})
|
||||
},
|
||||
|
||||
//海报生成 //画布 生成 海报[海报]
|
||||
saveImg () {
|
||||
var that = this;
|
||||
var posterDatas = that.data.posterDatas
|
||||
var canvas = posterDatas.canvas
|
||||
var ctx = posterDatas.ctx
|
||||
wx.showLoading({
|
||||
title: '海报生成中',
|
||||
mask: true
|
||||
});
|
||||
|
||||
//二维码
|
||||
var codeImg = new Promise(function (resolve, reject) {
|
||||
const photo = canvas.createImage();
|
||||
photo.src = that.data.inviteCode;
|
||||
photo.onload = (e) => {
|
||||
resolve(photo);
|
||||
}
|
||||
});
|
||||
|
||||
//背景素材
|
||||
var backImg = new Promise(function (resolve, reject) {
|
||||
const photo = canvas.createImage();
|
||||
photo.src = "https://api.siyuankunlun.cn/storage/images/2023/03/14/7777441f7a2b25353f2d6de61452418c.png";
|
||||
photo.onload = (e) => {
|
||||
resolve(photo);
|
||||
}
|
||||
});
|
||||
Promise.all([codeImg, backImg]).then(res => {
|
||||
|
||||
// 绘制背景
|
||||
ctx.drawImage(res[1], 0, 0, posterDatas.width, posterDatas.height);
|
||||
|
||||
// 绘制[二维码-白色背景]
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.fillRect(200, 540, 120, 120);
|
||||
|
||||
// 绘制[二维码-白色背景黑框]
|
||||
ctx.strokeStyle = "black";
|
||||
ctx.strokeRect(199, 539, 122, 122);
|
||||
|
||||
// 绘制[二维码]
|
||||
ctx.drawImage(res[0], 210, 550, 100, 100);
|
||||
|
||||
// 文字
|
||||
ctx.font = "bold 14px Arial"; //字体大小
|
||||
ctx.fillStyle = "#000"; //字体颜色
|
||||
ctx.textAlign = "center"
|
||||
ctx.fillText('扫描二维码了解更多', 260, 690);
|
||||
|
||||
// 关闭loading
|
||||
wx.hideLoading();
|
||||
//显示海报
|
||||
posterDatas.success = true;
|
||||
|
||||
that.setData({
|
||||
posterDatas
|
||||
})
|
||||
|
||||
this.onDownloadImges();
|
||||
|
||||
}).catch(err=>{})
|
||||
},
|
||||
|
||||
//下载图片[海报]
|
||||
onDownloadImges () {
|
||||
wx.showLoading({
|
||||
title: '保存中',
|
||||
mask: true
|
||||
});
|
||||
var that = this;
|
||||
var posterDatas = that.data.posterDatas;
|
||||
if (!posterDatas.pic) {
|
||||
that.onCanvasBuildImges();
|
||||
return;
|
||||
}
|
||||
//可写成函数调用 这里不做解释
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath: posterDatas.pic,
|
||||
success(res) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
icon: 'none',
|
||||
title: '已保存到相册,快去分享吧',
|
||||
})
|
||||
that.setData({
|
||||
posterDatas,
|
||||
shareSee: !that.data.shareSee
|
||||
})
|
||||
},
|
||||
fail() {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
icon: 'none',
|
||||
title: '进入设置页,开启“保存到相册”',
|
||||
})
|
||||
that.setData({
|
||||
posterDatas
|
||||
})
|
||||
return;
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//画布 转 图片[海报]
|
||||
onCanvasBuildImges () {
|
||||
var that = this;
|
||||
var posterDatas = that.data.posterDatas;
|
||||
wx.canvasToTempFilePath({
|
||||
canvas: posterDatas.canvas,
|
||||
width: posterDatas.width,
|
||||
height: posterDatas.height,
|
||||
destWidth: posterDatas.width * 3,
|
||||
destHeight: posterDatas.height * 3,
|
||||
success: res=> {
|
||||
posterDatas["pic"] = res.tempFilePath;
|
||||
that.setData({
|
||||
posterDatas
|
||||
})
|
||||
that.onDownloadImges();
|
||||
},
|
||||
fail() {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
icon: 'none',
|
||||
title: 'sorry 保存失败,请稍后再试.',
|
||||
})
|
||||
return;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享弹出
|
||||
*/
|
||||
shareTap() {
|
||||
this.setData({
|
||||
shareSee: !this.data.shareSee
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 微信分享
|
||||
*/
|
||||
onShareAppMessage(){
|
||||
return {
|
||||
title : this.data.userInfo.nickname + '邀请您了解锶源昆仑',
|
||||
path : "/pages/index/index?invite=" + this.data.userInfo.inviteText,
|
||||
imageUrl: "http://cdn.siyuankunlun.com/materials/2022/09/14/code.jpg"
|
||||
}
|
||||
}
|
||||
})
|
||||
4
pages/user/code/code.json
Normal file
4
pages/user/code/code.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "邀请码"
|
||||
}
|
||||
32
pages/user/code/code.wxml
Normal file
32
pages/user/code/code.wxml
Normal file
@@ -0,0 +1,32 @@
|
||||
<view class="code">
|
||||
<image src="https://api.siyuankunlun.cn/storage/images/2023/03/14/7777441f7a2b25353f2d6de61452418c.png" 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="/static/icons/share.png"></image>
|
||||
<view class="code-share-name">分享</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 海报canvas -->
|
||||
<!-- <canvas class="canvasImg" canvas-id="qrcodeCard"></canvas> -->
|
||||
<canvas type="2d" id="firstCanvas" class="canvasImg" style="width:{{posterDatas.width}}px;height:{{posterDatas.height}}px;"></canvas>
|
||||
|
||||
<!-- 分享弹出 -->
|
||||
<view class="sharePop {{shareSee ? 'active' : ''}}">
|
||||
<view class="shareCont">
|
||||
<button class="shareCont-label codeShare-button" open-type="share" hover-class="none">
|
||||
<image src="https://card.ysd-bs.com/storage/materials/2021/09/01/code_icon_00.png"></image>
|
||||
微信好友
|
||||
</button>
|
||||
<view class="shareCont-label" bindtap="saveImg">
|
||||
<image src="https://card.ysd-bs.com/storage/materials/2021/09/01/code_icon_02.png"></image>
|
||||
保存二维码
|
||||
</view>
|
||||
</view>
|
||||
<view class="shareCancel" bindtap="shareTap">取消</view>
|
||||
</view>
|
||||
164
pages/user/code/code.wxss
Normal file
164
pages/user/code/code.wxss
Normal file
@@ -0,0 +1,164 @@
|
||||
.code {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.code-back {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.code-cont {
|
||||
width: 450rpx;
|
||||
position: absolute;
|
||||
z-index: 9;
|
||||
text-align: center;
|
||||
right: 0;
|
||||
bottom: 13%;
|
||||
}
|
||||
|
||||
.code-img{
|
||||
margin: 0 auto 20rpx;
|
||||
overflow: hidden;
|
||||
width: 220rpx;
|
||||
height: 220rpx;
|
||||
border: 4rpx solid #000;
|
||||
background-color: #ffffff;
|
||||
padding: 10rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.code-img image {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.code-text {
|
||||
color: #000;
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.code-share {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
right: 0;
|
||||
bottom: 40%;
|
||||
background: linear-gradient(to right, #3f7fff, #568fff);
|
||||
width: 50rpx;
|
||||
text-align: center;
|
||||
border-radius: 26rpx 0 0 26rpx;
|
||||
padding: 24rpx 4rpx 24rpx 10rpx;
|
||||
box-shadow: 0 0 6rpx 6rpx rgba(0, 0, 0, .2);
|
||||
}
|
||||
|
||||
.code-share-name {
|
||||
writing-mode:vertical-rl;
|
||||
font-size: 28rpx;
|
||||
padding-left: 4rpx;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.code-share image {
|
||||
width: 30rpx;
|
||||
height: 30rpx;
|
||||
margin-bottom: 5rpx;
|
||||
}
|
||||
|
||||
.sharePop {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
z-index: 99;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
background-color: #0a1930;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.sharePop.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.shareCont-label image {
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
display: block;
|
||||
margin: 0 auto 10rpx;
|
||||
}
|
||||
|
||||
.shareCancel {
|
||||
border-top: 2rpx solid #0e2c58;
|
||||
color: #ffffff;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
line-height: 100rpx;
|
||||
}
|
||||
|
||||
.shareCont{
|
||||
display: flex;
|
||||
padding: 30rpx 0;
|
||||
}
|
||||
|
||||
.shareCont-label {
|
||||
color: #ffffff;
|
||||
flex: 2;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.codeShare-button {
|
||||
background-color: transparent;
|
||||
padding: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
/* canvas */
|
||||
.canvasImg {
|
||||
position: absolute;
|
||||
left: -1000%;
|
||||
height: 800px;
|
||||
width: 375px;
|
||||
}
|
||||
|
||||
/* 何院士样式 */
|
||||
.newCode-cont {
|
||||
width: 70%;
|
||||
height: 200rpx;
|
||||
position: absolute;
|
||||
z-index: 9;
|
||||
text-align: center;
|
||||
left: 15%;
|
||||
bottom: 19.5%;
|
||||
background: linear-gradient(to top, #a09084, #a58367);
|
||||
padding: 15rpx;
|
||||
box-sizing: border-box;
|
||||
border-radius: 30rpx;
|
||||
}
|
||||
|
||||
.newCode-img {
|
||||
height: 170rpx;
|
||||
margin: 0 auto;
|
||||
background: linear-gradient(to top, #e9d1bd, #c49b7a);
|
||||
border: 4rpx solid #f3c49d;
|
||||
border-radius: 30rpx;
|
||||
display: flex;
|
||||
padding: 10rpx 30rpx 10rpx 10rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.newCode-img-title {
|
||||
width: calc(100% - 140rpx);
|
||||
}
|
||||
|
||||
.newCode-img-title image {
|
||||
width: 80%;
|
||||
margin-top: 15rpx;
|
||||
}
|
||||
|
||||
.newCode-img-code {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user