feat: light app center and iframe refactor
This commit is contained in:
1 parent
728a4b1170
commit
9d73f27146
35 files changed
+1878
-246
No files matched your search
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 统一的外部 iframe 嵌套页渲染组件。
|
||||
*
|
||||
* XK / PG / TY 任务、资源管理等所有「把外部系统嵌进来」的页面共用此组件,
|
||||
* 只负责把已构造好的 `src` 稳健地渲染出来。URL 构造逻辑收敛在
|
||||
* `@/core/strategy/external-links`,各业务页只做薄封装。
|
||||
*
|
||||
* 关键点 —— `key={src}`:当地址变化(如 XK 在菜单间切换 gopath,只改 hash 片段)时,
|
||||
* 强制 React 重挂载一个全新的 iframe,触发完整加载,避免「只改 hash 时浏览器不重载、
|
||||
* 内嵌 SPA 来不及切换路由」导致的页面没变化问题。
|
||||
*/
|
||||
import { useTheme } from "@/contexts/ThemeContext";
|
||||
import "../task-components/css/iframe.css";
|
||||
|
||||
interface ExternalIframePageProps {
|
||||
/** 已构造好的完整地址;为空时展示加载占位(异步取址场景)。 */
|
||||
src: string;
|
||||
title?: string;
|
||||
loadingText?: string;
|
||||
}
|
||||
|
||||
export default function ExternalIframePage({
|
||||
src,
|
||||
title,
|
||||
loadingText = "加载中…",
|
||||
}: ExternalIframePageProps) {
|
||||
const { theme } = useTheme();
|
||||
const isDark = theme === "dark";
|
||||
|
||||
if (!src) {
|
||||
return (
|
||||
<div className={`flex h-full w-full items-center justify-center text-sm ${isDark ? "text-slate-400" : "text-slate-500"}`}>
|
||||
{loadingText}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="iframe-container">
|
||||
<iframe key={src} src={src} title={title} className="full-size-iframe" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+3
-6
@@ -5,11 +5,12 @@ import {
|
||||
getKnowledgeIframeSkin,
|
||||
} from "@/core/strategy/external-links";
|
||||
import { requestCrudService } from "@/service/request-axios-service";
|
||||
import "@/strategy-components/components/task-components/css/strategy-data.css";
|
||||
import ExternalIframePage from "../common/ExternalIframePage";
|
||||
|
||||
const service = requestCrudService;
|
||||
|
||||
const KnowledgeBaseResourceManagement: React.FC = () => {
|
||||
// 知识库地址需异步调接口换取(区别于其它 env 直拼的 iframe 页)。
|
||||
const [iframeUrl, setIframeUrl] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -40,11 +41,7 @@ const KnowledgeBaseResourceManagement: React.FC = () => {
|
||||
void initIframeUrl();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="strategy-data iframe-container">
|
||||
<iframe src={iframeUrl} className="full-size-iframe" title="知识库资源管理" />
|
||||
</div>
|
||||
);
|
||||
return <ExternalIframePage src={iframeUrl} title="知识库资源管理" />;
|
||||
};
|
||||
|
||||
export default KnowledgeBaseResourceManagement;
|
||||
+4
-13
@@ -1,20 +1,11 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useMemo } from "react";
|
||||
|
||||
import { getNetworkActorIframeUrl } from "@/core/strategy/external-links";
|
||||
import "@/strategy-components/components/task-components/css/strategy-data.css";
|
||||
import ExternalIframePage from "../common/ExternalIframePage";
|
||||
|
||||
const NetworkActorResourceManagement: React.FC = () => {
|
||||
const [iframeUrl, setIframeUrl] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
setIframeUrl(getNetworkActorIframeUrl());
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="strategy-data iframe-container">
|
||||
<iframe src={iframeUrl} className="full-size-iframe" title="网络xwt资源管理" />
|
||||
</div>
|
||||
);
|
||||
const src = useMemo(() => getNetworkActorIframeUrl(), []);
|
||||
return <ExternalIframePage src={src} title="网络xwt资源管理" />;
|
||||
};
|
||||
|
||||
export default NetworkActorResourceManagement;
|
||||
@@ -1,27 +0,0 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import "./css/iframe.css";
|
||||
|
||||
import { useTheme } from "@/contexts/ThemeContext";
|
||||
|
||||
const TYURL = import.meta.env.VITE_AIPI_B2ACTOR_URL || "";
|
||||
|
||||
const FanganTyPage: React.FC = () => {
|
||||
const { theme } = useTheme();
|
||||
const isDark = theme === "dark";
|
||||
const [iframeUrl, setIframeUrl] = useState("");
|
||||
useEffect(() => {
|
||||
initIframeUrl();
|
||||
}, []);
|
||||
const initIframeUrl = () => {
|
||||
const url = `${TYURL}/fromB/toPage?defaultPage=iframeFaty`;
|
||||
console.log({ iframeUrl: url });
|
||||
setIframeUrl(url);
|
||||
};
|
||||
return (
|
||||
<div className="iframe-container">
|
||||
<iframe src={iframeUrl} className="full-size-iframe"></iframe>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default FanganTyPage;
|
||||
@@ -1,24 +1,16 @@
|
||||
import { Outlet, useNavigate } from 'react-router-dom';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import React, { useMemo } from "react";
|
||||
|
||||
import { getPgIframeUrl } from "@/core/strategy/external-links";
|
||||
import ExternalIframePage from "../common/ExternalIframePage";
|
||||
|
||||
const userInfo = localStorage.getItem('userInfo');
|
||||
const pgLinkUrl = import.meta.env.VITE_AIPI_PGLINKTO_URL;
|
||||
interface TaskPgFromProps {
|
||||
gopath: string
|
||||
gopath: string;
|
||||
}
|
||||
const TaskPgFrom: React.FC<TaskPgFromProps> = ({gopath}) => {
|
||||
const [pgUrl, setPgUrl] = useState(pgLinkUrl);
|
||||
useEffect(() => {
|
||||
if(userInfo) {
|
||||
const userData = JSON.parse(userInfo);
|
||||
setPgUrl(`${pgUrl}?access_token=${userData.accessToken}&goPath=${gopath}`);
|
||||
}
|
||||
}, [gopath]);
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<iframe className="h-[calc(100vh-92px)]" src={pgUrl}></iframe>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default TaskPgFrom
|
||||
|
||||
const TaskPgFrom: React.FC<TaskPgFromProps> = ({ gopath }) => {
|
||||
// 每次从 base 重建(修复原先用状态做模板导致查询串累加的 bug);key={src} 强制重载。
|
||||
const src = useMemo(() => getPgIframeUrl(gopath), [gopath]);
|
||||
return <ExternalIframePage src={src} title="PG中任务" />;
|
||||
};
|
||||
|
||||
export default TaskPgFrom;
|
||||
@@ -0,0 +1,18 @@
|
||||
import React, { useMemo } from "react";
|
||||
|
||||
import { getTyIframeUrl } from "@/core/strategy/external-links";
|
||||
import ExternalIframePage from "../common/ExternalIframePage";
|
||||
|
||||
interface TaskTyFromProps {
|
||||
/** TY 系统页标识:iframeXdty(行动)/ iframeFaty(方案)/ iframeSysystem(综合)。 */
|
||||
defaultPage: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
/** TY 中任务统一入口(原 XingdongTy / FanganTy / XXTy 合并)。 */
|
||||
const TaskTyFrom: React.FC<TaskTyFromProps> = ({ defaultPage, title }) => {
|
||||
const src = useMemo(() => getTyIframeUrl(defaultPage), [defaultPage]);
|
||||
return <ExternalIframePage src={src} title={title} />;
|
||||
};
|
||||
|
||||
export default TaskTyFrom;
|
||||
@@ -1,23 +1,16 @@
|
||||
import { Outlet, useNavigate } from 'react-router-dom';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
const userInfo = localStorage.getItem('userInfo');
|
||||
const xkLinkUrl = import.meta.env.VITE_AIPI_XKLINKTO_URL;
|
||||
interface TaskPgFromProps {
|
||||
gopath: string
|
||||
import React, { useMemo } from "react";
|
||||
|
||||
import { getXkIframeUrl } from "@/core/strategy/external-links";
|
||||
import ExternalIframePage from "../common/ExternalIframePage";
|
||||
|
||||
interface TaskXkFromProps {
|
||||
gopath: string;
|
||||
}
|
||||
const TaskXkFrom: React.FC<TaskPgFromProps> = ({gopath}) => {
|
||||
const [xkUrl, setXkUrl] = useState(xkLinkUrl);
|
||||
useEffect(() => {
|
||||
if(userInfo) {
|
||||
const userData: any = JSON.parse(userInfo);
|
||||
setXkUrl(`${xkLinkUrl}${gopath}?accessToken=${userData.accessToken}`);
|
||||
}
|
||||
}, [gopath]);
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<iframe className="h-[calc(100vh-92px)]" src={xkUrl}></iframe>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default TaskXkFrom
|
||||
|
||||
const TaskXkFrom: React.FC<TaskXkFromProps> = ({ gopath }) => {
|
||||
// gopath 变化(菜单切换)时从 base 重建地址;ExternalIframePage 的 key={src} 会强制重载。
|
||||
const src = useMemo(() => getXkIframeUrl(gopath), [gopath]);
|
||||
return <ExternalIframePage src={src} title="XK中任务" />;
|
||||
};
|
||||
|
||||
export default TaskXkFrom;
|
||||
@@ -1,27 +0,0 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import "./css/iframe.css";
|
||||
|
||||
import { useTheme } from "@/contexts/ThemeContext";
|
||||
|
||||
const TYURL = import.meta.env.VITE_AIPI_B2ACTOR_URL || "";
|
||||
|
||||
const XXTyPage: React.FC = () => {
|
||||
const { theme } = useTheme();
|
||||
const isDark = theme === "dark";
|
||||
const [iframeUrl, setIframeUrl] = useState("");
|
||||
useEffect(() => {
|
||||
initIframeUrl();
|
||||
}, []);
|
||||
const initIframeUrl = () => {
|
||||
const url = `${TYURL}/fromB/toPage?defaultPage=iframeSysystem`;
|
||||
console.log({ iframeUrl: url });
|
||||
setIframeUrl(url);
|
||||
};
|
||||
return (
|
||||
<div className="iframe-container">
|
||||
<iframe src={iframeUrl} className="full-size-iframe"></iframe>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default XXTyPage;
|
||||
@@ -1,27 +0,0 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import "./css/iframe.css";
|
||||
|
||||
import { useTheme } from "@/contexts/ThemeContext";
|
||||
|
||||
const TYURL = import.meta.env.VITE_AIPI_B2ACTOR_URL || "";
|
||||
|
||||
const XingdongTyPage: React.FC = () => {
|
||||
const { theme } = useTheme();
|
||||
const isDark = theme === "dark";
|
||||
const [iframeUrl, setIframeUrl] = useState("");
|
||||
useEffect(() => {
|
||||
initIframeUrl();
|
||||
}, []);
|
||||
const initIframeUrl = () => {
|
||||
const url = `${TYURL}/fromB/toPage?defaultPage=iframeXdty`;
|
||||
console.log({ iframeUrl: url });
|
||||
setIframeUrl(url);
|
||||
};
|
||||
return (
|
||||
<div className="iframe-container">
|
||||
<iframe src={iframeUrl} className="full-size-iframe"></iframe>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default XingdongTyPage;
|
||||
Reference in new issue
Block a user