import { A as ApiResponse, P as PaginatedData, d as ProTableResponse } from '../api-DFOs5fnc.js'; import React$1, { Dispatch, SetStateAction } from 'react'; /** * ProTable 分页请求共享逻辑 * * 被 useTableData 和 useCrudList 共用,消除重复的 request 函数实现。 * 内部模块,不对外导出。 */ interface TableRequestParams { current?: number; pageSize?: number; [key: string]: unknown; } /** * CRUD 列表管理 Hook * * 封装 ProTable 列表页常见的完整 CRUD 逻辑: * 数据请求、搜索/筛选、删除确认、页面导航等。 * 比 useTableData 更完整,适用于标准的列表管理页面。 */ /** * CRUD 列表配置 */ interface UseCrudListOptions> { /** 列表数据请求 API */ fetchApi: (params: P) => Promise>>; /** 删除单条记录 API */ deleteApi?: (id: string | number) => Promise>; /** 批量删除 API */ batchDeleteApi?: (ids: (string | number)[]) => Promise>; /** 成功状态码,默认 '200' */ successCode?: string | number; /** 请求前的参数转换 */ transformParams?: (params: TableRequestParams) => P; /** 响应后的数据转换 */ transformData?: (list: T[]) => T[]; /** 页面路径前缀(用于导航到创建/编辑/详情页) */ basePath?: string; /** 导航函数 */ navigate?: (path: string) => void; /** 消息展示函数 */ showMessage?: (content: string, type: 'success' | 'error' | 'warning') => void; /** 确认弹窗函数 */ showConfirm?: (options: { title: string; content: string; onOk: () => Promise; }) => void; /** 请求失败回调 */ onError?: (error: Error) => void; /** 自定义文案(用于国际化) */ messages?: Partial; } /** CRUD 列表文案配置 */ interface CrudListMessages { deleteSuccess: string; deleteFailed: string; batchDeleteSuccess: (count: number) => string; batchDeleteFailed: string; confirmDeleteTitle: string; confirmDeleteContent: (name?: string) => string; confirmBatchDeleteTitle: string; confirmBatchDeleteContent: (count: number) => string; } /** * CRUD 列表返回值 */ interface UseCrudListReturn { /** ProTable 的 request 函数 */ request: (params: TableRequestParams, sort?: Record, filter?: TableRequestParams) => Promise>; /** actionRef - 传给 ProTable */ actionRef: React.MutableRefObject; /** 刷新表格 */ reload: () => void; /** 导航到创建页面 */ goCreate: () => void; /** 导航到编辑页面 */ goEdit: (id: string | number) => void; /** 导航到详情页面 */ goDetail: (id: string | number) => void; /** 删除单条记录(带确认弹窗) */ handleDelete: (id: string | number, name?: string) => void; /** 批量删除(带确认弹窗) */ handleBatchDelete: (ids: (string | number)[]) => void; } interface TableActionRef$1 { reload?: () => void; reloadAndRest?: () => void; clearSelected?: () => void; } /** * CRUD 列表管理 Hook * * @example * ```tsx * const { * request, actionRef, reload, * goCreate, goEdit, goDetail, * handleDelete, * } = useCrudList({ * fetchApi: getUserList, * deleteApi: deleteUser, * basePath: '/system/user', * navigate: history.push, * showMessage: (content, type) => message[type](content), * showConfirm: ({ title, content, onOk }) => Modal.confirm({ title, content, onOk }), * }); * * [ * * ]} * /> * ``` */ declare function useCrudList>(options: UseCrudListOptions): UseCrudListReturn; /** * 详情页数据管理 Hook * */ /** * useDetailPage 配置 */ interface UseDetailPageOptions { /** 详情数据请求 API */ fetchApi: (id: string | number) => Promise>; /** 记录 ID */ id: string | number | undefined; /** 是否在 ID 变化时自动请求,默认 true */ autoFetch?: boolean; /** 成功状态码,默认 '200' */ successCode?: string | number; /** 数据转换 */ transformData?: (data: T) => T; /** 请求成功回调 */ onSuccess?: (data: T) => void; /** 请求失败回调 */ onError?: (error: Error) => void; } /** * useDetailPage 返回值 */ interface UseDetailPageReturn { /** 详情数据 */ data: T | null; /** 加载中状态 */ loading: boolean; /** 错误信息 */ error: Error | null; /** 手动获取指定 ID 的数据(适用于 autoFetch: false 场景) */ fetch: (id: string | number) => Promise; /** 手动刷新当前数据 */ refresh: () => Promise; /** 手动设置数据 */ setData: Dispatch>; } /** * 详情页数据管理 Hook * * @example * ```tsx * const { data, loading, error, refresh } = useDetailPage({ * fetchApi: (id) => getUserDetail(id), * id: params.id, * onError: (err) => message.error(err.message), * }); * ``` */ declare function useDetailPage(options: UseDetailPageOptions): UseDetailPageReturn; /** * 详情页模式管理 Hook * * 管理详情页的 create / edit / view 三态切换、表单提交处理。 * 与 useDetailPage(数据获取)互补,专注于页面交互逻辑。 */ /** * 页面模式 */ type PageMode = 'create' | 'edit' | 'view'; /** * DetailPageMode 文案配置(支持国际化) */ interface DetailPageModeMessages { /** 创建成功提示,默认 'Created successfully' */ createSuccess: string; /** 更新成功提示,默认 'Updated successfully' */ updateSuccess: string; /** 操作失败提示,默认 'Operation failed' */ operationFailed: string; /** 缺少 API 函数错误提示,默认 'Config error: missing API function' */ missingApi: string; } /** * useDetailPageMode 配置 */ interface UseDetailPageModeOptions> { /** 当前记录 ID(有 ID 且非 create 模式时为编辑/查看模式) */ id?: string | number; /** 创建 API */ createApi?: (data: T) => Promise>; /** 更新 API */ updateApi?: (id: string | number, data: T) => Promise>; /** 成功状态码,默认 '200' */ successCode?: string | number; /** 初始模式,不传则根据 id 自动判断 */ initialMode?: PageMode; /** 导航函数(返回上一页) */ goBack?: () => void; /** 消息展示函数 */ showMessage?: (content: string, type: 'success' | 'error') => void; /** 自定义文案(支持国际化) */ messages?: Partial; /** 提交成功回调 */ onSuccess?: (mode: PageMode, data: unknown) => void; /** 提交失败回调 */ onError?: (error: Error) => void; } /** * useDetailPageMode 返回值 */ interface UseDetailPageModeReturn> { /** 当前页面模式 */ mode: PageMode; /** 是否为创建模式 */ isCreate: boolean; /** 是否为编辑模式 */ isEdit: boolean; /** 是否为查看模式 */ isView: boolean; /** 表单是否只读 */ readonly: boolean; /** 切换模式 */ setMode: (mode: PageMode) => void; /** 从查看切换到编辑 */ switchToEdit: () => void; /** 提交中状态 */ submitting: boolean; /** 提交表单 */ handleSubmit: (data: T) => Promise; /** 返回上一页 */ handleBack: () => void; } /** * 详情页模式管理 Hook * * @example * ```tsx * const { * mode, isCreate, readonly, submitting, * handleSubmit, handleBack, switchToEdit, * } = useDetailPageMode({ * id: params.id, * createApi: createUser, * updateApi: (id, data) => updateUser(id, data), * goBack: () => history.push('/user/list'), * showMessage: (content, type) => message[type](content), * onSuccess: () => actionRef.current?.reload(), * }); * * * ``` */ declare function useDetailPageMode>(options: UseDetailPageModeOptions): UseDetailPageModeReturn; /** * 文件下载 Hook */ /** * useDownload 返回值 */ interface UseDownloadReturn { /** 下载中状态 */ downloading: boolean; /** 执行下载 (从 URL) */ downloadFromUrl: (url: string, filename?: string) => Promise; /** 执行下载 (从 Blob) */ downloadFromBlob: (blob: Blob, filename: string) => void; /** 执行下载 (从 API 响应) */ downloadFromApi: (apiFn: () => Promise, filename?: string) => Promise; /** 下载 JSON 数据为文件 */ downloadJSON: (data: unknown, filename: string, options?: DownloadJSONOptions) => void; } /** * downloadJSON 选项 */ interface DownloadJSONOptions { /** 是否在文件名中添加时间戳,默认 true */ addTimestamp?: boolean; /** 日期格式函数(默认使用 ISO 日期格式 YYYYMMDDHHmmss) */ formatDate?: (date: Date) => string; } /** * 文件下载 Hook * * 支持从 URL、Blob、API 响应等多种方式下载文件。 * * @example * ```tsx * const { downloading, downloadFromUrl, downloadFromApi } = useDownload(); * * // 从 URL 下载 * * * // 从 API 下载 * * ``` */ declare function useDownload(): UseDownloadReturn; /** * 文件选择 Hook * * 提供浏览器原生文件选择能力,通过动态创建 input[type=file] 实现。 * 与 useFileUpload(管理上传过程)互补,本 hook 仅负责文件选择和读取。 * * 提供文件选择、验证和预览等功能 */ /** * 文件选择选项 */ interface FileSelectOptions { /** 接受的文件类型,如 '.json', '.csv', 'image/*' */ accept?: string; /** 是否允许多选 */ multiple?: boolean; } /** * useFileSelector 返回值 */ interface UseFileSelectorReturn { /** 选择并读取 JSON 文件,返回解析后的数据 */ selectJSONFile: (options?: FileSelectOptions) => Promise; /** 选择文件,返回 File 对象 */ selectFile: (options?: FileSelectOptions) => Promise; /** 选择多个文件,返回 File 数组 */ selectFiles: (options?: Omit) => Promise; } /** * 文件选择 Hook * * 通过动态创建隐藏的 input[type=file] 元素来选择文件。 * 内置并发防护,同一时间只允许一个文件选择操作。 * * @example * ```tsx * const { selectJSONFile, selectFile } = useFileSelector(); * * // 选择 JSON 文件 * const data = await selectJSONFile(); * * // 选择任意文件 * const file = await selectFile({ accept: '.csv,.xlsx' }); * ``` */ declare function useFileSelector(): UseFileSelectorReturn; /** * 文件上传 Hook */ /** * useFileUpload 配置 */ interface UseFileUploadOptions { /** * 上传 API 函数 * * @param file - 文件对象 * @param onProgress - 进度回调 * @param signal - AbortSignal,可用于取消上传 */ uploadApi: (file: File, onProgress?: (percent: number) => void, signal?: AbortSignal) => Promise; /** 允许的文件类型 (如 ['.jpg', '.png', 'image/*']) */ allowedTypes?: string[]; /** 最大文件大小 (字节) */ maxSize?: number; /** 上传成功回调 */ onSuccess?: (result: R, file: File) => void; /** 上传失败回调 */ onError?: (error: Error, file: File) => void; } /** * useFileUpload 返回值 */ interface UseFileUploadReturn { /** 上传中状态 */ uploading: boolean; /** 上传进度 (0-100) */ progress: number; /** 执行上传 */ upload: (file: File) => Promise; /** 取消上传 */ abort: () => void; /** 重置状态 */ reset: () => void; } /** * 文件上传 Hook * * 管理文件上传的进度、类型验证、大小限制和取消功能。 * * @example * ```tsx * const { uploading, progress, upload } = useFileUpload({ * uploadApi: (file) => uploadFile(file), * allowedTypes: ['.jpg', '.png'], * maxSize: 5 * 1024 * 1024, // 5MB * onSuccess: (result) => message.success('上传成功'), * onError: (err) => message.error(err.message), * }); * * { upload(file); return false; }}> * * * ``` */ declare function useFileUpload(options: UseFileUploadOptions): UseFileUploadReturn; /** * Form Modal 状态管理 Hook * * 将三个项目中大量重复的「Modal + Form + Loading + Create/Edit」模式 * 抽象为一个统一的 hook。 * * 功能: * - 自动管理 modal 的 open / close 状态 * - 区分 create 和 edit 模式 * - 编辑时自动回填 form 数据 (支持 transform) * - 提交时根据模式自动调用 create / update API * - 内置 loading 状态 + 防重复提交 * - 成功 / 失败消息自动处理 */ /** * 表单模式 */ type FormModalMode = 'create' | 'edit'; /** * FormModal 文案配置(支持国际化) */ interface FormModalMessages { /** 创建模式标题,默认 'Create' */ createTitle: string; /** 编辑模式标题,默认 'Edit' */ editTitle: string; /** 创建成功提示,默认 'Created successfully' */ createSuccess: string; /** 更新成功提示,默认 'Updated successfully' */ updateSuccess: string; /** 操作失败提示,默认 'Operation failed' */ operationFailed: string; } /** * useFormModal 配置 */ interface UseFormModalOptions = Record, RecordType = FormValues, CreateResult = unknown, UpdateResult = unknown> { /** Ant Design Form 实例 */ form: { setFieldsValue: (values: Partial) => void; resetFields: () => void; validateFields: () => Promise; }; /** 创建 API */ createApi?: (data: FormValues) => Promise>; /** 更新 API */ updateApi?: (data: FormValues) => Promise>; /** 成功状态码, 默认 '200' */ successCode?: string | number; /** * 将记录数据转换为表单初始值 * (编辑模式: record -> form values) */ transformToForm?: (record: RecordType) => Partial; /** * 将表单值转换为提交数据 * (提交时: form values -> API params) */ transformToSubmit?: (values: FormValues, mode: FormModalMode, record: RecordType | null) => FormValues; /** 自定义文案(支持国际化) */ messages?: Partial; /** 消息展示函数 */ showMessage?: (content: string, type: 'success' | 'error') => void; /** 提交成功回调 */ onSuccess?: (mode: FormModalMode, result: CreateResult | UpdateResult) => void; /** 提交失败回调 */ onError?: (error: Error) => void; /** modal 关闭时是否重置表单, 默认 true */ resetOnClose?: boolean; } /** * useFormModal 返回值 */ interface UseFormModalReturn> { /** modal 是否可见 */ visible: boolean; /** 当前模式 */ mode: FormModalMode; /** 当前编辑的记录数据 (create 模式为 null) */ record: RecordType | null; /** 提交中状态 */ loading: boolean; /** 模态框标题 (根据 mode 自动生成 'Create' / 'Edit') */ title: string; /** 打开 modal — 创建模式 */ openCreate: () => void; /** 打开 modal — 编辑模式 */ openEdit: (record: RecordType) => void; /** 关闭 modal */ close: () => void; /** 执行提交 (校验表单 + 调 API) */ submit: () => Promise; /** * 展开到 Modal 的 props * * @example * ```tsx * *
...
*
* ``` */ modalProps: { open: boolean; title: string; confirmLoading: boolean; onCancel: () => void; onOk: () => Promise; destroyOnClose: boolean; }; } /** * Form Modal 状态管理 Hook * * @example * ```tsx * const [form] = Form.useForm(); * * const { * modalProps, * openCreate, * openEdit, * } = useFormModal({ * form, * createApi: createUser, * updateApi: updateUser, * showMessage: (content, type) => message[type](content), * onSuccess: () => actionRef.current?.reload(), * }); * * // 工具栏 * * * // 行操作 * openEdit(record)}>编辑 * * // 弹窗 * *
* * * *
*
* ``` * * @example * ```tsx * // 带数据转换 * const { modalProps, openEdit } = useFormModal({ * form, * updateApi: updateUser, * transformToForm: (record) => ({ * ...record, * birthday: dayjs(record.birthday), * }), * transformToSubmit: (values) => ({ * ...values, * birthday: values.birthday?.format('YYYY-MM-DD'), * }), * showMessage: (content, type) => message[type](content), * onSuccess: () => reload(), * }); * ``` */ declare function useFormModal = Record, RecordType = FormValues, CreateResult = unknown, UpdateResult = unknown>(options: UseFormModalOptions): UseFormModalReturn; /** * 表单提交 Hook * * 封装表单提交的常见逻辑:loading 状态管理、防重复提交、成功/失败回调。 * 适用于各种表单场景(ProForm、Modal 表单、独立表单页等)。 * * 通用表单提交处理 */ /** * useFormSubmit 配置 */ interface UseFormSubmitOptions, R = unknown> { /** 提交 API 函数 */ submitApi: (data: T) => Promise>; /** 成功状态码,默认 '200' */ successCode?: string | number; /** 提交前的数据转换 */ transformData?: (data: T) => T; /** 成功提示消息 */ successMsg?: string; /** 消息展示函数 */ showMessage?: (content: string, type: 'success' | 'error') => void; /** 提交成功回调 */ onSuccess?: (data: R) => void; /** 提交失败回调 */ onError?: (error: Error) => void; /** 提交完成回调(无论成功或失败) */ onFinally?: () => void; } /** * useFormSubmit 返回值 */ interface UseFormSubmitReturn> { /** 提交中状态 */ submitting: boolean; /** 提交函数 */ submit: (data: T) => Promise; /** 重置提交状态 */ reset: () => void; } /** * 表单提交 Hook * * @example * ```tsx * // 基础用法 * const { submitting, submit } = useFormSubmit({ * submitApi: createUser, * successMsg: '创建成功', * showMessage: (content, type) => message[type](content), * onSuccess: () => history.push('/user/list'), * }); * * * * // Modal 表单 * const { submitting, submit } = useFormSubmit({ * submitApi: (data) => updateUser(id, data), * successMsg: '更新成功', * showMessage: (content, type) => message[type](content), * onSuccess: () => { modal.close(); actionRef.current?.reload(); }, * }); * * * ``` */ declare function useFormSubmit, R = unknown>(options: UseFormSubmitOptions): UseFormSubmitReturn; /** * i18n 便捷 Hook * * 简化 UmiJS useIntl().formatMessage() 的调用,提供更简洁的 API。 * */ /** * 国际化函数类型 */ type IntlFormatMessage = (descriptor: { id: string; defaultMessage?: string; }, values?: Record) => string; /** * useIntlText 配置 */ interface UseIntlTextOptions { /** formatMessage 函数(通常来自 useIntl()) */ formatMessage: IntlFormatMessage; /** key 前缀,自动拼接到所有 id 前面 */ prefix?: string; } /** * useIntlText 返回值 */ interface UseIntlTextReturn { /** 获取国际化文本 */ t: (id: string, defaultMessage?: string, values?: Record) => string; /** 获取国际化文本(带前缀的简写) */ tp: (id: string, defaultMessage?: string, values?: Record) => string; } /** * i18n 便捷 Hook * * @example * ```tsx * import { useIntl } from '@umijs/max'; * * function MyComponent() { * const intl = useIntl(); * const { t, tp } = useIntlText({ * formatMessage: intl.formatMessage, * prefix: 'pages.user', * }); * * return ( *
*

{t('app.title', '应用标题')}

*

{tp('name', '用户名')}

{// => pages.user.name} *

{tp('greeting', '你好, {name}', { name: 'Alice' })}

*
* ); * } * ``` */ declare function useIntlText(options: UseIntlTextOptions): UseIntlTextReturn; /** * 稳定引用 Hook * * 将任意值(尤其是回调函数)存入 ref,每次渲染时同步更新。 * 用于在 useCallback / useEffect 中安全读取最新值,同时避免将不稳定的 * 内联函数/对象放入依赖数组导致无限更新。 * * 采用 render-time 直接赋值模式(而非 useEffect),确保 ref 在 render 阶段 * 即刻同步,避免 render → commit 之间的 stale 窗口。 */ /** * 返回一个始终指向最新 `value` 的 ref 对象 * * @example * ```ts * const onSuccessRef = useLatestRef(options.onSuccess); * * const submit = useCallback(async () => { * const result = await api(); * onSuccessRef.current?.(result); // 始终调用最新回调 * }, [api]); // 无需将 onSuccess 放入依赖 * ``` */ declare function useLatestRef(value: T): React.MutableRefObject; /** * 非分页列表数据 Hook * * 用于加载不需要分页的简单列表数据,如下拉选项、标签列表、分类列表等。 * 与 useTableData(分页列表)互补。 */ /** * useListData 配置 */ interface UseListDataOptions { /** 列表数据请求 API */ fetchApi: (params?: P) => Promise>; /** 请求参数(变化时自动重新请求) */ params?: P; /** 是否在挂载时自动请求,默认 true */ autoLoad?: boolean; /** 成功状态码,默认 '200' */ successCode?: string | number; /** 数据转换 */ transformData?: (list: T[]) => T[]; /** 请求成功回调 */ onSuccess?: (list: T[]) => void; /** 请求失败回调 */ onError?: (error: Error) => void; } /** * useListData 返回值 */ interface UseListDataReturn { /** 列表数据 */ data: T[]; /** 加载中状态 */ loading: boolean; /** 错误信息 */ error: Error | null; /** 手动刷新 */ refresh: () => Promise; /** 手动设置数据 */ setData: React.Dispatch>; } /** * 非分页列表数据 Hook * * @example * ```tsx * // 基础用法:下拉选项 * const { data: categories, loading } = useListData({ * fetchApi: getCategoryList, * }); * * // 带参数:按条件加载 * const { data: tags, refresh } = useListData({ * fetchApi: (params) => getTagList(params), * params: { type: 'article' }, * }); * * // 数据转换:转为 Select options * const { data: options } = useListData({ * fetchApi: getRoleList, * transformData: (list) => list.map(r => ({ label: r.name, value: r.id })), * }); * ``` */ declare function useListData(options: UseListDataOptions): UseListDataReturn; /** * 模态框状态管理 Hook */ /** * useModal 返回值 */ interface UseModalReturn { /** 模态框是否可见 */ visible: boolean; /** 模态框携带的数据 */ data: T | null; /** 加载中状态 */ loading: boolean; /** 打开模态框 (可传入数据) */ open: (data?: T | undefined) => void; /** 关闭模态框 */ close: () => void; /** 切换模态框可见状态 */ toggle: () => void; /** 设置加载状态 */ setLoading: (loading: boolean) => void; /** 设置数据 */ setData: Dispatch>; } /** * 模态框状态管理 Hook * * @example * ```tsx * const editModal = useModal(); * * * * * * * ``` */ declare function useModal(): UseModalReturn; /** * 响应式断点检测 Hook */ /** * 断点配置 */ interface Breakpoints { /** 移动端最大宽度,默认 576 */ mobile?: number; /** 平板最大宽度,默认 768 */ tablet?: number; /** 桌面端最小宽度,默认 1200 */ desktop?: number; } /** * 响应式状态 */ interface ResponsiveState { /** 是否为移动端 (宽度 < mobile) */ isMobile: boolean; /** 是否为平板 (mobile <= 宽度 < desktop) */ isTablet: boolean; /** 是否为桌面端 (宽度 >= desktop) */ isDesktop: boolean; /** 当前视口宽度 */ width: number; } /** * 响应式断点检测 Hook * * 监听窗口大小变化,返回当前设备类型。 * * @param breakpoints - 自定义断点值 * @returns 响应式状态 * * @example * ```tsx * const { isMobile, isTablet, isDesktop } = useResponsive(); * * return isMobile ? : ; * ``` */ declare function useResponsive(breakpoints?: Breakpoints): ResponsiveState; /** * 表格配置 Hook * * 为 ProTable 生成标准化的配置: * - 工具栏按钮 (新建、导出、回收站) * - 行操作 (查看、编辑、删除) * - 分页配置 */ /** * 行操作项 */ interface RowAction> { /** 操作 key */ key: string; /** 显示文本 */ label: React$1.ReactNode; /** 点击回调 */ onClick?: (record: T) => void; /** 是否危险操作 (红色) */ danger?: boolean; /** 是否需要确认弹窗 */ confirm?: { title: string; content?: React$1.ReactNode | ((record: T) => React$1.ReactNode); }; /** 确认后的回调 */ onConfirm?: (record: T) => void | Promise; /** 是否隐藏 */ hidden?: boolean | ((record: T) => boolean); /** 是否禁用 */ disabled?: boolean | ((record: T) => boolean); } /** * 工具栏按钮 */ interface ToolbarAction { /** 按钮 key */ key: string; /** 显示文本 */ text: string; /** 按钮类型 */ type?: 'primary' | 'default' | 'dashed' | 'link' | 'text'; /** 点击回调 */ onClick: () => void; /** 图标 */ icon?: React$1.ReactNode; /** 是否隐藏 */ hidden?: boolean; } /** * 表格配置文案(支持国际化) */ interface TableConfigMessages { /** 操作列标题,默认 'Actions' */ actionColumnTitle: string; /** 总数展示函数,默认 (total) => `Total ${total}` */ showTotal: (total: number) => string; } /** * useTableConfig 配置 */ interface UseTableConfigOptions> { /** 行操作配置 */ rowActions?: ReadonlyArray>; /** 工具栏按钮 */ toolbar?: ReadonlyArray; /** 默认每页条数, 默认 10 */ defaultPageSize?: number; /** 可选每页条数, 默认 [10, 20, 50, 100] */ pageSizeOptions?: number[]; /** 表格行 key 字段, 默认 'id' */ rowKey?: string; /** 表格滚动宽度, 默认 'max-content' */ scrollX?: number | string; /** 操作列宽度 */ actionColumnWidth?: number; /** 操作列固定, 默认 'right' */ actionColumnFixed?: 'left' | 'right' | false; /** 自定义文案(支持国际化) */ messages?: Partial; /** 确认弹窗函数 (需外部注入,未提供时使用 Popconfirm) */ showConfirm?: (options: { title: string; content?: React$1.ReactNode; onOk: () => Promise | void; }) => void; } /** * useTableConfig 返回值 */ interface UseTableConfigReturn> { /** 传给 ProTable 的 pagination 配置 */ pagination: { pageSize: number; pageSizeOptions: number[]; showSizeChanger: boolean; showTotal: (total: number) => string; }; /** 表格属性 */ tableProps: { rowKey: string; scroll: { x: number | string; }; }; /** 工具栏渲染 — 传给 ProTable toolBarRender */ toolBarRender: () => React$1.ReactNode[]; /** 操作列配置 — 作为 columns 最后一列 */ actionColumn: { title: string; dataIndex: string; key: string; width?: number; fixed?: 'left' | 'right'; render: (_: unknown, record: T) => React$1.ReactNode; }; /** 生成行操作渲染 (给定 record) */ renderRowActions: (record: T) => React$1.ReactNode; } /** * 表格配置 Hook * * @example * ```tsx * const { * pagination, * tableProps, * toolBarRender, * actionColumn, * } = useTableConfig({ * toolbar: [ * { key: 'create', text: '新增', type: 'primary', onClick: () => openCreate() }, * { key: 'export', text: '导出', onClick: () => handleExport() }, * ], * rowActions: [ * { key: 'view', label: '查看', onClick: (r) => goDetail(r.id) }, * { key: 'edit', label: '编辑', onClick: (r) => openEdit(r) }, * { * key: 'delete', label: '删除', danger: true, * confirm: { title: '确认删除', content: (r) => `确定要删除 ${r.name} 吗?` }, * onConfirm: (r) => handleDelete(r.id), * }, * ], * showConfirm: ({ title, content, onOk }) => Modal.confirm({ title, content, onOk }), * }); * * const columns = [ * { title: '姓名', dataIndex: 'name' }, * { title: '邮箱', dataIndex: 'email' }, * actionColumn, // 操作列 * ]; * * * ``` */ declare function useTableConfig = Record>(options?: UseTableConfigOptions): UseTableConfigReturn; /** * ProTable 数据请求 Hook * */ /** * useTableData 配置 */ interface UseTableDataOptions> { /** API 请求函数 */ fetchApi: (params: P) => Promise>>; /** 成功状态码,默认 '200' */ successCode?: string | number; /** 请求前的参数转换 */ transformParams?: (params: TableRequestParams) => P; /** 响应后的数据转换 */ transformData?: (list: T[]) => T[]; /** 请求失败回调 */ onError?: (error: Error) => void; /** 数据加载完成回调 */ onDataLoaded?: (data: T[], total: number) => void; /** 默认额外查询参数 */ defaultParams?: Partial

; } /** * useTableData 返回值 */ interface UseTableDataReturn> { /** 传递给 ProTable 的 request 函数 */ request: (params: TableRequestParams, sort?: Record, filter?: TableRequestParams) => Promise>; /** 刷新表格 (需要配合 actionRef) */ reload: (resetPageIndex?: boolean) => Promise; /** 刷新并重置分页到第一页 */ reloadAndRest: () => Promise; /** 设置额外参数并重新加载(重置分页) */ search: (params?: Partial

) => void; /** 重置额外参数并重新加载 */ reset: () => void; /** 设置额外查询参数(不触发请求) */ setExtraParams: (params: Partial

) => void; /** 当前额外查询参数 */ extraParams: Partial

; /** 加载中状态 */ loading: boolean; /** actionRef - 传给 ProTable */ actionRef: React.MutableRefObject; } interface TablePageInfo { pageSize: number; total: number; current: number; } type TableEditableKey = React.Key | React.Key[]; type TableEditableRecord = Record; interface TableEditableState { recordKey: string; isEditable: unknown; preIsEditable: unknown; } interface TableActionRef { reload: (resetPageIndex?: boolean) => Promise; reloadAndRest?: () => Promise; reset?: () => void; clearSelected?: () => void; pageInfo?: TablePageInfo; isEditable: (row: TableEditableRecord & { index: number; }) => TableEditableState; startEditable: (recordKey: React.Key, record?: TableEditableRecord) => boolean; cancelEditable: (recordKey: TableEditableKey, needReTry?: boolean) => Promise; addEditRecord: (row: TableEditableRecord, options?: unknown) => boolean; saveEditable: (recordKey: TableEditableKey, needReTry?: boolean) => Promise; preEditableKeys: React.Key[] | undefined; onValuesChange: (value: TableEditableRecord, values: TableEditableRecord) => void; getRealIndex: ((record: TableEditableRecord) => number) | undefined; } /** * ProTable 数据请求 Hook * * @example * ```tsx * const { request, actionRef, reload, loading } = useTableData({ * fetchApi: (params) => getUserList(params), * transformParams: (params) => ({ * pageNo: params.current, * pageSize: params.pageSize, * ...params, * }), * onDataLoaded: (data, total) => console.log('loaded', total), * }); * * * ``` */ declare function useTableData>(options: UseTableDataOptions): UseTableDataReturn; /** * 用户偏好管理 Hook * * 提供用户偏好设置的读写能力: * - 支持 localStorage 缓存 (离线可用) * - 支持可选的 API 同步 (云端持久化) * - 自动合并默认值 (浅合并) * - 防抖同步 * */ /** * useUserPreference 配置 */ interface UseUserPreferenceOptions> { /** 偏好设置 key (localStorage 和 API 共用) */ key: string; /** 默认值 */ defaultValue: T; /** localStorage 缓存 key 前缀, 默认 'user-pref-' */ storagePrefix?: string; /** 是否启用 localStorage 缓存, 默认 true */ enableCache?: boolean; /** 读取 API (可选, 不传则仅使用 localStorage) */ fetchApi?: (key: string) => Promise>; /** 保存 API (可选) */ saveApi?: (key: string, value: T) => Promise>; /** API 成功状态码, 默认 '200' */ successCode?: string | number; /** 保存防抖延迟 (ms), 默认 500 */ debounceMs?: number; /** 值变化回调 */ onChange?: (value: T) => void; } /** * useUserPreference 返回值 */ interface UseUserPreferenceReturn { /** 当前偏好值 */ value: T; /** 设置偏好值 */ setValue: (value: T | ((prev: T) => T)) => void; /** 重置为默认值 */ reset: () => void; /** 是否正在加载 */ loading: boolean; /** 是否正在保存 */ saving: boolean; /** 手动同步到服务器 */ sync: () => Promise; } /** * 用户偏好管理 Hook * * @example * ```tsx * // 纯本地偏好 * const { value: theme, setValue: setTheme } = useUserPreference({ * key: 'theme', * defaultValue: { mode: 'light', primaryColor: '#1677ff' }, * }); * * // 带 API 同步 * const { value: layout, setValue: setLayout, loading } = useUserPreference({ * key: 'layout', * defaultValue: { sidebarCollapsed: false, contentWidth: 'fluid' }, * fetchApi: (key) => getUserPreference(key), * saveApi: (key, value) => saveUserPreference(key, value), * }); * * // 使用 * * setLayout(prev => ({ ...prev, sidebarCollapsed: !checked })) * } /> * ``` */ declare function useUserPreference>(options: UseUserPreferenceOptions): UseUserPreferenceReturn; export { type Breakpoints, type DetailPageModeMessages, type DownloadJSONOptions, type FileSelectOptions, type FormModalMessages, type FormModalMode, type PageMode, type RowAction, type TableConfigMessages, type ToolbarAction, type UseCrudListOptions, type UseCrudListReturn, type UseDetailPageModeOptions, type UseDetailPageModeReturn, type UseDetailPageOptions, type UseDetailPageReturn, type UseDownloadReturn, type UseFileSelectorReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseFormModalOptions, type UseFormModalReturn, type UseFormSubmitOptions, type UseFormSubmitReturn, type UseIntlTextOptions, type UseIntlTextReturn, type UseListDataOptions, type UseListDataReturn, type UseModalReturn, type UseTableConfigOptions, type UseTableConfigReturn, type UseTableDataOptions, type UseTableDataReturn, type UseUserPreferenceOptions, type UseUserPreferenceReturn, useCrudList, useDetailPage, useDetailPageMode, useDownload, useFileSelector, useFileUpload, useFormModal, useFormSubmit, useIntlText, useLatestRef, useListData, useModal, useResponsive, useTableConfig, useTableData, useUserPreference };