import * as React from 'react'; import { FastRow, FastCol, FastTabs, FastModal, FastDrawer, } from 'components/ui'; import { Component } from 'components/types'; import { isArray } from 'utils/isType'; import useLayout from './useLayout'; import './index.scss'; const LOADER_LIST = [ Component.Basic.Loader.Type.modal, Component.Basic.Loader.Type.drawer, Component.Basic.Loader.Type.cover, ]; function Layout(props: any) { const { modules, layoutRef, componentsRef, getContent, } = props; const { tabs, exchanges, // covers, modals, drawers, allModulesMap, setLayoutState, } = useLayout(modules, layoutRef); // 布局变化回调 const handleChange = (type: Component.Basic.Layout.Type) => ( name: string, value: string, ) => setLayoutState(type, name, value); const setLayout = (moduleList: any[], loaderUuid?: string) => ( {moduleList.map((module: any) => { const { uuid, type, col, modules: childModules, loader, } = module; let content = null; if (isArray(childModules) && childModules.length) { if (type === Component.Basic.Layout.Type.tabs) { const currentChildModule = childModules.find( (childModule: any) => childModule.uuid === tabs[uuid], ); content = ( <> { handleChange(Component.Basic.Layout.Type.tabs)(uuid, value); componentsRef.current[currentChildModule.filter].fetchData({ type: 'fetch', moduleIds: [currentChildModule.uuid], }); }} > {childModules.map((childModule: any) => ( childModule.label && ))} { currentChildModule.modules ? setLayout(currentChildModule.modules, loaderUuid) : getContent(tabs[uuid], loaderUuid) } ); } else if (type === Component.Basic.Layout.Type.exchange) { const currentChildModule = childModules.find( (childModule: any) => childModule.uuid === exchanges[uuid], ); content = currentChildModule.modules ? setLayout(currentChildModule.modules, loaderUuid) : getContent(exchanges[uuid]); } else if (!LOADER_LIST.includes(loader)) { content = setLayout(childModules, loaderUuid); } } else if (!LOADER_LIST.includes(loader)) { content = getContent(uuid, loaderUuid); } return {content}; })} ); return ( <> {setLayout(modules)} {modals.map((uuid: string) => ( setLayoutState(Component.Basic.Loader.Type.modal, uuid, false) } > {allModulesMap[uuid].modules ? setLayout(allModulesMap[uuid].modules, uuid) : getContent(uuid, uuid)} ))} { drawers.map((uuid: string) => ( setLayoutState(Component.Basic.Loader.Type.drawer, uuid, false) } > {allModulesMap[uuid].modules ? setLayout(allModulesMap[uuid].modules, uuid) : getContent(uuid, uuid)} )) } ); } export default Layout;