| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- /*
- * @Author: your name
- * @Date: 2021-11-09 13:56:33
- * @LastEditTime: 2025-04-27 13:43:23
- * @LastEditors: code4eat awesomedema@gmail.com
- * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- * @FilePath: /KC-MiddlePlatform/src/layouts/index.tsx
- */
- import { IRouteComponentProps, useModel, history } from 'umi';
- import ProLayout from '@ant-design/pro-layout';
- import TopBar from '@/components/topBar';
- import { Key, useEffect, useRef, useState } from 'react';
- import { getSpecifyMenuDetail, getUserPlatformNav } from '@/service/menu';
- import { getAppAccess, getSysParamsByCode } from '@/service';
- import { Input, Modal } from 'antd';
- import './style.less';
- import { KcimCenterSysId } from '@/constant';
- import { askAiReq } from '@/service/ai';
- import { createFromIconfontCN } from '@ant-design/icons';
- import ReactMarkdown from 'react-markdown';
- import AiChat from '@/components/intelligenceBot';
- const TopHoc = ({
- currentSelectedSys,
- openedSysLists,
- navData,
- set_emptyPageContent,
- logo,
- topBarTitle,
- }: {
- set_emptyPageContent: any;
- currentSelectedSys: TopBar.Tab | undefined;
- openedSysLists: TopBar.Tab[];
- navData: TopBar.PanelData[];
- logo: string;
- topBarTitle: string;
- }) => {
- const { initialState, setInitialState } = useModel('@@initialState');
- const onTabChangeHandle = async (data: TopBar.Tab[]) => {};
- const onTabClickHandle = async (data: TopBar.Tab) => {
- const { systemId = '', menuId = '' } = data;
- const resp = await getAppAccess(systemId.length > 0 ? systemId : menuId);
- if (!resp) {
- if (JSON.stringify(data) != '{}') {
- if (data.contentType != 7) {
- await setInitialState((s) => ({ ...s, currentSelectedSys: data } as any));
- }
- localStorage.removeItem('selectedKeys');
- localStorage.removeItem('openKeys');
- if (data.contentType == 4) {
- //空白页面
- if (data.isSetupMenu) {
- //体系菜单掩藏子应用的menu
- localStorage.setItem('isChildShowMenu', 'false');
- }
- history.push(`${data.path}?isEmpty=true&menuId=${data.menuId}`);
- } else {
- if (data.isSetupMenu) {
- //体系菜单掩藏子应用的menu
- localStorage.setItem('isChildShowMenu', 'false');
- } else {
- localStorage.setItem('isChildShowMenu', 'true');
- }
- if (data.contentType == 7 && data.type == 1) {
- window.open(data.url, '_blank');
- } else {
- history.push(data.path);
- }
- }
- }
- } else {
- Modal.error({
- title: '当前系统未注册,请联系管理员处理!',
- });
- }
- };
- const userPannelTabClickhandle = (tag: string) => {
- if (tag == 'LOGOUT') {
- if (initialState) {
- const { logout } = initialState;
- logout && logout();
- }
- }
- if (tag == 'SETTING') {
- if (initialState) {
- // setInitialState((s) => ({
- // ...s,
- // currentSelectedSys: {
- // menuId: -1,
- // name: '个人中心',
- // icon: '',
- // url: '',
- // systemId: '-1',
- // type:1,
- // contentType:'0',
- // path: '/personalCenter',
- // },
- // }));
- }
- history.push('/personalCenter');
- }
- };
- return (
- <TopBar
- navData={navData}
- logo={logo}
- topBarTitle={topBarTitle}
- userData={JSON.parse((localStorage.getItem('userInfo') ? localStorage.getItem('userInfo') : localStorage.getItem('userData')) as string)}
- openedTabs={openedSysLists}
- onTabChange={onTabChangeHandle}
- onTabClick={onTabClickHandle}
- currentTab={currentSelectedSys}
- userPannelTabClick={userPannelTabClickhandle}
- />
- );
- };
- /**
- * 定义单条消息的类型
- */
- type Message = {
- sender: 'user' | 'bot';
- content: string; // 可能包含纯文本或HTML
- };
- const IconFont = createFromIconfontCN({
- scriptUrl: '',
- });
- export default function Layout({ children, location, route, history, match }: IRouteComponentProps) {
- const { initialState, setInitialState } = useModel('@@initialState');
- const [navData, set_navData] = useState<TopBar.PanelData[]>([]);
- const [emptyPageContent, set_emptyPageContent] = useState('');
- const [isEmpty, set_isEmpty] = useState(false);
- const [topBarLogoUrl, set_topBarLogoUrl] = useState<string>('');
- const [topBarTitle, set_topBarTitle] = useState('');
- const queryParams = new URLSearchParams(location.search);
- const noTopBar = queryParams.get('noTopbar');
- const [ifShowAiBtn, set_ifShowAiBtn] = useState(false);
- const getNavData = async () => {
- const nav = await getUserPlatformNav();
- if (nav) {
- set_navData(nav as any);
- setInitialState((t) => ({ ...t, navData: nav } as any));
- }
- };
- const getAllParamsHanle = async () => {
- const resp = await getSysParamsByCode(KcimCenterSysId);
- if (resp) {
- resp.forEach((item: any) => {
- if (item.code == '1739122834787143680') {
- item.value && set_topBarLogoUrl(item.value);
- }
- if (item.code == '1739123252502073344') {
- item.value && set_topBarTitle(item.value);
- }
- if (item.code == '1907252043454746624') {
- item.value && set_ifShowAiBtn(item.value == '1');
- }
- });
- }
- };
- const getEmptyPageContent = async (menuId: Key) => {
- const menuItem = await getSpecifyMenuDetail(menuId);
- set_emptyPageContent(menuItem.description);
- };
- useEffect(() => {
- if (location.pathname != '/login') {
- getNavData();
- }
- if (location.pathname == '/index') {
- //localStorage.removeItem('currentSelectedTab');
- //localStorage.removeItem('isChildShowMenu');
- localStorage.removeItem('selectedKeys');
- localStorage.removeItem('openKeys');
- }
- if (location.query.isEmpty == 'true' && location.query.menuId) {
- getEmptyPageContent(location.query.menuId as string);
- }
- }, []);
- useEffect(() => {
- if (location.pathname != '/platform') {
- //排除已有系统的空白页面
- set_isEmpty(location.query.isEmpty == 'true');
- }
- });
- if (location.pathname == '/login') {
- return <div>{children}</div>;
- }
- useEffect(() => {
- getAllParamsHanle();
- }, []);
- // if (initialState?.currentSelectedSys) {
- // const { type, url, contentType } = initialState.currentSelectedSys;
- // if (type == 1 && contentType == 6) {
- // const userData = localStorage.getItem('userData');
- // const { token } = JSON.parse(userData as string);
- // return (
- // <iframe id={'bi_iframe'} style={{ width: '100%', height: '100%', border: 'none' }} src={addTokenToUrl(url as string, token)} onLoad={() => adjustIframe()} ></iframe>
- // )
- // }
- // }
- return (
- <ProLayout
- layout="top"
- contentStyle={{
- margin: 0,
- }}
- menuRender={false}
- menuItemRender={(item, dom) => {
- return (
- <a
- onClick={() => {
- history.push(`${item.path}${item.contentType == 4 ? `?isEmpty=true&menuId=${item.key}` : ''}` || '/');
- }}
- >
- {dom}
- </a>
- );
- }}
- menu={{
- request: async () => {
- return [
- {
- path: '/index',
- name: topBarTitle,
- },
- ];
- },
- }}
- pageTitleRender={false}
- headerRender={
- noTopBar != 'true'
- ? () => {
- return (
- initialState && (
- <TopHoc
- navData={navData}
- topBarTitle={topBarTitle}
- logo={topBarLogoUrl as string}
- set_emptyPageContent={set_emptyPageContent}
- currentSelectedSys={initialState.currentSelectedSys}
- openedSysLists={initialState.openedSysLists ? initialState.openedSysLists : []}
- />
- )
- );
- }
- : false
- }
- >
- {isEmpty && (
- <div style={{ textAlign: 'center', paddingTop: 100, height: '93vh' }}>
- <h1>{emptyPageContent}</h1>
- </div>
- )}
- {!isEmpty && (
- <div className="platform-children" style={{ height: noTopBar == 'true' ? 'auto' : `calc(100vh - 48px)`, minWidth: 1280 }}>
- {(window.self === window.top&&ifShowAiBtn)&&<AiChat />}
- <>{children}</>
- </div>
- )}
- </ProLayout>
- );
- }
|