This commit is contained in:
zhangmanman
2021-07-14 10:08:28 +08:00
parent ba6b09db50
commit bc38362878
36 changed files with 481 additions and 7 deletions

View File

@@ -2,7 +2,7 @@
import {req} from "../request"
//微信授权登录
const record = (code, iv, encryptedData) => req({url: "auth/openwx", method: "POST", data: {code: code, iv: iv, encryptedData: encryptedData}})
const record = (code, iv, encryptedData, parent_id) => req({url: "auth/openwx", method: "POST", data: {code: code, iv: iv, encryptedData: encryptedData, parent_id: parent_id || 0}})
//微信手机授权
const bindmobile = (code, iv, mobile) => req({url: "auth/bindmobile", method: "POST", data: {code: code, iv: iv, mobile: mobile}})

View File

@@ -58,6 +58,9 @@ const washcarBuy = (welfare_id, right_id, qty, address_id, is_deliver) => req({u
// 收银台提交
const washcarCreate = (welfare_id, right_id, qty, address_id, is_deliver) => req({url: "washcar/create", method: "POST", data:{welfare_id : welfare_id, right_id : right_id, qty : qty, address_id : address_id || '', is_deliver : is_deliver}})
// 我的分享
const myshare = (parent_id) => req({url: "user/share",data:{parent_id : parent_id || ''}})
export default({
index,
mobiles,
@@ -77,5 +80,6 @@ export default({
unicom,
merchant_card,
washcarBuy,
washcarCreate
washcarCreate,
myshare
})

View File

@@ -28,7 +28,8 @@
"pages/classify/classify",
"pages/washcar/washcar",
"pages/makeForm/makeForm",
"pages/car/index"
"pages/car/index",
"pages/code/code"
],
"window": {
"backgroundTextStyle": "light",

View File

@@ -126,9 +126,8 @@ Page({
*/
loginGo(e) {
let username = e.currentTarget.dataset.name
const wechatUserId = wx.getStorageSync("wechatUser")
wx.$api.enroll.tel(wechatUserId, username).then(res=>{
wx.$api.enroll.tel(this.data.wechatUserId, username).then(res=>{
app.globalData.token = res.data.token
app.globalData.isUser = true

170
pages/code/code.js Normal file
View File

@@ -0,0 +1,170 @@
/*
* 本时生活
*/
Page({
/**
* 页面的初始数据
*/
data: {
qrcode : '', //二维码
userInfo: '', //我的信息
isImgLay: false, //是否显示图片弹出层
parentId: '' //是否分享进入
},
/**
* 生命周期函数--监听页面加载
*/
onLoad (options) {
// 判断是否由分享进入
if(options.type == "share"){
// 写入缓存
this.setData({
parentId: options.parent_id
})
}
wx.$api.user.myshare(this.data.parentId).then(res=>{
this.setData({
qrcode : res.data.qrcode,
userInfo : res.data.user
})
})
},
/**
* 绘图
*/
dowImg(){
wx.showLoading({
title: '加载中',
})
let avatarImg = new Promise(success=>{
wx.getImageInfo({
src : this.data.userInfo.avatar,
success : res => {
success(res.path)
}
})
})
// 下载素材
let codeImg = new Promise(success => {
wx.getImageInfo({
src : this.data.qrcode,
success : res => {
success(res.path)
}
})
})
Promise.all([codeImg, avatarImg]).then(res => {
// 绘制海报
const ctx = wx.createCanvasContext('qrcodeCard')
ctx.save()
// 绘制背景
ctx.setFillStyle('#f7662d')
ctx.fillRect(0, 0, 375, 603)
// 绘制背景
ctx.drawImage('/static/img/user-codeImg-down.png', 0, 0, 375, 650)
// 绘制二维码
ctx.drawImage(res[0], 114, 390, 150, 150)
// 文字
ctx.setFontSize(16)
ctx.setFillStyle("#2f3245")
ctx.setTextAlign('center')
ctx.fillText(this.data.userInfo.nickname, 194, 350 , 270)
// 文字
ctx.setFontSize(14)
ctx.setFillStyle("#af7700")
ctx.setTextAlign('center')
ctx.fillText(this.data.userInfo.nickname + " -- " + "邀请您进入本时生活", 188, 570 , 270)
ctx.save();
ctx.beginPath(); //开始绘制
ctx.arc(70 / 2 + 156, 70 / 2 + 250, 70 / 2, 0, Math.PI * 2, false);
ctx.clip();
ctx.drawImage(res[1], 156, 250, 70, 70);
// 保存图片
ctx.draw(true, () => {
wx.hideLoading()
wx.canvasToTempFilePath({
canvasId: 'qrcodeCard',
x: 0,
y: 0,
success: res => {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success : res=>{
wx.showToast({
title: '分享海报已保存至相册',
icon : 'none'
})
},
fail : err=>{
wx.showModal({
title : '提示',
content : '暂未授权小程序写入您的相册,无法存储二维码海报',
confirmColor: '#d82526',
confirmText : '去设置',
success : info=>{
if (info.confirm){
wx.openSetting()
}
}
})
},
complete: e => {
console.log(e)
}
})
}
})
})
}).catch(err=>{
wx.showToast({
title: '海报下载,请检查网络',
icon : 'none'
})
})
},
/**
* 图片弹出层
*/
removeSaveImg(){
this.setData({
isImgLay: !this.data.isImgLay
})
},
/**
* 保存图片到本地
*/
saveImg(){
this.dowImg();
this.setData({
isImgLay: !this.data.isImgLay
})
},
/**
* 分享
*/
onShareAppMessage(){
return {
title : this.data.userInfo.nickname + "邀请您进入本时生活",
imageUrl: "",
query : "/pages/code/code?parent_id=" + this.data.userInfo.user_id + "&type=share"
}
}
})

6
pages/code/code.json Normal file
View File

@@ -0,0 +1,6 @@
{
"usingComponents": {},
"navigationBarTitleText": "我的邀请码",
"navigationBarBackgroundColor": "#332829",
"navigationBarTextStyle": "white"
}

48
pages/code/code.wxml Normal file
View File

@@ -0,0 +1,48 @@
<image class="codeTitle" src="/static/img/user-codeTitle.png"></image>
<view class="codeCont">
<image class="codeCont-gold" src="/static/img/user-codeGold.png"></image>
<image class="codeCont-tips" src="/static/img/user-codeTips-01.png" mode="widthFix"></image>
<view class="codeCont-text">
<image class="codeCont-avatar" src="{{userInfo.avatar}}" mode="aspectFill"></image>
<view class="codeCont-name">
{{userInfo.nickname}}
</view>
</view>
<image class="codeCont-words" src="/static/img/user-codeTips-02.png" mode="widthFix"></image>
<image class="codeCont-code" src="{{qrcode}}" mode="aspectFill"></image>
</view>
<view class="codeShare">
<button class="codeShare-label codeShare-button" open-type="share" hover-class="none">
微信好友
</button>
<view class="codeShare-label" bindtap="removeSaveImg" hover-class="none">
下载海报
</view>
</view>
<!-- 海报canvas -->
<canvas class="canvasImg" canvas-id="qrcodeCard"></canvas>
<!-- 图片弹出层 -->
<view class="user-lay sign-img-lay" wx:if="{{isImgLay}}">
<view class="user-back">
<image class="user-back-img" src="/static/img/user-codeImg-active.png" mode="aspectFill"></image>
<view class="user-back-cont">
<view class="user-back-avatar">
<image src="{{userInfo.avatar}}" mode="aspectFill"></image>
<view class="">
{{userInfo.nickname}}
</view>
</view>
<view class="user-back-yard">
<image src="{{qrcode}}" mode="aspectFill"></image>
<view class="codeBack-yard-name">
邀请好友扫码,即可绑定关系
</view>
</view>
</view>
</view>
<button class="sign-img-btn" size="mini" bindtap="saveImg">保存到相册</button>
<button class="sign-img-btn remove-btn" size="mini" bindtap="removeSaveImg">取消</button>
</view>

207
pages/code/code.wxss Normal file
View File

@@ -0,0 +1,207 @@
page {
background-color: #f5ecd8;
}
/* 标题 */
.codeTitle {
width: 100vw;
height: 45vh;
text-align: center;
position: absolute;
left: 0;
top: 0;
}
/* 按钮 */
.codeShare {
width: 100%;
position: fixed;
bottom: 0;
left: 0;
background-color: #333333;
display: flex;
padding: 30rpx 20rpx 40rpx;
box-sizing: border-box;
z-index: 9;
}
.codeShare-label {
width: calc(50% - 20rpx) !important;
margin: 0 10rpx;
font-weight: normal;
text-align: center;
height: 80rpx;
line-height: 80rpx;
padding: 0;
border-radius: 60rpx;
border: #c1a468 2rpx solid;
font-size: 32rpx;
color: #412f0b;
background: linear-gradient(to bottom, #eee3c8, #c1a468);
}
.codeShare-button {
color: #ffd887;
background: transparent;
}
/* 二维码 */
.codeCont {
position: relative;
width: 80vw;
left: 10vw;
top: 31.5vh;
background-color: #fff;
box-sizing: border-box;
border-radius: 10rpx;
justify-items: center;
text-align: center;
z-index: 8;
margin-bottom: 200rpx;
}
.codeCont-code {
width: 340rpx;
height: 340rpx;
margin: 20rpx 0 40rpx;
}
.codeCont-tips {
border-radius: 10rpx 10rpx 0 0;
width: 100%;
}
.codeCont-gold {
position: absolute;
width: 100rpx;
height: 100rpx;
right: 40rpx;
top: -40rpx;
}
.codeCont-text {
position: absolute;
width: 100%;
text-align: center;
top: 30rpx;
left: 0;
color: #71552d;
font-weight: 600;
}
.codeCont-avatar {
width: 130rpx;
height: 130rpx;
border-radius: 50%;
margin-bottom: 5rpx;
border: 6rpx solid #ebdcb9;
}
.codeCont-words {
margin-top: 40rpx;
width: 100%;
}
/* 弹窗背景图 */
.user-lay{
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-box-pack: center;
position: fixed;
background: rgba(0, 0, 0, .6);
height: 100vh;
width: 100vw;
top: 0;
left: 0;
z-index: 99;
box-sizing: border-box;
}
/* canvas */
.canvasImg{
position: absolute;
left: -1000%;
height: 650px;
width: 375px;
background: #fbf6f0;
}
/* 图片弹出层 */
.sign-img-lay{
text-align: center;
}
.sign-img-src{
width: 70vw;
vertical-align: top;
}
.sign-img-btn[size="mini"]{
margin-top: 40rpx;
background: #f5d48f;
font-weight: normal;
color: #2f3245;
height: 90rpx;
line-height: 90rpx;
padding: 0;
width: 70vw;
}
.remove-btn[size="mini"]{
margin-top: 20rpx;
background: #101010;
color: #e5c175;
font-weight: normal;
}
/* 背景 */
.user-back {
position: relative;
width: 100%;
height:600rpx;
text-align: center;
margin-top: 100rpx;
}
.user-back-img {
position: absolute;
width: 70vw;
left: 15vw;
top: 0;
height: 100%;
margin: 0 auto;
border-radius: 10rpx;
}
.user-back-cont {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
color: #2f3245;
}
.user-back-avatar image {
width: 140rpx;
height: 140rpx;
border-radius: 50%;
margin-top: -60rpx;
margin-bottom: 20rpx;
border: 6rpx solid #fff1d1;
}
.user-back-yard {
margin-top: 40rpx;
}
.codeBack-yard-name {
font-size: 28rpx;
color: #af7700;
}
.user-back-yard image {
width: 240rpx;
height: 240rpx;
margin-bottom: 20rpx;
}

View File

@@ -35,6 +35,20 @@ Page({
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 判断是否由分享进入
if(options.parent_id !== ""){
// 写入缓存
wx.setStorage({
key : 'parentId',
data : options.parent_id
})
}
},
/**
* 生命周期函数--监听页面显示
*/

View File

@@ -78,7 +78,7 @@ Page({
},
fail : res => {
//拒绝授权
this.showErrorModal('您拒绝了请求');
// this.showErrorModal('您拒绝了请求');
return;
}
})
@@ -92,7 +92,10 @@ Page({
iv = this.data.iv,
encryptedData = this.data.encryptedData
wx.$api.enroll.record(code, iv, encryptedData).then(res=>{
// 检查用户扫码进入
const parentId = wx.getStorageSync("parentId")
wx.$api.enroll.record(code, iv, encryptedData, parentId).then(res=>{
getApp().globalData.token = res.data.token
// 更新全局存储器用户状态
@@ -127,6 +130,9 @@ Page({
key : 'users',
data : res.data.users
})
// 清除扫码进入获取parent_id的缓存
wx.removeStorageSync('parentId')
})
}

View File

@@ -169,3 +169,16 @@
</view> -->
</view>
</view>
<!-- 我的工具 -->
<view class="userCard">
<view class="userCard-title">我的工具</view>
<view class="userOrder">
<view class="userOrder-label" bindtap="userNav" data-url="/pages/code/code">
<view class="userOrder-icon active">
<image src="/static/img/userCoupon.png"></image>
</view>
<text>我的邀请码</text>
</view>
</view>
</view>

View File

@@ -120,6 +120,12 @@
"pathName": "pages/car/index",
"query": "",
"scene": null
},
{
"name": "pages/code/code",
"pathName": "pages/code/code",
"query": "",
"scene": null
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 KiB

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB