import { CSSProperties, ReactNode } from 'react'; import { ProWaterMarkType } from '../ProWaterMark/propsType'; /** * @description 应用选项类型(无分组模式) */ export interface AppsOption { /** * @description 应用唯一标识值 * @default - */ value: string; /** * @description 应用名称 * @default - */ label: ReactNode; /** * @description 应用图标 * @default - */ icon?: ReactNode; /** * @description 点击回调 * @default - */ onChange?: (value: string, option: AppsOption) => void; /** * @description 允许扩展字段 */ [key: string]: any; } /** * @description 应用分组类型(分组模式) */ export interface AppsGroup { /** * @description 分组唯一标识 * @default - */ value: string; /** * @description 分组名称 * @default - */ label: ReactNode; /** * @description 分组图标 * @default - */ icon?: ReactNode; /** * @description 该分组下的应用列表 * @default [] */ options: AppsOption[]; /** * @description 允许扩展字段 */ [key: string]: any; } export interface MenusType { /** * @description 菜单ID * @default - */ id?: number; /** * @description 菜单唯一code * @default - */ code?: string; /** * @description 菜单名称 * @default - */ name?: string; /** * @description 菜单路由 * @default - */ url?: string; /** * @description 点击路由时,重定向地址 * @default - */ redirectUrl?: string; /** * @description 关联的上级id * @default - */ parentId?: number | null; /** * @description 备注 * @default - */ description?: any; /** * @description 扩展备用字段 * @default - */ extraInfo?: any; /** * @description 排序 * @default - */ sort?: number | undefined | null; /** * @description 是否隐藏菜单 * @default false */ hideInMenu?: boolean; /** * @description iconfont图标 * @default - */ icon?: string; /** * @description 图片icon * @default - */ imgUrl?: string; /** * @description 菜单类型 * @default - */ type?: string; /** * @description 当前菜单点击后的打开方式 * @default "_self" */ target?: '_blank' | '_parent' | '_self' | '_top'; /** * @description 标签页关联键;相同关联键的业务详情重复打开时复用已有标签页 */ relationKey?: string | number; /** * @description 允许扩展字段 */ [key: string]: any; } export interface DataSourceType { /** * @description 用户信息 * @default - */ userInfo?: any; /** * @description 处理后一级菜单详情 * @default [] */ menus?: MenusType[]; } /** * @description 是否带有菜单界面的配置 */ type pureKey = boolean | { topMenu?: boolean; leftMenu?: boolean; }; interface ProLayoutBaseProps { /** * @description 左侧logo * @default - */ logo?: ReactNode | string; /** * @description 类名 * @default "" */ className?: string; /** * @description iconfontUrl * @default - */ iconfontUrl?: string; /** * @description 右侧内容渲染 * @default - */ rightContentRender?: ReactNode; /** * @description 头部内容渲染 * @default - */ headerContentRender?: ReactNode; /** * @description 侧边栏底部渲染 * @default - */ sideMenuFooterRender?: ReactNode; /** * @description 头部标题区自定义渲染 * @default - */ headerTitleRender?: ReactNode; /** * @description 通告 * @default - */ headerNotice?: ReactNode | string; /** * @description 通告 * @default - */ notice?: ReactNode | string; /** * @description 标题 * @default - */ title?: string; /** * @description 数据源 * @default - */ dataSource?: DataSourceType | Partial; /** * @description 是否折叠 * @default false */ collapsed?: boolean; /** * @description 收起时显示菜单名称并使用 72px 侧栏;默认仅显示图标,宽度 48px * @default false */ collapsedMenuShowLabel?: boolean; /** * @description 菜单拼接路径前缀 * @default "" */ pathPrefix?: string; /** * @description 是否带有菜单界面,true不带,只显示content内容 * @default false */ pure?: pureKey; /** * @description 头部区域高度 * @default 64 */ headerHeight?: number; /** * @description 内容区域样式 * @default {} */ contentStyle?: CSSProperties; /** * @description 水印配置 * @default {} */ waterMarkProps?: ProWaterMarkType; /** * @description 折叠回调事件 * @default - */ onCollapsedChange?: (collapsed: boolean) => void; /** * @description 菜单点击回调事件,返回命中的菜单项数据和完整路径 * @default - */ onMenuClick?: (params: { item: MenusType | null; key: string; keyPath: string[]; }) => void | boolean; /** * @description 规定在何处打开被链接文档 * @default "_self" */ target?: '_blank' | '_parent' | '_self' | '_top'; /** * @description 子元素 * @default - */ children?: ReactNode; /** * @description 应用入口配置(支持分组和扁平两种模式) * @default - */ appsOptions?: AppsGroup[] | AppsOption[]; /** * @description 允许扩展字段 */ [key: string]: any; } export interface ProLayoutStatesType { /** * @description 是否折叠 * @default false */ collapsed?: boolean; /** * @description 通告 * @default - */ notice?: ReactNode | string; /** * @description 菜单列表 * @default [] */ menus?: MenusType[]; /** * @description 选中的路径 * @default "" */ selectedPath?: string; /** * @description 允许扩展字段 */ [key: string]: any; } export interface TabItem { /** * @description 标签唯一标识 */ id: string; /** * @description 组件标识码 */ code: string; /** * @description 标签名称 */ name: string; /** * @description 标签标题(废弃,保留兼容) */ title: string; /** * @description 标签关联路由。URL 同步模式下保存当前完整的 pathname + search + hash */ url?: string; /** * @description 是否可关闭 */ closable: boolean; /** * @description 是否固定标签(本质状态)。固定后不可关闭并排入左侧固定区; * closable 为其派生结果(pinned 时 closable=false)。未设置时以 closable===false 推导。 */ pinned?: boolean; /** * @description 关联菜单项 */ menuItem?: MenusType; /** * @description 额外扩展数据 */ extra?: Record; /** * @description 图标 */ icon?: ReactNode | string; /** * @description 标签页关联键;用于业务详情页复用已有标签页 */ relationKey?: string | number; /** * @description 最初打开当前业务标签链路的左侧菜单 code;仅用于激活来源菜单 */ menuCodeSource?: string; } export interface TabsState { tabsList: TabItem[]; activeKey: string; activeTabInfo?: TabItem; newTabIndex: number; activeComponent?: string; } export type TabsStorageStrategy = 'localStorage' | 'sessionStorage'; export interface TabsUrlSyncConfig { /** * @description 切换标签页时写入浏览器历史的方式 * @default 'replace' */ history?: 'replace' | 'push'; /** * @description 页签复用身份。url 保持完整 URL 唯一语义;relationKey 按关联键、无关联键的菜单 code、完整 URL 依次匹配 * @default 'url' */ identity?: 'url' | 'relationKey'; /** * @description 浏览器地址中的显式基础路径;Tab 内部 URL 可以不带该前缀 * @example '/wjs' */ basename?: string; } /** * @description 添加标签页的业务参数 */ export interface AddTabParams { /** * @description 组件标识码,用于映射到具体的 React 组件 */ code: string; /** * @description 标签页显示名称 */ name: string; /** * @description 应用内完整 URL。URL 同步模式下作为页签业务身份 * @example '/wjs/workbench/workbench/Record?recordTab=quote' */ url?: string; /** * @description 额外的业务数据 */ extra?: Record; /** * @description 标签页关联键;相同关联键的业务详情重复打开时复用已有标签页 */ relationKey?: string | number; /** * @description 最初打开当前业务标签链路的左侧菜单 code;仅用于激活来源菜单 */ menuCodeSource?: string; } /** * @description 添加标签页的选项 */ export interface AddTabOptions { /** * @description 是否强制创建新标签页(忽略已存在的相同标签页),默认 false */ forceNew?: boolean; /** * @description 是否静默追加:true 时新建 tab 不切换 active;当前已有 active 时保留原 active。 * 列表为空(activeKey 为空)时仍会激活,以保留首次进入默认激活的行为。 * 用于 fixed 声明式注入等不应抢用户 active 的场景。默认 false。 */ silent?: boolean; } /** * @description 更新标签页的展示、扩展数据与来源菜单身份 */ export interface UpdateTabParams { /** * @description 标签名称(更新时同步刷新 title) */ name?: string; /** * @description 图标 */ icon?: ReactNode | string; /** * @description 额外扩展数据(替换式覆盖,不做合并) */ extra?: Record; /** * @description 是否可关闭 */ closable?: boolean; /** * @description 是否固定标签(本质状态,driven closable) */ pinned?: boolean; /** * @description 最初打开当前业务标签链路的左侧菜单 code;用于兼容性迁移已缓存的来源身份 */ menuCodeSource?: string; } /** * @description 获取标签页信息返回值 */ export interface TabsInfoResult { /** 标签页列表 */ tabsList: TabItem[]; /** 当前激活的标签页信息 */ activeTabInfo?: TabItem; /** 当前激活的组件标识 */ activeComponent: string; } /** * @description ProLayout 标签页实例接口(类似 FormInstance) */ export interface ProLayoutTabsInstance { /** * @description 添加标签页 */ addTab: (params: AddTabParams, options?: AddTabOptions) => void; /** * @description 删除指定标签页;不传 tabId 时删除当前激活标签页 * @param tabId 目标标签页 id,省略时使用当前激活标签页 * @example * ```tsx * layoutTabs.removeTab(); * layoutTabs.removeTab('tab-id'); * ``` */ removeTab: (tabId?: string) => void; /** * @description 更新已存在标签页的展示信息(不会卸载/重挂渲染组件) * @param tabId 目标标签页 id * @param updates 仅更新传入的字段,extra 为替换式覆盖 */ updateTab: (tabId: string, updates: UpdateTabParams) => void; /** * @description 就地更新页签完整 URL,保持 tab id 与已挂载组件不变 */ updateTabUrl: (tabId: string, url: string) => void; /** * @description 获取标签页信息 */ getTabInfo: () => TabsInfoResult; /** * @description 在当前激活标签页内压入一个子视图(如详情页),入口页会被隐藏但不卸载 * @param node 要展示的子视图 React 节点 * @example * ```tsx * layoutTabs.pushView(); * ``` */ pushView: (node: ReactNode) => void; /** * @description 返回上一层:销毁当前激活标签页的栈顶子视图,露出下一层(栈空时露出入口页) */ back: () => void; /** * @description 获取当前激活标签页的子视图栈(栈底→栈顶顺序),入口页不在其中 */ getViewStack: () => ReactNode[]; } /** * @description iframe 路由表配置项 */ export interface IframeRoute { /** * @description 静态路径,与 `window.location.pathname` 完全匹配(忽略首尾斜杠)。 * 不支持 `:param` 动态片段;动态参数通过 query string 传递, * 自动作为 props 透传给业务组件。 * 业务方需保证 URL query 字段名与业务组件 props 名一致。 * @example '/wjs/policy/view' * 配合 URL: `/wjs/policy/view?taskId=123&policyId=456` */ path: string; /** * @description 命中后用于解析 activeComponent 的业务 code */ code: string; /** * @description 命中后的标签名称 */ name: string; } /** * @description iframe 嵌入配置 * * **触发条件**:URL query 上带 `?isIframe`(大小写不敏感,值不限,只看 key 是否存在)。 * 第三方系统通过在 iframe src 上拼 `?isIframe=1` 来触发组件库的嵌入模式。 * * 未带该 query 时(独立访问),即使配置了 `tabs.iframe`,组件库也完全不读取, * 维持完整 Layout 渲染。 */ export interface IframeConfig { /** * @description 路由表:按 URL pathname 顺序匹配,命中后自动 addTab * - URL query 自动合并进 extra,作为业务组件 props 透传 */ routes: IframeRoute[]; /** * @description 嵌入时是否使用纯净渲染(只显示内容区域) * - true (默认): 隐藏 Header / Menu / TabsBar,仅渲染当前 tab 内容 * - false: 完整 layout 渲染 * @default true */ pure?: boolean; } export interface TabsConfig { max?: number; storage?: TabsStorageStrategy; cacheKey?: string; /** * @description 是否将活动页签与浏览器 URL 双向同步。默认不同步,保持现有行为 * - true: 开启同步,切换页签时使用 replace * - object: 开启同步并自定义历史写入方式 * @default false */ urlSync?: boolean | TabsUrlSyncConfig; /** * @description 普通初始标签页。无缓存时每次 ProLayout 挂载只初始化一次;关闭全部后本次挂载期间不会重新添加 */ initialTabs?: AddTabParams[]; onTabChange?: (activeKey: string, activeTab: TabItem | undefined, allTabs: TabItem[]) => void; /** * @description 是否允许标签页拖拽排序 * @default true */ draggable?: boolean; /** * @description 激活组件解析函数,根据 component 标识返回对应的 React 组件 */ activeComponent?: (component: string) => React.ComponentType | null; /** * @description 空状态组件,当没有标签页时显示 */ empty?: ReactNode; /** * @description 自定义右键菜单项,会替换默认菜单项 */ menuItems?: import('antd').MenuProps['items']; /** * @description 自定义菜单项点击回调 */ tabMenuClick?: (params: { key: string; tab: TabItem; tabs: TabItem[]; }) => void; /** * @description 声明式固定标签页,传入菜单 code 数组,这些 tab 会在初始化时自动添加且不可关闭 * @example fixed: ['Workspace', 'PolicyInput'] */ fixed?: string[]; /** * @description iframe 嵌入配置,允许第三方系统通过 URL 定位到具体 tab * 仅在 URL 带 `?isIframe`(大小写不敏感)时生效 */ iframe?: IframeConfig; } export type ProLayoutMode = 'normal' | 'tabs'; export interface ProLayoutTabsProps extends ProLayoutBaseProps { mode: 'tabs'; tabs: TabsConfig; } export interface ProLayoutNormalProps extends ProLayoutBaseProps { mode?: 'normal'; tabs?: never; } export type ProLayoutType = ProLayoutTabsProps | ProLayoutNormalProps; export declare const isTabsMode: (props: ProLayoutType) => props is ProLayoutTabsProps; export declare const validateTabsProps: (mode?: ProLayoutMode, tabs?: TabsConfig) => void; export {};