Files
FunJiaUI_Vue_Package/UmTable/core/columns.d.ts
T
funjia e6c195e6fa feat: 产物更新,表格列支持冻结(fixed)
- funjiaui.es.js / cjs / umd 重新构建,包含列冻结能力
- UmTable/types.d.ts 新增 TFixed,IFieldMetaValue / IOperateItem 增加 fixed
- UmTable/core/columns.d.ts 新增 hasLeftFixedColumn 等导出
- UmTable/UmTableColumn.vue.d.ts 增加 fixed 属性

用法:数据列 fixed: "left" | "right" | true;
操作列在配置类上写 operateFixed = "right"。默认为不冻结,既有调用方行为不变。
2026-09-23 23:33:54 +08:00

118 lines
5.5 KiB
TypeScript
Raw 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 { VNode } from "vue";
import type { IToolbar, TDecoratorKey, TEvent, TFixed, TOperateType } from "../types";
import { type IEventTask, type TFireHook } from "./events";
/**
* 列 / 操作列 / 工具栏的装配逻辑。
*
* 改造前这段"扫描类元数据 -> 拼 h() 节点 -> 造事件闭包"的代码
* 全写在 UmByClass.vue 的 render() 里(200+ 行),
* 每次渲染都要重建一遍,且无法复用、无法单测。这里抽成纯函数。
*/
/** 收集数据列 VNode(按 sort 升序) */
export declare const collectDataColumns: (target: any) => VNode[];
/**
* 把配置里写的冻结值规范化成 el-table 认识的形式。
*
* - `true` / `"left"` -> `"left"`(`true` 是历史写法,语义就是左侧)
* - `"right"` -> `"right"`
* - `false` / 其他非法值 -> `undefined`(不冻结,交给诊断模块报出来)
*/
export declare const normalizeFixed: (value: TFixed | undefined) => "left" | "right" | undefined;
/** `fixed` 的合法取值(供诊断模块判断"写错的值") */
export declare const FIXED_VALUES: TFixed[];
/**
* 数据列里是否存在左侧冻结列。
*
* 序号 / 选择 / 展开列是组件自动插到最前面的,它们不在配置类里声明。
* 一旦有数据列冻结到左侧,这三列如果不跟着冻结,就会夹在边缘与冻结列之间,
* 导致后面的冻结列失效(el-table 要求冻结列从边缘起连续)。
* 所以组件用这个函数决定"要不要把前置列一起冻结"。
*/
export declare const hasLeftFixedColumn: (target: any) => boolean;
/** 数据列里是否存在右侧冻结列(用于判断操作列是否该并入右侧冻结组) */
export declare const hasRightFixedColumn: (target: any) => boolean;
/** 操作列分组:同一 id(缺省用 type)的多个方法会聚合到同一个按钮上 */
export interface IOperateGroup {
type: TOperateType;
sort: number;
title?: any;
isShow?: (rowData: any) => boolean;
tasks: IEventTask[];
}
/**
* 按 id(缺省用 type)聚合操作列配置。
*
* 说明:`@TableColumnMethodDecorator` 允许给多个方法配同一个 `type`,
* 分别声明 `es: "onBefore" / "onNow" / "onAfter"`,运行时串成一条链,
* 从而做到"先取详情 -> 再弹窗 -> 最后提交"。
*/
export declare const collectOperateGroups: (target: any) => IOperateGroup[];
/**
* 是否需要渲染操作列。
*
* 原判断:`(operates.length > 0 && !targetInstance.isShowOperate) || targetInstance?.isShowOperate?.()`
* - 存在操作按钮但 `isShowOperate()` 返回 false 时,因为 `!undefined` 为真仍会渲染出空操作列;
* - 没有操作按钮但 `isShowOperate()` 返回 true 时会渲染出一个空列。
* 这里改成明确的语义:有按钮 && (未配置 isShowOperate 或其为真)。
*/
export declare const resolveShowOperate: (target: any, hasOperate: boolean) => boolean;
/** 解析操作列宽度(支持实例属性与类静态属性两种写法) */
export declare const resolveOperateWidth: (target: any, fallback?: number | string) => number | string;
/**
* 解析操作列的冻结方向。
*
* 与 `operateWidth` 一样,在配置类上声明一个**普通属性**即可(不加装饰器):
* ```ts
* export class Employee {
* operateWidth = 190;
* operateFixed = "right"; // 操作列冻结在右侧
* }
* ```
*
* 默认不冻结 —— 这是新能力,不改变既有表格的行为。
*/
export declare const resolveOperateFixed: (target: any) => "left" | "right" | undefined;
export interface IBuildOperateColumnOptions {
fire: TFireHook;
/** 透传给操作事件的行数据集合 */
tableData?: any[];
width?: number | string;
/** 冻结方向,见 resolveOperateFixed */
fixed?: "left" | "right";
/** 需要延后执行 onAfter 的按钮类型,见 IDeferOptions */
deferAfterTypes?: string[];
}
/**
* 默认的"弹窗确认型"按钮类型。
*
* 这些按钮的 `onAfter` 会被摘出主事件链,由组件在弹窗给出结果后补跑。
* 单独抽成常量是为了让配置体检(`./diagnose`)和组件用同一份清单判断
* "这个按钮是不是应该有 onAfter" —— 两边各写一份字符串迟早会对不上。
*/
export declare const DEFAULT_DEFER_TYPES: string[];
/** 生成操作列 VNode;没有操作按钮时返回 null */
export declare const buildOperateColumn: (groups: IOperateGroup[], options: IBuildOperateColumnOptions) => VNode | null;
/** 工具栏收集结果 */
export interface IToolbarCollectResult {
toolbars: IToolbar[];
events: TEvent[];
}
/**
* 收集某个装饰器下、指定 `type` 的全部方法,按优先级降序返回。
*
* 用于"弹窗确定后补跑 onAfter"这类只需要部分阶段的场景:
* 同一个按钮的多个方法(不同 `es`)都要收进来,但只执行其中某几个阶段。
*/
export declare const collectTypedTasks: (target: any, decoratorKey: TDecoratorKey, type: string) => IEventTask[];
/**
* 收集工具栏按钮与对应事件。
*
* 关于 `rerunOnAfterFalsy`:原实现靠它实现"弹窗被取消 / 接口失败后重来一轮",
* 但事件链在 onAfter 返回假值时会用 `i -= 2` 回到第一阶段,若业务方法持续返回假值
* 就会把弹窗反复重开。改造后弹窗改为"挂起事件链、确认后再继续"(见 deferAfterTypes),
* 不再需要这个重跑机制,这里默认关闭,只在显式要求时启用。
*/
export declare const collectToolbar: (target: any, fire: TFireHook, options?: {
deferAfterTypes?: string[];
}) => IToolbarCollectResult;