|
@@ -1,74 +1,41 @@
|
|
|
"use client";
|
|
"use client";
|
|
|
|
|
|
|
|
-import { Modal } from "antd";
|
|
|
|
|
-
|
|
|
|
|
require("../polyfill");
|
|
require("../polyfill");
|
|
|
-import { useState, useEffect } from "react";
|
|
|
|
|
|
|
+import React, {
|
|
|
|
|
+ useState,
|
|
|
|
|
+ useEffect
|
|
|
|
|
+} from "react";
|
|
|
import {
|
|
import {
|
|
|
HashRouter as Router,
|
|
HashRouter as Router,
|
|
|
Routes,
|
|
Routes,
|
|
|
Route,
|
|
Route,
|
|
|
- useLocation,
|
|
|
|
|
- useNavigate
|
|
|
|
|
|
|
+ useLocation
|
|
|
} from "react-router-dom";
|
|
} from "react-router-dom";
|
|
|
import styles from "./home.module.scss";
|
|
import styles from "./home.module.scss";
|
|
|
-import BotIcon from "../icons/bot.svg";
|
|
|
|
|
import loadingIcon from "../icons/loading.gif";
|
|
import loadingIcon from "../icons/loading.gif";
|
|
|
-import { getCSSVar, useMobileScreen } from "../utils";
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ getCSSVar,
|
|
|
|
|
+ useMobileScreen
|
|
|
|
|
+} from "../utils";
|
|
|
import dynamic from "next/dynamic";
|
|
import dynamic from "next/dynamic";
|
|
|
import { Path, SlotID } from "../constant";
|
|
import { Path, SlotID } from "../constant";
|
|
|
import { ErrorBoundary } from "./error";
|
|
import { ErrorBoundary } from "./error";
|
|
|
-import { getISOLang, getLang } from "../locales";
|
|
|
|
|
|
|
+import { getISOLang } from "../locales";
|
|
|
import { SideBar } from "./sidebar";
|
|
import { SideBar } from "./sidebar";
|
|
|
import { useAppConfig } from "../store/config";
|
|
import { useAppConfig } from "../store/config";
|
|
|
-import { AuthPage } from "./auth";
|
|
|
|
|
import { getClientConfig } from "../config/client";
|
|
import { getClientConfig } from "../config/client";
|
|
|
import { type ClientApi, getClientApi } from "../client/api";
|
|
import { type ClientApi, getClientApi } from "../client/api";
|
|
|
-import { useAccessStore } from "../store";
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ useAccessStore
|
|
|
|
|
+} from "../store";
|
|
|
import api from "../api/api";
|
|
import api from "../api/api";
|
|
|
|
|
|
|
|
export function Loading() {
|
|
export function Loading() {
|
|
|
- /** second版本注释掉进度条 */
|
|
|
|
|
- // const [progress, setProgress] = useState(1);
|
|
|
|
|
- //
|
|
|
|
|
- // useEffect(() => {
|
|
|
|
|
- // let isMounted = true;
|
|
|
|
|
- //
|
|
|
|
|
- // const intervalId = setInterval(() => {
|
|
|
|
|
- // if (isMounted && progress < 100) {
|
|
|
|
|
- // // 每隔一段时间增加1%进度
|
|
|
|
|
- // setProgress(prevProgress => prevProgress + 1);
|
|
|
|
|
- // }
|
|
|
|
|
- // }, 30);// 每10毫秒更新1%进度
|
|
|
|
|
- //
|
|
|
|
|
- // return () => {
|
|
|
|
|
- // isMounted = false;
|
|
|
|
|
- // clearInterval(intervalId);
|
|
|
|
|
- // };
|
|
|
|
|
- // }, [progress]);
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className={styles["loading-content"] + " no-dark"}>
|
|
<div className={styles["loading-content"] + " no-dark"}>
|
|
|
<img src={loadingIcon.src} />
|
|
<img src={loadingIcon.src} />
|
|
|
- {/* seceond版本注释掉进度条 */}
|
|
|
|
|
- {/* <div style={{ width: '60%', height: 15, background: '#F5F6F9', borderRadius: 8, marginTop: '20%', position: 'relative' }}> */}
|
|
|
|
|
- {/* <div */}
|
|
|
|
|
- {/* style={{ */}
|
|
|
|
|
- {/* width: `${progress}%`, */}
|
|
|
|
|
- {/* height: 15, */}
|
|
|
|
|
- {/* background: '#265C7D', */}
|
|
|
|
|
- {/* borderRadius: 8, */}
|
|
|
|
|
- {/* display: 'flex', */}
|
|
|
|
|
- {/* justifyContent: 'flex-end', */}
|
|
|
|
|
- {/* alignItems: 'center', */}
|
|
|
|
|
- {/* position: 'absolute' */}
|
|
|
|
|
- {/* }} */}
|
|
|
|
|
- {/* > */}
|
|
|
|
|
- {/* <div style={{ color: '#FFFFFF', fontSize: 12, lineHeight: 12, marginRight: 4 }}> */}
|
|
|
|
|
- {/* {progress}% */}
|
|
|
|
|
- {/* </div> */}
|
|
|
|
|
- {/* </div> */}
|
|
|
|
|
- {/* </div> */}
|
|
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
@@ -242,7 +209,6 @@ function Screen() {
|
|
|
const config = useAppConfig();
|
|
const config = useAppConfig();
|
|
|
const location = useLocation();
|
|
const location = useLocation();
|
|
|
const isArtifact = location.pathname.includes(Path.Artifacts);
|
|
const isArtifact = location.pathname.includes(Path.Artifacts);
|
|
|
- const isAuth = location.pathname === Path.Auth;
|
|
|
|
|
|
|
|
|
|
const isMobileScreen = useMobileScreen();
|
|
const isMobileScreen = useMobileScreen();
|
|
|
const shouldTightBorder = getClientConfig()?.isApp || (config.tightBorder && !isMobileScreen);
|
|
const shouldTightBorder = getClientConfig()?.isApp || (config.tightBorder && !isMobileScreen);
|
|
@@ -260,8 +226,6 @@ function Screen() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const renderContent = () => {
|
|
const renderContent = () => {
|
|
|
- if (isAuth) return <AuthPage />;
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
{
|
|
{
|
|
@@ -329,119 +293,6 @@ export function Home() {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const jkLogin = async (data: { code: string, redirectUrl: string }, url: string) => {
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await api.post('jk_code_login', data);
|
|
|
|
|
- localStorage.setItem('userInfo', JSON.stringify(res.data));
|
|
|
|
|
- location.replace(url);
|
|
|
|
|
- } catch (error: any) {
|
|
|
|
|
- Modal.error({
|
|
|
|
|
- title: '登录失败',
|
|
|
|
|
- content: error.msg,
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const frameLogin = async (data: { clientId: string,
|
|
|
|
|
- workspaceId: string,
|
|
|
|
|
- workspaceName: string,
|
|
|
|
|
- userName: string,
|
|
|
|
|
- timestamp: string,
|
|
|
|
|
- signature: string }, url: string,fullUrl:string) => {
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await api.post('frame_login', data);
|
|
|
|
|
- localStorage.setItem('userInfo', JSON.stringify(res.data));
|
|
|
|
|
- location.replace(url);
|
|
|
|
|
- } catch (error: any) {
|
|
|
|
|
- Modal.error({
|
|
|
|
|
- title: '登录失败',
|
|
|
|
|
- content: error.msg,
|
|
|
|
|
- });
|
|
|
|
|
- //停留5秒
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- toUninLogin(url,fullUrl);
|
|
|
|
|
- }, 5000);
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const toUninLogin = async (originUrl:string, fullUrl:string) => {
|
|
|
|
|
- //测试环境
|
|
|
|
|
- //const loginUrl = 'https://esctest.sribs.com.cn/esc-sso/oauth2.0/authorize?client_id=e97f94cf93761f4d69e8&response_type=code';
|
|
|
|
|
- //生产环境
|
|
|
|
|
- const loginUrl = 'http://esc.sribs.com.cn:8080/esc-sso/oauth2.0/authorize?client_id=e97f94cf93761f4d69e8&response_type=code';
|
|
|
|
|
- const externalLoginUrl = loginUrl + `&redirect_uri=${encodeURIComponent(originUrl)}&state=${encodeURIComponent(fullUrl)}`;
|
|
|
|
|
- location.replace(externalLoginUrl);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- // ==============
|
|
|
|
|
- // 环境开关:暂时屏蔽 toUninLogin 跳转验证
|
|
|
|
|
- // 说明:设置 NEXT_PUBLIC_DISABLE_UNIN_LOGIN=1 时,跳过所有统一登录跳转
|
|
|
|
|
- // 用法:
|
|
|
|
|
- // 1) 临时禁用:NEXT_PUBLIC_DISABLE_UNIN_LOGIN=1 yarn dev
|
|
|
|
|
- // 2) 或在 .env.local 中加入 NEXT_PUBLIC_DISABLE_UNIN_LOGIN=1
|
|
|
|
|
- // ==============
|
|
|
|
|
- // const DISABLE_UNIN_LOGIN = typeof process !== 'undefined' && process.env.NEXT_PUBLIC_DISABLE_UNIN_LOGIN === '1';
|
|
|
|
|
- // if (DISABLE_UNIN_LOGIN) {
|
|
|
|
|
- // console.log('[Home] 统一登录验证已禁用,跳过 toUninLogin 验证');
|
|
|
|
|
- // return;
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // const loginRes = { "nickName": "建科咨询虚拟账号", "userId": "2222331845498970571", "token": "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjAyMDE4Mzg0LTFmNjctNDhkYi05NjNiLTJkOGNhMDMxNTkzMiJ9.zTkTv8gDgJN7tfyxJko_zG1VsESlZACeYkpdMbITqnIpIfvHkZo8l8_Kcv6zo77GnuDyzdpOEt-GzPufD2Ye8A" };
|
|
|
|
|
- // if (loginRes) {
|
|
|
|
|
- // return localStorage.setItem('userInfo', JSON.stringify(loginRes));
|
|
|
|
|
- // }
|
|
|
|
|
- const originUrl = window.location.origin;
|
|
|
|
|
- const fullUrl = window.location.href;
|
|
|
|
|
- const urlParams = new URLSearchParams(new URL(fullUrl).search);
|
|
|
|
|
- const code = urlParams.get('code');
|
|
|
|
|
- const state = urlParams.get('state');
|
|
|
|
|
- const userInfo = localStorage.getItem('userInfo');
|
|
|
|
|
-
|
|
|
|
|
- if (fullUrl.includes(originUrl + '/?code') && code && state) {// 通过code登陆
|
|
|
|
|
- if (!userInfo) {
|
|
|
|
|
- jkLogin({ code: code, redirectUrl: encodeURIComponent(originUrl) }, state);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- if (!userInfo) {
|
|
|
|
|
- //判断是否是frame方式联登/frame
|
|
|
|
|
- if (fullUrl.includes(originUrl + '/?frame=Y')) {
|
|
|
|
|
-
|
|
|
|
|
- const workspaceId = urlParams.get('workspace_id');
|
|
|
|
|
- const workspaceName = urlParams.get('workspace_name');
|
|
|
|
|
- const username = urlParams.get('username');
|
|
|
|
|
- const clientId = urlParams.get('client_id');
|
|
|
|
|
- const timestamp = urlParams.get('timestamp');
|
|
|
|
|
- const signature = urlParams.get('signature');
|
|
|
|
|
- if (!clientId || !workspaceId || !workspaceName || !username || !timestamp || !signature) {
|
|
|
|
|
- // 处理缺失参数的情况
|
|
|
|
|
- Modal.error({
|
|
|
|
|
- title: '参数错误',
|
|
|
|
|
- content: '缺少必要的参数',
|
|
|
|
|
- });
|
|
|
|
|
- //停留5秒
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- toUninLogin(originUrl,fullUrl);
|
|
|
|
|
- }, 5000);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- frameLogin({
|
|
|
|
|
- clientId: clientId,
|
|
|
|
|
- workspaceId: workspaceId,
|
|
|
|
|
- workspaceName: workspaceName,
|
|
|
|
|
- userName: username,
|
|
|
|
|
- timestamp: timestamp,
|
|
|
|
|
- signature: signature
|
|
|
|
|
- },originUrl,fullUrl);
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- toUninLogin(originUrl,fullUrl);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }, []);
|
|
|
|
|
-
|
|
|
|
|
if (!useHasHydrated()) {
|
|
if (!useHasHydrated()) {
|
|
|
return <Loading />;
|
|
return <Loading />;
|
|
|
}
|
|
}
|