|
1 | 1 | import { isBoolean } from '../../../shared/utils'; |
2 | | -import { watch, Ref, ref, computed, unref, ComponentInternalInstance } from 'vue'; |
3 | | -import type { Column, SortMethod, SortDirection, LevelColumn } from '../components/column/column-types'; |
| 2 | +import { watch, Ref, ref, computed, unref } from 'vue'; |
| 3 | +import type { Column, LevelColumn } from '../components/column/column-types'; |
4 | 4 | import type { DefaultRow, ITable, RowKeyType } from '../table-types'; |
5 | 5 | import type { TableStore } from './store-types'; |
6 | 6 | import { useExpand } from './use-expand'; |
7 | 7 | import { useEditTableCell } from './use-edit-table-cell'; |
8 | 8 | import { getRowIdentity } from '../utils'; |
| 9 | +import { useSort } from '../composables/use-sort'; |
9 | 10 |
|
10 | 11 | function replaceColumn(array: LevelColumn[], column: LevelColumn) { |
11 | 12 | return array.map((item) => { |
@@ -96,15 +97,7 @@ function doFlattenRows<T extends Record<string, unknown>>( |
96 | 97 | if ((data as Record<string, unknown>).children) { |
97 | 98 | rowLevelMap.value[getRowIdentity(data as Record<string, unknown>, rowKey)] = level; |
98 | 99 | // eslint-disable-next-line prefer-spread |
99 | | - result.push.apply( |
100 | | - result, |
101 | | - doFlattenRows<T>( |
102 | | - data.children as T[], |
103 | | - level + 1, |
104 | | - rowKey, |
105 | | - rowLevelMap, |
106 | | - hiddenRowKeys |
107 | | - )); |
| 100 | + result.push.apply(result, doFlattenRows<T>(data.children as T[], level + 1, rowKey, rowLevelMap, hiddenRowKeys)); |
108 | 101 | } |
109 | 102 | }); |
110 | 103 | return result; |
@@ -232,21 +225,6 @@ function createSelection<T extends Record<string, unknown>>(dataSource: Ref<T[]> |
232 | 225 | }; |
233 | 226 | } |
234 | 227 |
|
235 | | -function createSorter<T extends Record<string, unknown>>(dataSource: Ref<T[]>, _data: Ref<T[]>) { |
236 | | - const sortData = (direction: SortDirection, sortMethod: SortMethod<T>) => { |
237 | | - if (direction === 'ASC') { |
238 | | - _data.value = _data.value.sort((a, b) => (sortMethod ? (sortMethod(a, b) ? 1 : -1) : 0)); |
239 | | - } else if (direction === 'DESC') { |
240 | | - _data.value = _data.value.sort((a, b) => (sortMethod ? (sortMethod(a, b) ? -1 : 1) : 0)); |
241 | | - } else { |
242 | | - _data.value = [...dataSource.value]; |
243 | | - } |
244 | | - }; |
245 | | - |
246 | | - const thList: ComponentInternalInstance[] = []; |
247 | | - return { sortData, thList }; |
248 | | -} |
249 | | - |
250 | 228 | function createFixedLogic(columns: Ref<Column[]>) { |
251 | 229 | const isFixedLeft = computed(() => { |
252 | 230 | return columns.value.reduce((prev, current) => prev || !!current.fixedLeft, false); |
@@ -276,7 +254,7 @@ export function createStore<T extends Record<string, unknown>>(dataSource: Ref<T |
276 | 254 | flatRows |
277 | 255 | ); |
278 | 256 |
|
279 | | - const { sortData, thList } = createSorter<T>(dataSource, flatRows); |
| 257 | + const { thList, collectTh, sortData } = useSort(dataSource, flatRows); |
280 | 258 |
|
281 | 259 | const { isFixedLeft } = createFixedLogic(_columns); |
282 | 260 | const { isRowExpanded, updateExpandRows, setExpandRows, toggleRowExpansion } = useExpand(_data, table); |
@@ -315,6 +293,7 @@ export function createStore<T extends Record<string, unknown>>(dataSource: Ref<T |
315 | 293 | updateColumns, |
316 | 294 | updateRows, |
317 | 295 | getCheckedRows, |
| 296 | + collectTh, |
318 | 297 | sortData, |
319 | 298 | isRowChecked, |
320 | 299 | checkRow, |
|
0 commit comments