一键登录流程

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

@@ -58,11 +58,21 @@ const secretService = (name) =>{
}) })
} }
// 一键登录
const keyAuth = (data) => {
return request({
url: 'user/socialite/login/unicloud/app',
method: 'POST',
data: data
}, true)
}
export { export {
smsAuth, smsAuth,
getInvitationSms, getInvitationSms,
getSms, getSms,
userFigure, userFigure,
createUser, createUser,
secretService secretService,
keyAuth
} }

View File

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

View File

@@ -90,7 +90,6 @@
success : e => { success : e => {
if(e.confirm){ if(e.confirm){
this.$store.commit('setToken', ''); this.$store.commit('setToken', '');
this.$store.commit('setIsNew', 0);
this.$Router.replaceAll({name: 'Auth'}); this.$Router.replaceAll({name: 'Auth'});
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long