办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<script setup lang="ts">
import type { AuthApi } from '#/api';
 
import { onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { DEFAULT_HOME_PATH, DEFAULT_TENANT_ID } from '@vben/constants';
import { useAccessStore } from '@vben/stores';
 
import { message } from 'ant-design-vue';
 
import { authCallback } from '#/api';
import { useAuthStore } from '#/store';
 
import { accountBindList } from '../oauth-common';
 
const route = useRoute();
 
const code = route.query.code as string;
const state = route.query.state as string;
const stateJson = JSON.parse(atob(state));
// 来源
const source = route.query.source as string;
// 租户ID
const defaultTenantId = DEFAULT_TENANT_ID;
const tenantId = (stateJson.tenantId as string) ?? defaultTenantId;
const domain = stateJson.domain as string;
 
const accessStore = useAccessStore();
const authStore = useAuthStore();
 
const router = useRouter();
 
onMounted(async () => {
  // 如果域名不相等 则重定向处理
  const host = window.location.host;
  if (domain !== host) {
    const urlFull = new URL(window.location.href);
    urlFull.host = domain;
    window.location.href = urlFull.toString();
    return;
  }
 
  try {
    // 已经实现的平台
    const currentClient = accountBindList.find(
      (item) => item.source === source,
    );
    if (!currentClient) {
      message.error({ content: `未找到${source}平台` });
      return;
    }
    const data: AuthApi.OAuthLoginParams = {
      grantType: 'social',
      socialCode: code,
      socialState: state,
      source,
      tenantId,
    };
    // 没有token为登录 有token是授权
    if (accessStore.accessToken) {
      await authCallback(data);
      message.success(`${source}授权成功`);
    } else {
      // todo
      await authStore.authLogin(data as any);
      message.success(`${source}登录成功`);
    }
  } catch {
    // 500 你还没有绑定第三方账号,绑定后才可以登录!
  } finally {
    setTimeout(() => {
      router.push(DEFAULT_HOME_PATH);
    }, 1500);
  }
});
</script>
 
<template>
  <div></div>
</template>
 
<style scoped></style>