Commit 492d6bea authored by linwenqing's avatar linwenqing

refactor:授权手机号修改

parent ac9b0001
......@@ -29,7 +29,7 @@
</view>
</view>
<view class="u-m-r-10 avatar">
<u-avatar class="avatar-iamge" :src="avatar" size="140"></u-avatar>
<u-avatar class="avatar-iamge" :src="avatar" size="160"></u-avatar>
</view>
</view>
<view class="">
......
......@@ -35,6 +35,7 @@ export default {
return {
title: '微信授权登录',
host: '', //配置为自己的额服务器即可
back: false, //跳回页面
}
},
computed: {
......@@ -42,7 +43,11 @@ export default {
return process.uniEnv.qn_base_url + 'LOGO@3x.png'
},
},
onShow() {},
onLoad(params) {
if (params && params.back) {
this.back = true
}
},
methods: {
wxLogin() {
// 获取code 小程序专有,用户登录凭证。
......@@ -68,6 +73,12 @@ export default {
})
this.$u.api.loginWechatAuth(data).then((res) => {
uni.hideLoading()
if (this.back) {
this.$u.route({
type: 'back',
})
return
}
this.$u.vuex('vuex_token', res.token)
this.$u.vuex('openId', res.openId)
this.$u.vuex('userInfo', userInfo)
......
......@@ -86,7 +86,7 @@ export default {
student: {
isCertify: false,
},
token: null,
qiToken: null,
code: '',
count: 0,
}
......@@ -126,7 +126,7 @@ export default {
.getQiNiuToken({ bucketName: 'banshou-userprofile' })
.then((res) => {
console.log('chushihua token', res)
this.token = res //token为七牛云的token一般由后台接口提供
this.qiToken = res //token为七牛云的token一般由后台接口提供
getApp().globalData.qiNiuToken = res
})
this.$u.api.getUserInfo().then((res) => {
......@@ -159,7 +159,6 @@ export default {
},
getPhonenumber(e) {
console.log('eeeee', e)
let that = this
let params = {}
if (e && e.detail) {
if (e.detail.errMsg.indexOf('user deny') > -1) {
......@@ -172,14 +171,14 @@ export default {
iv: e.detail.iv,
}
} else {
that.$u.toast(e.detail.errMsg)
this.$u.toast(e.detail.errMsg)
return
}
} else {
that.$u.toast('授权失败,请重新授权')
this.$u.toast('授权失败,请重新授权')
return
}
that.syncUserinfo(params)
this.syncUserinfo(params)
},
syncUserinfo(params) {
let that = this
......@@ -190,24 +189,12 @@ export default {
uni.login({
provider: 'weixin',
success: (code_res) => {
//获取code
if (code_res.errMsg == 'login:ok') {
console.log('走的第一个2')
params.code = code_res.code
that.$u.api
.loginWechatAuth(params)
.then((res) => {
that.student.phoneNumber = res.phoneNumber
that.$u.api
.updateUserInfo({
phoneNumber: res.phoneNumber,
})
.then((ret) => {
that.$u.toast('绑定成功!')
})
})
.catch((err) => {
that.toLogin()
})
//传参到服务器解析
that.sendInfo(params)
}
},
})
......@@ -215,26 +202,39 @@ export default {
fail() {
console.log('走的第二个1', params)
// session_key 已经失效,需要重新执行登录流程
that.count++
if (that.count > 1) {
console.log('重试次数大于1')
that.toLogin()
}
that.syncUserinfo(params)
setTimeout(() => {
uni.navigateTo({
url: 'pages/login/index',
})
}, 800)
},
})
},
toLogin() {
that.$u.toast('登录信息失效,请重新登录后重试')
setTimeout(() => {
uni.navigateTo({
url: 'pages/login/index',
sendInfo(params) {
this.$u.api
.loginWechatAuth(params)
.then((res) => {
this.student.phoneNumber = res.phoneNumber
this.$u.api
.updateUserInfo({
phoneNumber: res.phoneNumber,
})
.then((ret) => {
this.$u.toast('绑定成功!')
})
})
.catch((err) => {
this.$u.route({
url: 'pages/login/index',
params: {
back: true,
},
})
})
}, 800)
},
changeHead() {
//获取图片
upload.getPhoto(2, this.token).then((res) => {
upload.getPhoto(2, this.qiToken).then((res) => {
this.student.avatarPath = process.uniEnv.qn_asset_url + res.key
this.$u.api.updateUserInfo({
avatarPath: this.student.avatarPath,
......@@ -243,7 +243,7 @@ export default {
},
changeCertPhoto() {
//获取图片
upload.getPhoto(2, this.token).then((res) => {
upload.getPhoto(2, this.qiToken).then((res) => {
//显示
this.student.certificatePhotoPath =
process.uniEnv.qn_asset_url + res.key
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment