/* * @Author: your name * @Date: 2022-01-06 15:25:39 * @LastEditTime: 2022-07-08 16:29:17 * @LastEditors: code4eat awesomedema@gmail.com * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @FilePath: /KC-MiddlePlatform/src/pages/platform/_layout.tsx */ import { IRouteComponentProps, useModel, Helmet } from 'umi'; // import { CrownOutlined, UserOutlined, SmileOutlined } from '@ant-design/icons'; import ProLayout, { PageContainer } from '@ant-design/pro-layout'; import { getPlatformMenu } from '@/service/menu'; import './index.less'; import { TreeItemType } from '@/utils'; import { SpacicalPageParamsType } from '@/typings'; import { useEffect, useState } from 'react'; export default function Layout({ children, location, route, history, match, ...rest }: IRouteComponentProps) { const { initialState, setInitialState } = useModel('@@initialState'); const [openKeys, set_openKeys] = useState([]); const [selectedKeys, set_selectedKeys] = useState([]); const [emptyPageContent, set_emptyPageContent] = useState(''); const isShowMenu = localStorage.getItem('isChildShowMenu'); // console.log({ children, location, route, history, match}); return ( { return ( { // console.log('_layout',item); set_emptyPageContent(item.description); history.push(`${item.path}${item.contentType == 4 ? `?isEmpty=true&menuId=${item.key}` : ''}` || '/'); }} > {dom} ) }} menuProps={{ openKeys: [...openKeys], selectedKeys: [...selectedKeys], onSelect: ({ key, keyPath, selectedKeys, domEvent }) => { set_selectedKeys(selectedKeys) }, onOpenChange: (keys: string[]) => { set_openKeys([...keys]); }, }} menu={{ autoClose: false, params: { initialState }, request: async () => { if (initialState) { const systemId = initialState.currentSelectedSys?.menuId; if (systemId) { const menuData = await getPlatformMenu(Number(systemId)); // console.log({menuData}); if (menuData.length > 0) { set_openKeys([menuData[0].key]); set_selectedKeys([menuData[0].key]); } const getVFromTree = (data: TreeItemType[], key: string) => { let result: SpacicalPageParamsType[] = []; function looper(data: TreeItemType[], key: string) { data.forEach((t) => { if (t[key] && t[key] != 0) { //非一般页面 result.push({ contentType: t[key], path: t['path'], reportId: t['reportId'], url: t['youshuUrl'], }); } if (t.children && t.children.length > 0) { looper(t.children, key); } }); } looper(data, key); return result; }; const _menu = getVFromTree(menuData, 'contentType'); setInitialState((t) => ({ ...t, spacicalPageParamsType: _menu })); return [...menuData, { name: 'SQL编辑器', path: '/platform/sqlEditer' }]; } return []; } return []; }, }} onPageChange={(location) => { }} layout="side" headerRender={false} navTheme="light" > { location.query.isEmpty == 'true' && (

{emptyPageContent}

) } { location.query.isEmpty != 'true' && ( 精益管理中台
{children}
) }
); }