stk-table-vue 1.2.4 → 1.2.6

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.
Files changed (68) hide show
  1. package/README.md +194 -194
  2. package/lib/{Dropdown-D_9cB0rD.js → Dropdown-BAANgg_5.js} +2 -2
  3. package/lib/{StkTable-CVcmlZi9.js → StkTable-CGcxwpdb.js} +22 -6
  4. package/lib/src/StkTable/StkTable.vue.d.ts +18 -4
  5. package/lib/src/StkTable/types/index.d.ts +4 -1
  6. package/lib/src/StkTable/useVirtualScroll.d.ts +6 -1
  7. package/lib/stk-table-vue.js +3 -3
  8. package/lib/style.css +1 -1
  9. package/package.json +93 -93
  10. package/src/StkTable/StkTable.vue +2362 -2338
  11. package/src/StkTable/components/DragHandle.vue +9 -9
  12. package/src/StkTable/components/SortIcon.vue +6 -6
  13. package/src/StkTable/components/TreeNodeCell.vue +19 -19
  14. package/src/StkTable/components/TriangleIcon.vue +3 -3
  15. package/src/StkTable/const.ts +50 -50
  16. package/src/StkTable/custom-cells/ChangeCell/ChangeCell.less +34 -34
  17. package/src/StkTable/custom-cells/ChangeCell/createChangeCell.ts +90 -90
  18. package/src/StkTable/custom-cells/ChangeCell/index.ts +4 -4
  19. package/src/StkTable/custom-cells/CheckboxCell/CheckboxCell.less +14 -14
  20. package/src/StkTable/custom-cells/CheckboxCell/CheckboxCell.vue +56 -56
  21. package/src/StkTable/custom-cells/CheckboxCell/createCheckboxCell.ts +146 -146
  22. package/src/StkTable/custom-cells/CheckboxCell/index.ts +5 -5
  23. package/src/StkTable/custom-cells/FilterCell/Dropdown/index.ts +16 -16
  24. package/src/StkTable/custom-cells/FilterCell/Dropdown/index.vue +186 -186
  25. package/src/StkTable/custom-cells/FilterCell/Filter.less +118 -118
  26. package/src/StkTable/custom-cells/FilterCell/Filter.vue +66 -66
  27. package/src/StkTable/custom-cells/FilterCell/createFilterCell.ts +120 -120
  28. package/src/StkTable/custom-cells/FilterCell/index.ts +6 -6
  29. package/src/StkTable/custom-cells/FilterCell/types.ts +43 -43
  30. package/src/StkTable/custom-cells/NumberCell/createNumberCell.ts +43 -43
  31. package/src/StkTable/custom-cells/NumberCell/index.ts +2 -2
  32. package/src/StkTable/custom-cells/utils/formatNumber.ts +137 -137
  33. package/src/StkTable/features/const.ts +1 -1
  34. package/src/StkTable/features/index.ts +1 -1
  35. package/src/StkTable/features/useAreaSelection.ts +1240 -1239
  36. package/src/StkTable/index.ts +20 -20
  37. package/src/StkTable/mergeCellsCache.ts +69 -69
  38. package/src/StkTable/registerFeature.ts +40 -40
  39. package/src/StkTable/style.less +791 -791
  40. package/src/StkTable/types/highlightDimOptions.ts +28 -28
  41. package/src/StkTable/types/index.ts +503 -500
  42. package/src/StkTable/useAutoResize.ts +87 -87
  43. package/src/StkTable/useColResize.ts +202 -202
  44. package/src/StkTable/useFixedCol.ts +168 -168
  45. package/src/StkTable/useFixedStyle.ts +75 -75
  46. package/src/StkTable/useGetFixedColPosition.ts +63 -63
  47. package/src/StkTable/useHighlight.ts +270 -270
  48. package/src/StkTable/useIndexResolver.ts +29 -29
  49. package/src/StkTable/useKeyboardArrowScroll.ts +114 -114
  50. package/src/StkTable/useMaxRowSpan.ts +60 -60
  51. package/src/StkTable/useMergeCells.ts +541 -541
  52. package/src/StkTable/useRowExpand.ts +81 -81
  53. package/src/StkTable/useScrollRowByRow.ts +96 -96
  54. package/src/StkTable/useScrollbar.ts +177 -177
  55. package/src/StkTable/useSorter.ts +267 -267
  56. package/src/StkTable/useTableColumns.ts +142 -142
  57. package/src/StkTable/useThDrag.ts +94 -94
  58. package/src/StkTable/useTrDrag.ts +100 -100
  59. package/src/StkTable/useTree.ts +253 -253
  60. package/src/StkTable/useVirtualScroll.ts +1032 -1025
  61. package/src/StkTable/useWheeling.ts +23 -23
  62. package/src/StkTable/utils/constRefUtils.ts +29 -29
  63. package/src/StkTable/utils/index.ts +331 -331
  64. package/src/StkTable/utils/rowHeightFenwickTree.ts +74 -74
  65. package/src/StkTable/utils/useTriggerRef.ts +33 -33
  66. package/src/VirtualTree.vue +622 -622
  67. package/src/VirtualTreeSelect.vue +367 -367
  68. package/src/vite-env.d.ts +10 -10
