11 changed files with 220 additions and 56 deletions
@ -0,0 +1,110 @@ |
|||||
|
// pages/weChatAuth/index.js
|
||||
|
import { store } from '../../utils/store.js' |
||||
|
import { UserModel } from '../../models/user.js' |
||||
|
let userModel = new UserModel() |
||||
|
import { AuthModel } from '../../models/auth.js' |
||||
|
let authModel = new AuthModel() |
||||
|
|
||||
|
|
||||
|
Page({ |
||||
|
|
||||
|
/** |
||||
|
* 页面的初始数据 |
||||
|
*/ |
||||
|
data: { |
||||
|
canIUse: wx.canIUse('button.open-type.getUserInfo'), |
||||
|
nickName: '', |
||||
|
avatarUrl: '', |
||||
|
userInfo: { |
||||
|
type: Object, |
||||
|
value: {} |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* 生命周期函数--监听页面加载 |
||||
|
*/ |
||||
|
onLoad: function (options) { |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* 生命周期函数--监听页面显示 |
||||
|
*/ |
||||
|
onShow: function () { |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
// 授权登录
|
||||
|
bindGetUserInfo(e) { |
||||
|
//console.log(e.detail.userInfo)
|
||||
|
if (e.detail.userInfo) { |
||||
|
let avatarUrl = e.detail.userInfo.avatarUrl |
||||
|
let nickName = e.detail.userInfo.nickName |
||||
|
store.saveUserInfo({ |
||||
|
nickName: nickName, |
||||
|
avatarUrl: avatarUrl, |
||||
|
phone: '' |
||||
|
}) |
||||
|
this.sendUserInfo(e.detail.userInfo) |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
// 上传用户信息
|
||||
|
sendUserInfo(weChatInfo) { |
||||
|
userModel.sendUserInfo(weChatInfo, res => { |
||||
|
this.getUserInfo() |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
// 获取用户信息
|
||||
|
getUserInfo() { |
||||
|
userModel.getUserInfo(res => { |
||||
|
console.log(res) |
||||
|
let nickName = res.result.nickName |
||||
|
let avatarUrl = res.result.avatarUrl |
||||
|
|
||||
|
if (nickName && avatarUrl) { |
||||
|
//console.log('已授权')
|
||||
|
this.setData({ |
||||
|
userInfo: res.result, |
||||
|
avatarUrl: res.result.avatarUrl, |
||||
|
nickName: res.result.nickName, |
||||
|
reAuth: true, |
||||
|
isAuth: false |
||||
|
}, () => { |
||||
|
if (store.hasPhone()) { |
||||
|
//console.log('已经绑定手机号码')
|
||||
|
} else { |
||||
|
//console.log('未绑定手机号码')
|
||||
|
wx.showModal({ |
||||
|
title: '温馨提示', |
||||
|
content: '是否前往验证手机号码?', |
||||
|
success(res) { |
||||
|
if (res.confirm) { |
||||
|
wx.redirectTo({ |
||||
|
url: '/pages/register/index', |
||||
|
}) |
||||
|
} else if (res.cancel) { |
||||
|
wx.switchTab({ |
||||
|
url: '/pages/home/index', |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
store.saveUserInfo({ |
||||
|
nickName: res.result.nickName, |
||||
|
avatarUrl: res.result.avatarUrl, |
||||
|
phone: res.result.phone || '' |
||||
|
}) |
||||
|
} else { |
||||
|
//console.log('未授权')
|
||||
|
this.setData({ |
||||
|
isAuth: true |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
}) |
@ -0,0 +1,3 @@ |
|||||
|
{ |
||||
|
"usingComponents": {} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
<!--pages/weChatAuth/index.wxml--> |
||||
|
<view class="container"> |
||||
|
<navigator open-type="switchTab" url="/pages/home/index"> |
||||
|
<image class="auth_cancel" src="/images/common/close.png"></image> |
||||
|
</navigator> |
||||
|
<view class="page_bd"> |
||||
|
<view class="image_view"> |
||||
|
<view class="title">市北人才</view> |
||||
|
<image class="img" src="/images/temp_1.png"></image> |
||||
|
</view> |
||||
|
<view class="description"> |
||||
|
<view class="h1"> |
||||
|
Hi,请登录~ |
||||
|
</view> |
||||
|
<view> |
||||
|
授权后,可以更好的体验我们哦~ |
||||
|
</view> |
||||
|
</view> |
||||
|
<button class="authBtn" type="primary" wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">微信用户登录</button> |
||||
|
<view wx:else>请升级微信版本</view> |
||||
|
</view> |
||||
|
</view> |
@ -0,0 +1,51 @@ |
|||||
|
/* pages/weChatAuth/index.wxss */ |
||||
|
.container { |
||||
|
position: relative; |
||||
|
padding: 0 20px; |
||||
|
display: flex; |
||||
|
height: 100vh; |
||||
|
justify-items: center; |
||||
|
align-items: center; |
||||
|
} |
||||
|
.auth_cancel { |
||||
|
position: absolute; |
||||
|
padding: 10px; |
||||
|
width: 30px; |
||||
|
height: 30px; |
||||
|
top: 0; |
||||
|
right: 20px; |
||||
|
} |
||||
|
.page_bd { |
||||
|
height: 65vh; |
||||
|
width: 100%; |
||||
|
} |
||||
|
.image_view{ |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
align-items: center; |
||||
|
justify-content: center; |
||||
|
} |
||||
|
.img{ |
||||
|
width: 180px; |
||||
|
height: 120px; |
||||
|
} |
||||
|
.title{ |
||||
|
font-size: 20px; |
||||
|
padding: 10px; |
||||
|
} |
||||
|
|
||||
|
.description{ |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
align-items: center; |
||||
|
justify-content: center; |
||||
|
} |
||||
|
.h1{ |
||||
|
padding: 20px 0 10px; |
||||
|
font-size: 20px; |
||||
|
font-weight: bold; |
||||
|
} |
||||
|
.authBtn{ |
||||
|
background-color: rgb(32,192,100); |
||||
|
top: 40px; |
||||
|
} |
Loading…
Reference in new issue