update 优化 !pr370 完成三方登录授权功能

This commit is contained in:
疯狂的狮子Li
2023-06-20 15:00:29 +08:00
committed by Michelle.Chung
parent 3b4ac3e525
commit 7340997cf5
6 changed files with 10 additions and 22 deletions

View File

@ -0,0 +1,36 @@
<template>
<div v-loading="loading" class="social-login"></div>
</template>
<script setup lang="ts">
import {socialLogin} from '@/api/login';
import {setToken} from '@/utils/auth';
const route = useRoute();
const router = useRouter();
/**
* 接收Route传递的参数
* @param {Object} route.query.
*/
const code = route.query.code;
const state = route.query.state;
const source = route.query.source as string;
const loading = ref(true);
await socialLogin(source, code, state)
.then(async (res) => {
if (res.code !== 200) {
ElMessage.error(res.msg);
router.go(-2);
return;
}
loading.value = false;
setToken(res.msg);
ElMessage.success('登录成功');
router.go(-2);
})
.catch(() => {
loading.value = false;
});
</script>