perf:优化OAuth登录

This commit is contained in:
不做码农 2022-06-25 17:17:30 +08:00
parent f10f608d9a
commit 6061592084
3 changed files with 10 additions and 8 deletions

View File

@ -42,11 +42,12 @@ const useUserStore = defineStore('user', {
/** /**
* 三方授权登录 * 三方授权登录
* @param {*} data * @param {*} data
* @param { *} param { authSource : ''}
* @returns * @returns
*/ */
oauthLogin(data) { oauthLogin(data, param) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
oauthCallback(data, { authSource: this.authSource }).then(res => { oauthCallback(data, param).then(res => {
const { code, data } = res const { code, data } = res
if (code == 200) { if (code == 200) {
setToken(data.token) setToken(data.token)
@ -59,8 +60,6 @@ const useUserStore = defineStore('user', {
console.log('login error ', res) console.log('login error ', res)
reject(res) //catch处理 reject(res) //catch处理
} }
}).catch(error => {
reject(error)
}) })
}) })
}, },

View File

@ -56,7 +56,7 @@
<div class="other-login"> <div class="other-login">
<el-divider>{{ $t('login.otherLoginWay') }}</el-divider> <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/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" /> <img src="../assets/icons/wechat-fill.png" alt="" class="login-icon" />
</div> </div>
</el-form> </el-form>

View File

@ -30,18 +30,20 @@ const userStore = useUserStore()
const loginForm = ref(undefined) const loginForm = ref(undefined)
const callbackQuery = ref(undefined) const callbackQuery = ref(undefined)
const redirect = ref(undefined) const redirect = ref(undefined)
const authSource = ref('')
const loading = ref(false) const loading = ref(false)
callbackQuery.value = getQueryObject() callbackQuery.value = getQueryObject()
redirect.value = route.query.redirect redirect.value = route.query.redirect
authSource.value = route.query.authSource
const userInfo = computed(() => { const userInfo = computed(() => {
return userStore.userInfo return userStore.userInfo
}) })
console.log(userInfo.value)
if (callbackQuery.value && callbackQuery.value.state != null) { if (callbackQuery.value && callbackQuery.value.state != null) {
loading.value = true loading.value = true
// action // action
userStore userStore
.oauthLogin(callbackQuery.value) .oauthLogin(callbackQuery.value, { authSource: authSource.value })
.then(() => { .then(() => {
proxy.$modal.msgSuccess(proxy.$t('login.loginSuccess')) proxy.$modal.msgSuccess(proxy.$t('login.loginSuccess'))
router.push({ path: redirect.value || '/' }) router.push({ path: redirect.value || '/' })
@ -57,6 +59,7 @@ if (callbackQuery.value && callbackQuery.value.state != null) {
@import '@/assets/styles/login.scss'; @import '@/assets/styles/login.scss';
.loading { .loading {
text-align: center; text-align: center;
color: #fff; color: #ccc;
padding: 10px;
} }
</style> </style>