|
@@ -12,7 +12,8 @@ Page({
|
|
pageLogin: false,
|
|
pageLogin: false,
|
|
showPhoneAuthBtn: true,
|
|
showPhoneAuthBtn: true,
|
|
showAvaNick: false,
|
|
showAvaNick: false,
|
|
- isNeedPhone: false,
|
|
|
|
|
|
+ isNeedPhoneBtn: false, // 是否需要显示手机号授权
|
|
|
|
+ isNeedHeadImgBtn: false,// 是否需要显示用户头像 昵称 授权
|
|
isRegister: false,
|
|
isRegister: false,
|
|
avatarUrl: '',
|
|
avatarUrl: '',
|
|
confirmAvatarUrl: '',
|
|
confirmAvatarUrl: '',
|
|
@@ -83,56 +84,48 @@ Page({
|
|
userLogin () {
|
|
userLogin () {
|
|
var that = this
|
|
var that = this
|
|
wx.login({
|
|
wx.login({
|
|
- success (res) {
|
|
|
|
- if (res.code) {
|
|
|
|
|
|
+ success (loginCode) {
|
|
|
|
+ if (loginCode.code) {
|
|
var data = {
|
|
var data = {
|
|
- code: res.code
|
|
|
|
|
|
+ code: loginCode.code
|
|
}
|
|
}
|
|
wx.showLoading({
|
|
wx.showLoading({
|
|
title: '登录中...',
|
|
title: '登录中...',
|
|
mask: true
|
|
mask: true
|
|
})
|
|
})
|
|
- ittLogin(data).then(loginRes => {
|
|
|
|
|
|
+ ittLogin(data).then(res => {
|
|
wx.hideLoading()
|
|
wx.hideLoading()
|
|
- app.globalData.accessToken = loginRes.data.accessToken
|
|
|
|
- that.setData({
|
|
|
|
- isNeedPhone: loginRes.data.isNeedPhone,
|
|
|
|
- isRegister: loginRes.data.isRegister
|
|
|
|
- })
|
|
|
|
- if (loginRes.data.isNeedPhone) {
|
|
|
|
- that.setData({
|
|
|
|
- showPhoneAuthBtn: true,
|
|
|
|
- showAvaNick: false
|
|
|
|
- })
|
|
|
|
|
|
+ app.globalData.accessToken = res.data.accessToken
|
|
|
|
+ app.globalData.userInfo.headImg= res.data.headImg
|
|
|
|
+ app.globalData.userInfo.userName = res.data.userName
|
|
|
|
+ app.globalData.userInfo.phoneNumber = res.data.phoneNumber
|
|
|
|
+ if (!res.data.isNeedPhone && res.data.headImg !== '') {
|
|
|
|
+ app.globalData.userInfo.login = true
|
|
} else {
|
|
} else {
|
|
- app.globalData.userInfo.phoneNumber = loginRes.data.phoneNumber
|
|
|
|
- if (loginRes.data.isRegister) {
|
|
|
|
|
|
+ if (res.data.isNeedPhone) { // true 代表需要手机号授权
|
|
that.setData({
|
|
that.setData({
|
|
- showPhoneAuthBtn: false,
|
|
|
|
- showAvaNick: true
|
|
|
|
|
|
+ isNeedPhoneBtn: true
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
- // 全部授权
|
|
|
|
- that.setData({
|
|
|
|
- showPhoneAuthBtn: false,
|
|
|
|
- showAvaNick: true,
|
|
|
|
- pageLogin: true,
|
|
|
|
- confirmAvatarUrl: loginRes.data.headImg,
|
|
|
|
- confirmNickname: loginRes.data.userName.length > 4 ? loginRes.data.userName.substring(0,4) : loginRes.data.userName
|
|
|
|
- })
|
|
|
|
- app.globalData.userInfo.login = true
|
|
|
|
- app.globalData.userInfo.phoneNumber = loginRes.data.phoneNumber
|
|
|
|
- app.globalData.userInfo.headImg = loginRes.data.headImg
|
|
|
|
- app.globalData.userInfo.userName = loginRes.data.userName
|
|
|
|
|
|
+ if (res.data.headImg == '') {
|
|
|
|
+ // 需要授权头像
|
|
|
|
+ that.setData({
|
|
|
|
+ overshow: true,
|
|
|
|
+ phone: res.data,
|
|
|
|
+ isNeedPhoneBtn: false,
|
|
|
|
+ isNeedHeadImgBtn: true
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ that.setData({
|
|
|
|
+ confirmAvatarUrl: app.globalData.userInfo.headImg,
|
|
|
|
+ confirmNickname: app.globalData.userInfo.userName,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}).catch(e => {
|
|
}).catch(e => {
|
|
wx.hideLoading()
|
|
wx.hideLoading()
|
|
- wx.showModal({
|
|
|
|
- content: e,
|
|
|
|
- confirmColor: '#333',
|
|
|
|
- showCancel: false
|
|
|
|
- })
|
|
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -155,35 +148,19 @@ Page({
|
|
// 拉起手机号授权弹窗
|
|
// 拉起手机号授权弹窗
|
|
getPhoneNumber (e) {
|
|
getPhoneNumber (e) {
|
|
var that = this
|
|
var that = this
|
|
- var phoneCode = e.detail.code
|
|
|
|
- wx.login({
|
|
|
|
- success (res) {
|
|
|
|
- if (res.code) {
|
|
|
|
- let data = {
|
|
|
|
- code: res.code
|
|
|
|
- }
|
|
|
|
- wx.showLoading({
|
|
|
|
- title: '登录中...',
|
|
|
|
- mask: true
|
|
|
|
- })
|
|
|
|
- ittLogin(data).then(ittLoginRes => {
|
|
|
|
- wx.hideLoading()
|
|
|
|
- that.bindMobileFn(phoneCode, ittLoginRes)
|
|
|
|
- }).catch(e => {
|
|
|
|
- wx.hideLoading()
|
|
|
|
- wx.showModal({
|
|
|
|
- content: e,
|
|
|
|
- confirmColor: '#333',
|
|
|
|
- showCancel: false
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ var phonePermission = e.detail.errMsg.split(':')[1]
|
|
|
|
+ if (phonePermission == 'ok') {
|
|
|
|
+ var phoneCode = e.detail.code
|
|
|
|
+ that.bindMobileFn(phoneCode)
|
|
|
|
+ } else {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '手机号授权失败',
|
|
|
|
+ icon: 'error'
|
|
|
|
+ })
|
|
|
|
+ }
|
|
},
|
|
},
|
|
// 绑定手机号
|
|
// 绑定手机号
|
|
- // isRegister = true 代表第一次进入显示获取头像
|
|
|
|
- bindMobileFn (phoneCode, ittLoginRes) {
|
|
|
|
|
|
+ bindMobileFn (phoneCode) {
|
|
var that = this
|
|
var that = this
|
|
var data = {
|
|
var data = {
|
|
mobileCode: phoneCode
|
|
mobileCode: phoneCode
|
|
@@ -195,25 +172,20 @@ Page({
|
|
bindMobile(data).then(res => {
|
|
bindMobile(data).then(res => {
|
|
wx.hideLoading()
|
|
wx.hideLoading()
|
|
app.globalData.userInfo.phoneNumber = res.data
|
|
app.globalData.userInfo.phoneNumber = res.data
|
|
- if (that.data.isRegister) {
|
|
|
|
|
|
+ if (app.globalData.userInfo.headImg == '') {
|
|
|
|
+ // 需要授权头像
|
|
that.setData({
|
|
that.setData({
|
|
overshow: true,
|
|
overshow: true,
|
|
phone: res.data,
|
|
phone: res.data,
|
|
- showPhoneAuthBtn: false,
|
|
|
|
- showAvaNick: true
|
|
|
|
|
|
+ isNeedPhoneBtn: false,
|
|
|
|
+ isNeedHeadImgBtn: true
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
that.setData({
|
|
that.setData({
|
|
- phone: res.data,
|
|
|
|
- showPhoneAuthBtn: false,
|
|
|
|
- showAvaNick: true,
|
|
|
|
- pageLogin: true,
|
|
|
|
- avatarUrl: ittLoginRes.data.headImg,
|
|
|
|
- nickname: ittLoginRes.data.userName.length > 4 ? ittLoginRes.data.userName.substring(0,4) : ittLoginRes.data.userName
|
|
|
|
|
|
+ confirmAvatarUrl: app.globalData.userInfo.headImg,
|
|
|
|
+ confirmNickname: app.globalData.userInfo.userName,
|
|
})
|
|
})
|
|
app.globalData.userInfo.login = true
|
|
app.globalData.userInfo.login = true
|
|
- app.globalData.userInfo.headImg = ittLoginRes.data.headImg
|
|
|
|
- app.globalData.userInfo.userName = ittLoginRes.data.userName
|
|
|
|
}
|
|
}
|
|
}).catch(e => {
|
|
}).catch(e => {
|
|
wx.hideLoading()
|
|
wx.hideLoading()
|
|
@@ -231,7 +203,22 @@ Page({
|
|
},
|
|
},
|
|
// 绑定用户头像和昵称
|
|
// 绑定用户头像和昵称
|
|
handleConfirmNickname () {
|
|
handleConfirmNickname () {
|
|
|
|
+ console.log(that.data.avatarUrl, that.data.nickname);
|
|
var that = this
|
|
var that = this
|
|
|
|
+ if (that.data.avatarUrl == '') {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '请选择头像',
|
|
|
|
+ icon: 'error'
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (that.data.nickname == '') {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '请输入昵称',
|
|
|
|
+ icon: 'error'
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
var data = {
|
|
var data = {
|
|
avatarUrl: that.data.avatarUrl,
|
|
avatarUrl: that.data.avatarUrl,
|
|
nickName: that.data.nickname
|
|
nickName: that.data.nickname
|
|
@@ -247,7 +234,7 @@ Page({
|
|
pageLogin: true,
|
|
pageLogin: true,
|
|
overshow: false,
|
|
overshow: false,
|
|
confirmAvatarUrl: that.data.avatarUrl,
|
|
confirmAvatarUrl: that.data.avatarUrl,
|
|
- confirmNickname: that.data.nickname.length > 4 ? that.data.nickname.substring(0,4) : that.data.nickname
|
|
|
|
|
|
+ confirmNickname: that.data.nickname
|
|
})
|
|
})
|
|
app.globalData.userInfo.headImg = that.data.confirmAvatarUrl
|
|
app.globalData.userInfo.headImg = that.data.confirmAvatarUrl
|
|
app.globalData.userInfo.userName = that.data.confirmNickname
|
|
app.globalData.userInfo.userName = that.data.confirmNickname
|