perf:优化OAuth登录
This commit is contained in:
parent
f10f608d9a
commit
6061592084
@ -42,11 +42,12 @@ const useUserStore = defineStore('user', {
|
||||
/**
|
||||
* 三方授权登录
|
||||
* @param {*} data
|
||||
* @param { *} param { authSource : ''}
|
||||
* @returns
|
||||
*/
|
||||
oauthLogin(data) {
|
||||
oauthLogin(data, param) {
|
||||
return new Promise((resolve, reject) => {
|
||||
oauthCallback(data, { authSource: this.authSource }).then(res => {
|
||||
oauthCallback(data, param).then(res => {
|
||||
const { code, data } = res
|
||||
if (code == 200) {
|
||||
setToken(data.token)
|
||||
@ -59,8 +60,6 @@ const useUserStore = defineStore('user', {
|
||||
console.log('login error ', res)
|
||||
reject(res) //catch处理
|
||||
}
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
@ -56,7 +56,7 @@
|
||||
<div class="other-login">
|
||||
<el-divider>{{ $t('login.otherLoginWay') }}</el-divider>
|
||||
<img src="../assets/icons/gitee-fill-round.png" alt="" class="login-icon" @click="onAuth('GITEE')" />
|
||||
<img src="../assets/icons/github-fill.png" alt="" class="login-icon" />
|
||||
<img src="../assets/icons/github-fill.png" alt="" class="login-icon" @click="onAuth('GITHUB')" />
|
||||
<img src="../assets/icons/wechat-fill.png" alt="" class="login-icon" />
|
||||
</div>
|
||||
</el-form>
|
||||
|
||||
@ -30,18 +30,20 @@ const userStore = useUserStore()
|
||||
const loginForm = ref(undefined)
|
||||
const callbackQuery = ref(undefined)
|
||||
const redirect = ref(undefined)
|
||||
const authSource = ref('')
|
||||
const loading = ref(false)
|
||||
callbackQuery.value = getQueryObject()
|
||||
redirect.value = route.query.redirect
|
||||
authSource.value = route.query.authSource
|
||||
|
||||
const userInfo = computed(() => {
|
||||
return userStore.userInfo
|
||||
})
|
||||
console.log(userInfo.value)
|
||||
if (callbackQuery.value && callbackQuery.value.state != null) {
|
||||
loading.value = true
|
||||
// 调用action的登录方法
|
||||
userStore
|
||||
.oauthLogin(callbackQuery.value)
|
||||
.oauthLogin(callbackQuery.value, { authSource: authSource.value })
|
||||
.then(() => {
|
||||
proxy.$modal.msgSuccess(proxy.$t('login.loginSuccess'))
|
||||
router.push({ path: redirect.value || '/' })
|
||||
@ -57,6 +59,7 @@ if (callbackQuery.value && callbackQuery.value.state != null) {
|
||||
@import '@/assets/styles/login.scss';
|
||||
.loading {
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
color: #ccc;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user