一键登录流程

This commit is contained in:
唐明明
2022-06-16 16:58:46 +08:00
parent ede11bb688
commit b5bcfef6c0
6 changed files with 3995 additions and 3952 deletions

View File

@@ -22,7 +22,7 @@
<view class="auth-agreement">
登录即表示同意<navigator hover-class="none" url="/pages/vip/agreement?id=3">用户协议</navigator><navigator hover-class="none" url="/pages/vip/agreement?id=4">隐私政策</navigator>
</view>
<view class="auth-other">
<view class="auth-other" v-if="isKeyAuth">
<button @click="login('Akey')">使用本机号码一键登录</button>
</view>
</view>
@@ -32,7 +32,8 @@
<script>
import {
smsAuth,
getInvitationSms
getInvitationSms,
keyAuth
} from '@/apis/interfaces/auth.js'
export default {
data() {
@@ -42,11 +43,18 @@
parentId : '',
getSms : false,
sendCode : '获取验证码',
isShowParent: false
isShowParent: false,
isKeyAuth : false
};
},
created() {
created () {
// 预登录
uni.preLogin({
provider: 'univerify',
success: res => {
this.isKeyAuth = true
}
})
},
methods: {
// 获取验证码
@@ -95,14 +103,7 @@
code : this.code,
parent_id : this.parentId
}).then((res) => {
this.$store.commit('setToken', res.token_type + ' ' + res.access_token);
if(res.is_new){
uni.setStorageSync('isnew', 0)
this.$Router.replace({name: 'AuthRole'})
return
}
uni.setStorageSync('isnew', 1)
this.$Router.pushTab({name: 'Life'})
this.setAuthToken(res.token_type + ' ' + res.access_token, res.is_new)
uni.hideLoading()
}).catch((err) => {
uni.showToast({
@@ -138,13 +139,39 @@
checkedImage: require('@/static/icon/checked-icon.png')
}
},
success: res => {
console.log(res)
success: Result => {
if(Result.errMsg === 'login:ok'){
let {access_token, openid} = Result.authResult
keyAuth({
access_token,
openid
}).then(res => {
this.setAuthToken(res.token_type + ' ' + res.access_token, res.is_new)
uni.closeAuthView()
}).catch(err => {
uni.showToast({
title: '登录失败:' + err.message,
icon : 'none'
})
uni.closeAuthView()
})
}
},
fail: err => {
console.log(err)
}
})
},
// setToken
setAuthToken(token, isNew){
this.$store.commit('setToken', token);
if(isNew){
uni.setStorageSync('isnew', 0)
this.$Router.replace({name: 'AuthRole'})
return
}
uni.setStorageSync('isnew', 1)
this.$Router.pushTab({name: 'Life'})
}
}
}