广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-04 dbfd4bc96205dd957827ee16c1149058fc2b88bb
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';
import { getRgb } from '@sa/color';
import { DARK_CLASS } from '@/constants/app';
import { fetchSocialLoginCallback } from '@/service/api';
import { useAuthStore } from '@/store/modules/auth';
import { useRouterPush } from '@/hooks/common/router';
import { localStg } from '@/utils/storage';
import { toggleHtmlClass } from '@/utils/common';
 
const route = useRoute();
const authStore = useAuthStore();
const { routerPushByKey } = useRouterPush();
 
/**
 * 接收Route传递的参数
 *
 * @param {Object} route.query.
 */
const code = route.query.code as string;
const state = route.query.state as string;
const source = route.query.source as string;
const stateJson = state ? JSON.parse(atob(state)) : {};
const tenantId = (stateJson.tenantId as string) ?? '000000';
const domain = (stateJson.domain as string) ?? window.location.host;
const msg = ref('正在登录,请稍后......');
 
const processResponse = async () => {
  window.$message?.success('登录成功');
  msg.value = '登录成功,2s 后即将跳转至首页';
  setTimeout(() => {
    msg.value = '登录成功,1s 后即将跳转至首页';
  }, 1000);
  setTimeout(() => {
    routerPushByKey(import.meta.env.VITE_ROUTE_HOME || 'home');
  }, 1000);
};
 
const handleError = () => {
  msg.value = '登录失败,2s 后即将跳转至登录页';
  setTimeout(() => {
    msg.value = '登录失败,1s 后即将跳转至登录页';
  }, 1000);
  setTimeout(() => {
    routerPushByKey('login');
  }, 1000);
};
 
const callbackByCode = async (data: Api.Auth.SocialLoginForm) => {
  const { error } = await fetchSocialLoginCallback({
    ...data,
    clientId: import.meta.env.VITE_APP_CLIENT_ID,
    grantType: 'social'
  });
  if (error) {
    handleError();
    return;
  }
  await processResponse();
};
 
const loginByCode = async (data: Api.Auth.SocialLoginForm) => {
  try {
    await authStore.logout();
    await authStore.login(data);
    await processResponse();
  } catch {
    handleError();
  }
};
 
const init = 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;
  }
 
  const data: Api.Auth.SocialLoginForm = {
    socialCode: code,
    socialState: state,
    tenantId,
    source,
    grantType: 'social'
  };
 
  if (!authStore.isLogin) {
    await loginByCode(data);
  } else {
    await callbackByCode(data);
  }
};
 
onMounted(async () => {
  await init();
});
 
const themeColor = localStg.get('themeColor') || '#2080f0';
const darkMode = localStg.get('darkMode') || false;
const { r, g, b } = getRgb(themeColor);
 
if (darkMode) {
  toggleHtmlClass(DARK_CLASS).add();
}
 
const primaryColor = `--primary-color: ${r} ${g} ${b}`;
</script>
 
<template>
  <div class="fixed-center flex-col bg-layout" :style="primaryColor">
    <div class="my-52px h-120px w-120px">
      <!-- From Uiverse.io by SchawnnahJ -->
      <div class="loader"></div>
    </div>
    <h2 class="text-30px text-primary-400 font-500">{{ msg }}</h2>
  </div>
</template>
 
<style lang="scss" scoped>
@use '@/styles/scss/loading.scss';
</style>