|
|
@@ -22,6 +22,7 @@ import { AuthPage } from "./auth";
|
|
|
import { getClientConfig } from "../config/client";
|
|
|
import { type ClientApi, getClientApi } from "../client/api";
|
|
|
import { useAccessStore } from "../store";
|
|
|
+import api from "../api/api";
|
|
|
|
|
|
export function Loading() {
|
|
|
/** second版本注释掉进度条 */
|
|
|
@@ -159,7 +160,6 @@ const MaskPage = dynamic(
|
|
|
}
|
|
|
);
|
|
|
|
|
|
-
|
|
|
export function useSwitchTheme() {
|
|
|
const config = useAppConfig();
|
|
|
|
|
|
@@ -241,7 +241,6 @@ function Screen() {
|
|
|
const isArtifact = location.pathname.includes(Path.Artifacts);
|
|
|
const isAuth = location.pathname === Path.Auth;
|
|
|
|
|
|
-
|
|
|
const isMobileScreen = useMobileScreen();
|
|
|
const shouldTightBorder =
|
|
|
getClientConfig()?.isApp || (config.tightBorder && !isMobileScreen);
|
|
|
@@ -261,7 +260,6 @@ function Screen() {
|
|
|
const renderContent = () => {
|
|
|
if (isAuth) return <AuthPage />;
|
|
|
|
|
|
-
|
|
|
return (
|
|
|
<>
|
|
|
{
|
|
|
@@ -301,7 +299,6 @@ export function useLoadData() {
|
|
|
const models = await api.llm.models();
|
|
|
config.mergeModels(models);
|
|
|
})();
|
|
|
- // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
}, []);
|
|
|
}
|
|
|
|
|
|
@@ -311,10 +308,43 @@ export function Home() {
|
|
|
useHtmlLang();
|
|
|
|
|
|
useEffect(() => {
|
|
|
- // console.log("[Config] got config from build time", getClientConfig());
|
|
|
useAccessStore.getState().fetch();
|
|
|
}, []);
|
|
|
|
|
|
+ const jkLogin = async (code: string, url: string) => {
|
|
|
+ console.log(code, '使用code换取token');
|
|
|
+ console.log(url, '登录成功后要跳转回登陆前的页面');
|
|
|
+ try {
|
|
|
+ const res = await api.post('jk_code_login', { code: code });
|
|
|
+ localStorage.setItem('userInfo', JSON.stringify(res.data));
|
|
|
+ window.open(url, '_self');
|
|
|
+ } catch (error) {
|
|
|
+ const originUrl = window.location.origin;
|
|
|
+ window.open(originUrl, '_self');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ 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, state);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const loginUrl = 'https://esctest.sribs.com.cn/esc-sso/oauth2.0/authorize?client_id=e971e84b574c40b2&response_type=code';
|
|
|
+ const externalLoginUrl = loginUrl + `&redirect_uri=${encodeURIComponent(originUrl)}&state=${encodeURIComponent(fullUrl)}`;
|
|
|
+ if (!userInfo) {
|
|
|
+ window.open(externalLoginUrl, '_self');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
if (!useHasHydrated()) {
|
|
|
return <Loading />;
|
|
|
}
|