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"。默认为不冻结,既有调用方行为不变。
This commit is contained in:
2026-09-23 23:33:54 +08:00
parent f26bd3f377
commit e6c195e6fa
6 changed files with 154 additions and 28 deletions
+8
View File
@@ -27,6 +27,10 @@ declare const _sfc_main: import("vue").DefineComponent<{
type: (NumberConstructor | StringConstructor)[]; type: (NumberConstructor | StringConstructor)[];
required: false; required: false;
}; };
fixed: {
type: null;
required: false;
};
showOverflowTooltip: { showOverflowTooltip: {
type: BooleanConstructor; type: BooleanConstructor;
required: false; required: false;
@@ -306,6 +310,10 @@ declare const _sfc_main: import("vue").DefineComponent<{
type: (NumberConstructor | StringConstructor)[]; type: (NumberConstructor | StringConstructor)[];
required: false; required: false;
}; };
fixed: {
type: null;
required: false;
};
showOverflowTooltip: { showOverflowTooltip: {
type: BooleanConstructor; type: BooleanConstructor;
required: false; required: false;
+38 -1
View File
@@ -1,5 +1,5 @@
import type { VNode } from "vue"; import type { VNode } from "vue";
import type { IToolbar, TDecoratorKey, TEvent, TOperateType } from "../types"; import type { IToolbar, TDecoratorKey, TEvent, TFixed, TOperateType } from "../types";
import { type IEventTask, type TFireHook } from "./events"; import { type IEventTask, type TFireHook } from "./events";
/** /**
* 列 / 操作列 / 工具栏的装配逻辑。 * 列 / 操作列 / 工具栏的装配逻辑。
@@ -10,6 +10,27 @@ import { type IEventTask, type TFireHook } from "./events";
*/ */
/** 收集数据列 VNode(按 sort 升序) */ /** 收集数据列 VNode(按 sort 升序) */
export declare const collectDataColumns: (target: any) => VNode[]; 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)的多个方法会聚合到同一个按钮上 */ /** 操作列分组:同一 id(缺省用 type)的多个方法会聚合到同一个按钮上 */
export interface IOperateGroup { export interface IOperateGroup {
type: TOperateType; type: TOperateType;
@@ -37,11 +58,27 @@ export declare const collectOperateGroups: (target: any) => IOperateGroup[];
export declare const resolveShowOperate: (target: any, hasOperate: boolean) => boolean; export declare const resolveShowOperate: (target: any, hasOperate: boolean) => boolean;
/** 解析操作列宽度(支持实例属性与类静态属性两种写法) */ /** 解析操作列宽度(支持实例属性与类静态属性两种写法) */
export declare const resolveOperateWidth: (target: any, fallback?: number | string) => number | string; 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 { export interface IBuildOperateColumnOptions {
fire: TFireHook; fire: TFireHook;
/** 透传给操作事件的行数据集合 */ /** 透传给操作事件的行数据集合 */
tableData?: any[]; tableData?: any[];
width?: number | string; width?: number | string;
/** 冻结方向,见 resolveOperateFixed */
fixed?: "left" | "right";
/** 需要延后执行 onAfter 的按钮类型,见 IDeferOptions */ /** 需要延后执行 onAfter 的按钮类型,见 IDeferOptions */
deferAfterTypes?: string[]; deferAfterTypes?: string[];
} }
+17
View File
@@ -15,6 +15,16 @@ import type { Component, VNode } from "vue";
export type TColumnType = "selection" | "index" | "expand" | "operate"; export type TColumnType = "selection" | "index" | "expand" | "operate";
/** 兼容历史命名 */ /** 兼容历史命名 */
export type columnType = TColumnType; export type columnType = TColumnType;
/**
* 列的冻结(固定列)方向。
*
* `true` 等价于 `"left"`,`false` / 不传表示不冻结。
*
* 注意冻结列必须**从表格边缘开始连续排列**:`"left"` 的列要排在最前面,
* `"right"` 的列要排在最后面,中间夹一个不冻结的列,后面的冻结列就不会生效。
* 组件会把序号 / 选择 / 展开列自动并入左侧冻结组,但数据列之间的顺序由 `sort` 决定。
*/
export type TFixed = boolean | "left" | "right";
/** 操作列按钮类型 */ /** 操作列按钮类型 */
export type TOperateType = "edit" | "del" | "copy" | "customOperateEvent"; export type TOperateType = "edit" | "del" | "copy" | "customOperateEvent";
/** /**
@@ -79,6 +89,13 @@ export interface IFieldMetaValue {
fieldName?: string; fieldName?: string;
width?: number; width?: number;
minWidth?: number; minWidth?: number;
/**
* 列的冻结方向(固定列)。
*
* 只在数据列(`@TableColumnPropertyDecorator`)上生效;
* 冻结列必须从表格边缘起连续排列,见 `TFixed` 的说明。
*/
fixed?: TFixed;
/** 用于初始化组件数据(级联数据的来源) */ /** 用于初始化组件数据(级联数据的来源) */
getData?: (currentData?: any) => MaybePromise<any>; getData?: (currentData?: any) => MaybePromise<any>;
/** 查询表单中所需要的组件类型 */ /** 查询表单中所需要的组件类型 */
+3 -3
View File
File diff suppressed because one or more lines are too long
+85 -21
View File
@@ -1416,6 +1416,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
label: null, label: null,
width: { default: 180 }, width: { default: 180 },
minWidth: null, minWidth: null,
fixed: null,
showOverflowTooltip: { type: Boolean }, showOverflowTooltip: { type: Boolean },
operateItems: { default: () => [] }, operateItems: { default: () => [] },
expandTemplate: null, expandTemplate: null,
@@ -1435,7 +1436,8 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
width: __props.minWidth ? void 0 : __props.width, width: __props.minWidth ? void 0 : __props.width,
"min-width": __props.minWidth, "min-width": __props.minWidth,
label: unref(resolvedLabel), label: unref(resolvedLabel),
"show-overflow-tooltip": __props.showOverflowTooltip "show-overflow-tooltip": __props.showOverflowTooltip,
fixed: __props.fixed
}, { }, {
default: withCtx((scope) => { default: withCtx((scope) => {
var _a, _b; var _a, _b;
@@ -1460,7 +1462,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
]; ];
}), }),
_: 1 _: 1
}, 8, ["type", "prop", "width", "min-width", "label", "show-overflow-tooltip"]); }, 8, ["type", "prop", "width", "min-width", "label", "show-overflow-tooltip", "fixed"]);
}; };
} }
}); });
@@ -3053,20 +3055,38 @@ async function runEventPipeline(options) {
} }
return current; return current;
} }
const collectDataColumns = (target) => scanDecoratedMembers(target, "table:field").map((member) => ({ const collectDataColumns = (target) => scanDecoratedMembers(target, "table:field").map((member) => {
sort: member.meta.sort || 1, var _a;
vnode: h(_sfc_main$e, { return {
prop: member.fieldName, sort: (_a = member.meta.sort) != null ? _a : 1,
label: member.meta.def, vnode: h(_sfc_main$e, {
fieldType: member.meta.fieldType, prop: member.fieldName,
width: member.meta.width, label: member.meta.def,
minWidth: member.meta.minWidth, fieldType: member.meta.fieldType,
columnRender: member.meta.columnRender, width: member.meta.width,
isShow: member.meta.isShow, minWidth: member.meta.minWidth,
showOverflowTooltip: member.meta.showOverflowTooltip, fixed: normalizeFixed(member.meta.fixed),
dateFormat: member.meta.dateFormat columnRender: member.meta.columnRender,
}) isShow: member.meta.isShow,
})).sort((a, b) => a.sort - b.sort).map((item) => item.vnode); showOverflowTooltip: member.meta.showOverflowTooltip,
dateFormat: member.meta.dateFormat
})
};
}).sort((a, b) => a.sort - b.sort).map((item) => item.vnode);
const normalizeFixed = (value) => {
if (value === true || value === "left")
return "left";
if (value === "right")
return "right";
return void 0;
};
const FIXED_VALUES = [true, false, "left", "right"];
const hasLeftFixedColumn = (target) => scanDecoratedMembers(target, "table:field").some(
(member) => normalizeFixed(member.meta.fixed) === "left"
);
const hasRightFixedColumn = (target) => scanDecoratedMembers(target, "table:field").some(
(member) => normalizeFixed(member.meta.fixed) === "right"
);
const collectOperateGroups = (target) => { const collectOperateGroups = (target) => {
var _a; var _a;
const groups = /* @__PURE__ */ new Map(); const groups = /* @__PURE__ */ new Map();
@@ -3117,6 +3137,12 @@ const resolveOperateWidth = (target, fallback = "120px") => {
const instance = createTargetInstance(target); const instance = createTargetInstance(target);
return (_b = (_a = instance.operateWidth) != null ? _a : target == null ? void 0 : target.operateWidth) != null ? _b : fallback; return (_b = (_a = instance.operateWidth) != null ? _a : target == null ? void 0 : target.operateWidth) != null ? _b : fallback;
}; };
const resolveOperateFixed = (target) => {
var _a;
const instance = createTargetInstance(target);
const value = (_a = instance.operateFixed) != null ? _a : target == null ? void 0 : target.operateFixed;
return normalizeFixed(value);
};
const isDeferredAfter = (type, deferred) => !!(deferred == null ? void 0 : deferred.some((item) => item === type)); const isDeferredAfter = (type, deferred) => !!(deferred == null ? void 0 : deferred.some((item) => item === type));
const withoutDeferredAfter = (tasks, deferred) => tasks.filter( const withoutDeferredAfter = (tasks, deferred) => tasks.filter(
(task) => { (task) => {
@@ -3138,6 +3164,7 @@ const buildOperateColumn = (groups, options) => {
fire, fire,
tableData = [], tableData = [],
width = "120px", width = "120px",
fixed,
deferAfterTypes deferAfterTypes
} = options; } = options;
const operateItems = [...groups].sort((a, b) => a.sort - b.sort).map((group) => ({ const operateItems = [...groups].sort((a, b) => a.sort - b.sort).map((group) => ({
@@ -3158,7 +3185,8 @@ const buildOperateColumn = (groups, options) => {
type: "operate", type: "operate",
label: "\u64CD\u4F5C", label: "\u64CD\u4F5C",
operateItems, operateItems,
width width,
fixed
}); });
}; };
const collectTypedTasks = (target, decoratorKey, type) => sortTasksByPriority( const collectTypedTasks = (target, decoratorKey, type) => sortTasksByPriority(
@@ -3410,6 +3438,15 @@ const diagnoseTarget = (target, options = {}) => {
hint: `\u5408\u6CD5\u503C\uFF1A${Object.keys(FIELD_TYPE_SET).join(" / ")}` hint: `\u5408\u6CD5\u503C\uFF1A${Object.keys(FIELD_TYPE_SET).join(" / ")}`
}); });
} }
if (dKey === "table:field" && meta.fixed !== void 0 && meta.fixed !== null && !FIXED_VALUES.includes(meta.fixed)) {
push({
level: "warn",
code: "invalid-fixed-value",
member: entry.member.key,
message: `fixed: ${JSON.stringify(meta.fixed)} \u4E0D\u662F\u5408\u6CD5\u7684\u51BB\u7ED3\u65B9\u5411\uFF0C\u8FD9\u4E00\u5217\u4E0D\u4F1A\u88AB\u51BB\u7ED3`,
hint: '\u53EF\u7528 "left" / "right"\uFF08true \u7B49\u4EF7\u4E8E "left"\uFF09'
});
}
} }
if ((formMeta == null ? void 0 : formMeta.fieldType) && FORM_UNIMPLEMENTED.has(formMeta.fieldType) && !formMeta.component) { if ((formMeta == null ? void 0 : formMeta.fieldType) && FORM_UNIMPLEMENTED.has(formMeta.fieldType) && !formMeta.component) {
push({ push({
@@ -3452,6 +3489,28 @@ const diagnoseTarget = (target, options = {}) => {
hint: "\u68C0\u67E5 @TableColumnPropertyDecorator \u662F\u5426\u6302\u5728\u4E86\u7C7B\u7684\u5C5E\u6027\u4E0A\uFF08\u800C\u4E0D\u662F\u9759\u6001\u5C5E\u6027 / \u6784\u9020\u51FD\u6570\u91CC\uFF09" hint: "\u68C0\u67E5 @TableColumnPropertyDecorator \u662F\u5426\u6302\u5728\u4E86\u7C7B\u7684\u5C5E\u6027\u4E0A\uFF08\u800C\u4E0D\u662F\u9759\u6001\u5C5E\u6027 / \u6784\u9020\u51FD\u6570\u91CC\uFF09"
}); });
} }
const orderedColumns = [...columns].sort(
(a, b) => {
var _a2, _b2;
return ((_a2 = a.meta.sort) != null ? _a2 : 1) - ((_b2 = b.meta.sort) != null ? _b2 : 1);
}
);
const fixDirs = orderedColumns.map((column) => normalizeFixed(column.meta.fixed));
const reportFixedEdge = (column, dir) => push({
level: "warn",
code: "fixed-column-not-at-edge",
member: column.key,
message: `"${column.meta.def || column.key}" \u51BB\u7ED3\u5230\u4E86${dir === "left" ? "\u5DE6" : "\u53F3"}\u4FA7\uFF0C\u4F46\u5B83\u7684${dir === "left" ? "\u524D\u9762" : "\u540E\u9762"}\u8FD8\u6709\u4E0D\u51BB\u7ED3\u7684\u5217\uFF0C\u8FD9\u4E00\u5217\u4E0D\u4F1A\u771F\u7684\u51BB\u7ED3`,
hint: `\u51BB\u7ED3\u5217\u5FC5\u987B\u4ECE\u8FB9\u7F18\u8D77\u8FDE\u7EED\uFF1A\u6539 sort \u628A\u5B83\u6392\u5230${dir === "left" ? "\u6700\u524D" : "\u6700\u540E"}\uFF0C\u6216\u8005\u8BA9\u76F8\u90BB\u7684\u5217\u4E00\u8D77 fixed`
});
orderedColumns.forEach((column, index) => {
const dir = fixDirs[index];
if (!dir)
return;
const blocked = dir === "left" ? fixDirs.slice(0, index).some((item) => item !== "left") : fixDirs.slice(index + 1).some((item) => item !== "right");
if (blocked)
reportFixedEdge(column, dir);
});
const hasFormSubmit = byType.has("edit") || byType.has("\u6DFB\u52A0"); const hasFormSubmit = byType.has("edit") || byType.has("\u6DFB\u52A0");
const primaryKeys = columns.filter( const primaryKeys = columns.filter(
(column) => column.meta.fieldType === "primaryKey" (column) => column.meta.fieldType === "primaryKey"
@@ -3569,12 +3628,14 @@ const _sfc_main$d = defineComponent({
}); });
let columnList = collectDataColumns(target); let columnList = collectDataColumns(target);
const deferAfterTypes = this.$attrs["defer-after-types"]; const deferAfterTypes = this.$attrs["defer-after-types"];
const leadFixed = hasLeftFixedColumn(target) ? "left" : void 0;
const operateGroups = collectOperateGroups(target); const operateGroups = collectOperateGroups(target);
if (resolveShowOperate(target, operateGroups.length > 0)) { if (resolveShowOperate(target, operateGroups.length > 0)) {
const operateColumn = buildOperateColumn(operateGroups, { const operateColumn = buildOperateColumn(operateGroups, {
fire, fire,
tableData: data, tableData: data,
width: resolveOperateWidth(target), width: resolveOperateWidth(target),
fixed: resolveOperateFixed(target),
deferAfterTypes deferAfterTypes
}); });
if (operateColumn) if (operateColumn)
@@ -3587,19 +3648,22 @@ const _sfc_main$d = defineComponent({
columnList = [ columnList = [
h(_sfc_main$e, { h(_sfc_main$e, {
type: "expand", type: "expand",
expandTemplate: this.$attrs["expand-template"] expandTemplate: this.$attrs["expand-template"],
fixed: leadFixed
}) })
].concat(columnList); ].concat(columnList);
} }
const hasIndex = this.$attrs["show-index"] !== false; const hasIndex = this.$attrs["show-index"] !== false;
if (hasIndex) { if (hasIndex) {
columnList = [ columnList = [
h(ElTableColumn, { type: "index", label: "\u5E8F\u53F7", width: 56 }) h(ElTableColumn, { type: "index", label: "\u5E8F\u53F7", width: 56, fixed: leadFixed })
].concat(columnList); ].concat(columnList);
} }
const enableSelection = toolbars.some((item) => item.type === "\u6279\u91CF\u5220\u9664"); const enableSelection = toolbars.some((item) => item.type === "\u6279\u91CF\u5220\u9664");
if (enableSelection) { if (enableSelection) {
columnList = [h(ElTableColumn, { type: "selection" })].concat(columnList); columnList = [
h(ElTableColumn, { type: "selection", fixed: leadFixed })
].concat(columnList);
} }
return h( return h(
UmTable, UmTable,
@@ -5629,4 +5693,4 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
}; };
} }
}); });
export { _sfc_main as AreaTree, DEFAULT_DEFER_TYPES, EVENT_PHASES, _sfc_main$k as Iconfont, TableColumnMethodDecorator, TableColumnPropertyDecorator, TableFormColumnPropertyDecorator, TableSearchFormPropertyDecorator, _sfc_main$d as UmByClass, UmByClassEnhance, UmColumnRender, _sfc_main$c as UmDialog, UmDistrictTree, UmDistrictTreeNode, UmPagination, UmSearchForm, _sfc_main$3 as UmSyncNodeForm, UmTable, _sfc_main$e as UmTableColumn, _sfc_main$b as UmTableDialog, UmTableForm, UmTableOperate, UmTableToolbar, _sfc_main$6 as UmTree, _sfc_main$5 as UmTreeSelect, buildOperateColumn, collectClassMembers, collectDataColumns, collectOperateGroups, collectToolbar, collectTypedTasks, createTargetInstance, diagnoseTarget, findMethodMeta, getMemberMeta, isDiagnosticsEnabled, normalizeFieldName, reportDiagnostics, reportDiagnosticsOnce, resolveOperateWidth, resolveShowOperate, runEventPipeline, scanDecoratedMembers, setDiagnosticsEnabled, sortTasksByPriority, transformFields }; export { _sfc_main as AreaTree, DEFAULT_DEFER_TYPES, EVENT_PHASES, FIXED_VALUES, _sfc_main$k as Iconfont, TableColumnMethodDecorator, TableColumnPropertyDecorator, TableFormColumnPropertyDecorator, TableSearchFormPropertyDecorator, _sfc_main$d as UmByClass, UmByClassEnhance, UmColumnRender, _sfc_main$c as UmDialog, UmDistrictTree, UmDistrictTreeNode, UmPagination, UmSearchForm, _sfc_main$3 as UmSyncNodeForm, UmTable, _sfc_main$e as UmTableColumn, _sfc_main$b as UmTableDialog, UmTableForm, UmTableOperate, UmTableToolbar, _sfc_main$6 as UmTree, _sfc_main$5 as UmTreeSelect, buildOperateColumn, collectClassMembers, collectDataColumns, collectOperateGroups, collectToolbar, collectTypedTasks, createTargetInstance, diagnoseTarget, findMethodMeta, getMemberMeta, hasLeftFixedColumn, hasRightFixedColumn, isDiagnosticsEnabled, normalizeFieldName, normalizeFixed, reportDiagnostics, reportDiagnosticsOnce, resolveOperateFixed, resolveOperateWidth, resolveShowOperate, runEventPipeline, scanDecoratedMembers, setDiagnosticsEnabled, sortTasksByPriority, transformFields };
+3 -3
View File
File diff suppressed because one or more lines are too long