index.tsx 5.2 KB

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