index.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-11-09 13:56:33
  4. * @LastEditTime: 2025-04-27 13:43:23
  5. * @LastEditors: code4eat awesomedema@gmail.com
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: /KC-MiddlePlatform/src/layouts/index.tsx
  8. */
  9. import { IRouteComponentProps, useModel, history } from 'umi';
  10. import ProLayout from '@ant-design/pro-layout';
  11. import TopBar from '@/components/topBar';
  12. import { Key, useEffect, useRef, useState } from 'react';
  13. import { getSpecifyMenuDetail, getUserPlatformNav } from '@/service/menu';
  14. import { getAppAccess, getSysParamsByCode } from '@/service';
  15. import { Input, Modal } from 'antd';
  16. import './style.less';
  17. import { KcimCenterSysId } from '@/constant';
  18. import { askAiReq } from '@/service/ai';
  19. import { createFromIconfontCN } from '@ant-design/icons';
  20. import ReactMarkdown from 'react-markdown';
  21. import AiChat from '@/components/intelligenceBot';
  22. const TopHoc = ({
  23. currentSelectedSys,
  24. openedSysLists,
  25. navData,
  26. set_emptyPageContent,
  27. logo,
  28. topBarTitle,
  29. }: {
  30. set_emptyPageContent: any;
  31. currentSelectedSys: TopBar.Tab | undefined;
  32. openedSysLists: TopBar.Tab[];
  33. navData: TopBar.PanelData[];
  34. logo: string;
  35. topBarTitle: string;
  36. }) => {
  37. const { initialState, setInitialState } = useModel('@@initialState');
  38. const onTabChangeHandle = async (data: TopBar.Tab[]) => {};
  39. const onTabClickHandle = async (data: TopBar.Tab) => {
  40. const { systemId = '', menuId = '' } = data;
  41. const resp = await getAppAccess(systemId.length > 0 ? systemId : menuId);
  42. if (!resp) {
  43. if (JSON.stringify(data) != '{}') {
  44. if (data.contentType != 7) {
  45. await setInitialState((s) => ({ ...s, currentSelectedSys: data } as any));
  46. }
  47. localStorage.removeItem('selectedKeys');
  48. localStorage.removeItem('openKeys');
  49. if (data.contentType == 4) {
  50. //空白页面
  51. if (data.isSetupMenu) {
  52. //体系菜单掩藏子应用的menu
  53. localStorage.setItem('isChildShowMenu', 'false');
  54. }
  55. history.push(`${data.path}?isEmpty=true&menuId=${data.menuId}`);
  56. } else {
  57. if (data.isSetupMenu) {
  58. //体系菜单掩藏子应用的menu
  59. localStorage.setItem('isChildShowMenu', 'false');
  60. } else {
  61. localStorage.setItem('isChildShowMenu', 'true');
  62. }
  63. if (data.contentType == 7 && data.type == 1) {
  64. window.open(data.url, '_blank');
  65. } else {
  66. history.push(data.path);
  67. }
  68. }
  69. }
  70. } else {
  71. Modal.error({
  72. title: '当前系统未注册,请联系管理员处理!',
  73. });
  74. }
  75. };
  76. const userPannelTabClickhandle = (tag: string) => {
  77. if (tag == 'LOGOUT') {
  78. if (initialState) {
  79. const { logout } = initialState;
  80. logout && logout();
  81. }
  82. }
  83. if (tag == 'SETTING') {
  84. if (initialState) {
  85. // setInitialState((s) => ({
  86. // ...s,
  87. // currentSelectedSys: {
  88. // menuId: -1,
  89. // name: '个人中心',
  90. // icon: '',
  91. // url: '',
  92. // systemId: '-1',
  93. // type:1,
  94. // contentType:'0',
  95. // path: '/personalCenter',
  96. // },
  97. // }));
  98. }
  99. history.push('/personalCenter');
  100. }
  101. };
  102. return (
  103. <TopBar
  104. navData={navData}
  105. logo={logo}
  106. topBarTitle={topBarTitle}
  107. userData={JSON.parse((localStorage.getItem('userInfo') ? localStorage.getItem('userInfo') : localStorage.getItem('userData')) as string)}
  108. openedTabs={openedSysLists}
  109. onTabChange={onTabChangeHandle}
  110. onTabClick={onTabClickHandle}
  111. currentTab={currentSelectedSys}
  112. userPannelTabClick={userPannelTabClickhandle}
  113. />
  114. );
  115. };
  116. /**
  117. * 定义单条消息的类型
  118. */
  119. type Message = {
  120. sender: 'user' | 'bot';
  121. content: string; // 可能包含纯文本或HTML
  122. };
  123. const IconFont = createFromIconfontCN({
  124. scriptUrl: '',
  125. });
  126. export default function Layout({ children, location, route, history, match }: IRouteComponentProps) {
  127. const { initialState, setInitialState } = useModel('@@initialState');
  128. const [navData, set_navData] = useState<TopBar.PanelData[]>([]);
  129. const [emptyPageContent, set_emptyPageContent] = useState('');
  130. const [isEmpty, set_isEmpty] = useState(false);
  131. const [topBarLogoUrl, set_topBarLogoUrl] = useState<string>('');
  132. const [topBarTitle, set_topBarTitle] = useState('');
  133. const queryParams = new URLSearchParams(location.search);
  134. const noTopBar = queryParams.get('noTopbar');
  135. const [ifShowAiBtn, set_ifShowAiBtn] = useState(false);
  136. const getNavData = async () => {
  137. const nav = await getUserPlatformNav();
  138. if (nav) {
  139. set_navData(nav as any);
  140. setInitialState((t) => ({ ...t, navData: nav } as any));
  141. }
  142. };
  143. const getAllParamsHanle = async () => {
  144. const resp = await getSysParamsByCode(KcimCenterSysId);
  145. if (resp) {
  146. resp.forEach((item: any) => {
  147. if (item.code == '1739122834787143680') {
  148. item.value && set_topBarLogoUrl(item.value);
  149. }
  150. if (item.code == '1739123252502073344') {
  151. item.value && set_topBarTitle(item.value);
  152. }
  153. if (item.code == '1907252043454746624') {
  154. item.value && set_ifShowAiBtn(item.value == '1');
  155. }
  156. });
  157. }
  158. };
  159. const getEmptyPageContent = async (menuId: Key) => {
  160. const menuItem = await getSpecifyMenuDetail(menuId);
  161. set_emptyPageContent(menuItem.description);
  162. };
  163. useEffect(() => {
  164. if (location.pathname != '/login') {
  165. getNavData();
  166. }
  167. if (location.pathname == '/index') {
  168. //localStorage.removeItem('currentSelectedTab');
  169. //localStorage.removeItem('isChildShowMenu');
  170. localStorage.removeItem('selectedKeys');
  171. localStorage.removeItem('openKeys');
  172. }
  173. if (location.query.isEmpty == 'true' && location.query.menuId) {
  174. getEmptyPageContent(location.query.menuId as string);
  175. }
  176. }, []);
  177. useEffect(() => {
  178. if (location.pathname != '/platform') {
  179. //排除已有系统的空白页面
  180. set_isEmpty(location.query.isEmpty == 'true');
  181. }
  182. });
  183. if (location.pathname == '/login') {
  184. return <div>{children}</div>;
  185. }
  186. useEffect(() => {
  187. getAllParamsHanle();
  188. }, []);
  189. // if (initialState?.currentSelectedSys) {
  190. // const { type, url, contentType } = initialState.currentSelectedSys;
  191. // if (type == 1 && contentType == 6) {
  192. // const userData = localStorage.getItem('userData');
  193. // const { token } = JSON.parse(userData as string);
  194. // return (
  195. // <iframe id={'bi_iframe'} style={{ width: '100%', height: '100%', border: 'none' }} src={addTokenToUrl(url as string, token)} onLoad={() => adjustIframe()} ></iframe>
  196. // )
  197. // }
  198. // }
  199. return (
  200. <ProLayout
  201. layout="top"
  202. contentStyle={{
  203. margin: 0,
  204. }}
  205. menuRender={false}
  206. menuItemRender={(item, dom) => {
  207. return (
  208. <a
  209. onClick={() => {
  210. history.push(`${item.path}${item.contentType == 4 ? `?isEmpty=true&menuId=${item.key}` : ''}` || '/');
  211. }}
  212. >
  213. {dom}
  214. </a>
  215. );
  216. }}
  217. menu={{
  218. request: async () => {
  219. return [
  220. {
  221. path: '/index',
  222. name: topBarTitle,
  223. },
  224. ];
  225. },
  226. }}
  227. pageTitleRender={false}
  228. headerRender={
  229. noTopBar != 'true'
  230. ? () => {
  231. return (
  232. initialState && (
  233. <TopHoc
  234. navData={navData}
  235. topBarTitle={topBarTitle}
  236. logo={topBarLogoUrl as string}
  237. set_emptyPageContent={set_emptyPageContent}
  238. currentSelectedSys={initialState.currentSelectedSys}
  239. openedSysLists={initialState.openedSysLists ? initialState.openedSysLists : []}
  240. />
  241. )
  242. );
  243. }
  244. : false
  245. }
  246. >
  247. {isEmpty && (
  248. <div style={{ textAlign: 'center', paddingTop: 100, height: '93vh' }}>
  249. <h1>{emptyPageContent}</h1>
  250. </div>
  251. )}
  252. {!isEmpty && (
  253. <div className="platform-children" style={{ height: noTopBar == 'true' ? 'auto' : `calc(100vh - 48px)`, minWidth: 1280 }}>
  254. {(window.self === window.top&&ifShowAiBtn)&&<AiChat />}
  255. <>{children}</>
  256. </div>
  257. )}
  258. </ProLayout>
  259. );
  260. }