UNPKG

@pwc-ra/components

Version:

PwC RA shared components library

327 lines (312 loc) 8.58 kB
import React$1, { ReactNode } from 'react'; import { MenuProps } from 'antd'; import * as axios from 'axios'; import { AxiosRequestConfig, AxiosResponse } from 'axios'; interface User { id: string; username: string; email: string; tenants: Array<{ id: string; code: string; name: string; }>; } interface PageHeaderContextType { currentUser: User | null; loading: boolean; error: string | null; selectedTenant: { id: string; code: string; name: string; } | null; setSelectedTenant: (tenant: { id: string; code: string; name: string; } | null) => void; logout: () => void; } interface GlobalPageHeaderState { currentUser: User | null; selectedTenant: { id: string; code: string; name: string; } | null; loading: boolean; error: string | null; } declare const PageHeaderState: { /** * 获取当前用户信息 */ getCurrentUser: () => User | null; /** * 获取当前选中的租户 */ getSelectedTenant: () => { id: string; code: string; name: string; } | null; /** * 获取加载状态 */ isLoading: () => boolean; /** * 获取错误信息 */ getError: () => string | null; /** * 监听状态变化 * @param callback 状态变化时的回调函数 * @returns 取消监听的函数 */ subscribe: (callback: (state: GlobalPageHeaderState) => void) => (() => void); }; interface PageHeaderProviderProps { children: ReactNode; /** * 租户信息存储在 localStorage 中的 key * 如果不提供,则不会持久化租户选择 */ tenantStorageKey?: string; } declare const PageHeaderProvider: React$1.FC<PageHeaderProviderProps>; declare const usePageHeader: () => PageHeaderContextType; interface Product { id: string; name: string; url: string; icon?: string; category?: string; order?: number; } interface PageHeaderProps { collapsed: boolean; onCollapse: () => void; onProductChange?: (productId: string) => void; /** * 自定义额外内容,将显示在顶部导航栏右侧 */ extra?: React$1.ReactNode; /** * 自定义额外内容,将显示在顶部导航栏左侧(logo 右侧) */ leftExtra?: React$1.ReactNode; /** * 自定义 Logo,可以是 ReactNode 或者字符串 * 如果是字符串,将显示为标题文本 * 如果是 ReactNode,将直接渲染该节点 */ logo?: React$1.ReactNode | string; /** * 是否显示租户选择器,默认为 true */ showTenantSelector?: boolean; /** * 是否显示产品选择器,默认为 true */ showProductSelector?: boolean; } declare const PageHeader: React$1.FC<PageHeaderProps>; type MenuItem = Required<MenuProps>['items'][number]; interface SidebarProps { /** * 侧边栏是否折叠 */ collapsed: boolean; /** * 侧边栏菜单项 */ menuItems: MenuItem[]; /** * 产品名称 */ productName: string; /** * 产品图标 */ productIcon?: ReactNode; /** * 侧边栏宽度,默认为 200 */ width?: number; /** * 侧边栏折叠时的宽度,默认为 80 */ collapsedWidth?: number; /** * 侧边栏头部高度,默认为 64 */ headerHeight?: number; /** * 菜单点击回调 */ onMenuClick?: (key: string) => void; /** * 自定义类名 */ className?: string; /** * 自定义样式 */ style?: React.CSSProperties; /** * 是否显示产品名称,默认为 true */ showProductName?: boolean; } /** * 侧边栏组件 */ declare const Sidebar: React$1.FC<SidebarProps>; interface BreadcrumbRoute { path: string; title: string; onClick?: () => void; } interface BreadcrumbProps { /** * 面包屑路由配置 */ routes: BreadcrumbRoute[]; /** * 自定义路径映射,用于将路径映射到显示名称 */ pathNameMap?: Record<string, string>; /** * 自定义点击事件处理函数 */ onItemClick?: (path: string, index: number) => void; /** * 自定义样式 */ className?: string; /** * 自定义样式 */ style?: React$1.CSSProperties; /** * 是否在最后一项禁用点击 */ disableLastItemClick?: boolean; /** * 自定义最后一项的样式 */ lastItemStyle?: React$1.CSSProperties; } declare const Breadcrumb: React$1.FC<BreadcrumbProps>; interface MainLayoutProps { /** * 菜单项配置 */ menuItems: MenuItem[]; /** * 产品名称 */ productName: string; /** * 产品图标 */ productIcon: ReactNode; /** * 内容区域 */ children: ReactNode; /** * 面包屑组件 */ breadcrumb?: ReactNode; /** * 初始侧边栏是否折叠 */ defaultCollapsed?: boolean; /** * 自定义内容区域样式 */ contentStyle?: React$1.CSSProperties; /** * 自定义内容包装区域样式 */ contentWrapperStyle?: React$1.CSSProperties; /** * 自定义类名 */ className?: string; /** * 自定义顶部导航栏右侧额外内容 */ headerExtra?: ReactNode; /** * 自定义顶部导航栏左侧额外内容(logo右侧) */ headerLeftExtra?: ReactNode; /** * 自定义 Logo,可以是 ReactNode 或者字符串 * 如果是字符串,将显示为标题文本 * 如果是 ReactNode,将直接渲染该节点 */ logo?: React$1.ReactNode | string; /** * 是否显示租户选择器,默认为 true */ showTenantSelector?: boolean; /** * 是否显示产品选择器,默认为 true */ showProductSelector?: boolean; /** * 是否显示产品名称,默认为 true */ showProductName?: boolean; /** * 侧边栏宽度,默认为 200 */ sidebarWidth?: number; } declare const MainLayout: React$1.FC<MainLayoutProps>; declare const initKeycloak: (configUrl?: string) => Promise<boolean>; declare const login: () => false | Promise<void>; declare const logout: () => false | Promise<void>; declare const getToken: () => string | null; declare const updateToken: (minValidity: number) => Promise<boolean>; declare const isLoggedIn: () => boolean; declare const getUsername: () => any; declare const getRoles: () => string[]; declare const isKeycloakInitialized: () => boolean; declare const ensureKeycloakInitialized: (timeout?: number) => Promise<boolean>; interface CustomRequestConfig { /** * 控制数据格式转换行为 * - true: 启用数据格式转换 * - false: 禁用数据格式转换 * - 默认为 true */ transformKeys?: boolean; /** * 是否等待Keycloak初始化 * - true: 等待Keycloak初始化完成后再发送请求 * - false: 不等待Keycloak初始化,直接发送请求 * - 默认为 true */ waitForAuth?: boolean; } type ExtendedRequestConfig = AxiosRequestConfig & CustomRequestConfig; declare const setAutoTransformKeys: (enabled: boolean) => void; declare const setWaitForAuth: (enabled: boolean) => void; declare const http: { get: <T>(url: string, config?: ExtendedRequestConfig) => Promise<AxiosResponse<T, any>>; post: <T>(url: string, data?: any, config?: ExtendedRequestConfig) => Promise<AxiosResponse<T, any>>; put: <T>(url: string, data?: any, config?: ExtendedRequestConfig) => Promise<AxiosResponse<T, any>>; delete: <T>(url: string, config?: ExtendedRequestConfig) => Promise<AxiosResponse<T, any>>; }; declare const getCurrentUser: () => Promise<axios.AxiosResponse<User, any>>; /** * 获取产品菜单数据 * @returns 处理后的产品列表 */ declare const getProductMenu: () => Promise<Product[]>; export { Breadcrumb, type BreadcrumbProps, type BreadcrumbRoute, MainLayout, type MainLayoutProps, type MenuItem, PageHeader, type PageHeaderProps, PageHeaderProvider, PageHeaderState, type Product, Sidebar, type SidebarProps, type User, ensureKeycloakInitialized, getCurrentUser, getProductMenu, getRoles, getToken, getUsername, http, initKeycloak, isKeycloakInitialized, isLoggedIn, login, logout, setAutoTransformKeys, setWaitForAuth, updateToken, usePageHeader };