兰宝车间质量管理系统-前端
thiszhc
2023-07-01 6e3aec7c50c1dadcbbafbd5f04880f5395480f67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<template>
  <div v-loading="loading" class="social-login"></div>
</template>
 
<script setup lang="ts">
import { socialLogin } from '@/api/login';
import { setToken } from '@/utils/auth';
import Cookies from 'js-cookie';
import { getToken } from '@/utils/auth';
import router from '@/router';
 
const route = useRoute();
const loading = ref(true);
 
 
/**
 * 接收Route传递的参数
 * @param {Object} route.query.
 */
const code = route.query.code;
const state = route.query.state;
const source = route.query.source as string;
const tenantId = Cookies.get("tenantId") ? Cookies.get("tenantId") as string : '000000';
 
/**
 * 通过code获取token
 * @param {string} source
 * @param {string} code
 * @param {string} state
 */
await socialLogin(source, tenantId, code, state)
  .then(async (res) => {
    if (res.code !== 200) {
      ElMessage.error(res.msg);
      location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
      return;
    }
    loading.value = false;
    setToken(res.data.access_token)
    ElMessage.success(res.msg);
    location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
  })
  .catch(() => {
    loading.value = false;
  });
</script>