Files
funjia f26bd3f377 feat: 更新为 1.2.0 构建产物(内核重构版)
- 产物替换为 funjiaui.es.js / funjiaui.cjs.js / funjiaui.umd.js
- style.css 更新,新增 index.d.ts 与各组件类型声明目录
- 移除旧产物 um_table.es.js(1.0.0 的 ES 包,历史与 v1.0.0 标签仍可回溯)
- package.json 补齐 module / types / unpkg / jsdelivr / files 字段,
  并将 vue、element-plus、@element-plus/icons-vue 声明为 peerDependencies
- 新增 README 说明产物清单与用法
2026-09-19 01:04:09 +08:00

69 lines
3.0 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 type { TExecutionSequence, TMethodMetaValue } from "../types";
/**
* 事件链执行器。
*
* 改造前"按 priority 排序 -> 按 es 分阶段 -> 依次 await"这套逻辑
* 在 UmByClass(操作列 / 工具栏)和 UmByClassEnhance(弹窗确认)里被复制了 3 份,
* 参数顺序、是否透传行数据、是否支持重跑都各不相同。这里统一。
*/
/** 一个待执行的事件 */
export interface IEventTask {
event: (...args: any[]) => any;
meta: TMethodMetaValue;
}
/** 阶段顺序 */
export declare const EVENT_PHASES: TExecutionSequence[];
/** 按优先级排序(数字越大越先执行),不修改入参数组 */
export declare const sortTasksByPriority: (tasks: IEventTask[]) => IEventTask[];
/**
* 阶段之间的钩子,把控制权交回业务组件(弹窗、消息提示等都挂在这里)。
* - `data`:当前累积的数据
* - `type`:按钮类型("添加" / "edit" / "del" / "批量删除" ...),业务侧据此分支
* - `phase`:当前阶段
* - `meta`:该阶段第一个事件的元数据
* @returns 处理后的数据,作为下一阶段的输入
*/
export type TFireHook = (data: any, type: string, phase: TExecutionSequence, meta?: TMethodMetaValue) => Promise<any> | any;
export interface IRunEventPipelineOptions {
tasks: IEventTask[];
/** 原始入参,恒作为每个事件的第一个参数 */
rowId: any;
/**
* "当前数据"(第二个参数,也是 fire 钩子拿到的 `data`)的初始值,
* 缺省等于 `rowId`。
*
* 操作列会把整行数据作为初始值传进来:行数据通常已经是完整的,
* 组件不应该强迫使用方再写一个 `es: "onBefore"` 的方法去查一遍详情,
* 否则一旦漏写,`edit` 拿到的就只有一个行 id,表单会静默变成空的。
*/
initial?: any;
/** 按钮类型,透传给 fire 钩子 */
type: string;
/** 阶段间的钩子 */
fire: TFireHook;
/** 透传给事件的额外参数(如整表数据) */
extra?: any[];
/**
* 只执行指定阶段(默认按 onBefore -> onNow -> onAfter 全跑)。
* 弹窗"确定"时只需要补跑 onAfter,用这个参数收窄。
*/
phases?: TExecutionSequence[];
/**
* onAfter 返回假值时是否回到第一阶段重跑。
* 原 UmByClass 工具栏分支用 `i -= 2` 实现,一旦事件始终返回假值会死循环卡死页面,
* 这里保留该行为但加上最大重跑次数保护。
*/
rerunOnAfterFalsy?: boolean;
maxRerun?: number;
}
/**
* 依次执行 onBefore -> onNow -> onAfter。
*
* 事件签名固定为 `(rowId, currentData, meta, ...extra)`
* - `rowId`:原始入参(行 id / 选中项),恒定不变;
* - `currentData`:上一个事件的返回值,同阶段多个事件形成"责任链";
* - `meta`:该事件的元数据;
* - `...extra`:组件透传的额外数据(如整表数据)。
*/
export declare function runEventPipeline(options: IRunEventPipelineOptions): Promise<any>;