import React, { ReactNode, useEffect, useState } from "react"; import DefCustomPage from "./def-custom-page"; import { ProgramConfig } from "../index"; import DraggableModal from "../module/draggable-modal"; interface Props { serverKey?: string; height?: number | string; minHeight?: number | string; width?: number; bodyWidth?: number | string; title?: ReactNode; code?: string; //详情模板code mainCode?: string; //模块名称 sourceId: string; customPath: string; open: boolean; onCancel: () => void; params?: { [key: string]: any }; // 自定义页面过滤传参 } const Index = (props: Props) => { const { width, title, height, bodyWidth, code, sourceId, open, mainCode, customPath, onCancel, minHeight, params } = props; const [customStyle, setCustomStyle] = useState<{ [key: string]: any }>({}); const [customWidth, setCustomWidth] = useState(width); const [customBodyWidth, setBodyWidth] = useState(bodyWidth); const [customPage, setCustomPage] = useState(""); const getCustomPage = () => { if (open) { let Page = ProgramConfig.getCustomPage(customPath); if (!Page) { setCustomPage(React.createElement(DefCustomPage)); return; } const { width: styleWidth, bodyWidth: styleBodyWidth, ...otherStyle } = Page().props?.customStyle || {}; setCustomStyle(otherStyle || {}); setCustomWidth(styleWidth || width); setBodyWidth(styleBodyWidth || bodyWidth); setCustomPage(React.createElement(Page, { code, sourceId, mainCode, pageName: customPath, params })); } }; useEffect(() => { getCustomPage(); }, [open]); return ( {customPage} ); } export default Index;