You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.5 KiB
110 lines
2.5 KiB
// 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
|
|
})
|
|
}
|
|
})
|
|
}
|
|
})
|