resolver-egretimp-plus 0.1.30 → 0.1.31
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/dist/h5/index.js +18 -18
- package/dist/web/index.js +128 -128
- package/dist/web/index.js.LICENSE.txt +15 -0
- package/package.json +5 -1
- package/scripts/webpack.config.js +18 -2
- package/src/components/packages-web/CustomComponentTable.jsx +8 -5
- package/src/components/table/index.ts +29 -0
- package/src/components/table/src/composables/use-scrollbar.ts +30 -0
- package/src/components/table/src/config.ts +256 -0
- package/src/components/table/src/filter-panel.vue +260 -0
- package/src/components/table/src/h-helper.ts +34 -0
- package/src/components/table/src/layout-observer.ts +78 -0
- package/src/components/table/src/store/current.ts +85 -0
- package/src/components/table/src/store/expand.ts +76 -0
- package/src/components/table/src/store/helper.ts +74 -0
- package/src/components/table/src/store/index.ts +246 -0
- package/src/components/table/src/store/tree.ts +230 -0
- package/src/components/table/src/store/watcher.ts +543 -0
- package/src/components/table/src/table/defaults.ts +402 -0
- package/src/components/table/src/table/key-render-helper.ts +27 -0
- package/src/components/table/src/table/style-helper.ts +378 -0
- package/src/components/table/src/table/utils-helper.ts +47 -0
- package/src/components/table/src/table-body/defaults.ts +52 -0
- package/src/components/table/src/table-body/events-helper.ts +203 -0
- package/src/components/table/src/table-body/index.ts +119 -0
- package/src/components/table/src/table-body/render-helper.ts +283 -0
- package/src/components/table/src/table-body/styles-helper.ts +164 -0
- package/src/components/table/src/table-column/defaults.ts +237 -0
- package/src/components/table/src/table-column/index.ts +202 -0
- package/src/components/table/src/table-column/render-helper.ts +214 -0
- package/src/components/table/src/table-column/watcher-helper.ts +88 -0
- package/src/components/table/src/table-footer/index.ts +128 -0
- package/src/components/table/src/table-footer/mapState-helper.ts +33 -0
- package/src/components/table/src/table-footer/style-helper.ts +51 -0
- package/src/components/table/src/table-header/event-helper.ts +213 -0
- package/src/components/table/src/table-header/index.ts +244 -0
- package/src/components/table/src/table-header/style.helper.ts +119 -0
- package/src/components/table/src/table-header/utils-helper.ts +94 -0
- package/src/components/table/src/table-layout.ts +259 -0
- package/src/components/table/src/table.vue +389 -0
- package/src/components/table/src/tableColumn.ts +3 -0
- package/src/components/table/src/tokens.ts +5 -0
- package/src/components/table/src/util.ts +521 -0
- package/src/components/table/style/css.ts +5 -0
- package/src/components/table/style/index.ts +5 -0
- package/tsconfig.json +19 -0
- package/vue-shims.d.ts +4 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { getCurrentInstance, ref, toRefs, unref, watch } from 'vue'
|
|
3
|
+
import { hasOwn } from 'element-plus/es/utils/index.mjs'
|
|
4
|
+
import {
|
|
5
|
+
getColumnById,
|
|
6
|
+
getColumnByKey,
|
|
7
|
+
getKeysMap,
|
|
8
|
+
getRowIdentity,
|
|
9
|
+
orderBy,
|
|
10
|
+
toggleRowStatus,
|
|
11
|
+
} from '../util'
|
|
12
|
+
import useExpand from './expand'
|
|
13
|
+
import useCurrent from './current'
|
|
14
|
+
import useTree from './tree'
|
|
15
|
+
|
|
16
|
+
import type { Ref } from 'vue'
|
|
17
|
+
import type { TableColumnCtx } from '../table-column/defaults'
|
|
18
|
+
import type { Table, TableRefs } from '../table/defaults'
|
|
19
|
+
import type { StoreFilter } from '.'
|
|
20
|
+
|
|
21
|
+
const sortData = (data, states) => {
|
|
22
|
+
const sortingColumn = states.sortingColumn
|
|
23
|
+
if (!sortingColumn || typeof sortingColumn.sortable === 'string') {
|
|
24
|
+
return data
|
|
25
|
+
}
|
|
26
|
+
return orderBy(
|
|
27
|
+
data,
|
|
28
|
+
states.sortProp,
|
|
29
|
+
states.sortOrder,
|
|
30
|
+
sortingColumn.sortMethod,
|
|
31
|
+
sortingColumn.sortBy
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const doFlattenColumns = (columns) => {
|
|
36
|
+
const result = []
|
|
37
|
+
columns.forEach((column) => {
|
|
38
|
+
if (column.children && column.children.length > 0) {
|
|
39
|
+
// eslint-disable-next-line prefer-spread
|
|
40
|
+
result.push.apply(result, doFlattenColumns(column.children))
|
|
41
|
+
} else {
|
|
42
|
+
result.push(column)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
return result
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function useWatcher<T>() {
|
|
49
|
+
const instance = getCurrentInstance() as Table<T>
|
|
50
|
+
const { size: tableSize } = toRefs(instance.proxy?.$props as any)
|
|
51
|
+
const rowKey: Ref<string> = ref(null)
|
|
52
|
+
const data: Ref<T[]> = ref([])
|
|
53
|
+
const _data: Ref<T[]> = ref([])
|
|
54
|
+
const isComplex = ref(false)
|
|
55
|
+
const _columns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
56
|
+
const originColumns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
57
|
+
const columns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
58
|
+
const fixedColumns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
59
|
+
const rightFixedColumns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
60
|
+
const leafColumns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
61
|
+
const fixedLeafColumns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
62
|
+
const rightFixedLeafColumns: Ref<TableColumnCtx<T>[]> = ref([])
|
|
63
|
+
const updateOrderFns: (() => void)[] = []
|
|
64
|
+
const leafColumnsLength = ref(0)
|
|
65
|
+
const fixedLeafColumnsLength = ref(0)
|
|
66
|
+
const rightFixedLeafColumnsLength = ref(0)
|
|
67
|
+
const isAllSelected = ref(false)
|
|
68
|
+
const selection: Ref<T[]> = ref([])
|
|
69
|
+
const reserveSelection = ref(false)
|
|
70
|
+
const selectOnIndeterminate = ref(false)
|
|
71
|
+
const selectable: Ref<(row: T, index: number) => boolean> = ref(null)
|
|
72
|
+
const filters: Ref<StoreFilter> = ref({})
|
|
73
|
+
const filteredData = ref(null)
|
|
74
|
+
const sortingColumn = ref(null)
|
|
75
|
+
const sortProp = ref(null)
|
|
76
|
+
const sortOrder = ref(null)
|
|
77
|
+
const hoverRow = ref(null)
|
|
78
|
+
|
|
79
|
+
watch(data, () => instance.state && scheduleLayout(false), {
|
|
80
|
+
deep: true,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// 检查 rowKey 是否存在
|
|
84
|
+
const assertRowKey = () => {
|
|
85
|
+
if (!rowKey.value) throw new Error('[ElTable] prop row-key is required')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 更新 fixed
|
|
89
|
+
const updateChildFixed = (column: TableColumnCtx<T>) => {
|
|
90
|
+
column.children?.forEach((childColumn) => {
|
|
91
|
+
childColumn.fixed = column.fixed
|
|
92
|
+
updateChildFixed(childColumn)
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 更新列
|
|
97
|
+
const updateColumns = () => {
|
|
98
|
+
_columns.value.forEach((column) => {
|
|
99
|
+
updateChildFixed(column)
|
|
100
|
+
})
|
|
101
|
+
fixedColumns.value = _columns.value.filter(
|
|
102
|
+
(column) => column.fixed === true || column.fixed === 'left'
|
|
103
|
+
)
|
|
104
|
+
rightFixedColumns.value = _columns.value.filter(
|
|
105
|
+
(column) => column.fixed === 'right'
|
|
106
|
+
)
|
|
107
|
+
if (
|
|
108
|
+
fixedColumns.value.length > 0 &&
|
|
109
|
+
_columns.value[0] &&
|
|
110
|
+
_columns.value[0].type === 'selection' &&
|
|
111
|
+
!_columns.value[0].fixed
|
|
112
|
+
) {
|
|
113
|
+
_columns.value[0].fixed = true
|
|
114
|
+
fixedColumns.value.unshift(_columns.value[0])
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const notFixedColumns = _columns.value.filter((column) => !column.fixed)
|
|
118
|
+
originColumns.value = []
|
|
119
|
+
.concat(fixedColumns.value)
|
|
120
|
+
.concat(notFixedColumns)
|
|
121
|
+
.concat(rightFixedColumns.value)
|
|
122
|
+
const leafColumns = doFlattenColumns(notFixedColumns)
|
|
123
|
+
const fixedLeafColumns = doFlattenColumns(fixedColumns.value)
|
|
124
|
+
const rightFixedLeafColumns = doFlattenColumns(rightFixedColumns.value)
|
|
125
|
+
|
|
126
|
+
leafColumnsLength.value = leafColumns.length
|
|
127
|
+
fixedLeafColumnsLength.value = fixedLeafColumns.length
|
|
128
|
+
rightFixedLeafColumnsLength.value = rightFixedLeafColumns.length
|
|
129
|
+
|
|
130
|
+
columns.value = []
|
|
131
|
+
.concat(fixedLeafColumns)
|
|
132
|
+
.concat(leafColumns)
|
|
133
|
+
.concat(rightFixedLeafColumns)
|
|
134
|
+
isComplex.value =
|
|
135
|
+
fixedColumns.value.length > 0 || rightFixedColumns.value.length > 0
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 更新 DOM
|
|
139
|
+
const scheduleLayout = (needUpdateColumns?: boolean, immediate = false) => {
|
|
140
|
+
if (needUpdateColumns) {
|
|
141
|
+
updateColumns()
|
|
142
|
+
}
|
|
143
|
+
if (immediate) {
|
|
144
|
+
instance.state.doLayout()
|
|
145
|
+
} else {
|
|
146
|
+
instance.state.debouncedUpdateLayout()
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 选择
|
|
151
|
+
const isSelected = (row) => {
|
|
152
|
+
return selection.value.includes(row)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const clearSelection = () => {
|
|
156
|
+
isAllSelected.value = false
|
|
157
|
+
const oldSelection = selection.value
|
|
158
|
+
selection.value = []
|
|
159
|
+
if (oldSelection.length) {
|
|
160
|
+
instance.emit('selection-change', [])
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const cleanSelection = () => {
|
|
165
|
+
let deleted
|
|
166
|
+
if (rowKey.value) {
|
|
167
|
+
deleted = []
|
|
168
|
+
const selectedMap = getKeysMap(selection.value, rowKey.value)
|
|
169
|
+
const dataMap = getKeysMap(data.value, rowKey.value)
|
|
170
|
+
for (const key in selectedMap) {
|
|
171
|
+
if (hasOwn(selectedMap, key) && !dataMap[key]) {
|
|
172
|
+
deleted.push(selectedMap[key].row)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
deleted = selection.value.filter((item) => !data.value.includes(item))
|
|
177
|
+
}
|
|
178
|
+
if (deleted.length) {
|
|
179
|
+
const newSelection = selection.value.filter(
|
|
180
|
+
(item) => !deleted.includes(item)
|
|
181
|
+
)
|
|
182
|
+
selection.value = newSelection
|
|
183
|
+
instance.emit('selection-change', newSelection.slice())
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const getSelectionRows = () => {
|
|
188
|
+
return (selection.value || []).slice()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const toggleRowSelection = (
|
|
192
|
+
row: T,
|
|
193
|
+
selected = undefined,
|
|
194
|
+
emitChange = true
|
|
195
|
+
) => {
|
|
196
|
+
const changed = toggleRowStatus(selection.value, row, selected)
|
|
197
|
+
if (changed) {
|
|
198
|
+
const newSelection = (selection.value || []).slice()
|
|
199
|
+
// 调用 API 修改选中值,不触发 select 事件
|
|
200
|
+
if (emitChange) {
|
|
201
|
+
instance.emit('select', newSelection, row)
|
|
202
|
+
}
|
|
203
|
+
instance.emit('selection-change', newSelection)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const _toggleAllSelection = () => {
|
|
208
|
+
// when only some rows are selected (but not all), select or deselect all of them
|
|
209
|
+
// depending on the value of selectOnIndeterminate
|
|
210
|
+
const value = selectOnIndeterminate.value
|
|
211
|
+
? !isAllSelected.value
|
|
212
|
+
: !(isAllSelected.value || selection.value.length)
|
|
213
|
+
isAllSelected.value = value
|
|
214
|
+
|
|
215
|
+
let selectionChanged = false
|
|
216
|
+
let childrenCount = 0
|
|
217
|
+
const rowKey = instance?.store?.states?.rowKey.value
|
|
218
|
+
data.value.forEach((row, index) => {
|
|
219
|
+
const rowIndex = index + childrenCount
|
|
220
|
+
if (selectable.value) {
|
|
221
|
+
if (
|
|
222
|
+
selectable.value.call(null, row, rowIndex) &&
|
|
223
|
+
toggleRowStatus(selection.value, row, value)
|
|
224
|
+
) {
|
|
225
|
+
selectionChanged = true
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
if (toggleRowStatus(selection.value, row, value)) {
|
|
229
|
+
selectionChanged = true
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
childrenCount += getChildrenCount(getRowIdentity(row, rowKey))
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
if (selectionChanged) {
|
|
236
|
+
instance.emit(
|
|
237
|
+
'selection-change',
|
|
238
|
+
selection.value ? selection.value.slice() : []
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
instance.emit('select-all', (selection.value || []).slice())
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const updateSelectionByRowKey = () => {
|
|
245
|
+
const selectedMap = getKeysMap(selection.value, rowKey.value)
|
|
246
|
+
data.value.forEach((row) => {
|
|
247
|
+
const rowId = getRowIdentity(row, rowKey.value)
|
|
248
|
+
const rowInfo = selectedMap[rowId]
|
|
249
|
+
if (rowInfo) {
|
|
250
|
+
selection.value[rowInfo.index] = row
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const updateAllSelected = () => {
|
|
256
|
+
// data 为 null 时,解构时的默认值会被忽略
|
|
257
|
+
if (data.value?.length === 0) {
|
|
258
|
+
isAllSelected.value = false
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let selectedMap
|
|
263
|
+
if (rowKey.value) {
|
|
264
|
+
selectedMap = getKeysMap(selection.value, rowKey.value)
|
|
265
|
+
}
|
|
266
|
+
const isSelected = function (row) {
|
|
267
|
+
if (selectedMap) {
|
|
268
|
+
return !!selectedMap[getRowIdentity(row, rowKey.value)]
|
|
269
|
+
} else {
|
|
270
|
+
return selection.value.includes(row)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
let isAllSelected_ = true
|
|
274
|
+
let selectedCount = 0
|
|
275
|
+
let childrenCount = 0
|
|
276
|
+
for (let i = 0, j = (data.value || []).length; i < j; i++) {
|
|
277
|
+
const keyProp = instance?.store?.states?.rowKey.value
|
|
278
|
+
const rowIndex = i + childrenCount
|
|
279
|
+
const item = data.value[i]
|
|
280
|
+
const isRowSelectable =
|
|
281
|
+
selectable.value && selectable.value.call(null, item, rowIndex)
|
|
282
|
+
if (!isSelected(item)) {
|
|
283
|
+
if (!selectable.value || isRowSelectable) {
|
|
284
|
+
isAllSelected_ = false
|
|
285
|
+
break
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
selectedCount++
|
|
289
|
+
}
|
|
290
|
+
childrenCount += getChildrenCount(getRowIdentity(item, keyProp))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (selectedCount === 0) isAllSelected_ = false
|
|
294
|
+
isAllSelected.value = isAllSelected_
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// gets the number of all child nodes by rowKey
|
|
298
|
+
const getChildrenCount = (rowKey: string) => {
|
|
299
|
+
if (!instance || !instance.store) return 0
|
|
300
|
+
const { treeData } = instance.store.states
|
|
301
|
+
let count = 0
|
|
302
|
+
const children = treeData.value[rowKey]?.children
|
|
303
|
+
if (children) {
|
|
304
|
+
count += children.length
|
|
305
|
+
children.forEach((childKey) => {
|
|
306
|
+
count += getChildrenCount(childKey)
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
return count
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// 过滤与排序
|
|
313
|
+
const updateFilters = (columns, values) => {
|
|
314
|
+
if (!Array.isArray(columns)) {
|
|
315
|
+
columns = [columns]
|
|
316
|
+
}
|
|
317
|
+
const filters_ = {}
|
|
318
|
+
columns.forEach((col) => {
|
|
319
|
+
filters.value[col.id] = values
|
|
320
|
+
filters_[col.columnKey || col.id] = values
|
|
321
|
+
})
|
|
322
|
+
return filters_
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const updateSort = (column, prop, order) => {
|
|
326
|
+
if (sortingColumn.value && sortingColumn.value !== column) {
|
|
327
|
+
sortingColumn.value.order = null
|
|
328
|
+
}
|
|
329
|
+
sortingColumn.value = column
|
|
330
|
+
sortProp.value = prop
|
|
331
|
+
sortOrder.value = order
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const execFilter = () => {
|
|
335
|
+
let sourceData = unref(_data)
|
|
336
|
+
Object.keys(filters.value).forEach((columnId) => {
|
|
337
|
+
const values = filters.value[columnId]
|
|
338
|
+
if (!values || values.length === 0) return
|
|
339
|
+
const column = getColumnById(
|
|
340
|
+
{
|
|
341
|
+
columns: columns.value,
|
|
342
|
+
},
|
|
343
|
+
columnId
|
|
344
|
+
)
|
|
345
|
+
if (column && column.filterMethod) {
|
|
346
|
+
sourceData = sourceData.filter((row) => {
|
|
347
|
+
return values.some((value) =>
|
|
348
|
+
column.filterMethod.call(null, value, row, column)
|
|
349
|
+
)
|
|
350
|
+
})
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
filteredData.value = sourceData
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const execSort = () => {
|
|
358
|
+
data.value = sortData(filteredData.value, {
|
|
359
|
+
sortingColumn: sortingColumn.value,
|
|
360
|
+
sortProp: sortProp.value,
|
|
361
|
+
sortOrder: sortOrder.value,
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 根据 filters 与 sort 去过滤 data
|
|
366
|
+
const execQuery = (ignore = undefined) => {
|
|
367
|
+
if (!(ignore && ignore.filter)) {
|
|
368
|
+
execFilter()
|
|
369
|
+
}
|
|
370
|
+
execSort()
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const clearFilter = (columnKeys) => {
|
|
374
|
+
const { tableHeaderRef } = instance.refs as TableRefs
|
|
375
|
+
if (!tableHeaderRef) return
|
|
376
|
+
const panels = Object.assign({}, tableHeaderRef.filterPanels)
|
|
377
|
+
|
|
378
|
+
const keys = Object.keys(panels)
|
|
379
|
+
if (!keys.length) return
|
|
380
|
+
|
|
381
|
+
if (typeof columnKeys === 'string') {
|
|
382
|
+
columnKeys = [columnKeys]
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (Array.isArray(columnKeys)) {
|
|
386
|
+
const columns_ = columnKeys.map((key) =>
|
|
387
|
+
getColumnByKey(
|
|
388
|
+
{
|
|
389
|
+
columns: columns.value,
|
|
390
|
+
},
|
|
391
|
+
key
|
|
392
|
+
)
|
|
393
|
+
)
|
|
394
|
+
keys.forEach((key) => {
|
|
395
|
+
const column = columns_.find((col) => col.id === key)
|
|
396
|
+
if (column) {
|
|
397
|
+
column.filteredValue = []
|
|
398
|
+
}
|
|
399
|
+
})
|
|
400
|
+
instance.store.commit('filterChange', {
|
|
401
|
+
column: columns_,
|
|
402
|
+
values: [],
|
|
403
|
+
silent: true,
|
|
404
|
+
multi: true,
|
|
405
|
+
})
|
|
406
|
+
} else {
|
|
407
|
+
keys.forEach((key) => {
|
|
408
|
+
const column = columns.value.find((col) => col.id === key)
|
|
409
|
+
if (column) {
|
|
410
|
+
column.filteredValue = []
|
|
411
|
+
}
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
filters.value = {}
|
|
415
|
+
instance.store.commit('filterChange', {
|
|
416
|
+
column: {},
|
|
417
|
+
values: [],
|
|
418
|
+
silent: true,
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const clearSort = () => {
|
|
424
|
+
if (!sortingColumn.value) return
|
|
425
|
+
|
|
426
|
+
updateSort(null, null, null)
|
|
427
|
+
instance.store.commit('changeSortCondition', {
|
|
428
|
+
silent: true,
|
|
429
|
+
})
|
|
430
|
+
}
|
|
431
|
+
const {
|
|
432
|
+
setExpandRowKeys,
|
|
433
|
+
toggleRowExpansion,
|
|
434
|
+
updateExpandRows,
|
|
435
|
+
states: expandStates,
|
|
436
|
+
isRowExpanded,
|
|
437
|
+
} = useExpand({
|
|
438
|
+
data,
|
|
439
|
+
rowKey,
|
|
440
|
+
})
|
|
441
|
+
const {
|
|
442
|
+
updateTreeExpandKeys,
|
|
443
|
+
toggleTreeExpansion,
|
|
444
|
+
updateTreeData,
|
|
445
|
+
loadOrToggle,
|
|
446
|
+
states: treeStates,
|
|
447
|
+
} = useTree({
|
|
448
|
+
data,
|
|
449
|
+
rowKey,
|
|
450
|
+
})
|
|
451
|
+
const {
|
|
452
|
+
updateCurrentRowData,
|
|
453
|
+
updateCurrentRow,
|
|
454
|
+
setCurrentRowKey,
|
|
455
|
+
states: currentData,
|
|
456
|
+
} = useCurrent({
|
|
457
|
+
data,
|
|
458
|
+
rowKey,
|
|
459
|
+
})
|
|
460
|
+
// 适配层,expand-row-keys 在 Expand 与 TreeTable 中都有使用
|
|
461
|
+
const setExpandRowKeysAdapter = (val: string[]) => {
|
|
462
|
+
// 这里会触发额外的计算,但为了兼容性,暂时这么做
|
|
463
|
+
setExpandRowKeys(val)
|
|
464
|
+
updateTreeExpandKeys(val)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// 展开行与 TreeTable 都要使用
|
|
468
|
+
const toggleRowExpansionAdapter = (row: T, expanded?: boolean) => {
|
|
469
|
+
const hasExpandColumn = columns.value.some(({ type }) => type === 'expand')
|
|
470
|
+
if (hasExpandColumn) {
|
|
471
|
+
toggleRowExpansion(row, expanded)
|
|
472
|
+
} else {
|
|
473
|
+
toggleTreeExpansion(row, expanded)
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
assertRowKey,
|
|
479
|
+
updateColumns,
|
|
480
|
+
scheduleLayout,
|
|
481
|
+
isSelected,
|
|
482
|
+
clearSelection,
|
|
483
|
+
cleanSelection,
|
|
484
|
+
getSelectionRows,
|
|
485
|
+
toggleRowSelection,
|
|
486
|
+
_toggleAllSelection,
|
|
487
|
+
toggleAllSelection: null,
|
|
488
|
+
updateSelectionByRowKey,
|
|
489
|
+
updateAllSelected,
|
|
490
|
+
updateFilters,
|
|
491
|
+
updateCurrentRow,
|
|
492
|
+
updateSort,
|
|
493
|
+
execFilter,
|
|
494
|
+
execSort,
|
|
495
|
+
execQuery,
|
|
496
|
+
clearFilter,
|
|
497
|
+
clearSort,
|
|
498
|
+
toggleRowExpansion,
|
|
499
|
+
setExpandRowKeysAdapter,
|
|
500
|
+
setCurrentRowKey,
|
|
501
|
+
toggleRowExpansionAdapter,
|
|
502
|
+
isRowExpanded,
|
|
503
|
+
updateExpandRows,
|
|
504
|
+
updateCurrentRowData,
|
|
505
|
+
loadOrToggle,
|
|
506
|
+
updateTreeData,
|
|
507
|
+
states: {
|
|
508
|
+
tableSize,
|
|
509
|
+
rowKey,
|
|
510
|
+
data,
|
|
511
|
+
_data,
|
|
512
|
+
isComplex,
|
|
513
|
+
_columns,
|
|
514
|
+
originColumns,
|
|
515
|
+
columns,
|
|
516
|
+
fixedColumns,
|
|
517
|
+
rightFixedColumns,
|
|
518
|
+
leafColumns,
|
|
519
|
+
fixedLeafColumns,
|
|
520
|
+
rightFixedLeafColumns,
|
|
521
|
+
updateOrderFns,
|
|
522
|
+
leafColumnsLength,
|
|
523
|
+
fixedLeafColumnsLength,
|
|
524
|
+
rightFixedLeafColumnsLength,
|
|
525
|
+
isAllSelected,
|
|
526
|
+
selection,
|
|
527
|
+
reserveSelection,
|
|
528
|
+
selectOnIndeterminate,
|
|
529
|
+
selectable,
|
|
530
|
+
filters,
|
|
531
|
+
filteredData,
|
|
532
|
+
sortingColumn,
|
|
533
|
+
sortProp,
|
|
534
|
+
sortOrder,
|
|
535
|
+
hoverRow,
|
|
536
|
+
...expandStates,
|
|
537
|
+
...treeStates,
|
|
538
|
+
...currentData,
|
|
539
|
+
},
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export default useWatcher
|