index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-11-09 13:56:33
  4. * @LastEditTime: 2022-07-08 16:35:31
  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 { useEffect, useState } from 'react';
  13. import { getPlatformMenu, getUserPlatformNav } from '@/service/menu';
  14. import { NavSelecterData } from '@/components/NavSelecter';
  15. const TopHoc = ({ currentSelectedSys, openedSysLists, navData }: { currentSelectedSys: TopBar.Tab | undefined, openedSysLists: TopBar.Tab[], navData: TopBar.PanelData[] }) => {
  16. const { initialState, setInitialState } = useModel('@@initialState');
  17. const onTabChangeHandle = async (data: TopBar.Tab[]) => {
  18. // await setInitialState((s) => ({ ...s, openedSysLists: [...data] }));
  19. // localStorage.setItem('initialState', JSON.stringify(initialState)); //缓存tab状态,防止刷新丢失
  20. };
  21. const onTabClickHandle = async (data: TopBar.Tab) => {
  22. await setInitialState((s) => ({ ...s, currentSelectedSys: data }));
  23. console.log({data});
  24. if(data.type == 4){
  25. //空白页面
  26. history.push(`${data.path}?isEmpty=true&menuId=${data.menuId}`);
  27. }else{
  28. if(data.isSetupMenu){
  29. //体系菜单掩藏子应用的menu
  30. localStorage.setItem('isChildShowMenu','false');
  31. }else{
  32. localStorage.setItem('isChildShowMenu','true');
  33. }
  34. history.push(data.path);
  35. }
  36. };
  37. const userPannelTabClickhandle = (tag: string) => {
  38. if (tag == 'LOGOUT') {
  39. if (initialState) {
  40. const { logout } = initialState;
  41. logout && logout();
  42. }
  43. }
  44. if (tag == 'SETTING') {
  45. if (initialState) {
  46. setInitialState((s) => ({
  47. ...s,
  48. currentSelectedSys: {
  49. menuId: -1,
  50. name: '个人中心',
  51. icon: '',
  52. url: '',
  53. systemId: '-1',
  54. type:1,
  55. path: '/personalCenter',
  56. },
  57. }));
  58. }
  59. }
  60. };
  61. return (
  62. <TopBar
  63. navData={navData}
  64. userData={initialState?.userData}
  65. openedTabs={openedSysLists}
  66. onTabChange={onTabChangeHandle}
  67. onTabClick={onTabClickHandle}
  68. currentTab={currentSelectedSys}
  69. userPannelTabClick={userPannelTabClickhandle}
  70. />
  71. );
  72. };
  73. export default function Layout({ children, location, route, history, match }: IRouteComponentProps) {
  74. const { initialState, setInitialState } = useModel('@@initialState');
  75. const [navData, set_navData] = useState<TopBar.PanelData[]>([]);
  76. const [emptyPageContent, set_emptyPageContent] = useState('');
  77. const [isEmpty,set_isEmpty] = useState(false);
  78. const getNavData = async () => {
  79. const nav = await getUserPlatformNav();
  80. if (nav) {
  81. set_navData(nav);
  82. }
  83. }
  84. useEffect(() => {
  85. if (location.pathname != '/login') {
  86. getNavData();
  87. }
  88. }, [])
  89. useEffect(()=>{
  90. set_isEmpty(location.query.isEmpty == 'true');
  91. })
  92. if (location.pathname == '/login') {
  93. return <div>{children}</div>;
  94. }
  95. return (
  96. <ProLayout
  97. layout="top"
  98. contentStyle={{
  99. margin: 0,
  100. }}
  101. menuItemRender={(item, dom) => {
  102. return (
  103. <a
  104. onClick={() => {
  105. set_emptyPageContent(item.description);
  106. history.push(`${item.path}${item.contentType == 4 ? `?isEmpty=true&menuId=${item.key}` : ''}` || '/');
  107. }}
  108. >
  109. {dom}
  110. </a>
  111. )
  112. }}
  113. menu={{
  114. request: async () => {
  115. return [
  116. {
  117. path: '/index',
  118. name: '欢迎进入医管平台'
  119. }
  120. ]
  121. },
  122. }}
  123. pageTitleRender={false}
  124. headerRender={() =>
  125. initialState && (
  126. <TopHoc
  127. navData={navData}
  128. currentSelectedSys={initialState.currentSelectedSys}
  129. openedSysLists={initialState.openedSysLists ? initialState.openedSysLists : []}
  130. />
  131. )
  132. }
  133. >
  134. {
  135. isEmpty&& (
  136. <div style={{ textAlign: 'center', paddingTop: 100,height:'93vh' }}>
  137. <h1>{emptyPageContent}</h1>
  138. </div>
  139. )
  140. }
  141. {!isEmpty&&(<div style={{ height: `calc(100vh - 48px)`, overflowY: 'scroll' }}>{children}</div>)}
  142. </ProLayout>
  143. );
  144. }