This commit is contained in:
张慢慢
2021-05-24 13:56:00 +08:00
commit a7995d90bc
208 changed files with 13143 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
/*
* 本时生活
*/
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
wechatUserId: "",
loginCode : "",
userInfo : "",
isLogin : false,
iv : '',
enData : '',
loginTel : [] //用户手机号
},
/**
* 生命周期函数--监听页面加载
*/
onLoad (options) {
// 登录方式-活动
this.setData({
way : options.way
})
if(options.type == "mobiles") {
wx.$api.user.mobiles().then(res=>{
this.setData({
loginTel : res.data
})
})
}else {
// 获取用户手机列表
const logintel = wx.getStorageSync("users")
this.setData({
loginTel : logintel
})
}
},
/**
* 生命周期函数--页面显示
*/
onShow() {
wx.login({
success: res => {
this.setData({
loginCode: res.code
})
}
})
},
/**
* 绑定手机号码
*/
mobile(e){
if(e.detail.errMsg == "getPhoneNumber:ok"){
this.setData({
isLogin : true,
iv : e.detail.iv,
enData : e.detail.encryptedData
})
this.binMobel()
}else{
wx.showToast({
title: '拒绝了手机号码授权',
icon : 'none'
})
}
},
/**
* 绑定手机号码
*/
binMobel(){
let code = this.data.loginCode,
iv = this.data.iv,
mobile = this.data.enData
wx.$api.enroll.bindmobile(code, iv, mobile).then(res=>{
this.setData({
isLogin: false
})
getApp().globalData.token = res.data.token
// 更新全局存储器用户状态
getApp().globalData.isUser = true
// 写入缓存
wx.setStorage({
key : 'token',
data : res.data.token
})
if(this.data.way == "activity") {
// 回到活动首页
wx.reLaunch({
url: '/pages/activityInfo/activityInfo'
})
} else {
// 回到个人中心
wx.switchTab({
url: '/pages/user/user'
})
}
})
},
/**
* 点击账号登录
*/
loginGo(e) {
let username = e.currentTarget.dataset.name,
wechatUser_id = app.globalData.wechatUser
wx.$api.enroll.tel(wechatUser_id, username).then(res=>{
app.globalData.token = res.data.token
app.globalData.isUser = true
// 写入缓存
wx.setStorage({
key : 'token',
data : res.data.token
})
if(this.data.way == "activity") {
// 回到活动首页
wx.reLaunch({
url: '/pages/activityInfo/activityInfo'
})
} else {
// 回到个人中心
wx.switchTab({
url: '/pages/user/user'
})
}
})
}
})

View File

@@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "绑定手机号"
}

View File

@@ -0,0 +1,26 @@
<!-- 切换手机号 -->
<view class="chooseTel-title" wx:if="{{loginTel != ''}}">
<text>切换手机号登录</text>
轻触账户以登录
</view>
<!-- 用户列表 -->
<block wx:if="{{loginTel != ''}}">
<view class="chooseList" wx:for="{{loginTel}}" wx:key="loginTel" bindtap="loginGo" data-name="{{item.username}}">
<view class="chooseList-left">
<image class="chooseList-img" src="{{item.avatar}}" mode="aspectFill"></image>
<view class="chooseList-tel">{{item.username}}</view>
</view>
<view class="chooseList-btn" wx:if="{{item.isThisUser}}">当前登录</view>
</view>
</block>
<!-- 用户列表 -->
<block wx:else>
<view class="chooseTips">
<image src="/static/img/tel_img.png" mode="aspectFill"></image>
<text>您还没有绑定手机号</text>
</view>
</block>
<button hover-class="none" class="chooseAdd" open-type="getPhoneNumber" bindgetphonenumber="mobile" disabled="{{isLogin}}">绑定手机号码</button>

View File

@@ -0,0 +1,75 @@
/* 切换手机号 */
.chooseTel-title {
background: #fff;
padding: 40rpx 30rpx;
color: #999;
}
.chooseTel-title text {
font-size: 36rpx;
font-weight: 600;
margin-bottom: 20rpx;
display: block;
color: #000;
}
.chooseList {
display: flex;
background: #fff;
line-height: 100rpx;
padding: 20rpx;
box-sizing: border-box;
}
.chooseList-left {
display: flex;
}
.chooseList-img {
width: 90rpx;
height: 90rpx;
border-radius: 50%;
margin-right: 30rpx;
}
.chooseList-btn {
font-size: 24rpx;
background: #00c12d;
border-radius: 30rpx;
height: 42rpx;
line-height: 42rpx;
color: #fff;
padding: 0 15rpx;
margin-top: 28rpx;
margin-left: 30rpx;
}
.chooseAdd {
width: calc(100% - 60rpx);
margin: 60rpx auto 0;
background: #fff;
border-radius: 50rpx;
line-height: 80rpx;
height: 80rpx;
text-align: center;
box-shadow: 0 0 10rpx rgba(0, 0,0, .05);
padding: 0;
}
.chooseTips {
background: #fff;
text-align: center;
padding: 30rpx 0 50rpx;
}
.chooseTips image {
width: 400rpx;
height: 350rpx;
display: block;
margin: 0 auto 20rpx;
}
.chooseTips text {
font-size: 34rpx;
color: #999;
}