Files
2026-09-22 16:04:51 +08:00

172 lines
6.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { WidgetType, WidgetContainerProps } from './button';
export { default as useMergedState } from 'rc-util/lib/hooks/useMergedState';
export { default as useEvent } from 'rc-util/lib/hooks/useEvent';
/**
* 返回一个强制刷新函数;组件卸载后调用无效果
* @returns {() => void} 调用后触发一次重新渲染
*/
declare function useUpdate(): () => void;
/**
* 类似 useState,但 setState 支持传入更新完成后的回调
* @param {*} initialState 初始状态
* @returns {[*, (newState: *, callback?: (state: *) => void) => void]} [当前状态, 支持回调的 setState]
*/
declare function useStateWithCallback(initialState: any): [any, (newState: any, callback?: (state: any) => void) => void];
/**
* 依赖做深度比较的 useEffect,deps 引用变化但深度相等时不会重新执行
* @param {(prevDeps: *) => void} callback 副作用回调,参数为上一次的 deps
* @param {*} deps 依赖值(任意可深度比较的值,不要求是数组)
* @param {(a: *, b: *) => boolean} [compare] 自定义比较函数,默认使用 lodash isEqual
*/
declare function useDeepEqualEffect(callback: (prevDeps: any) => void, deps: any, compare?: (a: any, b: any) => boolean): void;
/** useDeepEqualEffect 的别名 */
declare function useDeepEffect(callback: (prevDeps: any) => void, deps: any, compare?: (a: any, b: any) => boolean): void;
/**
* 解析表单字段的选项配置,支持静态数组或一段 JavaScript 表达式(动态计算选项,可依赖其他字段的值)
* @param {Array|string} options 静态选项数组,或语言为 javascript 时的表达式源码
* @param {string} [language] 选项的类型,'javascript' 时把 options 当表达式执行
* @param {string} [type] 选项 value 的目标类型,用于类型转换(如 'string'/'number')
* @param {*} [form] 关联的 rc-field-form 表单实例,不传时 rc-field-form 会自建一个
* @param {*} [basicForm] 表达式里 getFieldValueForBasicForm 取值用的外层表单实例
* @returns {Array} 解析后的选项列表
*/
declare function useOptions(options: any[] | string, language?: string, type?: string, form?: any, basicForm?: any): any[];
/**
* 发起 GET 请求并通过 WebSocket 订阅后续更新,数据变化时自动重新拉取
* @param {string|{url: string, [key: string]: *}} param 请求地址,或包含 url 的请求配置对象
* @returns {*} 最新一次响应的数据,初始为 undefined
*/
declare function useSubscribeRequest(param: string | {
url: string;
[key: string]: any;
}): any;
/**
* 生成一个用于更新组件 props 的函数;命中 router/query 类型的字段会走路由跳转,其余走本地 state 合并
* @param {Object} $props props 的类型/来源配置
* @param {(local: Object) => void} setLocal 合并本地 props 的函数
* @returns {(patch: Object) => void} 应用一批 props 变更
*/
declare function useWidgetPropsUpdater($props: any, setLocal: (local: any) => void): (patch: any) => void;
/**
* 解析组件 props 配置(支持路由参数、表达式等来源),并允许外部局部覆盖
* @param {Object} $props props 的类型/来源配置
* @param {Object} [data] 表达式求值时可用的上下文数据
* @param {Object} [fns] 表达式求值时可调用的额外函数
* @param {Array} [deps] 触发重新解析的额外依赖项
* @returns {[Object, (patch: Object) => void, Object]} [最终生效的 props, 更新 props 的函数, 被本地覆盖的字段]
*/
declare function useWidgetProps($props: any, data?: any, fns?: any, deps?: any[]): [any, (patch: any) => void, any];
// ===== 用户数据结构(复用类型,JSDoc 无法跨文件引用,放 .d.ts) =====
interface UserRoleBinding {
user_uuid: string
role_uuid: string
created_at: string
updated_at: string
created_user: string
owned_user: string
}
interface UserInfo {
uuid: string
username: string
nickname: string
email: string
last_login_ip: string
is_active: 0 | 1
UserRole: UserRoleBinding[]
[key: string]: unknown
}
interface MenuItem {
/** 菜单唯一标识 */
uuid: string
/** 菜单显示名称 */
name: string
/** 图标 class 名 */
icon: string
/** 行为目标(组件标识 / 路由 uuid 等),含义随 widgetType 而定 */
widget: string
/** 行为类型 */
widgetType: WidgetType
/** 传给目标组件的 props 映射配置 */
widgetProps: Record<string, unknown>
/** 传给目标组件的 $setting 配置 */
widgetSetting: Record<string, unknown>
/** 弹窗容器配置 */
widgetContainerSetting: WidgetContainerProps
/** 子菜单 */
children?: MenuItem[]
}
interface RouteItem {
/** 路由唯一标识 */
uuid: string
/** 路由名称 */
name: string
/** react-router path,支持动态参数(如 /page/:id) */
uri: string
/** 是否为布局路由(外层 layout,不直接渲染页面内容) */
isLayout: boolean
/** 是否需要登录才能访问 */
isLogin: boolean
/** 是否为手机端专属路由 */
isPhone: boolean
/** 路由类型 */
type: Exclude<WidgetType, 'redirect'>
/** 是否精确匹配路径 */
exact: boolean
/** widget 标识(等同于 ButtonProps.widget),经 core.getWidgetComponent 加载 */
component: string
/** 传给页面组件的 props 映射配置 */
widgetProps: Record<string, unknown>
/** 传给页面组件的 $setting 配置 */
widgetSetting: Record<string, unknown>
/** 弹窗容器配置 */
widgetContainerSetting: WidgetContainerProps
/** 附加配置(如 layout 标识等) */
extra?: Record<string, unknown>
}
// ===== http — Proxy 模式产生交叉类型,JSDoc 无法表达 =====
/** 每次请求自动附加的请求头 */
interface HttpHeaders {
/** 客户端平台标识,固定为 'web' */
Platform: string
/** SaaS 租户标识,单租户时为 null */
SaaS: string | null
/** JWT Bearer token,未登录时为 undefined */
Authorization: string | undefined
}
// ===== func — ff-worker-pipe 无类型文件,显式声明 =====
/**
* 基于 Worker 的表达式执行引擎单例;
* exec 在独立 Worker 上下文中求值一段 JS 表达式/源码
*/
interface WorkerPipeInstance {
/**
* 在 Worker 上下文中执行一段 JS 表达式
* @param expression 要执行的表达式字符串
* @param args 传给表达式的参数(可在表达式内作为第一个参数使用)
* @param fns 注入到表达式执行作用域的额外可调用函数
* @param session 会话标识;相同 session 共享 Worker 侧工作区(this)
*/
exec: (
expression: string,
args?: Record<string, unknown>,
fns?: Record<string, Function>,
session?: string
) => Promise<unknown>
/** 清除指定 session 的 Worker 侧工作区 */
clear: (session: string) => void
}
export { useDeepEffect, useDeepEqualEffect, useOptions, useStateWithCallback, useSubscribeRequest, useUpdate, useWidgetProps, useWidgetPropsUpdater };
export type { HttpHeaders, MenuItem, RouteItem, UserInfo, UserRoleBinding, WorkerPipeInstance };