一键登录流程

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 {
smsAuth,
getInvitationSms,
getSms,
userFigure,
createUser,
secretService
secretService,
keyAuth
}

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 () {
// 预登录
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'})
}
}
}

View File

@@ -90,7 +90,6 @@
success : e => {
if(e.confirm){
this.$store.commit('setToken', '');
this.$store.commit('setIsNew', 0);
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