@qin-ui/antd-vue-pro 2.5.3 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI-CONTEXT.md +30 -10
- package/api.json +23 -3
- package/es/antd-vue-pro.css +6 -6
- package/es/components/component-provider/types/index.d.ts +1 -1
- package/es/components/component-provider/types/index.d.ts.map +1 -1
- package/es/components/table/components/ProTable.vue.d.ts +3 -1
- package/es/components/table/components/ProTable.vue.d.ts.map +1 -1
- package/es/components/table/components/TableEllipsisTooltip.vue.d.ts +19 -0
- package/es/components/table/components/TableEllipsisTooltip.vue.d.ts.map +1 -0
- package/es/components/table/hooks/useEllipsisTooltip.d.ts +45 -0
- package/es/components/table/hooks/useEllipsisTooltip.d.ts.map +1 -0
- package/es/components/table/hooks/useEllipsisTooltipColumns.d.ts +19 -0
- package/es/components/table/hooks/useEllipsisTooltipColumns.d.ts.map +1 -0
- package/es/components/table/index.d.ts +1 -1
- package/es/components/table/index.d.ts.map +1 -1
- package/es/components/table/types/index.d.ts +46 -2
- package/es/components/table/types/index.d.ts.map +1 -1
- package/es/index.js +438 -87
- package/es/index.js.map +1 -1
- package/es/shared/ui/index.d.ts +2 -1
- package/es/shared/ui/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/component-provider/types/index.ts +1 -0
- package/src/components/table/components/ProTable.vue +128 -56
- package/src/components/table/components/TableEllipsisTooltip.vue +90 -0
- package/src/components/table/hooks/useEllipsisTooltip.ts +244 -0
- package/src/components/table/hooks/useEllipsisTooltipColumns.ts +139 -0
- package/src/components/table/index.ts +7 -1
- package/src/components/table/types/index.ts +62 -2
- package/src/shared/ui/index.ts +2 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { computed, toRaw, toValue, type ComputedRef } from 'vue';
|
|
2
|
+
import { isObjectItem, isPlainObject } from '../../../shared/core';
|
|
3
|
+
import { ELLIPSIS_TOOLTIP_CELL_ATTR } from './useEllipsisTooltip';
|
|
4
|
+
|
|
5
|
+
type ColumnTransformResult = {
|
|
6
|
+
columns: any[];
|
|
7
|
+
changed: boolean;
|
|
8
|
+
hasTooltip: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 省略 Tooltip 列转换
|
|
13
|
+
*
|
|
14
|
+
* @description 一次遍历完成 hidden 过滤、分组子列递归与 showTooltip 列标记;
|
|
15
|
+
* 仅对发生变化的列生成克隆并登记原始列,供宿主回传列对象时还原。
|
|
16
|
+
* 列还原最多回溯两跳(宿主克隆 → 转换克隆 → 原始列),依赖单遍转换每列最多产生一层克隆。
|
|
17
|
+
*
|
|
18
|
+
* @param getColumns - 读取原始列配置
|
|
19
|
+
* @param globalEnabled - 是否全局启用列 Tooltip
|
|
20
|
+
* @returns 可见列、是否含 Tooltip 列与列还原函数
|
|
21
|
+
*/
|
|
22
|
+
export function useEllipsisTooltipColumns(
|
|
23
|
+
getColumns: () => any[],
|
|
24
|
+
globalEnabled: () => boolean = () => false
|
|
25
|
+
): {
|
|
26
|
+
columns: ComputedRef<any[]>;
|
|
27
|
+
hasTooltip: ComputedRef<boolean>;
|
|
28
|
+
resolveOriginalColumn: (column: any) => any;
|
|
29
|
+
resolveSorterColumn: (sorter: any) => any;
|
|
30
|
+
} {
|
|
31
|
+
const originalColumns = new WeakMap<object, any>();
|
|
32
|
+
|
|
33
|
+
const registerColumnClone = (next: any, source: any) => {
|
|
34
|
+
if (next !== source && isObjectItem(next) && !originalColumns.has(next)) {
|
|
35
|
+
originalColumns.set(next, source);
|
|
36
|
+
}
|
|
37
|
+
return next;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// 宿主内部列克隆通过 __originColumn__ 回指原始列(@private)
|
|
41
|
+
const resolveOriginalColumn = (column: any) => {
|
|
42
|
+
const raw = toRaw(column);
|
|
43
|
+
const source = originalColumns.get(raw) ?? raw.__originColumn__;
|
|
44
|
+
if (!isObjectItem(source)) return column;
|
|
45
|
+
return originalColumns.get(toRaw(source)) ?? source;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const resolveSorterColumn = (sorter: any) =>
|
|
49
|
+
sorter && typeof sorter === 'object' && sorter.column
|
|
50
|
+
? { ...sorter, column: resolveOriginalColumn(sorter.column) }
|
|
51
|
+
: sorter;
|
|
52
|
+
|
|
53
|
+
const transformColumns = (
|
|
54
|
+
columns: any[],
|
|
55
|
+
global: boolean,
|
|
56
|
+
ancestors: Set<object> = new Set()
|
|
57
|
+
): ColumnTransformResult => {
|
|
58
|
+
const list: any[] = [];
|
|
59
|
+
let changed = false;
|
|
60
|
+
let hasTooltip = false;
|
|
61
|
+
|
|
62
|
+
for (const column of columns) {
|
|
63
|
+
if (!isObjectItem(column) || toValue(column.hidden)) {
|
|
64
|
+
changed = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let childChanged = false;
|
|
69
|
+
let childColumns = column.children;
|
|
70
|
+
let childHasTooltip = false;
|
|
71
|
+
|
|
72
|
+
if (Array.isArray(column.children) && column.children.length > 0) {
|
|
73
|
+
if (ancestors.has(column)) {
|
|
74
|
+
changed = true;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
ancestors.add(column);
|
|
78
|
+
const child = transformColumns(column.children, global, ancestors);
|
|
79
|
+
ancestors.delete(column);
|
|
80
|
+
childChanged = child.changed;
|
|
81
|
+
childColumns = child.columns;
|
|
82
|
+
childHasTooltip = child.hasTooltip;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const ellipsis = column.ellipsis;
|
|
86
|
+
const explicit =
|
|
87
|
+
ellipsis === false
|
|
88
|
+
? false
|
|
89
|
+
: isPlainObject(ellipsis)
|
|
90
|
+
? ellipsis.showTooltip
|
|
91
|
+
: undefined;
|
|
92
|
+
const tooltipEnabled =
|
|
93
|
+
explicit === false ? false : global || explicit === true;
|
|
94
|
+
let next = column;
|
|
95
|
+
|
|
96
|
+
if (childChanged || tooltipEnabled) {
|
|
97
|
+
const { showTooltip: _showTooltip, ...restEllipsis } = isPlainObject(
|
|
98
|
+
ellipsis
|
|
99
|
+
)
|
|
100
|
+
? ellipsis
|
|
101
|
+
: {};
|
|
102
|
+
const customCell = column.customCell;
|
|
103
|
+
next = {
|
|
104
|
+
...column,
|
|
105
|
+
...(childChanged ? { children: childColumns } : {}),
|
|
106
|
+
...(tooltipEnabled
|
|
107
|
+
? {
|
|
108
|
+
ellipsis: { ...restEllipsis, showTitle: false },
|
|
109
|
+
customCell: (
|
|
110
|
+
record: any,
|
|
111
|
+
rowIndex: number,
|
|
112
|
+
cellColumn: any
|
|
113
|
+
) => ({
|
|
114
|
+
...(customCell?.(record, rowIndex, cellColumn) ?? {}),
|
|
115
|
+
[ELLIPSIS_TOOLTIP_CELL_ATTR]: '',
|
|
116
|
+
}),
|
|
117
|
+
}
|
|
118
|
+
: {}),
|
|
119
|
+
};
|
|
120
|
+
registerColumnClone(next, column);
|
|
121
|
+
changed = true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (tooltipEnabled || childHasTooltip) hasTooltip = true;
|
|
125
|
+
list.push(next);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { columns: changed ? list : columns, changed, hasTooltip };
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const state = computed(() => transformColumns(getColumns(), globalEnabled()));
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
columns: computed(() => state.value.columns),
|
|
135
|
+
hasTooltip: computed(() => state.value.hasTooltip),
|
|
136
|
+
resolveOriginalColumn,
|
|
137
|
+
resolveSorterColumn,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -10,7 +10,13 @@ export type ProTableProps = ComponentProps<typeof ProTable>;
|
|
|
10
10
|
export type ProTableInstance = ComponentExposed<typeof ProTable>;
|
|
11
11
|
|
|
12
12
|
// 仅导出核心列配置类型
|
|
13
|
-
export {
|
|
13
|
+
export {
|
|
14
|
+
type Column,
|
|
15
|
+
type ColumnControlConfig,
|
|
16
|
+
type ColumnEllipsis,
|
|
17
|
+
type Columns,
|
|
18
|
+
type EllipsisTooltipConfig,
|
|
19
|
+
} from './types';
|
|
14
20
|
|
|
15
21
|
// 仅导出核心表格 Hook 与类型
|
|
16
22
|
export { useTable, type Table } from './hooks';
|
|
@@ -1,9 +1,64 @@
|
|
|
1
|
-
import type { ColumnType } from '../../../shared/ui';
|
|
1
|
+
import type { ColumnType, TooltipProps } from '../../../shared/ui';
|
|
2
2
|
import type { Data, KeyExpandString, Paths, Path } from '../../../shared/core';
|
|
3
3
|
import type { ComputedRef, MaybeRef } from 'vue';
|
|
4
4
|
|
|
5
5
|
type MaybeRefOrComputedRef<T = any> = MaybeRef<T> | ComputedRef<T>;
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 列内容省略配置
|
|
9
|
+
*
|
|
10
|
+
* @description 在宿主 `ellipsis` 基础上增加 `showTooltip`:单元格文本横向溢出时,
|
|
11
|
+
* 悬停由表格级共享的同一个 Tooltip 展示完整文本。`showTooltip` 为 `true` 时不输出宿主原生 `title`。
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const column: Column<User> = {
|
|
16
|
+
* dataIndex: 'name',
|
|
17
|
+
* ellipsis: { showTooltip: true },
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export type ColumnEllipsis = NonNullable<
|
|
24
|
+
Exclude<ColumnType['ellipsis'], boolean>
|
|
25
|
+
> & {
|
|
26
|
+
/** 文本溢出时是否显示表格级共享 Tooltip */
|
|
27
|
+
showTooltip?: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ProTable 共享省略 Tooltip 配置
|
|
32
|
+
*
|
|
33
|
+
* @description 复用宿主 Tooltip 的容器、延迟、方位与浮层样式字段,控制表格级单例 Tooltip。
|
|
34
|
+
* ProTable 侧另接受 `true` 作为全局启用简写;列上 `showTooltip: false` 或 `ellipsis: false` 可退出。
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const config: EllipsisTooltipConfig = {
|
|
39
|
+
* getPopupContainer: () => document.body,
|
|
40
|
+
* mouseEnterDelay: 0.2,
|
|
41
|
+
* mouseLeaveDelay: 0.1,
|
|
42
|
+
* placement: 'top',
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export type EllipsisTooltipConfig = Pick<
|
|
49
|
+
TooltipProps,
|
|
50
|
+
| 'getPopupContainer'
|
|
51
|
+
| 'mouseEnterDelay'
|
|
52
|
+
| 'mouseLeaveDelay'
|
|
53
|
+
| 'placement'
|
|
54
|
+
| 'arrow'
|
|
55
|
+
| 'autoAdjustOverflow'
|
|
56
|
+
| 'color'
|
|
57
|
+
| 'overlayClassName'
|
|
58
|
+
| 'overlayStyle'
|
|
59
|
+
| 'overlayInnerStyle'
|
|
60
|
+
>;
|
|
61
|
+
|
|
7
62
|
/**
|
|
8
63
|
* 表格列配置类型
|
|
9
64
|
*
|
|
@@ -11,6 +66,7 @@ type MaybeRefOrComputedRef<T = any> = MaybeRef<T> | ComputedRef<T>;
|
|
|
11
66
|
* - 类型安全的 dataIndex(基于泛型 D 推导路径),优先使用
|
|
12
67
|
* - key 作为辅助标识,当 dataIndex 不满足需求时使用
|
|
13
68
|
* - hidden 属性用于控制列显隐
|
|
69
|
+
* - ellipsis 支持 `{ showTooltip: boolean }` 的表格级共享 Tooltip
|
|
14
70
|
* - 所有 Ant Design Vue 原生的列属性依然可用(title、width、fixed、align 等)
|
|
15
71
|
*
|
|
16
72
|
* @template D - 表格行数据类型
|
|
@@ -37,7 +93,7 @@ type MaybeRefOrComputedRef<T = any> = MaybeRef<T> | ComputedRef<T>;
|
|
|
37
93
|
*/
|
|
38
94
|
export type Column<D extends Data = Data> = Omit<
|
|
39
95
|
ColumnType,
|
|
40
|
-
'dataIndex' | 'key'
|
|
96
|
+
'dataIndex' | 'key' | 'ellipsis'
|
|
41
97
|
> & {
|
|
42
98
|
/**
|
|
43
99
|
* 列数据路径(主要字段)
|
|
@@ -59,6 +115,10 @@ export type Column<D extends Data = Data> = Omit<
|
|
|
59
115
|
* @default false
|
|
60
116
|
*/
|
|
61
117
|
hidden?: MaybeRefOrComputedRef<boolean>;
|
|
118
|
+
/**
|
|
119
|
+
* 列内容省略配置;`true` 等价于宿主默认省略,对象形态额外支持表格级共享 Tooltip
|
|
120
|
+
*/
|
|
121
|
+
ellipsis?: boolean | ColumnEllipsis;
|
|
62
122
|
/**
|
|
63
123
|
* 分组子列;提供时该列作为分组表头渲染,子列沿用同一配置类型
|
|
64
124
|
*/
|
package/src/shared/ui/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ export {
|
|
|
36
36
|
Transfer,
|
|
37
37
|
TreeSelect,
|
|
38
38
|
RangePicker,
|
|
39
|
+
Tooltip,
|
|
39
40
|
type FormItemInstance,
|
|
40
41
|
type FormInstance,
|
|
41
42
|
type RowProps as GridProps,
|
|
@@ -45,6 +46,7 @@ export {
|
|
|
45
46
|
} from 'ant-design-vue';
|
|
46
47
|
|
|
47
48
|
export { type ColumnType, tableProps } from 'ant-design-vue/es/table';
|
|
49
|
+
export type { TooltipProps } from 'ant-design-vue';
|
|
48
50
|
export { type RangePickerProps } from 'ant-design-vue/es/date-picker';
|
|
49
51
|
export { useConfigContextInject } from 'ant-design-vue/es/config-provider/context';
|
|
50
52
|
export {
|