@@ -1,267 +1,267 @@
1
- import { computed, ref, toRaw, type Ref } from 'vue';
2
- import { DEFAULT_SORT_CONFIG } from './const';
3
- import type { Order, SortConfig, SortOption, SortState, StkTableColumn, UniqKey } from './types/index';
4
- import { tableSort } from './utils/index';
5
-
6
- /**
7
- * 排序切换顺序
8
- * 循环顺序:null → desc → asc → null → ...
9
- */
10
- const SORT_SWITCH_ORDER: Order[] = [null, 'desc', 'asc'] as const;
11
-
12
- /**
13
- * 排序 Hook
14
- * 管理表格排序状态和相关操作
15
- * @param props 表格 props
16
- * @param colKeyGen 列 key 生成函数
17
- * @param tableHeaderLast 表头最后一行(叶子节点)
18
- * @param dataSourceCopy 数据源副本 ref
19
- * @param initDataSource 初始化数据源函数
20
- * @param emits 事件发射函数
21
- * @param onDataSourceChange 数据源变化后的刷新回调(重算虚拟滚动等,见 #80)
22
- * @returns 排序相关状态和方法
23
- */
24
- export function useSorter<DT extends Record<string, any>>(
25
- props: any,
26
- emits: any,
27
- colKeyGen: Ref<(col: StkTableColumn<DT>) => string>,
28
- tableHeaderLast: Ref<StkTableColumn<DT>[]>,
29
- dataSourceCopy: Ref<DT[]>,
30
- initDataSource: (data?: DT[], option?: { forceSort?: boolean }) => void,
31
- onDataSourceChange: () => void,
32
- ) {
33
- /** 多列排序状态数组 */
34
- const sortStates = ref<SortState<DT>[]>([]);
35
-
36
- /** 是否启用多列排序 */
37
- const isMultiSort = computed(() => props.sortConfig.multiSort ?? false);
38
-
39
- /** 多列排序限制 */
40
- const multiSortLimit = computed(() => props.sortConfig.multiSortLimit ?? 3);
41
-
42
- /** 对外暴露:当前排序的列 key(只读计算属性) */
43
- const sortCol = computed<keyof DT | undefined>(() => sortStates.value[0]?.dataIndex);
44
-
45
- /**
46
- * 获取列的排序状态
47
- */
48
- function getColumnSortState(colKey: UniqKey): SortState<DT> | undefined {
49
- return sortStates.value[getSortStateIndex(colKey)] as SortState<DT> | undefined;
50
- }
51
-
52
- /**
53
- * 获取列的排序状态索引
54
- */
55
- function getSortStateIndex(colKey: UniqKey): number {
56
- return sortStates.value.findIndex(s => s.key === colKey || s.dataIndex === colKey);
57
- }
58
-
59
- function getTableCol(state: { key?: SortState<DT>['key']; dataIndex: SortState<DT>['dataIndex'] }) {
60
- return tableHeaderLast.value.find(c => (state.key && colKeyGen.value(c) === state.key) || c.dataIndex === state.dataIndex);
61
- }
62
-
63
- /**
64
- * 获取排序列信息
65
- */
66
- function getSortColumns(): { key: keyof DT | undefined; order: Order }[] {
67
- return sortStates.value.map(s => ({ key: s.key || s.dataIndex, order: s.order }));
68
- }
69
-
70
- /**
71
- * 添加或更新排序状态到 sortStates
72
- * @param newState 新的排序状态
73
- * @param mode '1' - 追加模式(多列排序),0 - 替换模式(单列排序)
74
- */
75
- function addOrUpdateSortState(newState: SortState<DT>, mode?: 1 | 0) {
76
- const existingIndex = getSortStateIndex(newState.key || newState.dataIndex);
77
-
78
- if (existingIndex >= 0) {
79
- // 移除已存在的相同列
80
- sortStates.value.splice(existingIndex, 1);
81
- }
82
-
83
- if (mode && isMultiSort.value) {
84
- // 多列排序模式:检查数量限制,然后添加到最前面
85
- if (sortStates.value.length >= multiSortLimit.value) {
86
- sortStates.value.pop();
87
- }
88
- sortStates.value.unshift(newState as any);
89
- } else {
90
- sortStates.value = [newState as any];
91
- }
92
- }
93
-
94
- /**
95
- * 更新排序状态(点击表头时调用)
96
- */
97
- function updateSortState(col: StkTableColumn<DT>, sortConfig: SortConfig<DT>): Order {
98
- const colKey = colKeyGen.value(col);
99
- const existingIndex = getSortStateIndex(colKey);
100
- let newOrder: Order;
101
-
102
- const defaultSort = sortConfig.defaultSort;
103
-
104
- if (existingIndex >= 0) {
105
- const currentOrder = sortStates.value[existingIndex].order;
106
- if (currentOrder && defaultSort && (defaultSort.key === colKey || defaultSort.dataIndex === col.dataIndex)) {
107
- // If click default sort column
108
- const defaultSwitchOrder = SORT_SWITCH_ORDER.filter(order => order !== null);
109
- const currentIndex = defaultSwitchOrder.indexOf(currentOrder);
110
- newOrder = defaultSwitchOrder[(currentIndex + 1) % defaultSwitchOrder.length];
111
- } else {
112
- // Click other column
113
- const currentIndex = SORT_SWITCH_ORDER.indexOf(currentOrder);
114
- newOrder = SORT_SWITCH_ORDER[(currentIndex + 1) % 3];
115
- }
116
-
117
- if (newOrder) {
118
- const updatedState = { ...sortStates.value[existingIndex], order: newOrder };
119
- addOrUpdateSortState(updatedState as any, 1);
120
- } else {
121
- sortStates.value.splice(existingIndex, 1); // Delete sort state
122
- if (defaultSort?.order) {
123
- // Has default sort
124
- const defaultSortCol = getTableCol(defaultSort);
125
- const { key, sortField, sortType } = defaultSortCol || {};
126
- addOrUpdateSortState({ key, sortField, sortType, ...defaultSort }, 1);
127
- }
128
- }
129
- } else {
130
- newOrder = SORT_SWITCH_ORDER[1];
131
-
132
- const newState: SortState<DT> = {
133
- key: colKey,
134
- dataIndex: col.dataIndex,
135
- sortField: col.sortField,
136
- sortType: col.sortType,
137
- order: newOrder,
138
- };
139
-
140
- addOrUpdateSortState(newState, 1);
141
- }
142
-
143
- return newOrder;
144
- }
145
-
146
- /**
147
- * 对数据源执行排序
148
- * tableSort 内部会根据 sortChildren 配置自动处理树形递归排序
149
- */
150
- function sortData(dataSource: DT[]): DT[] {
151
- if (!sortStates.value.length) return dataSource;
152
-
153
- const sortConfig = { ...DEFAULT_SORT_CONFIG, ...props.sortConfig };
154
- let result = dataSource.slice();
155
-
156
- // 从后往前排序,这样前面的排序优先级更高
157
- for (let i = sortStates.value.length - 1; i >= 0; i--) {
158
- const state = sortStates.value[i];
159
- const col = getTableCol(state);
160
- if (col && state.order) {
161
- const colSortConfig = { ...sortConfig, ...col.sortConfig };
162
- result = tableSort(col, state.order, result, colSortConfig);
163
- }
164
- }
165
-
166
- return result;
167
- }
168
-
169
- /**
170
- * 表头点击排序
171
- */
172
- function onColumnSort(col: StkTableColumn<DT> | undefined | null) {
173
- if (!col) {
174
- console.warn('onColumnSort: not found col:', col);
175
- return;
176
- }
177
- if (!col.sorter) {
178
- // 点击表头触发的排序,如果列没有配置 sorter 则不处理。setSorter 触发的排序则保持通行。
179
- return;
180
- }
181
-
182
- const sortConfig: SortConfig<DT> = { ...DEFAULT_SORT_CONFIG, ...props.sortConfig, ...col.sortConfig };
183
- const order = updateSortState(col, sortConfig);
184
-
185
- if (!props.sortRemote) {
186
- initDataSource();
187
- // #80:排序后数据窗口需重算,否则残留 startIndex/endIndex 会“吃掉”数据
188
- onDataSourceChange();
189
- }
190
-
191
- emits('sort-change', col, order, toRaw(dataSourceCopy.value), sortConfig);
192
- }
193
-
194
- /**
195
- * 设置表头排序状态
196
- */
197
- function setSorter(
198
- colKey: string,
199
- order: Order,
200
- option: { sortOption?: SortOption<DT>; force?: boolean; silent?: boolean; sort?: boolean; append?: boolean } = {},
201
- ): DT[] {
202
- const newOption = { silent: true, sortOption: null, sort: true, append: false, ...option };
203
- const colKeyGenValue = colKeyGen.value;
204
- let column: StkTableColumn<DT> | undefined;
205
-
206
- if (order) {
207
- column = newOption.sortOption || tableHeaderLast.value.find(it => colKeyGenValue(it) === colKey);
208
- if (column) {
209
- const newState: SortState<DT> = {
210
- key: colKey,
211
- dataIndex: column.dataIndex,
212
- sortField: column.sortField,
213
- sortType: column.sortType,
214
- order,
215
- };
216
-
217
- const mode = newOption.append && isMultiSort.value ? 1 : 0;
218
- addOrUpdateSortState(newState, mode);
219
- }
220
- } else {
221
- sortStates.value = [];
222
- }
223
-
224
- if (newOption.sort && dataSourceCopy.value?.length) {
225
- if (!props.sortRemote || newOption.force) {
226
- initDataSource(props.dataSource, { forceSort: newOption.force });
227
- // #80:与 onColumnSort 一致,排序后重算虚拟滚动窗口
228
- onDataSourceChange();
229
- }
230
- }
231
-
232
- if (!newOption.silent) {
233
- if (!column) {
234
- column = newOption.sortOption || tableHeaderLast.value.find(it => colKeyGenValue(it) === colKey);
235
- }
236
- if (column) {
237
- emits('sort-change', column, order, toRaw(dataSourceCopy.value), props.sortConfig);
238
- } else {
239
- console.warn('Can not find column by key:', colKey);
240
- }
241
- }
242
-
243
- return dataSourceCopy.value;
244
- }
245
-
246
- /**
247
- * 重置排序器
248
- */
249
- function resetSorter() {
250
- sortStates.value = [];
251
- initDataSource();
252
- // #80:重置后同样重算虚拟滚动窗口
253
- onDataSourceChange();
254
- }
255
-
256
- /**
257
- * 处理默认排序
258
- */
259
- function dealDefaultSorter() {
260
- if (!props.sortConfig.defaultSort) return;
261
- const { key, dataIndex, order, silent } = { silent: true, ...props.sortConfig.defaultSort };
262
- setSorter((key || dataIndex) as string, order, { force: false, silent });
263
- }
264
-
265
- // 只返回需要在组件外部使用的方法和状态
266
- return [sortStates, sortCol, onColumnSort, setSorter, resetSorter, getSortColumns, dealDefaultSorter, getColumnSortState, sortData] as const;
267
- }
1
+ import { computed, ref, toRaw, type Ref } from 'vue';
2
+ import { DEFAULT_SORT_CONFIG } from './const';
3
+ import type { Order, SortConfig, SortOption, SortState, StkTableColumn, UniqKey } from './types/index';
4
+ import { tableSort } from './utils/index';
5
+
6
+ /**
7
+ * 排序切换顺序
8
+ * 循环顺序:null → desc → asc → null → ...
9
+ */
10
+ const SORT_SWITCH_ORDER: Order[] = [null, 'desc', 'asc'] as const;
11
+
12
+ /**
13
+ * 排序 Hook
14
+ * 管理表格排序状态和相关操作
15
+ * @param props 表格 props
16
+ * @param colKeyGen 列 key 生成函数
17
+ * @param tableHeaderLast 表头最后一行(叶子节点)
18
+ * @param dataSourceCopy 数据源副本 ref
19
+ * @param initDataSource 初始化数据源函数
20
+ * @param emits 事件发射函数
21
+ * @param onDataSourceChange 数据源变化后的刷新回调(重算虚拟滚动等,见 #80)
22
+ * @returns 排序相关状态和方法
23
+ */
24
+ export function useSorter<DT extends Record<string, any>>(
25
+ props: any,
26
+ emits: any,
27
+ colKeyGen: Ref<(col: StkTableColumn<DT>) => string>,
28
+ tableHeaderLast: Ref<StkTableColumn<DT>[]>,
29
+ dataSourceCopy: Ref<DT[]>,
30
+ initDataSource: (data?: DT[], option?: { forceSort?: boolean }) => void,
31
+ onDataSourceChange: () => void,
32
+ ) {
33
+ /** 多列排序状态数组 */
34
+ const sortStates = ref<SortState<DT>[]>([]);
35
+
36
+ /** 是否启用多列排序 */
37
+ const isMultiSort = computed(() => props.sortConfig.multiSort ?? false);
38
+
39
+ /** 多列排序限制 */
40
+ const multiSortLimit = computed(() => props.sortConfig.multiSortLimit ?? 3);
41
+
42
+ /** 对外暴露:当前排序的列 key(只读计算属性) */
43
+ const sortCol = computed<keyof DT | undefined>(() => sortStates.value[0]?.dataIndex);
44
+
45
+ /**
46
+ * 获取列的排序状态
47
+ */
48
+ function getColumnSortState(colKey: UniqKey): SortState<DT> | undefined {
49
+ return sortStates.value[getSortStateIndex(colKey)] as SortState<DT> | undefined;
50
+ }
51
+
52
+ /**
53
+ * 获取列的排序状态索引
54
+ */
55
+ function getSortStateIndex(colKey: UniqKey): number {
56
+ return sortStates.value.findIndex(s => s.key === colKey || s.dataIndex === colKey);
57
+ }
58
+
59
+ function getTableCol(state: { key?: SortState<DT>['key']; dataIndex: SortState<DT>['dataIndex'] }) {
60
+ return tableHeaderLast.value.find(c => (state.key && colKeyGen.value(c) === state.key) || c.dataIndex === state.dataIndex);
61
+ }
62
+
63
+ /**
64
+ * 获取排序列信息
65
+ */
66
+ function getSortColumns(): { key: keyof DT | undefined; order: Order }[] {
67
+ return sortStates.value.map(s => ({ key: s.key || s.dataIndex, order: s.order }));
68
+ }
69
+
70
+ /**
71
+ * 添加或更新排序状态到 sortStates
72
+ * @param newState 新的排序状态
73
+ * @param mode '1' - 追加模式(多列排序),0 - 替换模式(单列排序)
74
+ */
75
+ function addOrUpdateSortState(newState: SortState<DT>, mode?: 1 | 0) {
76
+ const existingIndex = getSortStateIndex(newState.key || newState.dataIndex);
77
+
78
+ if (existingIndex >= 0) {
79
+ // 移除已存在的相同列
80
+ sortStates.value.splice(existingIndex, 1);
81
+ }
82
+
83
+ if (mode && isMultiSort.value) {
84
+ // 多列排序模式:检查数量限制,然后添加到最前面
85
+ if (sortStates.value.length >= multiSortLimit.value) {
86
+ sortStates.value.pop();
87
+ }
88
+ sortStates.value.unshift(newState as any);
89
+ } else {
90
+ sortStates.value = [newState as any];
91
+ }
92
+ }
93
+
94
+ /**
95
+ * 更新排序状态(点击表头时调用)
96
+ */
97
+ function updateSortState(col: StkTableColumn<DT>, sortConfig: SortConfig<DT>): Order {
98
+ const colKey = colKeyGen.value(col);
99
+ const existingIndex = getSortStateIndex(colKey);
100
+ let newOrder: Order;
101
+
102
+ const defaultSort = sortConfig.defaultSort;
103
+
104
+ if (existingIndex >= 0) {
105
+ const currentOrder = sortStates.value[existingIndex].order;
106
+ if (currentOrder && defaultSort && (defaultSort.key === colKey || defaultSort.dataIndex === col.dataIndex)) {
107
+ // If click default sort column
108
+ const defaultSwitchOrder = SORT_SWITCH_ORDER.filter(order => order !== null);
109
+ const currentIndex = defaultSwitchOrder.indexOf(currentOrder);
110
+ newOrder = defaultSwitchOrder[(currentIndex + 1) % defaultSwitchOrder.length];
111
+ } else {
112
+ // Click other column
113
+ const currentIndex = SORT_SWITCH_ORDER.indexOf(currentOrder);
114
+ newOrder = SORT_SWITCH_ORDER[(currentIndex + 1) % 3];
115
+ }
116
+
117
+ if (newOrder) {
118
+ const updatedState = { ...sortStates.value[existingIndex], order: newOrder };
119
+ addOrUpdateSortState(updatedState as any, 1);
120
+ } else {
121
+ sortStates.value.splice(existingIndex, 1); // Delete sort state
122
+ if (defaultSort?.order) {
123
+ // Has default sort
124
+ const defaultSortCol = getTableCol(defaultSort);
125
+ const { key, sortField, sortType } = defaultSortCol || {};
126
+ addOrUpdateSortState({ key, sortField, sortType, ...defaultSort }, 1);
127
+ }
128
+ }
129
+ } else {
130
+ newOrder = SORT_SWITCH_ORDER[1];
131
+
132
+ const newState: SortState<DT> = {
133
+ key: colKey,
134
+ dataIndex: col.dataIndex,
135
+ sortField: col.sortField,
136
+ sortType: col.sortType,
137
+ order: newOrder,
138
+ };
139
+
140
+ addOrUpdateSortState(newState, 1);
141
+ }
142
+
143
+ return newOrder;
144
+ }
145
+
146
+ /**
147
+ * 对数据源执行排序
148
+ * tableSort 内部会根据 sortChildren 配置自动处理树形递归排序
149
+ */
150
+ function sortData(dataSource: DT[]): DT[] {
151
+ if (!sortStates.value.length) return dataSource;
152
+
153
+ const sortConfig = { ...DEFAULT_SORT_CONFIG, ...props.sortConfig };
154
+ let result = dataSource.slice();
155
+
156
+ // 从后往前排序,这样前面的排序优先级更高
157
+ for (let i = sortStates.value.length - 1; i >= 0; i--) {
158
+ const state = sortStates.value[i];
159
+ const col = getTableCol(state);
160
+ if (col && state.order) {
161
+ const colSortConfig = { ...sortConfig, ...col.sortConfig };
162
+ result = tableSort(col, state.order, result, colSortConfig);
163
+ }
164
+ }
165
+
166
+ return result;
167
+ }
168
+
169
+ /**
170
+ * 表头点击排序
171
+ */
172
+ function onColumnSort(col: StkTableColumn<DT> | undefined | null) {
173
+ if (!col) {
174
+ console.warn('onColumnSort: not found col:', col);
175
+ return;
176
+ }
177
+ if (!col.sorter) {
178
+ // 点击表头触发的排序,如果列没有配置 sorter 则不处理。setSorter 触发的排序则保持通行。
179
+ return;
180
+ }
181
+
182
+ const sortConfig: SortConfig<DT> = { ...DEFAULT_SORT_CONFIG, ...props.sortConfig, ...col.sortConfig };
183
+ const order = updateSortState(col, sortConfig);
184
+
185
+ if (!props.sortRemote) {
186
+ initDataSource();
187
+ // #80:排序后数据窗口需重算,否则残留 startIndex/endIndex 会“吃掉”数据
188
+ onDataSourceChange();
189
+ }
190
+
191
+ emits('sort-change', col, order, toRaw(dataSourceCopy.value), sortConfig);
192
+ }
193
+
194
+ /**
195
+ * 设置表头排序状态
196
+ */
197
+ function setSorter(
198
+ colKey: string,
199
+ order: Order,
200
+ option: { sortOption?: SortOption<DT>; force?: boolean; silent?: boolean; sort?: boolean; append?: boolean } = {},
201
+ ): DT[] {
202
+ const newOption = { silent: true, sortOption: null, sort: true, append: false, ...option };
203
+ const colKeyGenValue = colKeyGen.value;
204
+ let column: StkTableColumn<DT> | undefined;
205
+
206
+ if (order) {
207
+ column = newOption.sortOption || tableHeaderLast.value.find(it => colKeyGenValue(it) === colKey);
208
+ if (column) {
209
+ const newState: SortState<DT> = {
210
+ key: colKey,
211
+ dataIndex: column.dataIndex,
212
+ sortField: column.sortField,
213
+ sortType: column.sortType,
214
+ order,
215
+ };
216
+
217
+ const mode = newOption.append && isMultiSort.value ? 1 : 0;
218
+ addOrUpdateSortState(newState, mode);
219
+ }
220
+ } else {
221
+ sortStates.value = [];
222
+ }
223
+
224
+ if (newOption.sort && dataSourceCopy.value?.length) {
225
+ if (!props.sortRemote || newOption.force) {
226
+ initDataSource(props.dataSource, { forceSort: newOption.force });
227
+ // #80:与 onColumnSort 一致,排序后重算虚拟滚动窗口
228
+ onDataSourceChange();
229
+ }
230
+ }
231
+
232
+ if (!newOption.silent) {
233
+ if (!column) {
234
+ column = newOption.sortOption || tableHeaderLast.value.find(it => colKeyGenValue(it) === colKey);
235
+ }
236
+ if (column) {
237
+ emits('sort-change', column, order, toRaw(dataSourceCopy.value), props.sortConfig);
238
+ } else {
239
+ console.warn('Can not find column by key:', colKey);
240
+ }
241
+ }
242
+
243
+ return dataSourceCopy.value;
244
+ }
245
+
246
+ /**
247
+ * 重置排序器
248
+ */
249
+ function resetSorter() {
250
+ sortStates.value = [];
251
+ initDataSource();
252
+ // #80:重置后同样重算虚拟滚动窗口
253
+ onDataSourceChange();
254
+ }
255
+
256
+ /**
257
+ * 处理默认排序
258
+ */
259
+ function dealDefaultSorter() {
260
+ if (!props.sortConfig.defaultSort) return;
261
+ const { key, dataIndex, order, silent } = { silent: true, ...props.sortConfig.defaultSort };
262
+ setSorter((key || dataIndex) as string, order, { force: false, silent });
263
+ }
264
+
265
+ // 只返回需要在组件外部使用的方法和状态
266
+ return [sortStates, sortCol, onColumnSort, setSorter, resetSorter, getSortColumns, dealDefaultSorter, getColumnSortState, sortData] as const;
267
+ }