@antdv-vue/pro-table 0.0.0-stage → 2.0.3
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/CHANGELOG.md +255 -0
- package/README.md +106 -2
- package/dist/InternalTable.d.ts +360 -0
- package/dist/InternalTable.js +444 -0
- package/dist/RenderTypings.d.ts +33 -0
- package/dist/RenderTypings.js +1 -0
- package/dist/ResizableTableTitle.d.ts +24 -0
- package/dist/ResizableTableTitle.js +89 -0
- package/dist/Store/Provide.d.ts +68 -0
- package/dist/Store/Provide.js +132 -0
- package/dist/Table.d.ts +363 -0
- package/dist/Table.js +151 -0
- package/dist/TableRender.d.ts +54 -0
- package/dist/TableRender.js +295 -0
- package/dist/components/Alert/index.d.ts +45 -0
- package/dist/components/Alert/index.js +94 -0
- package/dist/components/Alert/style/index.d.ts +8 -0
- package/dist/components/Alert/style/index.js +11 -0
- package/dist/components/ColumnSetting/CheckboxList.d.ts +24 -0
- package/dist/components/ColumnSetting/CheckboxList.js +138 -0
- package/dist/components/ColumnSetting/CheckboxListItem.d.ts +17 -0
- package/dist/components/ColumnSetting/CheckboxListItem.js +84 -0
- package/dist/components/ColumnSetting/GroupCheckboxList.d.ts +22 -0
- package/dist/components/ColumnSetting/GroupCheckboxList.js +82 -0
- package/dist/components/ColumnSetting/ToolTipIcon.d.ts +12 -0
- package/dist/components/ColumnSetting/ToolTipIcon.js +47 -0
- package/dist/components/ColumnSetting/index.d.ts +26 -0
- package/dist/components/ColumnSetting/index.js +117 -0
- package/dist/components/ColumnSetting/style/index.d.ts +8 -0
- package/dist/components/ColumnSetting/style/index.js +73 -0
- package/dist/components/DragSortTable/index.d.ts +375 -0
- package/dist/components/DragSortTable/index.js +166 -0
- package/dist/components/DragSortTable/style/index.d.ts +8 -0
- package/dist/components/DragSortTable/style/index.js +25 -0
- package/dist/components/Dropdown/Button.d.ts +20 -0
- package/dist/components/Dropdown/Button.js +155 -0
- package/dist/components/Dropdown/index.d.ts +27 -0
- package/dist/components/Dropdown/index.js +149 -0
- package/dist/components/EditableTable/CellEditorTable.d.ts +63 -0
- package/dist/components/EditableTable/CellEditorTable.js +167 -0
- package/dist/components/EditableTable/EditableTable.d.ts +67 -0
- package/dist/components/EditableTable/EditableTable.js +141 -0
- package/dist/components/EditableTable/InternalEditableTable.d.ts +189 -0
- package/dist/components/EditableTable/InternalEditableTable.js +508 -0
- package/dist/components/EditableTable/RowEditorTable.d.ts +63 -0
- package/dist/components/EditableTable/RowEditorTable.js +147 -0
- package/dist/components/EditableTable/context.d.ts +9 -0
- package/dist/components/EditableTable/context.js +11 -0
- package/dist/components/EditableTable/index.d.ts +5 -0
- package/dist/components/EditableTable/index.js +5 -0
- package/dist/components/Form/FormRender.d.ts +77 -0
- package/dist/components/Form/FormRender.js +198 -0
- package/dist/components/Form/index.d.ts +33 -0
- package/dist/components/Form/index.js +91 -0
- package/dist/components/ToolBar/DensityIcon.d.ts +22 -0
- package/dist/components/ToolBar/DensityIcon.js +71 -0
- package/dist/components/ToolBar/FullScreenIcon.d.ts +6 -0
- package/dist/components/ToolBar/FullScreenIcon.js +30 -0
- package/dist/components/ToolBar/HeaderMenu.d.ts +22 -0
- package/dist/components/ToolBar/HeaderMenu.js +84 -0
- package/dist/components/ToolBar/index.d.ts +102 -0
- package/dist/components/ToolBar/index.js +322 -0
- package/dist/components/ToolBar/style/index.d.ts +8 -0
- package/dist/components/ToolBar/style/index.js +116 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/pro-table.esm.js +3274 -0
- package/dist/style/index.d.ts +11 -0
- package/dist/style/index.js +162 -0
- package/dist/typing.d.ts +409 -0
- package/dist/typing.js +1 -0
- package/dist/useFetchData.d.ts +10 -0
- package/dist/useFetchData.js +243 -0
- package/dist/utils/cellRenderToFromItem.d.ts +52 -0
- package/dist/utils/cellRenderToFromItem.js +163 -0
- package/dist/utils/columnRender.d.ts +54 -0
- package/dist/utils/columnRender.js +148 -0
- package/dist/utils/columnSort.d.ts +7 -0
- package/dist/utils/columnSort.js +17 -0
- package/dist/utils/genProColumnsToColumns.d.ts +69 -0
- package/dist/utils/genProColumnsToColumns.js +197 -0
- package/dist/utils/index.d.ts +122 -0
- package/dist/utils/index.js +227 -0
- package/dist/utils/useDragSort.d.ts +182 -0
- package/dist/utils/useDragSort.js +162 -0
- package/package.json +67 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ContainerReturnType } from "../Store/Provide.js";
|
|
2
|
+
import { FilterValue as FilterValue$1, ProColumnType, ProColumns, ProSorter } from "../typing.js";
|
|
3
|
+
import { ParamsType } from "@antdv-vue/pro-provider";
|
|
4
|
+
import { Key, ProFieldValueObjectType, ProFieldValueType, ProSchemaComponentTypes, UseEditableUtilType } from "@antdv-vue/pro-utils";
|
|
5
|
+
import { TableProps } from "antdv-next";
|
|
6
|
+
import { ProFieldEmptyText } from "@antdv-vue/pro-field";
|
|
7
|
+
import { SortOrder } from "antdv-next/dist/table/index";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/genProColumnsToColumns.d.ts
|
|
10
|
+
type ResizeWidthMap = Record<string, number>;
|
|
11
|
+
type ColumnToColumnParams<T, U, ValueType> = {
|
|
12
|
+
columns?: ProColumns<T, ValueType>[];
|
|
13
|
+
counter?: ContainerReturnType<T, U, ValueType>;
|
|
14
|
+
columnEmptyText?: ProFieldEmptyText;
|
|
15
|
+
type?: ProSchemaComponentTypes;
|
|
16
|
+
marginSM: number;
|
|
17
|
+
editableUtils?: UseEditableUtilType<T>;
|
|
18
|
+
childrenColumnName?: string;
|
|
19
|
+
proFilter?: Record<string, FilterValue$1>;
|
|
20
|
+
proSort?: Record<string, SortOrder>;
|
|
21
|
+
columnResizeWidthMap?: ResizeWidthMap;
|
|
22
|
+
} & Partial<Pick<TableProps<T>, 'rowKey'>>;
|
|
23
|
+
/**
|
|
24
|
+
* 根据 key 和 dataIndex 生成唯一 id
|
|
25
|
+
*
|
|
26
|
+
* @param key 用户设置的 key
|
|
27
|
+
* @param index 序列号,理论上唯一
|
|
28
|
+
*/
|
|
29
|
+
declare function genColumnKey<T>(key?: T, index?: Key): string;
|
|
30
|
+
/**
|
|
31
|
+
* 将 ProTable - column - dataIndex 转为字符串形式
|
|
32
|
+
*
|
|
33
|
+
* @param dataIndex Column 中的 dataIndex
|
|
34
|
+
*/
|
|
35
|
+
declare function parseDataIndex<T, K>(dataIndex: ProColumnType<T, K>['dataIndex']): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 判断是否为本地筛选
|
|
38
|
+
* @param filters 筛选配置
|
|
39
|
+
* @param onFilter 筛选函数
|
|
40
|
+
* @returns 是否为本地筛选
|
|
41
|
+
*/
|
|
42
|
+
declare function isLocalFilter<T, K>(filters: ProColumnType<T, K>['filters'], onFilter: ProColumnType<T, K>['onFilter']): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 判断是否为本地排序
|
|
45
|
+
* @param sorter 排序配置
|
|
46
|
+
* @returns 是否为本地排序
|
|
47
|
+
*/
|
|
48
|
+
declare function isLocalSorter<T>(sorter: ProSorter<T>): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* 解析对应排序值,用作双向绑定
|
|
51
|
+
* @param proSort 排序配置
|
|
52
|
+
* @param columnProps 列配置
|
|
53
|
+
* @returns 排序值
|
|
54
|
+
*/
|
|
55
|
+
declare function parseProSortOrder<T, K>(proSort?: Record<string, SortOrder>, columnProps?: ProColumnType<T, K>): SortOrder | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* 解析对应筛选值,用作双向绑定
|
|
58
|
+
* @param proFilter 筛选配置
|
|
59
|
+
* @param columnProps 列配置
|
|
60
|
+
* @returns 筛选值
|
|
61
|
+
*/
|
|
62
|
+
declare function parseProFilteredValue<T, K>(proFilter?: Record<string, FilterValue$1>, columnProps?: ProColumnType<T, K>): FilterValue$1 | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* 转化 columns 到 pro 的格式 主要是 render 方法的自行实现
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
declare function genProColumnsToColumns<T extends Record<string, any>, U extends ParamsType, ValueType extends (ProFieldValueType | ProFieldValueObjectType)>(params: ColumnToColumnParams<T, U, ValueType>, parents?: ProColumns<T, any>): ProColumns<T, ValueType>[] | undefined;
|
|
68
|
+
//#endregion
|
|
69
|
+
export { genColumnKey, genProColumnsToColumns, isLocalFilter, isLocalSorter, parseDataIndex, parseProFilteredValue, parseProSortOrder };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import columnRender, { defaultOnFilter, renderColumnsTitle } from "./columnRender.js";
|
|
2
|
+
import { shallowReactive } from "vue";
|
|
3
|
+
import { omitBoolean, omitUndefinedAndEmptyArr, runFunction } from "@antdv-vue/pro-utils";
|
|
4
|
+
import { Table } from "antdv-next";
|
|
5
|
+
import { proFieldParsingValueEnumToArray } from "@antdv-vue/pro-field";
|
|
6
|
+
//#region src/utils/genProColumnsToColumns.ts
|
|
7
|
+
const columnResizeWidthMaps = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function getColumnResizeWidthMap(columns, inheritedMap) {
|
|
9
|
+
if (inheritedMap) return inheritedMap;
|
|
10
|
+
if (!columns) return shallowReactive({});
|
|
11
|
+
const existingMap = columnResizeWidthMaps.get(columns);
|
|
12
|
+
if (existingMap) return existingMap;
|
|
13
|
+
const nextMap = shallowReactive({});
|
|
14
|
+
columnResizeWidthMaps.set(columns, nextMap);
|
|
15
|
+
return nextMap;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 根据 key 和 dataIndex 生成唯一 id
|
|
19
|
+
*
|
|
20
|
+
* @param key 用户设置的 key
|
|
21
|
+
* @param index 序列号,理论上唯一
|
|
22
|
+
*/
|
|
23
|
+
function genColumnKey(key, index) {
|
|
24
|
+
if (key) return Array.isArray(key) ? key.join("-") : key.toString();
|
|
25
|
+
return `${index}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 将 ProTable - column - dataIndex 转为字符串形式
|
|
29
|
+
*
|
|
30
|
+
* @param dataIndex Column 中的 dataIndex
|
|
31
|
+
*/
|
|
32
|
+
function parseDataIndex(dataIndex) {
|
|
33
|
+
if (Array.isArray(dataIndex)) return dataIndex.join(",");
|
|
34
|
+
return dataIndex?.toString();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 判断是否为本地筛选
|
|
38
|
+
* @param filters 筛选配置
|
|
39
|
+
* @param onFilter 筛选函数
|
|
40
|
+
* @returns 是否为本地筛选
|
|
41
|
+
*/
|
|
42
|
+
function isLocalFilter(filters, onFilter) {
|
|
43
|
+
return !!filters && !!onFilter;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 判断是否为本地排序
|
|
47
|
+
* @param sorter 排序配置
|
|
48
|
+
* @returns 是否为本地排序
|
|
49
|
+
*/
|
|
50
|
+
function isLocalSorter(sorter) {
|
|
51
|
+
return typeof sorter === "function" || typeof sorter === "object" && typeof sorter.compare === "function";
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 解析对应排序值,用作双向绑定
|
|
55
|
+
* @param proSort 排序配置
|
|
56
|
+
* @param columnProps 列配置
|
|
57
|
+
* @returns 排序值
|
|
58
|
+
*/
|
|
59
|
+
function parseProSortOrder(proSort, columnProps) {
|
|
60
|
+
const { sorter, sortOrder: columnSortOrder, dataIndex } = columnProps || {};
|
|
61
|
+
if (columnSortOrder !== void 0) return columnSortOrder;
|
|
62
|
+
if (sorter == null) return void 0;
|
|
63
|
+
if (isLocalSorter(sorter)) return void 0;
|
|
64
|
+
const sortKey = typeof sorter === "string" ? sorter : parseDataIndex(dataIndex);
|
|
65
|
+
return sortKey ? proSort?.[sortKey] : void 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 解析对应筛选值,用作双向绑定
|
|
69
|
+
* @param proFilter 筛选配置
|
|
70
|
+
* @param columnProps 列配置
|
|
71
|
+
* @returns 筛选值
|
|
72
|
+
*/
|
|
73
|
+
function parseProFilteredValue(proFilter, columnProps) {
|
|
74
|
+
const { filters, onFilter, filteredValue: columnFilteredValue, dataIndex } = columnProps || {};
|
|
75
|
+
if (columnFilteredValue !== void 0) return columnFilteredValue;
|
|
76
|
+
if (filters == null) return void 0;
|
|
77
|
+
if (isLocalFilter(filters, onFilter)) return void 0;
|
|
78
|
+
const filterKey = parseDataIndex(dataIndex);
|
|
79
|
+
return filterKey ? proFilter?.[filterKey] : void 0;
|
|
80
|
+
}
|
|
81
|
+
function parseColumnFilterSort(proFilter, proSort, columnProps) {
|
|
82
|
+
return {
|
|
83
|
+
filteredValue: parseProFilteredValue(proFilter, columnProps),
|
|
84
|
+
sortOrder: parseProSortOrder(proSort, columnProps)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function resolveOnFilter(columnProps) {
|
|
88
|
+
const { onFilter, dataIndex } = columnProps;
|
|
89
|
+
if (onFilter === true) return (value, row) => defaultOnFilter(value, row, dataIndex);
|
|
90
|
+
return omitBoolean(onFilter);
|
|
91
|
+
}
|
|
92
|
+
function resolveFilters(columnProps) {
|
|
93
|
+
const { filters = [], valueEnum } = columnProps;
|
|
94
|
+
if (filters === true) return proFieldParsingValueEnumToArray(runFunction(valueEnum, void 0)).filter((valueItem) => valueItem && valueItem.value !== "all");
|
|
95
|
+
return filters;
|
|
96
|
+
}
|
|
97
|
+
function getColumnConfig(columnsMap, columnKey, columnProps) {
|
|
98
|
+
return { fixed: (columnsMap?.[columnKey] || { fixed: columnProps.fixed }).fixed };
|
|
99
|
+
}
|
|
100
|
+
function updateSubNameRecord(rowData, index, keyName, childrenColumnName, subNameRecord) {
|
|
101
|
+
if (!(Object.prototype.toString.call(rowData) === "[object Object]") || rowData === null || !Reflect.has(rowData, keyName)) return;
|
|
102
|
+
const record = rowData;
|
|
103
|
+
const uniqueKey = record?.[keyName];
|
|
104
|
+
const parentInfo = subNameRecord.get(uniqueKey) || [];
|
|
105
|
+
(record?.[childrenColumnName])?.forEach((item) => {
|
|
106
|
+
const itemUniqueKey = item[keyName];
|
|
107
|
+
if (!subNameRecord.has(itemUniqueKey)) subNameRecord.set(itemUniqueKey, parentInfo.concat([index, childrenColumnName]));
|
|
108
|
+
});
|
|
109
|
+
return uniqueKey;
|
|
110
|
+
}
|
|
111
|
+
function createCellRender(columnProps, context, subNameRecord) {
|
|
112
|
+
let keyName = context.rowKey ?? "id";
|
|
113
|
+
return (text, rowData, index) => {
|
|
114
|
+
if (typeof context.rowKey === "function") keyName = context.rowKey(rowData, index);
|
|
115
|
+
const uniqueKey = updateSubNameRecord(rowData, index, keyName, context.childrenColumnName, subNameRecord);
|
|
116
|
+
return columnRender({
|
|
117
|
+
columnProps,
|
|
118
|
+
text,
|
|
119
|
+
rowData,
|
|
120
|
+
index,
|
|
121
|
+
columnEmptyText: context.columnEmptyText,
|
|
122
|
+
counter: context.counter,
|
|
123
|
+
type: context.type,
|
|
124
|
+
marginSM: context.marginSM,
|
|
125
|
+
subName: subNameRecord.get(uniqueKey),
|
|
126
|
+
editableUtils: context.editableUtils
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 转化 columns 到 pro 的格式 主要是 render 方法的自行实现
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
function genProColumnsToColumns(params, parents) {
|
|
135
|
+
const { columns, counter, proFilter, proSort, columnEmptyText, marginSM, editableUtils, rowKey = "id", type = "table", childrenColumnName = "children" } = params;
|
|
136
|
+
const subNameRecord = /* @__PURE__ */ new Map();
|
|
137
|
+
const columnResizeWidthMap = getColumnResizeWidthMap(columns, params.columnResizeWidthMap);
|
|
138
|
+
return columns?.map((columnProps, columnsIndex) => {
|
|
139
|
+
if (columnProps === Table.EXPAND_COLUMN) return columnProps;
|
|
140
|
+
if (columnProps === Table.SELECTION_COLUMN) return columnProps;
|
|
141
|
+
const { key, dataIndex, valueEnum, valueType = "text", children } = columnProps;
|
|
142
|
+
const columnKey = genColumnKey(key || dataIndex?.toString(), [parents?.key, columnsIndex].filter(Boolean).join("-"));
|
|
143
|
+
if (!valueEnum && !valueType && !children) return {
|
|
144
|
+
index: columnsIndex,
|
|
145
|
+
...columnProps
|
|
146
|
+
};
|
|
147
|
+
const { filteredValue, sortOrder } = parseColumnFilterSort(proFilter, proSort, columnProps);
|
|
148
|
+
const { fixed } = getColumnConfig(counter?.columnsMap?.value, columnKey, columnProps);
|
|
149
|
+
const width = columnResizeWidthMap[columnKey] ?? columnProps.width ?? (columnProps.fixed ? 200 : void 0);
|
|
150
|
+
const finalColumns = omitUndefinedAndEmptyArr({
|
|
151
|
+
index: columnsIndex,
|
|
152
|
+
key: columnKey,
|
|
153
|
+
...columnProps,
|
|
154
|
+
title: renderColumnsTitle(columnProps),
|
|
155
|
+
valueEnum,
|
|
156
|
+
filters: resolveFilters(columnProps),
|
|
157
|
+
onFilter: resolveOnFilter(columnProps),
|
|
158
|
+
filteredValue,
|
|
159
|
+
sortOrder,
|
|
160
|
+
fixed,
|
|
161
|
+
width,
|
|
162
|
+
children: columnProps.children ? genProColumnsToColumns({
|
|
163
|
+
...params,
|
|
164
|
+
columns: columnProps.children || [],
|
|
165
|
+
columnResizeWidthMap
|
|
166
|
+
}, {
|
|
167
|
+
...columnProps,
|
|
168
|
+
key: columnKey
|
|
169
|
+
}) : void 0,
|
|
170
|
+
render: createCellRender(columnProps, {
|
|
171
|
+
rowKey,
|
|
172
|
+
type,
|
|
173
|
+
childrenColumnName,
|
|
174
|
+
counter,
|
|
175
|
+
marginSM,
|
|
176
|
+
columnEmptyText,
|
|
177
|
+
editableUtils
|
|
178
|
+
}, subNameRecord)
|
|
179
|
+
});
|
|
180
|
+
if (columnProps.resizable) finalColumns.onHeaderCell = (data, cellIndex) => {
|
|
181
|
+
const headerCellProps = columnProps.onHeaderCell?.(data, cellIndex);
|
|
182
|
+
return {
|
|
183
|
+
...headerCellProps,
|
|
184
|
+
resizable: true,
|
|
185
|
+
width: finalColumns.width,
|
|
186
|
+
onResize: (event, { size }) => {
|
|
187
|
+
columnResizeWidthMap[columnKey] = size.width;
|
|
188
|
+
finalColumns.width = size.width;
|
|
189
|
+
headerCellProps?.onResize?.(event, { size });
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
return finalColumns;
|
|
194
|
+
})?.filter((item) => !item?.hideInTable);
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
export { genColumnKey, genProColumnsToColumns, isLocalFilter, isLocalSorter, parseDataIndex, parseProFilteredValue, parseProSortOrder };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ActionType, Bordered, BorderedType, FilterValue as FilterValue$1, ProColumns, ProTableInstance, UseFetchDataAction } from "../typing.js";
|
|
2
|
+
import { ComputedRef, ShallowRef, UnwrapRef, VNode } from "vue";
|
|
3
|
+
import * as _$_antdv_vue_pro_form0 from "@antdv-vue/pro-form";
|
|
4
|
+
import { IntlType } from "@antdv-vue/pro-provider";
|
|
5
|
+
import { AddLineOptions, Key, PageInfo, ProFieldValueObjectType, ProFieldValueType, RecordKey, UseEditableUtilType } from "@antdv-vue/pro-utils";
|
|
6
|
+
import { TablePaginationConfig } from "antdv-next";
|
|
7
|
+
import { FilterValue, SortOrder, SorterResult } from "antdv-next/dist/table/index";
|
|
8
|
+
import { GetRowKey } from "@v-c/table";
|
|
9
|
+
|
|
10
|
+
//#region src/utils/index.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* 检查值是否存在 为了 避开 0 和 false
|
|
13
|
+
*
|
|
14
|
+
* @param value
|
|
15
|
+
*/
|
|
16
|
+
declare function checkUndefinedOrNull(value: any): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 合并用户 props 和 预设的 props
|
|
19
|
+
*
|
|
20
|
+
* @param pagination
|
|
21
|
+
* @param pageInfo
|
|
22
|
+
* @param intl
|
|
23
|
+
*/
|
|
24
|
+
declare function mergePagination<T>(pagination: TablePaginationConfig | boolean | undefined, pageInfo: UnwrapRef<UseFetchDataAction<T>['pageInfo']> & {
|
|
25
|
+
setPageInfo: any;
|
|
26
|
+
}, intl: IntlType): TablePaginationConfig | false | undefined;
|
|
27
|
+
type PostDataType<T> = (data: T) => T;
|
|
28
|
+
/**
|
|
29
|
+
* 一个转化的 pipeline 列表
|
|
30
|
+
*
|
|
31
|
+
* @param data
|
|
32
|
+
* @param pipeline
|
|
33
|
+
*/
|
|
34
|
+
declare function postDataPipeline<T>(data: T, pipeline: PostDataType<T>[]): T;
|
|
35
|
+
declare function isBordered(borderType: BorderedType, border?: Bordered): boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 获取用户的 action 信息
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
declare function useActionType<T extends Record<string, any>>(action: UseFetchDataAction<T>, props: {
|
|
41
|
+
nativeElement: ComputedRef<HTMLDivElement | null | undefined>;
|
|
42
|
+
focus: () => void;
|
|
43
|
+
fullScreen: () => Promise<void>;
|
|
44
|
+
onCleanSelected: () => Promise<void>;
|
|
45
|
+
resetAll: () => Promise<void>;
|
|
46
|
+
editableUtils: UseEditableUtilType<T>;
|
|
47
|
+
}): ActionType<any, T>;
|
|
48
|
+
declare function isMergeCell(dom?: VNode<any, any, {
|
|
49
|
+
colSpan?: string;
|
|
50
|
+
}>): string | false | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* 根据 key 和 dataIndex 生成唯一 id
|
|
53
|
+
*
|
|
54
|
+
* @param key 用户设置的 key
|
|
55
|
+
* @param index 序列号,理论上唯一
|
|
56
|
+
*/
|
|
57
|
+
declare function genColumnKey(key?: string | number | Key, index?: number | string): string;
|
|
58
|
+
/**
|
|
59
|
+
* 平铺所有columns, 用于判断是用的是本地筛选/排序
|
|
60
|
+
* @param columns 列配置
|
|
61
|
+
*/
|
|
62
|
+
declare function flattenColumns<T extends Record<string, any>, ValueType extends (ProFieldValueType | ProFieldValueObjectType)>(columns?: ProColumns<T, ValueType>[]): ProColumns<T, ValueType>[];
|
|
63
|
+
/**
|
|
64
|
+
* 获取服务端筛选数据
|
|
65
|
+
* @param filters 筛选数据
|
|
66
|
+
* @param columns 列配置
|
|
67
|
+
* @returns 服务端筛选数据
|
|
68
|
+
*/
|
|
69
|
+
declare function getServerFilterResult<T, ValueType>(filters: Record<string, FilterValue | null>, columns: ProColumns<T, ValueType>[]): Record<string, FilterValue$1>;
|
|
70
|
+
/**
|
|
71
|
+
* 获取服务端排序数据
|
|
72
|
+
* @param sorterResult 排序数据
|
|
73
|
+
* @returns 服务端排序数据
|
|
74
|
+
*/
|
|
75
|
+
declare function getServerSorterResult<T extends Record<string, any>>(sorterResult: SorterResult<T> | SorterResult<T>[]): Record<string, SortOrder | undefined>;
|
|
76
|
+
/**
|
|
77
|
+
* 从 ProColumns 数组中取出默认的排序和筛选数据
|
|
78
|
+
*
|
|
79
|
+
* @param columns ProColumns
|
|
80
|
+
*/
|
|
81
|
+
declare function parseServerDefaultColumnConfig<T, ValueType>(columns: ProColumns<T, ValueType>[]): {
|
|
82
|
+
sort: Record<string, SortOrder>;
|
|
83
|
+
filter: Record<string, FilterValue$1>;
|
|
84
|
+
};
|
|
85
|
+
declare function useProTableInstanceExpose<T extends Record<string, any>>(tableRef: ShallowRef<ProTableInstance<T> | null>): {
|
|
86
|
+
readonly nativeElement: HTMLDivElement | null | undefined;
|
|
87
|
+
readonly pageInfo: PageInfo | undefined;
|
|
88
|
+
readonly formRef: _$_antdv_vue_pro_form0.ProFormInstance<T> | null;
|
|
89
|
+
preEditableKeys: ComputedRef<Key[] | undefined>;
|
|
90
|
+
focus: () => void | undefined;
|
|
91
|
+
fullScreen: () => Promise<void | undefined>;
|
|
92
|
+
cleanSelected: () => Promise<void | undefined>;
|
|
93
|
+
addEditRecord: (row: T, options?: AddLineOptions) => Promise<boolean | undefined>;
|
|
94
|
+
cancelEditable: (recordKey: RecordKey, needReTry?: boolean) => Promise<boolean | undefined>;
|
|
95
|
+
getRealIndex: (record: T) => number | undefined;
|
|
96
|
+
isEditable: (row: T & {
|
|
97
|
+
index: number;
|
|
98
|
+
}) => {
|
|
99
|
+
recordKey: string;
|
|
100
|
+
isEditable: boolean;
|
|
101
|
+
preIsEditable: boolean;
|
|
102
|
+
} | undefined;
|
|
103
|
+
onValuesChange: (value: T, values: T) => void | undefined;
|
|
104
|
+
reload: (resetPageIndex?: boolean) => Promise<void | undefined>;
|
|
105
|
+
reloadAndRest: () => Promise<void | undefined>;
|
|
106
|
+
reset: () => Promise<void | undefined>;
|
|
107
|
+
saveEditable: (recordKey: RecordKey, needReTry?: boolean) => Promise<boolean | undefined>;
|
|
108
|
+
scrollTo: (arg: number | {
|
|
109
|
+
index?: number | undefined;
|
|
110
|
+
key?: Key | undefined;
|
|
111
|
+
top?: number;
|
|
112
|
+
}) => void | undefined;
|
|
113
|
+
setPageInfo: (page: Partial<PageInfo>) => Promise<void | undefined>;
|
|
114
|
+
startEditable: (recordKey: Key, record?: T) => Promise<boolean | undefined>;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* 将 editableKeys 解析为 RowEditableConfig.onChange 的第二参数,
|
|
118
|
+
* 与 useEditableArray 内 setEditableRowKeys 一致:single 为单条(可为空场景下的 undefined),multiple 为数组。
|
|
119
|
+
*/
|
|
120
|
+
declare function resolveEditingPayloadForRowEditableOnChange<DataType extends Record<string, any>>(keys: Key[], dataSource: readonly DataType[] | undefined, getRowKey: GetRowKey<DataType>, editableType: 'single' | 'multiple' | undefined, childrenColumnName?: string): DataType | DataType[];
|
|
121
|
+
//#endregion
|
|
122
|
+
export { checkUndefinedOrNull, flattenColumns, genColumnKey, getServerFilterResult, getServerSorterResult, isBordered, isMergeCell, mergePagination, parseServerDefaultColumnConfig, postDataPipeline, resolveEditingPayloadForRowEditableOnChange, useActionType, useProTableInstanceExpose };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { isLocalFilter, isLocalSorter } from "./genProColumnsToColumns.js";
|
|
2
|
+
import { computed, isVNode } from "vue";
|
|
3
|
+
//#region src/utils/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* 检查值是否存在 为了 避开 0 和 false
|
|
6
|
+
*
|
|
7
|
+
* @param value
|
|
8
|
+
*/
|
|
9
|
+
function checkUndefinedOrNull(value) {
|
|
10
|
+
return value !== void 0 && value !== null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 合并用户 props 和 预设的 props
|
|
14
|
+
*
|
|
15
|
+
* @param pagination
|
|
16
|
+
* @param pageInfo
|
|
17
|
+
* @param intl
|
|
18
|
+
*/
|
|
19
|
+
function mergePagination(pagination, pageInfo, intl) {
|
|
20
|
+
if (pagination === false) return false;
|
|
21
|
+
const { total, current, pageSize, setPageInfo } = pageInfo;
|
|
22
|
+
return {
|
|
23
|
+
showTotal: (all, range) => `${intl.getMessage({
|
|
24
|
+
id: "pagination.total.range",
|
|
25
|
+
defaultMessage: "第"
|
|
26
|
+
})} ${range[0]}-${range[1]} ${intl.getMessage({
|
|
27
|
+
id: "pagination.total.total",
|
|
28
|
+
defaultMessage: "条/总共"
|
|
29
|
+
})} ${all} ${intl.getMessage({
|
|
30
|
+
id: "pagination.total.item",
|
|
31
|
+
defaultMessage: "条"
|
|
32
|
+
})}`,
|
|
33
|
+
total,
|
|
34
|
+
...typeof pagination === "object" ? pagination : {},
|
|
35
|
+
current: pagination !== true && pagination ? pagination.current ?? current : current,
|
|
36
|
+
pageSize: pagination !== true && pagination ? pagination.pageSize ?? pageSize : pageSize,
|
|
37
|
+
onChange: (page, newPageSize) => {
|
|
38
|
+
const { onChange } = pagination;
|
|
39
|
+
onChange?.(page, newPageSize || 20);
|
|
40
|
+
if (newPageSize !== pageSize || current !== page) setPageInfo({
|
|
41
|
+
pageSize: newPageSize,
|
|
42
|
+
current: page
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 一个转化的 pipeline 列表
|
|
49
|
+
*
|
|
50
|
+
* @param data
|
|
51
|
+
* @param pipeline
|
|
52
|
+
*/
|
|
53
|
+
function postDataPipeline(data, pipeline) {
|
|
54
|
+
if (pipeline.filter((item) => item).length < 1) return data;
|
|
55
|
+
return pipeline.reduce((pre, postData) => {
|
|
56
|
+
return postData(pre);
|
|
57
|
+
}, data);
|
|
58
|
+
}
|
|
59
|
+
function isBordered(borderType, border) {
|
|
60
|
+
if (border === void 0) return false;
|
|
61
|
+
if (typeof border === "boolean") return border;
|
|
62
|
+
return border[borderType];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 获取用户的 action 信息
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
function useActionType(action, props) {
|
|
69
|
+
const { messageContextHolder, ...rest } = props.editableUtils;
|
|
70
|
+
return {
|
|
71
|
+
...rest,
|
|
72
|
+
get pageInfo() {
|
|
73
|
+
return action.pageInfo.value;
|
|
74
|
+
},
|
|
75
|
+
get nativeElement() {
|
|
76
|
+
return props.nativeElement.value;
|
|
77
|
+
},
|
|
78
|
+
focus: () => props.focus(),
|
|
79
|
+
reload: async (resetPageIndex) => {
|
|
80
|
+
if (resetPageIndex) await action.setPageInfo({ current: 1 });
|
|
81
|
+
await action?.reload();
|
|
82
|
+
},
|
|
83
|
+
reloadAndRest: async () => {
|
|
84
|
+
await props.onCleanSelected();
|
|
85
|
+
await action.setPageInfo({ current: 1 });
|
|
86
|
+
await action?.reload();
|
|
87
|
+
},
|
|
88
|
+
reset: async () => {
|
|
89
|
+
await props.resetAll();
|
|
90
|
+
await action?.reset?.();
|
|
91
|
+
await action?.reload();
|
|
92
|
+
},
|
|
93
|
+
fullScreen: async () => await props.fullScreen(),
|
|
94
|
+
clearSelected: async () => await props.onCleanSelected(),
|
|
95
|
+
setPageInfo: async (rest) => await action.setPageInfo(rest)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function isMergeCell(dom) {
|
|
99
|
+
return dom && isVNode(dom) && dom?.props?.colSpan;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 根据 key 和 dataIndex 生成唯一 id
|
|
103
|
+
*
|
|
104
|
+
* @param key 用户设置的 key
|
|
105
|
+
* @param index 序列号,理论上唯一
|
|
106
|
+
*/
|
|
107
|
+
function genColumnKey(key, index) {
|
|
108
|
+
if (key) return Array.isArray(key) ? key.join("-") : key.toString();
|
|
109
|
+
return `${index}`;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 将 ProTable - column - dataIndex 转为字符串形式
|
|
113
|
+
*
|
|
114
|
+
* @param dataIndex Column 中的 dataIndex
|
|
115
|
+
*/
|
|
116
|
+
function parseDataIndex(dataIndex) {
|
|
117
|
+
if (Array.isArray(dataIndex)) return dataIndex.join(",");
|
|
118
|
+
return dataIndex?.toString();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 平铺所有columns, 用于判断是用的是本地筛选/排序
|
|
122
|
+
* @param columns 列配置
|
|
123
|
+
*/
|
|
124
|
+
function flattenColumns(columns) {
|
|
125
|
+
const _columns = [];
|
|
126
|
+
columns?.forEach((column) => {
|
|
127
|
+
if (column.children) _columns.push(...flattenColumns(column.children));
|
|
128
|
+
else _columns.push(column);
|
|
129
|
+
});
|
|
130
|
+
return _columns;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 获取服务端筛选数据
|
|
134
|
+
* @param filters 筛选数据
|
|
135
|
+
* @param columns 列配置
|
|
136
|
+
* @returns 服务端筛选数据
|
|
137
|
+
*/
|
|
138
|
+
function getServerFilterResult(filters, columns) {
|
|
139
|
+
return Object.entries(filters).reduce((acc, [key, value]) => {
|
|
140
|
+
const column = columns.find((column) => parseDataIndex(column.dataIndex) === key);
|
|
141
|
+
if (column != null && !isLocalFilter(column.filters, column.onFilter)) acc[key] = value;
|
|
142
|
+
return acc;
|
|
143
|
+
}, {});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 获取服务端排序数据
|
|
147
|
+
* @param sorterResult 排序数据
|
|
148
|
+
* @returns 服务端排序数据
|
|
149
|
+
*/
|
|
150
|
+
function getServerSorterResult(sorterResult) {
|
|
151
|
+
return (Array.isArray(sorterResult) ? sorterResult : [sorterResult]).reduce((acc, item) => {
|
|
152
|
+
const sorter = item.column?.sorter;
|
|
153
|
+
if (sorter != null && isLocalSorter(sorter)) return acc;
|
|
154
|
+
const sortKey = typeof sorter === "string" ? sorter : parseDataIndex(item.column?.dataIndex);
|
|
155
|
+
if (sortKey != null) acc[sortKey] = item.order;
|
|
156
|
+
return acc;
|
|
157
|
+
}, {});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 从 ProColumns 数组中取出默认的排序和筛选数据
|
|
161
|
+
*
|
|
162
|
+
* @param columns ProColumns
|
|
163
|
+
*/
|
|
164
|
+
function parseServerDefaultColumnConfig(columns) {
|
|
165
|
+
const filter = {};
|
|
166
|
+
const sort = {};
|
|
167
|
+
columns.forEach((column) => {
|
|
168
|
+
const dataIndex = parseDataIndex(column.dataIndex);
|
|
169
|
+
if (!dataIndex) return;
|
|
170
|
+
if (column.filters && !isLocalFilter(column.filters, column.onFilter)) filter[dataIndex] = column.defaultFilteredValue ?? null;
|
|
171
|
+
if (column.sorter && !isLocalSorter(column.sorter)) if (typeof column.sorter === "string") sort[column.sorter] = column.defaultSortOrder ?? null;
|
|
172
|
+
else sort[dataIndex] = column.defaultSortOrder ?? null;
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
sort,
|
|
176
|
+
filter
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function useProTableInstanceExpose(tableRef) {
|
|
180
|
+
return {
|
|
181
|
+
get nativeElement() {
|
|
182
|
+
return tableRef.value?.nativeElement;
|
|
183
|
+
},
|
|
184
|
+
get pageInfo() {
|
|
185
|
+
return tableRef.value?.pageInfo;
|
|
186
|
+
},
|
|
187
|
+
get formRef() {
|
|
188
|
+
return tableRef.value?.formRef?.nativeElement ? tableRef.value?.formRef : null;
|
|
189
|
+
},
|
|
190
|
+
preEditableKeys: computed(() => tableRef.value?.preEditableKeys?.value),
|
|
191
|
+
focus: () => tableRef.value?.focus?.(),
|
|
192
|
+
fullScreen: async () => await tableRef.value?.fullScreen(),
|
|
193
|
+
cleanSelected: async () => await tableRef.value?.clearSelected?.(),
|
|
194
|
+
addEditRecord: async (row, options) => await tableRef.value?.addEditRecord?.(row, options),
|
|
195
|
+
cancelEditable: async (recordKey, needReTry) => await tableRef.value?.cancelEditable?.(recordKey, needReTry),
|
|
196
|
+
getRealIndex: (record) => tableRef.value?.getRealIndex?.(record),
|
|
197
|
+
isEditable: (row) => tableRef.value?.isEditable?.(row),
|
|
198
|
+
onValuesChange: (value, values) => tableRef.value?.onValuesChange?.(value, values),
|
|
199
|
+
reload: async (resetPageIndex) => await tableRef.value?.reload?.(resetPageIndex),
|
|
200
|
+
reloadAndRest: async () => await tableRef.value?.reloadAndRest?.(),
|
|
201
|
+
reset: async () => await tableRef.value?.reset?.(),
|
|
202
|
+
saveEditable: async (recordKey, needReTry) => await tableRef.value?.saveEditable?.(recordKey, needReTry),
|
|
203
|
+
scrollTo: (arg) => tableRef.value?.scrollTo?.(arg),
|
|
204
|
+
setPageInfo: async (page) => tableRef.value?.setPageInfo(page),
|
|
205
|
+
startEditable: async (recordKey, record) => await tableRef.value?.startEditable?.(recordKey, record)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 将 editableKeys 解析为 RowEditableConfig.onChange 的第二参数,
|
|
210
|
+
* 与 useEditableArray 内 setEditableRowKeys 一致:single 为单条(可为空场景下的 undefined),multiple 为数组。
|
|
211
|
+
*/
|
|
212
|
+
function resolveEditingPayloadForRowEditableOnChange(keys, dataSource, getRowKey, editableType, childrenColumnName = "children") {
|
|
213
|
+
const cleanKeys = keys.filter((key) => key !== void 0);
|
|
214
|
+
const kvMap = /* @__PURE__ */ new Map();
|
|
215
|
+
const dig = (records) => {
|
|
216
|
+
records.forEach((record, index) => {
|
|
217
|
+
const rowKey = getRowKey(record, index);
|
|
218
|
+
kvMap.set(rowKey, record);
|
|
219
|
+
if (record && typeof record === "object" && childrenColumnName in record) dig(record[childrenColumnName] || []);
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
dig(dataSource ?? []);
|
|
223
|
+
const editingRecords = cleanKeys.map((key) => kvMap.get(key)).filter((k) => k !== void 0);
|
|
224
|
+
return (editableType || "single") === "single" ? editingRecords[0] : editingRecords;
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
export { checkUndefinedOrNull, flattenColumns, genColumnKey, getServerFilterResult, getServerSorterResult, isBordered, isMergeCell, mergePagination, parseServerDefaultColumnConfig, postDataPipeline, resolveEditingPayloadForRowEditableOnChange, useActionType, useProTableInstanceExpose };
|