2023-06-20 04:12:49 +00:00
|
|
|
<template>
|
|
|
|
<div v-loading="loading" class="social-login"></div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-07-01 02:26:58 +08:00
|
|
|
import { socialLogin } from '@/api/login';
|
|
|
|
import { setToken } from '@/utils/auth';
|
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
import { getToken } from '@/utils/auth';
|
|
|
|
import router from '@/router';
|
2023-06-20 04:12:49 +00:00
|
|
|
|
|
|
|
const route = useRoute();
|
2023-07-01 02:26:58 +08:00
|
|
|
const loading = ref(true);
|
2023-06-20 04:12:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 接收Route传递的参数
|
|
|
|
* @param {Object} route.query.
|
|
|
|
*/
|
|
|
|
const code = route.query.code;
|
|
|
|
const state = route.query.state;
|
|
|
|
const source = route.query.source as string;
|
2023-07-01 02:26:58 +08:00
|
|
|
const tenantId = Cookies.get("tenantId") ? Cookies.get("tenantId") as string : '000000';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过code获取token
|
|
|
|
* @param {string} source
|
|
|
|
* @param {string} code
|
|
|
|
* @param {string} state
|
|
|
|
*/
|
2023-07-01 15:05:48 +08:00
|
|
|
await socialLogin(source, tenantId, code, state)
|
2023-06-20 04:12:49 +00:00
|
|
|
.then(async (res) => {
|
|
|
|
if (res.code !== 200) {
|
|
|
|
ElMessage.error(res.msg);
|
2023-06-21 17:03:26 +08:00
|
|
|
location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
|
2023-06-20 04:12:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
loading.value = false;
|
2023-07-01 15:05:48 +08:00
|
|
|
setToken(res.data.access_token)
|
|
|
|
ElMessage.success(res.msg);
|
2023-06-21 17:03:26 +08:00
|
|
|
location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
|
2023-06-20 04:12:49 +00:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
loading.value = false;
|
|
|
|
});
|
|
|
|
</script>
|