_layout.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-06 15:25:39
  4. * @LastEditTime: 2022-07-08 16:29:17
  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/pages/platform/_layout.tsx
  8. */
  9. import { IRouteComponentProps, useModel, Helmet } from 'umi';
  10. // import { CrownOutlined, UserOutlined, SmileOutlined } from '@ant-design/icons';
  11. import ProLayout, { PageContainer } from '@ant-design/pro-layout';
  12. import { getPlatformMenu } from '@/service/menu';
  13. import './index.less';
  14. import { TreeItemType } from '@/utils';
  15. import { SpacicalPageParamsType } from '@/typings';
  16. import { useEffect, useState } from 'react';
  17. export default function Layout({ children, location, route, history, match, ...rest }: IRouteComponentProps) {
  18. const { initialState, setInitialState } = useModel('@@initialState');
  19. const [openKeys, set_openKeys] = useState<string[]>([]);
  20. const [selectedKeys, set_selectedKeys] = useState<string[]>([]);
  21. const [emptyPageContent, set_emptyPageContent] = useState('');
  22. const isShowMenu = localStorage.getItem('isChildShowMenu');
  23. // console.log({ children, location, route, history, match});
  24. return (
  25. <ProLayout
  26. style={{
  27. height: 'calc(100vh - 50px)',
  28. }}
  29. logoStyle={{
  30. display: 'none',
  31. }}
  32. location={{
  33. }}
  34. siderWidth={isShowMenu == 'true' ? 220 : 0}
  35. pageTitleRender={false}
  36. disableContentMargin
  37. menuItemRender={(item, dom) => {
  38. return (
  39. <a
  40. onClick={() => {
  41. // console.log('_layout',item);
  42. set_emptyPageContent(item.description);
  43. history.push(`${item.path}${item.contentType == 4 ? `?isEmpty=true&menuId=${item.key}` : ''}` || '/');
  44. }}
  45. >
  46. {dom}
  47. </a>
  48. )
  49. }}
  50. menuProps={{
  51. openKeys: [...openKeys],
  52. selectedKeys: [...selectedKeys],
  53. onSelect: ({ key, keyPath, selectedKeys, domEvent }) => {
  54. set_selectedKeys(selectedKeys)
  55. },
  56. onOpenChange: (keys: string[]) => {
  57. set_openKeys([...keys]);
  58. },
  59. }}
  60. menu={{
  61. autoClose: false,
  62. params: {
  63. initialState
  64. },
  65. request: async () => {
  66. if (initialState) {
  67. const systemId = initialState.currentSelectedSys?.menuId;
  68. if (systemId) {
  69. const menuData = await getPlatformMenu(Number(systemId));
  70. // console.log({menuData});
  71. if (menuData.length > 0) {
  72. set_openKeys([menuData[0].key]);
  73. set_selectedKeys([menuData[0].key]);
  74. }
  75. const getVFromTree = (data: TreeItemType[], key: string) => {
  76. let result: SpacicalPageParamsType[] = [];
  77. function looper(data: TreeItemType[], key: string) {
  78. data.forEach((t) => {
  79. if (t[key] && t[key] != 0) {
  80. //非一般页面
  81. result.push({
  82. contentType: t[key],
  83. path: t['path'],
  84. reportId: t['reportId'],
  85. url: t['youshuUrl'],
  86. });
  87. }
  88. if (t.children && t.children.length > 0) {
  89. looper(t.children, key);
  90. }
  91. });
  92. }
  93. looper(data, key);
  94. return result;
  95. };
  96. const _menu = getVFromTree(menuData, 'contentType');
  97. setInitialState((t) => ({ ...t, spacicalPageParamsType: _menu }));
  98. return [...menuData, {
  99. name: 'SQL编辑器',
  100. path: '/platform/sqlEditer'
  101. }];
  102. }
  103. return [];
  104. }
  105. return [];
  106. },
  107. }}
  108. onPageChange={(location) => { }}
  109. layout="side"
  110. headerRender={false}
  111. navTheme="light"
  112. >
  113. {
  114. location.query.isEmpty == 'true' && (
  115. <div style={{ textAlign: 'center', paddingTop: 100 }}>
  116. <h1>{emptyPageContent}</h1>
  117. </div>
  118. )
  119. }
  120. {
  121. location.query.isEmpty != 'true' && (
  122. <PageContainer
  123. className="kcmpPageContainer"
  124. header={{
  125. title: false,
  126. }}
  127. style={{
  128. margin: 0,
  129. }}
  130. >
  131. <Helmet>
  132. <title>精益管理中台</title>
  133. </Helmet>
  134. <div className="page" style={{ height: 'calc(100vh - 98px)', overflowY: 'scroll' }}>
  135. {children}
  136. </div>
  137. </PageContainer>
  138. )
  139. }
  140. </ProLayout>
  141. );
  142. }