vxe-table 3.20.5 → 3.20.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 (141) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +106 -106
  3. package/es/index.esm.js +1 -2
  4. package/es/style.css +1 -1
  5. package/es/table/src/methods.js +20 -0
  6. package/es/table/src/table.js +36 -0
  7. package/es/table/src/util.js +3 -4
  8. package/es/table/style.css +48 -18
  9. package/es/ui/index.js +1 -1
  10. package/es/ui/src/log.js +1 -1
  11. package/es/vxe-table/style.css +48 -18
  12. package/lib/index.common.js +1 -2
  13. package/lib/index.umd.js +3251 -1876
  14. package/lib/index.umd.min.js +1 -1
  15. package/lib/style.css +1 -1
  16. package/lib/table/src/methods.js +2 -1
  17. package/lib/table/src/methods.min.js +1 -1
  18. package/lib/table/src/table.js +44 -0
  19. package/lib/table/src/table.min.js +1 -1
  20. package/lib/table/src/util.js +4 -6
  21. package/lib/table/src/util.min.js +1 -1
  22. package/lib/table/style/style.css +48 -18
  23. package/lib/ui/index.js +1 -1
  24. package/lib/ui/index.min.js +1 -1
  25. package/lib/ui/src/log.js +1 -1
  26. package/lib/ui/src/log.min.js +1 -1
  27. package/lib/v-x-e-table/index.js +1 -2
  28. package/lib/v-x-e-table/index.min.js +1 -1
  29. package/lib/vxe-colgroup/index.js +1 -2
  30. package/lib/vxe-colgroup/index.min.js +1 -1
  31. package/lib/vxe-column/index.js +1 -2
  32. package/lib/vxe-column/index.min.js +1 -1
  33. package/lib/vxe-grid/index.js +1 -2
  34. package/lib/vxe-grid/index.min.js +1 -1
  35. package/lib/vxe-table/index.js +1 -2
  36. package/lib/vxe-table/index.min.js +1 -1
  37. package/lib/vxe-table/style/style.css +48 -18
  38. package/lib/vxe-toolbar/index.js +1 -2
  39. package/lib/vxe-toolbar/index.min.js +1 -1
  40. package/lib/vxe-ui/index.js +1 -2
  41. package/lib/vxe-ui/index.min.js +1 -1
  42. package/lib/vxe-v-x-e-table/index.js +1 -2
  43. package/lib/vxe-v-x-e-table/index.min.js +1 -1
  44. package/package.json +93 -93
  45. package/packages/colgroup/index.ts +22 -22
  46. package/packages/column/index.ts +22 -22
  47. package/packages/components.ts +42 -42
  48. package/packages/grid/index.ts +22 -22
  49. package/packages/grid/src/grid.ts +1935 -1935
  50. package/packages/index.ts +4 -4
  51. package/packages/locale/lang/ar-EG.ts +832 -832
  52. package/packages/locale/lang/de-DE.ts +832 -832
  53. package/packages/locale/lang/en-US.ts +832 -832
  54. package/packages/locale/lang/es-ES.ts +832 -832
  55. package/packages/locale/lang/fr-FR.ts +832 -832
  56. package/packages/locale/lang/hu-HU.ts +832 -832
  57. package/packages/locale/lang/hy-AM.ts +832 -832
  58. package/packages/locale/lang/id-ID.ts +832 -832
  59. package/packages/locale/lang/it-IT.ts +832 -832
  60. package/packages/locale/lang/ja-JP.ts +832 -832
  61. package/packages/locale/lang/ko-KR.ts +832 -832
  62. package/packages/locale/lang/ms-MY.ts +832 -832
  63. package/packages/locale/lang/nb-NO.ts +832 -832
  64. package/packages/locale/lang/pt-BR.ts +832 -832
  65. package/packages/locale/lang/ru-RU.ts +832 -832
  66. package/packages/locale/lang/th-TH.ts +832 -832
  67. package/packages/locale/lang/ug-CN.ts +832 -832
  68. package/packages/locale/lang/uk-UA.ts +832 -832
  69. package/packages/locale/lang/uz-UZ.ts +832 -832
  70. package/packages/locale/lang/vi-VN.ts +832 -832
  71. package/packages/locale/lang/zh-CHT.ts +832 -832
  72. package/packages/locale/lang/zh-CN.ts +832 -832
  73. package/packages/locale/lang/zh-HK.ts +3 -3
  74. package/packages/locale/lang/zh-MO.ts +3 -3
  75. package/packages/locale/lang/zh-TC.ts +3 -3
  76. package/packages/locale/lang/zh-TW.ts +3 -3
  77. package/packages/table/index.ts +49 -49
  78. package/packages/table/module/custom/mixin.ts +369 -369
  79. package/packages/table/module/custom/panel.ts +1461 -1461
  80. package/packages/table/module/edit/mixin.ts +1123 -1123
  81. package/packages/table/module/export/export-panel.ts +658 -658
  82. package/packages/table/module/export/import-panel.ts +319 -319
  83. package/packages/table/module/export/mixin.ts +1693 -1693
  84. package/packages/table/module/export/util.ts +24 -24
  85. package/packages/table/module/filter/mixin.ts +507 -507
  86. package/packages/table/module/filter/panel.ts +329 -329
  87. package/packages/table/module/keyboard/mixin.ts +513 -513
  88. package/packages/table/module/menu/mixin.ts +329 -329
  89. package/packages/table/module/menu/panel.ts +212 -212
  90. package/packages/table/module/validator/mixin.ts +626 -626
  91. package/packages/table/render/index.ts +1456 -1456
  92. package/packages/table/src/body.ts +969 -969
  93. package/packages/table/src/cell.ts +1285 -1285
  94. package/packages/table/src/column.ts +205 -205
  95. package/packages/table/src/columnInfo.ts +228 -228
  96. package/packages/table/src/footer.ts +388 -388
  97. package/packages/table/src/group.ts +51 -51
  98. package/packages/table/src/header.ts +602 -602
  99. package/packages/table/src/methods.ts +12939 -12920
  100. package/packages/table/src/props.ts +311 -311
  101. package/packages/table/src/store.ts +15 -15
  102. package/packages/table/src/table.ts +2502 -2460
  103. package/packages/table/src/util.ts +1012 -1012
  104. package/packages/toolbar/index.ts +18 -18
  105. package/packages/toolbar/src/toolbar.ts +856 -856
  106. package/packages/ui/index.ts +530 -530
  107. package/packages/ui/src/anime.ts +52 -52
  108. package/packages/ui/src/comp.ts +3 -3
  109. package/packages/ui/src/dom.ts +236 -236
  110. package/packages/ui/src/log.ts +8 -8
  111. package/packages/ui/src/utils.ts +56 -56
  112. package/packages/ui/src/vn.ts +65 -65
  113. package/packages/v-x-e-table/index.ts +4 -4
  114. package/styles/all.scss +7 -7
  115. package/styles/base.scss +16 -16
  116. package/styles/components/grid.scss +89 -89
  117. package/styles/components/icon.scss +225 -225
  118. package/styles/components/old-icon.scss +715 -715
  119. package/styles/components/table-module/all.scss +6 -6
  120. package/styles/components/table-module/custom.scss +527 -527
  121. package/styles/components/table-module/export.scss +130 -130
  122. package/styles/components/table-module/filter.scss +130 -130
  123. package/styles/components/table-module/menu.scss +81 -81
  124. package/styles/components/table.scss +2679 -2679
  125. package/styles/components/toolbar.scss +119 -119
  126. package/styles/default.scss +2 -2
  127. package/styles/helpers/baseMixin.scss +95 -95
  128. package/styles/index.scss +3 -3
  129. package/styles/modules.scss +5 -5
  130. package/styles/theme/base.scss +93 -93
  131. package/styles/theme/dark.scss +49 -49
  132. package/styles/theme/light.scss +44 -44
  133. package/styles/variable.scss +43 -43
  134. package/types/all.d.ts +53 -53
  135. package/types/index.d.ts +4 -4
  136. /package/es/{iconfont.1773710661615.ttf → iconfont.1773972972913.ttf} +0 -0
  137. /package/es/{iconfont.1773710661615.woff → iconfont.1773972972913.woff} +0 -0
  138. /package/es/{iconfont.1773710661615.woff2 → iconfont.1773972972913.woff2} +0 -0
  139. /package/lib/{iconfont.1773710661615.ttf → iconfont.1773972972913.ttf} +0 -0
  140. /package/lib/{iconfont.1773710661615.woff → iconfont.1773972972913.woff} +0 -0
  141. /package/lib/{iconfont.1773710661615.woff2 → iconfont.1773972972913.woff2} +0 -0
@@ -1,1012 +1,1012 @@
1
- import XEUtils from 'xe-utils'
2
- import { ColumnInfo } from './columnInfo'
3
- import { isScale, isPx, queryElement } from '../../ui/src/dom'
4
- import { warnLog, errLog } from '../../ui/src/log'
5
- import { eqEmptyValue } from '../../ui/src/utils'
6
-
7
- import type { VxeTableDefines, VxeTableConstructor, TableReactData, TableInternalData, VxeTablePrivateMethods, VxeTablePropTypes } from '../../../types'
8
-
9
- export function createInternalData (): TableInternalData {
10
- return {
11
- tZindex: 0,
12
- currKeyField: '',
13
- isCurrDeepKey: false,
14
- elemStore: {},
15
- // 存放横向 X 虚拟滚动相关的信息
16
- scrollXStore: {
17
- preloadSize: 0,
18
- offsetSize: 0,
19
- visibleSize: 0,
20
- visibleStartIndex: 0,
21
- visibleEndIndex: 0,
22
- startIndex: 0,
23
- endIndex: 0
24
- },
25
- // 存放纵向 Y 虚拟滚动相关信息
26
- scrollYStore: {
27
- preloadSize: 0,
28
- offsetSize: 0,
29
- visibleSize: 0,
30
- visibleStartIndex: 0,
31
- visibleEndIndex: 0,
32
- startIndex: 0,
33
- endIndex: 0
34
- },
35
- // 表格宽度
36
- tableWidth: 0,
37
- // 表格高度
38
- tableHeight: 0,
39
- customHeight: 0,
40
- customMinHeight: 0,
41
- customMaxHeight: 0,
42
- // 当前 hover 行
43
- hoverRow: null,
44
- // 最后滚动位置
45
- lastScrollLeft: 0,
46
- lastScrollTop: 0,
47
- // 单选框属性,已选中保留的行
48
- radioReserveRow: null,
49
- // 复选框属性,已选中保留的行集合
50
- checkboxReserveRowMap: {},
51
- // 行数据,已展开保留的行集合
52
- rowExpandedReserveRowMap: {},
53
- // 树结构数据,已展开保留的行集合
54
- treeExpandedReserveRowMap: {},
55
- // 树结构数据,不确定状态的集合
56
- treeIndeterminateRowMaps: {},
57
- // 列表完整数据、条件处理后
58
- tableFullData: [],
59
- afterFullData: [],
60
- afterTreeFullData: [],
61
- afterGroupFullData: [],
62
- // 列表条件处理后数据集合
63
- afterFullRowMaps: {},
64
- // 树结构完整数据、条件处理后
65
- tableFullTreeData: [],
66
- // 行分组全量数据、条件处理后
67
- tableFullGroupData: [],
68
- tableSynchData: [],
69
- tableSourceData: [],
70
- // 收集的列配置(带分组)
71
- collectColumn: [],
72
- // 完整所有列(不带分组)
73
- tableFullColumn: [],
74
- // 渲染所有列
75
- visibleColumn: [],
76
-
77
- // 全量数据集(包括当前和已删除)
78
- fullAllDataRowIdData: {},
79
- // 数据集(仅当前)
80
- fullDataRowIdData: {},
81
- // 数据集(仅可视)
82
- visibleDataRowIdData: {},
83
-
84
- keepUpdateFieldMaps: {},
85
-
86
- footerFullDataRowData: {},
87
-
88
- // 渲染中缓存数据
89
- sourceDataRowIdData: {},
90
- fullColumnIdData: {},
91
- fullColumnFieldData: {},
92
-
93
- // 合并表头单元格的数据
94
- mergeHeaderList: [],
95
- mergeHeaderMaps: {},
96
- // 已合并单元格数据集合
97
- mergeHeaderCellMaps: {},
98
- // 合并单元格的数据
99
- mergeBodyList: [],
100
- mergeBodyMaps: {},
101
- // 已合并单元格数据集合
102
- mergeBodyCellMaps: {},
103
- // 合并表尾的数据
104
- mergeFooterList: [],
105
- mergeFooterMaps: {},
106
- // 已合并表尾数据集合
107
- mergeFooterCellMaps: {},
108
-
109
- // 已展开的行集合
110
- rowExpandedMaps: {},
111
- // 懒加载中的展开行的集合
112
- rowExpandLazyLoadedMaps: {},
113
- // 已展开的分组行
114
- rowGroupExpandedMaps: {},
115
- // 已展开树节点集合
116
- treeExpandedMaps: {},
117
- // 懒加载中的树节点的集合
118
- treeExpandLazyLoadedMaps: {},
119
- // 复选框属性,已选中的行集合
120
- selectCheckboxMaps: {},
121
- // 已标记的对象集
122
- pendingRowMaps: {},
123
- // 已新增的临时行
124
- insertRowMaps: {},
125
- // 已删除行
126
- removeRowMaps: {},
127
-
128
- cvCacheMaps: {},
129
-
130
- // 表头高度
131
- tHeaderHeight: 0,
132
- // 表体高度
133
- tBodyHeight: 0,
134
- // 表尾高度
135
- tFooterHeight: 0,
136
-
137
- teleportToWrapperElem: null,
138
- popupToWrapperElem: null,
139
-
140
- lastSTime: 0,
141
-
142
- inited: false,
143
- tooltipTimeout: null,
144
- initStatus: false,
145
- isActivated: false
146
- }
147
- }
148
-
149
- export function createReactData (): TableReactData {
150
- return {
151
- updateColFlag: 0,
152
- // 低性能的静态列
153
- staticColumns: [],
154
- // 渲染的列分组
155
- tableGroupColumn: [],
156
- // 可视区渲染的列
157
- tableColumn: [],
158
- // 渲染中的数据
159
- tableData: [],
160
- // 是否启用了横向 X 可视渲染方式加载
161
- scrollXLoad: false,
162
- // 是否启用了纵向 Y 可视渲染方式加载
163
- scrollYLoad: false,
164
- // 是否存在纵向滚动条
165
- overflowY: true,
166
- // 是否存在横向滚动条
167
- overflowX: false,
168
- // 纵向滚动条的宽度
169
- scrollbarWidth: 0,
170
- // 横向滚动条的高度
171
- scrollbarHeight: 0,
172
- // 行高
173
- rowHeight: 0,
174
- // 表格父容器的高度
175
- parentHeight: 0,
176
- // 是否使用分组表头
177
- isGroup: false,
178
- isAllOverflow: false,
179
- // 复选框属性,是否全选
180
- isAllSelected: false,
181
- // 复选框属性,有选中且非全选状态
182
- isIndeterminate: false,
183
- // 当前行
184
- currentRow: null,
185
- // 单选框属性,选中列
186
- currentColumn: null,
187
- // 单选框属性,选中行
188
- selectRadioRow: null,
189
- // 表尾合计数据
190
- footerTableData: [],
191
- // 行分组列信息
192
- rowGroupColumn: null,
193
- // 展开列信息
194
- expandColumn: null,
195
- checkboxColumn: null,
196
- radioColumn: null,
197
- // 树节点列信息
198
- treeNodeColumn: null,
199
- hasFixedColumn: false,
200
- // 刷新列标识,当列筛选被改变时,触发表格刷新数据
201
- upDataFlag: 0,
202
- // 刷新列标识,当列的特定属性被改变时,触发表格刷新列
203
- reColumnFlag: 0,
204
- // 初始化标识
205
- initStore: {
206
- filter: false,
207
- import: false,
208
- export: false,
209
- custom: false
210
- },
211
- // 自定义列相关的信息
212
- customStore: {
213
- btnEl: null,
214
- isAll: false,
215
- isIndeterminate: false,
216
- activeBtn: false,
217
- activeWrapper: false,
218
- visible: false,
219
- maxHeight: null,
220
- popupTop: 0,
221
- oldSortMaps: {},
222
- oldFixedMaps: {},
223
- oldVisibleMaps: {}
224
- },
225
- customColumnList: [],
226
- // 当前选中的筛选列
227
- filterStore: {
228
- isAllSelected: false,
229
- isIndeterminate: false,
230
- style: null,
231
- column: null,
232
- visible: false,
233
- maxHeight: null
234
- },
235
- // 存放列相关的信息
236
- columnStore: {
237
- leftList: [],
238
- centerList: [],
239
- rightList: [],
240
- resizeList: [],
241
- pxList: [],
242
- pxMinList: [],
243
- autoMinList: [],
244
- scaleList: [],
245
- scaleMinList: [],
246
- autoList: [],
247
- remainList: []
248
- },
249
- // 存放快捷菜单的信息
250
- ctxMenuStore: {
251
- selected: null,
252
- visible: false,
253
- showChild: false,
254
- selectChild: null,
255
- list: [],
256
- style: null
257
- },
258
- // 存放可编辑相关信息
259
- editStore: {
260
- indexs: {
261
- columns: []
262
- },
263
- titles: {
264
- columns: []
265
- },
266
- // 选中源
267
- selected: {
268
- row: null,
269
- column: null
270
- },
271
- // 已复制源
272
- copyed: {
273
- cut: false,
274
- rows: [],
275
- columns: []
276
- },
277
- // 激活
278
- actived: {
279
- row: null,
280
- column: null
281
- },
282
- // 当前被强制聚焦单元格,只会在鼠标点击后算聚焦
283
- focused: {
284
- row: null,
285
- column: null
286
- }
287
- },
288
- // 存放 tooltip 相关信息
289
- tooltipStore: {
290
- row: null,
291
- column: null,
292
- content: null,
293
- visible: false,
294
- type: null,
295
- currOpts: {}
296
- },
297
- // 存放数据校验相关信息
298
- validStore: {
299
- visible: false
300
- },
301
- validErrorMaps: {},
302
- // 导入相关信息
303
- importStore: {
304
- inited: false,
305
- file: null,
306
- type: '',
307
- modeList: [],
308
- typeList: [],
309
- filename: '',
310
- visible: false
311
- },
312
- importParams: {
313
- mode: '',
314
- types: null,
315
- message: true
316
- },
317
- // 导出相关信息
318
- exportStore: {
319
- inited: false,
320
- name: '',
321
- modeList: [],
322
- typeList: [],
323
- columns: [],
324
- isPrint: false,
325
- hasFooter: false,
326
- hasMerge: false,
327
- hasTree: false,
328
- hasColgroup: false,
329
- visible: false
330
- },
331
- exportParams: {
332
- filename: '',
333
- sheetName: '',
334
- mode: '',
335
- type: '',
336
- isColgroup: false,
337
- isMerge: false,
338
- isAllExpand: false,
339
- useStyle: false,
340
- original: false,
341
- message: true,
342
- isHeader: false,
343
- isTitle: false,
344
- isFooter: false
345
- },
346
-
347
- visiblwRowsFlag: 1,
348
-
349
- isRowGroupStatus: false,
350
- rowGroupList: [],
351
- aggHandleFields: [],
352
- aggHandleAggColumns: [],
353
-
354
- rowGroupExpandedFlag: 1,
355
- rowExpandedFlag: 1,
356
- treeExpandedFlag: 1,
357
- updateCheckboxFlag: 1,
358
- pendingRowFlag: 1,
359
- insertRowFlag: 1,
360
- removeRowFlag: 1,
361
-
362
- mergeHeadFlag: 1,
363
- mergeBodyFlag: 1,
364
- mergeFootFlag: 1,
365
-
366
- rowHeightStore: {
367
- large: 52,
368
- default: 48,
369
- medium: 44,
370
- small: 40,
371
- mini: 36
372
- },
373
-
374
- scrollVMLoading: false,
375
- scrollYHeight: 0,
376
- scrollYTop: 0,
377
- isScrollYBig: false,
378
- scrollXLeft: 0,
379
- scrollXWidth: 0,
380
- isScrollXBig: false,
381
-
382
- lazScrollLoading: false,
383
-
384
- rowExpandHeightFlag: 1,
385
- calcCellHeightFlag: 1,
386
- resizeHeightFlag: 1,
387
- resizeWidthFlag: 1,
388
-
389
- isCustomStatus: false,
390
-
391
- isCrossDragRow: false,
392
- dragRow: null,
393
- isCrossDragCol: false,
394
- dragCol: null,
395
- dragTipText: '',
396
-
397
- isDragResize: false,
398
- isRowLoading: false,
399
- isColLoading: false
400
- }
401
- }
402
-
403
- const getAllConvertColumns = (columns: any, parentColumn?: any) => {
404
- const result: any[] = []
405
- columns.forEach((column: any) => {
406
- column.parentId = parentColumn ? parentColumn.id : null
407
- if (column.visible) {
408
- if (column.children && column.children.length && column.children.some((column: any) => column.visible)) {
409
- result.push(column)
410
- result.push(...getAllConvertColumns(column.children, column))
411
- } else {
412
- result.push(column)
413
- }
414
- }
415
- })
416
- return result
417
- }
418
-
419
- export const convertHeaderColumnToRows = (originColumns: any) => {
420
- let maxLevel = 1
421
- const traverse = (column: any, parent?: any) => {
422
- if (parent) {
423
- column.level = parent.level + 1
424
- if (maxLevel < column.level) {
425
- maxLevel = column.level
426
- }
427
- }
428
- if (column.children && column.children.length && column.children.some((column: any) => column.visible)) {
429
- let colSpan = 0
430
- column.children.forEach((subColumn: any) => {
431
- if (subColumn.visible) {
432
- traverse(subColumn, column)
433
- colSpan += subColumn.colSpan
434
- }
435
- })
436
- column.colSpan = colSpan
437
- } else {
438
- column.colSpan = 1
439
- }
440
- }
441
-
442
- originColumns.forEach((column: any) => {
443
- column.level = 1
444
- traverse(column)
445
- })
446
-
447
- const rows: any[] = []
448
- for (let i = 0; i < maxLevel; i++) {
449
- rows.push([])
450
- }
451
-
452
- const allColumns = getAllConvertColumns(originColumns)
453
-
454
- allColumns.forEach((column) => {
455
- if (column.children && column.children.length && column.children.some((column: any) => column.visible)) {
456
- column.rowSpan = 1
457
- } else {
458
- column.rowSpan = maxLevel - column.level + 1
459
- }
460
- rows[column.level - 1].push(column)
461
- })
462
-
463
- return rows
464
- }
465
-
466
- export function convertHeaderToGridRows (spanColumns: VxeTableDefines.ColumnInfo[][]) {
467
- const rSize = spanColumns.length
468
- const cSize = spanColumns[0].reduce((sum, cell) => sum + cell.colSpan, 0)
469
-
470
- const occupiedRows: boolean[][] = []
471
- const fullRows: any[][] = []
472
- for (let rIndex = 0; rIndex < rSize; rIndex++) {
473
- const oCols: boolean[] = []
474
- const dCols: string[] = []
475
- for (let cIndex = 0; cIndex < cSize; cIndex++) {
476
- oCols.push(false)
477
- dCols.push('')
478
- }
479
- occupiedRows.push(oCols)
480
- fullRows.push(dCols)
481
- }
482
-
483
- for (let rIndex = 0; rIndex < rSize; rIndex++) {
484
- let currColIndex = 0
485
- for (const column of spanColumns[rIndex]) {
486
- const { colSpan, rowSpan } = column
487
- let startColIndex = -1
488
- for (let ccIndex = currColIndex; ccIndex <= cSize - colSpan; ccIndex++) {
489
- let oFlag = true
490
- for (let csIndex = 0; csIndex < colSpan; csIndex++) {
491
- if (occupiedRows[rIndex][ccIndex + csIndex]) {
492
- oFlag = false
493
- break
494
- }
495
- }
496
- if (oFlag) {
497
- startColIndex = ccIndex
498
- break
499
- }
500
- }
501
- if (startColIndex === -1) {
502
- for (let j = 0; j <= cSize - colSpan; j++) {
503
- let oFlag = true
504
- for (let k = 0; k < colSpan; k++) {
505
- if (occupiedRows[rIndex][j + k]) {
506
- oFlag = false
507
- break
508
- }
509
- }
510
- if (oFlag) {
511
- startColIndex = j
512
- break
513
- }
514
- }
515
- if (startColIndex === -1) {
516
- // error
517
- break
518
- }
519
- }
520
-
521
- for (let srIndex = rIndex; srIndex < rIndex + rowSpan; srIndex++) {
522
- for (let scIndex = startColIndex; scIndex < startColIndex + colSpan; scIndex++) {
523
- occupiedRows[srIndex][scIndex] = true
524
- fullRows[srIndex][scIndex] = column
525
- }
526
- }
527
- currColIndex = startColIndex + colSpan
528
- }
529
- }
530
- return fullRows
531
- }
532
-
533
- export function restoreScrollLocation ($xeTable: VxeTableConstructor, scrollLeft: number, scrollTop: number) {
534
- const internalData = $xeTable as unknown as TableInternalData
535
-
536
- if (scrollLeft || scrollTop) {
537
- internalData.intoRunScroll = false
538
- internalData.inVirtualScroll = false
539
- internalData.inWheelScroll = false
540
- internalData.inHeaderScroll = false
541
- internalData.inBodyScroll = false
542
- internalData.inFooterScroll = false
543
- internalData.scrollRenderType = ''
544
- // 还原滚动状态
545
- return $xeTable.scrollTo(scrollLeft, scrollTop)
546
- }
547
- return $xeTable.clearScroll()
548
- }
549
-
550
- export function toTreePathSeq (path: any) {
551
- return path.map((num: any, i: any) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
552
- }
553
-
554
- export function getRowUniqueId () {
555
- return XEUtils.uniqueId('row_')
556
- }
557
-
558
- /**
559
- * 生成行的唯一主键
560
- */
561
- export function createRowId (rowOpts: VxeTablePropTypes.RowConfig, row: any, keyField: string) {
562
- const { createKeyMethod } = rowOpts
563
- if (createKeyMethod) {
564
- return '' + createKeyMethod({ row, keyField })
565
- }
566
- return getRowUniqueId()
567
- }
568
-
569
- export function hasDeepKey (rowKey: string) {
570
- return rowKey.indexOf('.') > -1
571
- }
572
-
573
- // 行主键 key
574
- export function getRowkey ($xeTable: VxeTableConstructor) {
575
- const internalData = $xeTable as unknown as TableInternalData
576
- const { currKeyField } = internalData
577
- return currKeyField
578
- }
579
-
580
- // 行主键 value
581
- export function getRowid ($xeTable: VxeTableConstructor, row: any) {
582
- const internalData = $xeTable as unknown as TableInternalData
583
- const { isCurrDeepKey, currKeyField } = internalData
584
- return row ? encodeRowid((isCurrDeepKey ? getDeepRowIdByKey : getFastRowIdByKey)(row, currKeyField)) : ''
585
- }
586
-
587
- export function createHandleUpdateRowId ($xeTable: VxeTableConstructor) {
588
- const internalData = $xeTable as unknown as TableInternalData
589
- const { isCurrDeepKey, currKeyField } = internalData
590
- const rowOpts = $xeTable.computeRowOpts
591
- const updateRId = isCurrDeepKey ? updateDeepRowKey : updateFastRowKey
592
- return {
593
- rowKey: currKeyField,
594
- handleUpdateRowId (row: any) {
595
- return row ? updateRId(rowOpts, row, currKeyField) : ''
596
- }
597
- }
598
- }
599
-
600
- export function createHandleGetRowId ($xeTable: VxeTableConstructor) {
601
- const internalData = $xeTable as unknown as TableInternalData
602
- const { isCurrDeepKey, currKeyField } = internalData
603
- const getRId = isCurrDeepKey ? getDeepRowIdByKey : getFastRowIdByKey
604
- return {
605
- rowKey: currKeyField,
606
- handleGetRowId (row: any) {
607
- return row ? encodeRowid(getRId(row, currKeyField)) : ''
608
- }
609
- }
610
- }
611
-
612
- // 编码行主键
613
- export function encodeRowid (rowVal: string) {
614
- return XEUtils.eqNull(rowVal) ? '' : encodeURIComponent(rowVal)
615
- }
616
-
617
- function getDeepRowIdByKey (row: any, rowKey: string) {
618
- return XEUtils.get(row, rowKey)
619
- }
620
-
621
- function updateDeepRowKey (rowOpts: VxeTablePropTypes.RowConfig, row: any, rowKey: string) {
622
- let rowid = encodeRowid(getDeepRowIdByKey(row, rowKey))
623
- if (eqEmptyValue(rowid)) {
624
- const newRowid = createRowId(rowOpts, row, rowKey)
625
- rowid = '' + newRowid
626
- XEUtils.set(row, rowKey, rowid)
627
- }
628
- return rowid
629
- }
630
-
631
- function getFastRowIdByKey (row: any, rowKey: string) {
632
- return row[rowKey]
633
- }
634
-
635
- function updateFastRowKey (rowOpts: VxeTablePropTypes.RowConfig, row: any, rowKey: string) {
636
- let rowid = encodeRowid(getFastRowIdByKey(row, rowKey))
637
- if (eqEmptyValue(rowid)) {
638
- const newRowid = createRowId(rowOpts, row, rowKey)
639
- rowid = '' + newRowid
640
- row[rowKey] = newRowid
641
- }
642
- return rowid
643
- }
644
-
645
- function getPaddingLeftRightSize (elem: HTMLElement | null) {
646
- if (elem) {
647
- const computedStyle = getComputedStyle(elem)
648
- const paddingLeft = XEUtils.toNumber(computedStyle.paddingLeft)
649
- const paddingRight = XEUtils.toNumber(computedStyle.paddingRight)
650
- return paddingLeft + paddingRight
651
- }
652
- return 0
653
- }
654
-
655
- function getElementMarginAndWidth (elem: HTMLElement | null) {
656
- if (elem) {
657
- const computedStyle = getComputedStyle(elem)
658
- const marginLeft = XEUtils.toNumber(computedStyle.marginLeft)
659
- const marginRight = XEUtils.toNumber(computedStyle.marginRight)
660
- return elem.offsetWidth + marginLeft + marginRight
661
- }
662
- return 0
663
- }
664
-
665
- export function getCalcHeight (height: number | 'unset' | undefined | null) {
666
- if (height === 'unset') {
667
- return 0
668
- }
669
- return height || 0
670
- }
671
-
672
- export function handleFieldOrColumn ($xeTable: VxeTableConstructor, fieldOrColumn: any) {
673
- if (fieldOrColumn) {
674
- return XEUtils.isString(fieldOrColumn) || XEUtils.isNumber(fieldOrColumn) ? $xeTable.getColumnByField(`${fieldOrColumn}`) : fieldOrColumn
675
- }
676
- return null
677
- }
678
-
679
- export function handleRowidOrRow ($xeTable: VxeTableConstructor, rowidOrRow: any) {
680
- if (rowidOrRow) {
681
- const rowid = XEUtils.isString(rowidOrRow) || XEUtils.isNumber(rowidOrRow) ? rowidOrRow : getRowid($xeTable, rowidOrRow)
682
- return $xeTable.getRowById(rowid)
683
- }
684
- return null
685
- }
686
-
687
- export function getCellRestHeight (rowRest: VxeTableDefines.RowCacheItem, cellOpts: VxeTablePropTypes.CellConfig, rowOpts: VxeTablePropTypes.RowConfig, defaultRowHeight: number) {
688
- return rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
689
- }
690
-
691
- // 组装列配置
692
- export function assembleColumn (_vm: any) {
693
- const $xeTable = _vm.$xeTable as VxeTableConstructor & VxeTablePrivateMethods
694
- const reactData = $xeTable as unknown as TableReactData
695
- const { staticColumns } = reactData
696
-
697
- const { $el, $xeColumn, columnConfig } = _vm
698
- const groupConfig = $xeColumn ? $xeColumn.columnConfig : null
699
- if (groupConfig) {
700
- if ($xeColumn.$options._componentTag === 'vxe-table-column') {
701
- errLog('vxe.error.groupTag', [`<vxe-table-colgroup title=${$xeColumn.title} ...>`, `<vxe-table-column title=${$xeColumn.title} ...>`])
702
- } else if ($xeColumn.$options._componentTag === 'vxe-column') {
703
- warnLog('vxe.error.groupTag', [`<vxe-colgroup title=${$xeColumn.title} ...>`, `<vxe-column title=${$xeColumn.title} ...>`])
704
- }
705
- if (!groupConfig.children) {
706
- groupConfig.children = []
707
- }
708
- columnConfig.defaultParentId = groupConfig.id
709
- groupConfig.children.splice(XEUtils.arrayIndexOf($xeColumn.$el.children, $el), 0, columnConfig)
710
- } else {
711
- staticColumns.splice(XEUtils.arrayIndexOf(($xeTable.$refs.hideColumn as any).children, $el), 0, columnConfig)
712
- }
713
- }
714
-
715
- // 销毁列
716
- export function destroyColumn (_vm: any) {
717
- const $xeTable = _vm.$xeTable as VxeTableConstructor & VxeTablePrivateMethods
718
- const reactData = $xeTable as unknown as TableReactData
719
- const { staticColumns } = reactData
720
-
721
- const { columnConfig } = _vm
722
- const matchObj = XEUtils.findTree(staticColumns, column => column === columnConfig)
723
- if (matchObj) {
724
- matchObj.items.splice(matchObj.index, 1)
725
- }
726
- }
727
-
728
- export function getRootColumn ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, column: any) {
729
- const internalData = $xeTable as unknown as TableInternalData
730
-
731
- const { fullColumnIdData } = internalData
732
- if (!column) {
733
- return null
734
- }
735
- let parentColId = column.parentId
736
- while (fullColumnIdData[parentColId]) {
737
- const column = fullColumnIdData[parentColId].column
738
- parentColId = column.parentId
739
- if (!parentColId) {
740
- return column
741
- }
742
- }
743
- return column
744
- }
745
-
746
- export function toFilters (filters: any, colid?: string) {
747
- if (filters) {
748
- if (XEUtils.isArray(filters)) {
749
- return filters.map(({ label, value, data, resetValue, checked }) => {
750
- return { label, value, data, resetValue, checked: !!checked, _checked: !!checked, _colId: colid }
751
- })
752
- }
753
- return []
754
- }
755
- return filters
756
- }
757
-
758
- export function getColReMinWidth (params: any) {
759
- const { $table, column, cell } = params
760
- const internalData = $table
761
- const { showHeaderOverflow: allColumnHeaderOverflow, resizableOpts } = $table
762
- const { minWidth } = resizableOpts
763
- // 如果自定义调整宽度逻辑
764
- if (minWidth) {
765
- const customMinWidth = XEUtils.isFunction(minWidth) ? minWidth(params) : minWidth
766
- if (customMinWidth !== 'auto') {
767
- return Math.max(1, XEUtils.toNumber(customMinWidth))
768
- }
769
- }
770
- const { elemStore } = internalData
771
- const { showHeaderOverflow, minWidth: colMinWidth } = column
772
- const headOverflow = XEUtils.isUndefined(showHeaderOverflow) || XEUtils.isNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
773
- const showEllipsis = headOverflow === 'ellipsis'
774
- const showTitle = headOverflow === 'title'
775
- const showTooltip = headOverflow === true || headOverflow === 'tooltip'
776
- const hasEllipsis = showTitle || showTooltip || showEllipsis
777
- const minTitleWidth = XEUtils.floor((XEUtils.toNumber(getComputedStyle(cell).fontSize) || 14) * 1.8)
778
- const paddingLeftRight = getPaddingLeftRightSize(cell) + getPaddingLeftRightSize(queryElement(cell, '.vxe-cell'))
779
- let mWidth = minTitleWidth + paddingLeftRight
780
- // 默认最小宽处理
781
- if (hasEllipsis) {
782
- const dragIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--drag-handle'))
783
- const checkboxIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--checkbox'))
784
- const requiredIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--required-icon'))
785
- const editIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--edit-icon'))
786
- const prefixIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell-title-prefix-icon'))
787
- const suffixIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell-title-suffix-icon'))
788
- const sortIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--sort'))
789
- const filterIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--filter'))
790
- mWidth += dragIconWidth + checkboxIconWidth + requiredIconWidth + editIconWidth + prefixIconWidth + suffixIconWidth + filterIconWidth + sortIconWidth
791
- }
792
- // 如果设置最小宽
793
- if (colMinWidth) {
794
- const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
795
- if (bodyScrollElem) {
796
- if (isScale(colMinWidth)) {
797
- const bodyWidth = bodyScrollElem.clientWidth - 1
798
- const meanWidth = bodyWidth / 100
799
- return Math.max(mWidth, Math.floor(XEUtils.toInteger(colMinWidth) * meanWidth))
800
- } else if (isPx(colMinWidth)) {
801
- return Math.max(mWidth, XEUtils.toInteger(colMinWidth))
802
- }
803
- }
804
- }
805
- return mWidth
806
- }
807
-
808
- export function getFirstChildColumn (column: VxeTableDefines.ColumnInfo): VxeTableDefines.ColumnInfo {
809
- const { children } = column
810
- if (children && children.length) {
811
- return getFirstChildColumn(XEUtils.first(children))
812
- }
813
- return column
814
- }
815
-
816
- export function getLastChildColumn (column: VxeTableDefines.ColumnInfo): VxeTableDefines.ColumnInfo {
817
- const { children } = column
818
- if (children && children.length) {
819
- return getFirstChildColumn(XEUtils.last(children))
820
- }
821
- return column
822
- }
823
-
824
- export function getCellValue (row: any, column: any) {
825
- return XEUtils.get(row, column.field)
826
- }
827
-
828
- export function setCellValue (row: any, column:any, value: any) {
829
- return XEUtils.set(row, column.field, value)
830
- }
831
-
832
- export function getRefElem (refEl: any) {
833
- if (refEl) {
834
- return (refEl.$el || refEl) as HTMLElement
835
- }
836
- return null
837
- }
838
-
839
- export function clearTableDefaultStatus ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) {
840
- const props = $xeTable
841
- const internalData = $xeTable as unknown as TableInternalData
842
-
843
- internalData.initStatus = false
844
- const actionList = [
845
- $xeTable.clearSort(),
846
- $xeTable.clearCurrentRow(),
847
- $xeTable.clearCurrentColumn(),
848
- $xeTable.clearRadioRow(),
849
- $xeTable.clearRadioReserve(),
850
- $xeTable.clearCheckboxRow(),
851
- $xeTable.clearCheckboxReserve(),
852
- $xeTable.clearRowExpand(),
853
- $xeTable.clearTreeExpand(),
854
- $xeTable.clearTreeExpandReserve(),
855
- $xeTable.clearPendingRow()
856
- ]
857
- if ($xeTable.clearFilter) {
858
- actionList.push(
859
- $xeTable.clearFilter()
860
- )
861
- }
862
- if ($xeTable.clearSelected && (props.keyboardConfig || props.mouseConfig)) {
863
- actionList.push(
864
- $xeTable.clearSelected()
865
- )
866
- }
867
- if ($xeTable.clearCellAreas && props.mouseConfig) {
868
- actionList.push(
869
- $xeTable.clearCellAreas(),
870
- $xeTable.clearCopyCellArea()
871
- )
872
- }
873
- return Promise.all(actionList).then(() => {
874
- return $xeTable.clearScroll()
875
- })
876
- }
877
-
878
- export function clearTableAllStatus (_vm: any) {
879
- if (_vm.clearFilter) {
880
- _vm.clearFilter()
881
- }
882
- return clearTableDefaultStatus(_vm)
883
- }
884
-
885
- export function isColumnInfo (column: any) {
886
- return column instanceof ColumnInfo
887
- }
888
-
889
- // 获取所有的列,排除分组
890
- export function getColumnList (columns: VxeTableDefines.ColumnInfo[]) {
891
- const result: VxeTableDefines.ColumnInfo[] = []
892
- columns.forEach((column) => {
893
- result.push(...(column.children && column.children.length ? getColumnList(column.children) : [column]))
894
- })
895
- return result
896
- }
897
-
898
- export function createColumn ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, options: any, renderOptions: any): any {
899
- return isColumnInfo(options) ? options : new ColumnInfo($xeTable, options, renderOptions)
900
- }
901
-
902
- export function rowToVisible ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, row: any) {
903
- const tableProps = $xeTable
904
- const reactData = $xeTable as unknown as TableReactData
905
- const internalData = $xeTable as unknown as TableInternalData
906
-
907
- const { showOverflow } = tableProps
908
- const { scrollYLoad, scrollYTop } = reactData
909
- const { elemStore, afterFullData, fullAllDataRowIdData, isResizeCellHeight } = internalData
910
- const rowOpts = $xeTable.computeRowOpts
911
- const cellOpts = $xeTable.computeCellOpts
912
- const defaultRowHeight = $xeTable.computeDefaultRowHeight
913
- const leftFixedWidth = $xeTable.computeLeftFixedWidth
914
- const rightFixedWidth = $xeTable.computeRightFixedWidth
915
- const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
916
- const rowid = getRowid($xeTable, row)
917
- if (bodyScrollElem) {
918
- const bodyHeight = bodyScrollElem.clientHeight
919
- const bodyScrollTop = bodyScrollElem.scrollTop
920
- const trElem: HTMLTableRowElement | null = bodyScrollElem.querySelector(`[rowid="${rowid}"]`)
921
- if (trElem) {
922
- const trOffsetTop = trElem.offsetTop + (scrollYLoad ? scrollYTop : 0)
923
- const trHeight = trElem.clientHeight
924
- // 检测行是否在可视区中
925
- if (trOffsetTop < bodyScrollTop || trOffsetTop > bodyScrollTop + bodyHeight) {
926
- return $xeTable.scrollTo(null, trOffsetTop)
927
- } else if (trOffsetTop + trHeight >= bodyHeight + bodyScrollTop) {
928
- return $xeTable.scrollTo(null, bodyScrollTop + trHeight)
929
- }
930
- } else {
931
- // 如果是虚拟渲染滚动
932
- if (scrollYLoad) {
933
- const isCustomCellHeight = isResizeCellHeight || cellOpts.height || rowOpts.height
934
- if (!isCustomCellHeight && showOverflow) {
935
- return $xeTable.scrollTo(null, ($xeTable.findRowIndexOf(afterFullData, row) - 1) * defaultRowHeight)
936
- }
937
- const rowRest = fullAllDataRowIdData[rowid] || {}
938
- const rHeight = rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
939
- const scrollTop = rowRest.oTop
940
- if (scrollTop < bodyScrollTop) {
941
- return $xeTable.scrollTo(null, scrollTop - leftFixedWidth - 1)
942
- }
943
- return $xeTable.scrollTo(null, (scrollTop + rHeight) - (bodyHeight - rightFixedWidth - 1))
944
- }
945
- }
946
- }
947
- return Promise.resolve()
948
- }
949
-
950
- export function colToVisible ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, isForce: boolean, column: VxeTableDefines.ColumnInfo, row?: any) {
951
- const reactData = $xeTable as unknown as TableReactData
952
- const internalData = $xeTable as unknown as TableInternalData
953
-
954
- const { scrollXLoad, scrollXLeft } = reactData
955
- const { elemStore, visibleColumn } = internalData
956
- const leftFixedWidth = $xeTable.computeLeftFixedWidth
957
- const rightFixedWidth = $xeTable.computeRightFixedWidth
958
- const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
959
- if (column.fixed) {
960
- return Promise.resolve()
961
- }
962
- if (bodyScrollElem) {
963
- const bodyWidth = bodyScrollElem.clientWidth
964
- const bodyScrollLeft = bodyScrollElem.scrollLeft
965
- let tdElem: HTMLTableCellElement | null = null
966
- if (row) {
967
- const rowid = getRowid($xeTable, row)
968
- tdElem = bodyScrollElem.querySelector(`[rowid="${rowid}"] .${column.id}`)
969
- }
970
- if (!tdElem) {
971
- tdElem = bodyScrollElem.querySelector(`.${column.id}`)
972
- }
973
- if (tdElem) {
974
- const tdOffsetLeft = tdElem.offsetLeft + (scrollXLoad ? scrollXLeft : 0)
975
- const cellWidth = tdElem.clientWidth
976
- // 检测是否在可视区中
977
- if (isForce || (
978
- !(tdOffsetLeft <= (bodyScrollLeft + leftFixedWidth) && (tdOffsetLeft + cellWidth) > (bodyScrollLeft + leftFixedWidth)) &&
979
- !(tdOffsetLeft >= (bodyScrollLeft + leftFixedWidth) && tdOffsetLeft < (bodyScrollLeft + bodyWidth - rightFixedWidth))
980
- )) {
981
- if (tdOffsetLeft < (bodyScrollLeft + leftFixedWidth)) {
982
- return $xeTable.scrollTo(tdOffsetLeft - leftFixedWidth - 1)
983
- } else if ((tdOffsetLeft + cellWidth - bodyScrollLeft) > (bodyWidth - rightFixedWidth)) {
984
- return $xeTable.scrollTo((tdOffsetLeft + cellWidth) - (bodyWidth - rightFixedWidth - 1))
985
- }
986
- }
987
- } else {
988
- if (scrollXLoad) {
989
- let tdOffsetLeft = 0
990
- const cellWidth = column.renderWidth
991
- for (let i = 0; i < visibleColumn.length; i++) {
992
- const currCol = visibleColumn[i]
993
- if (currCol === column || currCol.id === column.id) {
994
- break
995
- }
996
- tdOffsetLeft += currCol.renderWidth
997
- }
998
- // 检测是否在可视区中
999
- if (isForce || (
1000
- !(tdOffsetLeft <= (bodyScrollLeft + leftFixedWidth) && (tdOffsetLeft + cellWidth) > (bodyScrollLeft + leftFixedWidth)) &&
1001
- !(tdOffsetLeft >= (bodyScrollLeft + leftFixedWidth) && tdOffsetLeft < (bodyScrollLeft + bodyWidth - rightFixedWidth))
1002
- )) {
1003
- if (tdOffsetLeft < bodyScrollLeft) {
1004
- return $xeTable.scrollTo(tdOffsetLeft - leftFixedWidth - 1)
1005
- }
1006
- return $xeTable.scrollTo((tdOffsetLeft + cellWidth) - (bodyWidth - rightFixedWidth - 1))
1007
- }
1008
- }
1009
- }
1010
- }
1011
- return Promise.resolve()
1012
- }
1
+ import XEUtils from 'xe-utils'
2
+ import { ColumnInfo } from './columnInfo'
3
+ import { isScale, isPx, queryElement } from '../../ui/src/dom'
4
+ import { warnLog, errLog } from '../../ui/src/log'
5
+ import { eqEmptyValue } from '../../ui/src/utils'
6
+
7
+ import type { VxeTableDefines, VxeTableConstructor, TableReactData, TableInternalData, VxeTablePrivateMethods, VxeTablePropTypes } from '../../../types'
8
+
9
+ export function createInternalData (): TableInternalData {
10
+ return {
11
+ tZindex: 0,
12
+ currKeyField: '',
13
+ isCurrDeepKey: false,
14
+ elemStore: {},
15
+ // 存放横向 X 虚拟滚动相关的信息
16
+ scrollXStore: {
17
+ preloadSize: 0,
18
+ offsetSize: 0,
19
+ visibleSize: 0,
20
+ visibleStartIndex: 0,
21
+ visibleEndIndex: 0,
22
+ startIndex: 0,
23
+ endIndex: 0
24
+ },
25
+ // 存放纵向 Y 虚拟滚动相关信息
26
+ scrollYStore: {
27
+ preloadSize: 0,
28
+ offsetSize: 0,
29
+ visibleSize: 0,
30
+ visibleStartIndex: 0,
31
+ visibleEndIndex: 0,
32
+ startIndex: 0,
33
+ endIndex: 0
34
+ },
35
+ // 表格宽度
36
+ tableWidth: 0,
37
+ // 表格高度
38
+ tableHeight: 0,
39
+ customHeight: 0,
40
+ customMinHeight: 0,
41
+ customMaxHeight: 0,
42
+ // 当前 hover 行
43
+ hoverRow: null,
44
+ // 最后滚动位置
45
+ lastScrollLeft: 0,
46
+ lastScrollTop: 0,
47
+ // 单选框属性,已选中保留的行
48
+ radioReserveRow: null,
49
+ // 复选框属性,已选中保留的行集合
50
+ checkboxReserveRowMap: {},
51
+ // 行数据,已展开保留的行集合
52
+ rowExpandedReserveRowMap: {},
53
+ // 树结构数据,已展开保留的行集合
54
+ treeExpandedReserveRowMap: {},
55
+ // 树结构数据,不确定状态的集合
56
+ treeIndeterminateRowMaps: {},
57
+ // 列表完整数据、条件处理后
58
+ tableFullData: [],
59
+ afterFullData: [],
60
+ afterTreeFullData: [],
61
+ afterGroupFullData: [],
62
+ // 列表条件处理后数据集合
63
+ afterFullRowMaps: {},
64
+ // 树结构完整数据、条件处理后
65
+ tableFullTreeData: [],
66
+ // 行分组全量数据、条件处理后
67
+ tableFullGroupData: [],
68
+ tableSynchData: [],
69
+ tableSourceData: [],
70
+ // 收集的列配置(带分组)
71
+ collectColumn: [],
72
+ // 完整所有列(不带分组)
73
+ tableFullColumn: [],
74
+ // 渲染所有列
75
+ visibleColumn: [],
76
+
77
+ // 全量数据集(包括当前和已删除)
78
+ fullAllDataRowIdData: {},
79
+ // 数据集(仅当前)
80
+ fullDataRowIdData: {},
81
+ // 数据集(仅可视)
82
+ visibleDataRowIdData: {},
83
+
84
+ keepUpdateFieldMaps: {},
85
+
86
+ footerFullDataRowData: {},
87
+
88
+ // 渲染中缓存数据
89
+ sourceDataRowIdData: {},
90
+ fullColumnIdData: {},
91
+ fullColumnFieldData: {},
92
+
93
+ // 合并表头单元格的数据
94
+ mergeHeaderList: [],
95
+ mergeHeaderMaps: {},
96
+ // 已合并单元格数据集合
97
+ mergeHeaderCellMaps: {},
98
+ // 合并单元格的数据
99
+ mergeBodyList: [],
100
+ mergeBodyMaps: {},
101
+ // 已合并单元格数据集合
102
+ mergeBodyCellMaps: {},
103
+ // 合并表尾的数据
104
+ mergeFooterList: [],
105
+ mergeFooterMaps: {},
106
+ // 已合并表尾数据集合
107
+ mergeFooterCellMaps: {},
108
+
109
+ // 已展开的行集合
110
+ rowExpandedMaps: {},
111
+ // 懒加载中的展开行的集合
112
+ rowExpandLazyLoadedMaps: {},
113
+ // 已展开的分组行
114
+ rowGroupExpandedMaps: {},
115
+ // 已展开树节点集合
116
+ treeExpandedMaps: {},
117
+ // 懒加载中的树节点的集合
118
+ treeExpandLazyLoadedMaps: {},
119
+ // 复选框属性,已选中的行集合
120
+ selectCheckboxMaps: {},
121
+ // 已标记的对象集
122
+ pendingRowMaps: {},
123
+ // 已新增的临时行
124
+ insertRowMaps: {},
125
+ // 已删除行
126
+ removeRowMaps: {},
127
+
128
+ cvCacheMaps: {},
129
+
130
+ // 表头高度
131
+ tHeaderHeight: 0,
132
+ // 表体高度
133
+ tBodyHeight: 0,
134
+ // 表尾高度
135
+ tFooterHeight: 0,
136
+
137
+ teleportToWrapperElem: null,
138
+ popupToWrapperElem: null,
139
+
140
+ lastSTime: 0,
141
+
142
+ inited: false,
143
+ tooltipTimeout: null,
144
+ initStatus: false,
145
+ isActivated: false
146
+
147
+ // _sToTime: null
148
+ }
149
+ }
150
+
151
+ export function createReactData (): TableReactData {
152
+ return {
153
+ updateColFlag: 0,
154
+ // 低性能的静态列
155
+ staticColumns: [],
156
+ // 渲染的列分组
157
+ tableGroupColumn: [],
158
+ // 可视区渲染的列
159
+ tableColumn: [],
160
+ // 渲染中的数据
161
+ tableData: [],
162
+ // 是否启用了横向 X 可视渲染方式加载
163
+ scrollXLoad: false,
164
+ // 是否启用了纵向 Y 可视渲染方式加载
165
+ scrollYLoad: false,
166
+ // 是否存在纵向滚动条
167
+ overflowY: true,
168
+ // 是否存在横向滚动条
169
+ overflowX: false,
170
+ // 纵向滚动条的宽度
171
+ scrollbarWidth: 0,
172
+ // 横向滚动条的高度
173
+ scrollbarHeight: 0,
174
+ // 行高
175
+ rowHeight: 0,
176
+ // 表格父容器的高度
177
+ parentHeight: 0,
178
+ // 是否使用分组表头
179
+ isGroup: false,
180
+ isAllOverflow: false,
181
+ // 复选框属性,是否全选
182
+ isAllSelected: false,
183
+ // 复选框属性,有选中且非全选状态
184
+ isIndeterminate: false,
185
+ // 当前行
186
+ currentRow: null,
187
+ // 单选框属性,选中列
188
+ currentColumn: null,
189
+ // 单选框属性,选中行
190
+ selectRadioRow: null,
191
+ // 表尾合计数据
192
+ footerTableData: [],
193
+ // 行分组列信息
194
+ rowGroupColumn: null,
195
+ // 展开列信息
196
+ expandColumn: null,
197
+ checkboxColumn: null,
198
+ radioColumn: null,
199
+ // 树节点列信息
200
+ treeNodeColumn: null,
201
+ hasFixedColumn: false,
202
+ // 刷新列标识,当列筛选被改变时,触发表格刷新数据
203
+ upDataFlag: 0,
204
+ // 刷新列标识,当列的特定属性被改变时,触发表格刷新列
205
+ reColumnFlag: 0,
206
+ // 初始化标识
207
+ initStore: {
208
+ filter: false,
209
+ import: false,
210
+ export: false,
211
+ custom: false
212
+ },
213
+ // 自定义列相关的信息
214
+ customStore: {
215
+ btnEl: null,
216
+ isAll: false,
217
+ isIndeterminate: false,
218
+ activeBtn: false,
219
+ activeWrapper: false,
220
+ visible: false,
221
+ maxHeight: null,
222
+ popupTop: 0,
223
+ oldSortMaps: {},
224
+ oldFixedMaps: {},
225
+ oldVisibleMaps: {}
226
+ },
227
+ customColumnList: [],
228
+ // 当前选中的筛选列
229
+ filterStore: {
230
+ isAllSelected: false,
231
+ isIndeterminate: false,
232
+ style: null,
233
+ column: null,
234
+ visible: false,
235
+ maxHeight: null
236
+ },
237
+ // 存放列相关的信息
238
+ columnStore: {
239
+ leftList: [],
240
+ centerList: [],
241
+ rightList: [],
242
+ resizeList: [],
243
+ pxList: [],
244
+ pxMinList: [],
245
+ autoMinList: [],
246
+ scaleList: [],
247
+ scaleMinList: [],
248
+ autoList: [],
249
+ remainList: []
250
+ },
251
+ // 存放快捷菜单的信息
252
+ ctxMenuStore: {
253
+ selected: null,
254
+ visible: false,
255
+ showChild: false,
256
+ selectChild: null,
257
+ list: [],
258
+ style: null
259
+ },
260
+ // 存放可编辑相关信息
261
+ editStore: {
262
+ indexs: {
263
+ columns: []
264
+ },
265
+ titles: {
266
+ columns: []
267
+ },
268
+ // 选中源
269
+ selected: {
270
+ row: null,
271
+ column: null
272
+ },
273
+ // 已复制源
274
+ copyed: {
275
+ cut: false,
276
+ rows: [],
277
+ columns: []
278
+ },
279
+ // 激活
280
+ actived: {
281
+ row: null,
282
+ column: null
283
+ },
284
+ // 当前被强制聚焦单元格,只会在鼠标点击后算聚焦
285
+ focused: {
286
+ row: null,
287
+ column: null
288
+ }
289
+ },
290
+ // 存放 tooltip 相关信息
291
+ tooltipStore: {
292
+ row: null,
293
+ column: null,
294
+ content: null,
295
+ visible: false,
296
+ type: null,
297
+ currOpts: {}
298
+ },
299
+ // 存放数据校验相关信息
300
+ validStore: {
301
+ visible: false
302
+ },
303
+ validErrorMaps: {},
304
+ // 导入相关信息
305
+ importStore: {
306
+ inited: false,
307
+ file: null,
308
+ type: '',
309
+ modeList: [],
310
+ typeList: [],
311
+ filename: '',
312
+ visible: false
313
+ },
314
+ importParams: {
315
+ mode: '',
316
+ types: null,
317
+ message: true
318
+ },
319
+ // 导出相关信息
320
+ exportStore: {
321
+ inited: false,
322
+ name: '',
323
+ modeList: [],
324
+ typeList: [],
325
+ columns: [],
326
+ isPrint: false,
327
+ hasFooter: false,
328
+ hasMerge: false,
329
+ hasTree: false,
330
+ hasColgroup: false,
331
+ visible: false
332
+ },
333
+ exportParams: {
334
+ filename: '',
335
+ sheetName: '',
336
+ mode: '',
337
+ type: '',
338
+ isColgroup: false,
339
+ isMerge: false,
340
+ isAllExpand: false,
341
+ useStyle: false,
342
+ original: false,
343
+ message: true,
344
+ isHeader: false,
345
+ isTitle: false,
346
+ isFooter: false
347
+ },
348
+
349
+ visiblwRowsFlag: 1,
350
+
351
+ isRowGroupStatus: false,
352
+ rowGroupList: [],
353
+ aggHandleFields: [],
354
+ aggHandleAggColumns: [],
355
+
356
+ rowGroupExpandedFlag: 1,
357
+ rowExpandedFlag: 1,
358
+ treeExpandedFlag: 1,
359
+ updateCheckboxFlag: 1,
360
+ pendingRowFlag: 1,
361
+ insertRowFlag: 1,
362
+ removeRowFlag: 1,
363
+
364
+ mergeHeadFlag: 1,
365
+ mergeBodyFlag: 1,
366
+ mergeFootFlag: 1,
367
+
368
+ rowHeightStore: {
369
+ large: 52,
370
+ default: 48,
371
+ medium: 44,
372
+ small: 40,
373
+ mini: 36
374
+ },
375
+
376
+ scrollVMLoading: false,
377
+ scrollYHeight: 0,
378
+ scrollYTop: 0,
379
+ isScrollYBig: false,
380
+ scrollXLeft: 0,
381
+ scrollXWidth: 0,
382
+ isScrollXBig: false,
383
+
384
+ lazScrollLoading: false,
385
+
386
+ rowExpandHeightFlag: 1,
387
+ calcCellHeightFlag: 1,
388
+ resizeHeightFlag: 1,
389
+ resizeWidthFlag: 1,
390
+
391
+ isCustomStatus: false,
392
+
393
+ isCrossDragRow: false,
394
+ dragRow: null,
395
+ isCrossDragCol: false,
396
+ dragCol: null,
397
+ dragTipText: '',
398
+
399
+ isDragResize: false,
400
+ isRowLoading: false,
401
+ isColLoading: false
402
+ }
403
+ }
404
+
405
+ const getAllConvertColumns = (columns: any, parentColumn?: any) => {
406
+ const result: any[] = []
407
+ columns.forEach((column: any) => {
408
+ column.parentId = parentColumn ? parentColumn.id : null
409
+ if (column.visible) {
410
+ if (column.children && column.children.length && column.children.some((column: any) => column.visible)) {
411
+ result.push(column)
412
+ result.push(...getAllConvertColumns(column.children, column))
413
+ } else {
414
+ result.push(column)
415
+ }
416
+ }
417
+ })
418
+ return result
419
+ }
420
+
421
+ export const convertHeaderColumnToRows = (originColumns: any) => {
422
+ let maxLevel = 1
423
+ const traverse = (column: any, parent?: any) => {
424
+ if (parent) {
425
+ column.level = parent.level + 1
426
+ if (maxLevel < column.level) {
427
+ maxLevel = column.level
428
+ }
429
+ }
430
+ if (column.children && column.children.length && column.children.some((column: any) => column.visible)) {
431
+ let colSpan = 0
432
+ column.children.forEach((subColumn: any) => {
433
+ if (subColumn.visible) {
434
+ traverse(subColumn, column)
435
+ colSpan += subColumn.colSpan
436
+ }
437
+ })
438
+ column.colSpan = colSpan
439
+ } else {
440
+ column.colSpan = 1
441
+ }
442
+ }
443
+
444
+ originColumns.forEach((column: any) => {
445
+ column.level = 1
446
+ traverse(column)
447
+ })
448
+
449
+ const rows: any[] = []
450
+ for (let i = 0; i < maxLevel; i++) {
451
+ rows.push([])
452
+ }
453
+
454
+ const allColumns = getAllConvertColumns(originColumns)
455
+
456
+ allColumns.forEach((column) => {
457
+ if (column.children && column.children.length && column.children.some((column: any) => column.visible)) {
458
+ column.rowSpan = 1
459
+ } else {
460
+ column.rowSpan = maxLevel - column.level + 1
461
+ }
462
+ rows[column.level - 1].push(column)
463
+ })
464
+
465
+ return rows
466
+ }
467
+
468
+ export function convertHeaderToGridRows (spanColumns: VxeTableDefines.ColumnInfo[][]) {
469
+ const rSize = spanColumns.length
470
+ const cSize = spanColumns[0].reduce((sum, cell) => sum + cell.colSpan, 0)
471
+
472
+ const occupiedRows: boolean[][] = []
473
+ const fullRows: any[][] = []
474
+ for (let rIndex = 0; rIndex < rSize; rIndex++) {
475
+ const oCols: boolean[] = []
476
+ const dCols: string[] = []
477
+ for (let cIndex = 0; cIndex < cSize; cIndex++) {
478
+ oCols.push(false)
479
+ dCols.push('')
480
+ }
481
+ occupiedRows.push(oCols)
482
+ fullRows.push(dCols)
483
+ }
484
+
485
+ for (let rIndex = 0; rIndex < rSize; rIndex++) {
486
+ let currColIndex = 0
487
+ for (const column of spanColumns[rIndex]) {
488
+ const { colSpan, rowSpan } = column
489
+ let startColIndex = -1
490
+ for (let ccIndex = currColIndex; ccIndex <= cSize - colSpan; ccIndex++) {
491
+ let oFlag = true
492
+ for (let csIndex = 0; csIndex < colSpan; csIndex++) {
493
+ if (occupiedRows[rIndex][ccIndex + csIndex]) {
494
+ oFlag = false
495
+ break
496
+ }
497
+ }
498
+ if (oFlag) {
499
+ startColIndex = ccIndex
500
+ break
501
+ }
502
+ }
503
+ if (startColIndex === -1) {
504
+ for (let j = 0; j <= cSize - colSpan; j++) {
505
+ let oFlag = true
506
+ for (let k = 0; k < colSpan; k++) {
507
+ if (occupiedRows[rIndex][j + k]) {
508
+ oFlag = false
509
+ break
510
+ }
511
+ }
512
+ if (oFlag) {
513
+ startColIndex = j
514
+ break
515
+ }
516
+ }
517
+ if (startColIndex === -1) {
518
+ // error
519
+ break
520
+ }
521
+ }
522
+
523
+ for (let srIndex = rIndex; srIndex < rIndex + rowSpan; srIndex++) {
524
+ for (let scIndex = startColIndex; scIndex < startColIndex + colSpan; scIndex++) {
525
+ occupiedRows[srIndex][scIndex] = true
526
+ fullRows[srIndex][scIndex] = column
527
+ }
528
+ }
529
+ currColIndex = startColIndex + colSpan
530
+ }
531
+ }
532
+ return fullRows
533
+ }
534
+
535
+ export function restoreScrollLocation ($xeTable: VxeTableConstructor, scrollLeft: number, scrollTop: number) {
536
+ const internalData = $xeTable as unknown as TableInternalData
537
+
538
+ if (scrollLeft || scrollTop) {
539
+ internalData.intoRunScroll = false
540
+ internalData.inVirtualScroll = false
541
+ internalData.inWheelScroll = false
542
+ internalData.inHeaderScroll = false
543
+ internalData.inBodyScroll = false
544
+ internalData.inFooterScroll = false
545
+ internalData.scrollRenderType = ''
546
+ // 还原滚动状态
547
+ return $xeTable.scrollTo(scrollLeft, scrollTop)
548
+ }
549
+ return $xeTable.clearScroll()
550
+ }
551
+
552
+ export function toTreePathSeq (path: any) {
553
+ return path.map((num: any, i: any) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
554
+ }
555
+
556
+ export function getRowUniqueId () {
557
+ return XEUtils.uniqueId('row_')
558
+ }
559
+
560
+ /**
561
+ * 生成行的唯一主键
562
+ */
563
+ export function createRowId (rowOpts: VxeTablePropTypes.RowConfig, row: any, keyField: string) {
564
+ const { createKeyMethod } = rowOpts
565
+ if (createKeyMethod) {
566
+ return '' + createKeyMethod({ row, keyField })
567
+ }
568
+ return getRowUniqueId()
569
+ }
570
+
571
+ export function hasDeepKey (rowKey: string) {
572
+ return rowKey.indexOf('.') > -1
573
+ }
574
+
575
+ // 行主键 key
576
+ export function getRowkey ($xeTable: VxeTableConstructor) {
577
+ const internalData = $xeTable as unknown as TableInternalData
578
+ const { currKeyField } = internalData
579
+ return currKeyField
580
+ }
581
+
582
+ // 行主键 value
583
+ export function getRowid ($xeTable: VxeTableConstructor, row: any) {
584
+ const internalData = $xeTable as unknown as TableInternalData
585
+ const { isCurrDeepKey, currKeyField } = internalData
586
+ return row ? encodeRowid((isCurrDeepKey ? getDeepRowIdByKey : getFastRowIdByKey)(row, currKeyField)) : ''
587
+ }
588
+
589
+ export function createHandleUpdateRowId ($xeTable: VxeTableConstructor) {
590
+ const internalData = $xeTable as unknown as TableInternalData
591
+ const { isCurrDeepKey, currKeyField } = internalData
592
+ const rowOpts = $xeTable.computeRowOpts
593
+ const updateRId = isCurrDeepKey ? updateDeepRowKey : updateFastRowKey
594
+ return {
595
+ rowKey: currKeyField,
596
+ handleUpdateRowId (row: any) {
597
+ return row ? updateRId(rowOpts, row, currKeyField) : ''
598
+ }
599
+ }
600
+ }
601
+
602
+ export function createHandleGetRowId ($xeTable: VxeTableConstructor) {
603
+ const internalData = $xeTable as unknown as TableInternalData
604
+ const { isCurrDeepKey, currKeyField } = internalData
605
+ const getRId = isCurrDeepKey ? getDeepRowIdByKey : getFastRowIdByKey
606
+ return {
607
+ rowKey: currKeyField,
608
+ handleGetRowId (row: any) {
609
+ return row ? encodeRowid(getRId(row, currKeyField)) : ''
610
+ }
611
+ }
612
+ }
613
+
614
+ // 编码行主键
615
+ export function encodeRowid (rowVal: string) {
616
+ return XEUtils.eqNull(rowVal) ? '' : encodeURIComponent(rowVal)
617
+ }
618
+
619
+ function getDeepRowIdByKey (row: any, rowKey: string) {
620
+ return XEUtils.get(row, rowKey)
621
+ }
622
+
623
+ function updateDeepRowKey (rowOpts: VxeTablePropTypes.RowConfig, row: any, rowKey: string) {
624
+ let rowid = encodeRowid(getDeepRowIdByKey(row, rowKey))
625
+ if (eqEmptyValue(rowid)) {
626
+ const newRowid = createRowId(rowOpts, row, rowKey)
627
+ rowid = '' + newRowid
628
+ XEUtils.set(row, rowKey, rowid)
629
+ }
630
+ return rowid
631
+ }
632
+
633
+ function getFastRowIdByKey (row: any, rowKey: string) {
634
+ return row[rowKey]
635
+ }
636
+
637
+ function updateFastRowKey (rowOpts: VxeTablePropTypes.RowConfig, row: any, rowKey: string) {
638
+ let rowid = encodeRowid(getFastRowIdByKey(row, rowKey))
639
+ if (eqEmptyValue(rowid)) {
640
+ const newRowid = createRowId(rowOpts, row, rowKey)
641
+ rowid = '' + newRowid
642
+ row[rowKey] = newRowid
643
+ }
644
+ return rowid
645
+ }
646
+
647
+ function getPaddingLeftRightSize (elem: HTMLElement | null) {
648
+ if (elem) {
649
+ const computedStyle = getComputedStyle(elem)
650
+ const paddingLeft = XEUtils.toNumber(computedStyle.paddingLeft)
651
+ const paddingRight = XEUtils.toNumber(computedStyle.paddingRight)
652
+ return paddingLeft + paddingRight
653
+ }
654
+ return 0
655
+ }
656
+
657
+ function getElementMarginAndWidth (elem: HTMLElement | null) {
658
+ if (elem) {
659
+ const computedStyle = getComputedStyle(elem)
660
+ const marginLeft = XEUtils.toNumber(computedStyle.marginLeft)
661
+ const marginRight = XEUtils.toNumber(computedStyle.marginRight)
662
+ return elem.offsetWidth + marginLeft + marginRight
663
+ }
664
+ return 0
665
+ }
666
+
667
+ export function getCalcHeight (height: number | 'unset' | undefined | null) {
668
+ if (height === 'unset') {
669
+ return 0
670
+ }
671
+ return height || 0
672
+ }
673
+
674
+ export function handleFieldOrColumn ($xeTable: VxeTableConstructor, fieldOrColumn: any) {
675
+ if (fieldOrColumn) {
676
+ return XEUtils.isString(fieldOrColumn) || XEUtils.isNumber(fieldOrColumn) ? $xeTable.getColumnByField(`${fieldOrColumn}`) : fieldOrColumn
677
+ }
678
+ return null
679
+ }
680
+
681
+ export function handleRowidOrRow ($xeTable: VxeTableConstructor, rowidOrRow: any) {
682
+ if (rowidOrRow) {
683
+ const rowid = XEUtils.isString(rowidOrRow) || XEUtils.isNumber(rowidOrRow) ? rowidOrRow : getRowid($xeTable, rowidOrRow)
684
+ return $xeTable.getRowById(rowid)
685
+ }
686
+ return null
687
+ }
688
+
689
+ export function getCellRestHeight (rowRest: VxeTableDefines.RowCacheItem, cellOpts: VxeTablePropTypes.CellConfig, rowOpts: VxeTablePropTypes.RowConfig, defaultRowHeight: number) {
690
+ return rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
691
+ }
692
+
693
+ // 组装列配置
694
+ export function assembleColumn (_vm: any) {
695
+ const $xeTable = _vm.$xeTable as VxeTableConstructor & VxeTablePrivateMethods
696
+ const reactData = $xeTable as unknown as TableReactData
697
+ const { staticColumns } = reactData
698
+
699
+ const { $el, $xeColumn, columnConfig } = _vm
700
+ const groupConfig = $xeColumn ? $xeColumn.columnConfig : null
701
+ if (groupConfig) {
702
+ if ($xeColumn.$options._componentTag === 'vxe-table-column') {
703
+ errLog('vxe.error.groupTag', [`<vxe-table-colgroup title=${$xeColumn.title} ...>`, `<vxe-table-column title=${$xeColumn.title} ...>`])
704
+ } else if ($xeColumn.$options._componentTag === 'vxe-column') {
705
+ warnLog('vxe.error.groupTag', [`<vxe-colgroup title=${$xeColumn.title} ...>`, `<vxe-column title=${$xeColumn.title} ...>`])
706
+ }
707
+ if (!groupConfig.children) {
708
+ groupConfig.children = []
709
+ }
710
+ columnConfig.defaultParentId = groupConfig.id
711
+ groupConfig.children.splice(XEUtils.arrayIndexOf($xeColumn.$el.children, $el), 0, columnConfig)
712
+ } else {
713
+ staticColumns.splice(XEUtils.arrayIndexOf(($xeTable.$refs.hideColumn as any).children, $el), 0, columnConfig)
714
+ }
715
+ }
716
+
717
+ // 销毁列
718
+ export function destroyColumn (_vm: any) {
719
+ const $xeTable = _vm.$xeTable as VxeTableConstructor & VxeTablePrivateMethods
720
+ const reactData = $xeTable as unknown as TableReactData
721
+ const { staticColumns } = reactData
722
+
723
+ const { columnConfig } = _vm
724
+ const matchObj = XEUtils.findTree(staticColumns, column => column === columnConfig)
725
+ if (matchObj) {
726
+ matchObj.items.splice(matchObj.index, 1)
727
+ }
728
+ }
729
+
730
+ export function getRootColumn ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, column: any) {
731
+ const internalData = $xeTable as unknown as TableInternalData
732
+
733
+ const { fullColumnIdData } = internalData
734
+ if (!column) {
735
+ return null
736
+ }
737
+ let parentColId = column.parentId
738
+ while (fullColumnIdData[parentColId]) {
739
+ const column = fullColumnIdData[parentColId].column
740
+ parentColId = column.parentId
741
+ if (!parentColId) {
742
+ return column
743
+ }
744
+ }
745
+ return column
746
+ }
747
+
748
+ export function toFilters (filters: any, colid?: string) {
749
+ if (filters) {
750
+ if (XEUtils.isArray(filters)) {
751
+ return filters.map(({ label, value, data, resetValue, checked }) => {
752
+ return { label, value, data, resetValue, checked: !!checked, _checked: !!checked, _colId: colid }
753
+ })
754
+ }
755
+ return []
756
+ }
757
+ return filters
758
+ }
759
+
760
+ export function getColReMinWidth (params: any) {
761
+ const { $table, column, cell } = params
762
+ const internalData = $table
763
+ const { showHeaderOverflow: allColumnHeaderOverflow, resizableOpts } = $table
764
+ const { minWidth } = resizableOpts
765
+ // 如果自定义调整宽度逻辑
766
+ if (minWidth) {
767
+ const customMinWidth = XEUtils.isFunction(minWidth) ? minWidth(params) : minWidth
768
+ if (customMinWidth !== 'auto') {
769
+ return Math.max(1, XEUtils.toNumber(customMinWidth))
770
+ }
771
+ }
772
+ const { elemStore } = internalData
773
+ const { showHeaderOverflow, minWidth: colMinWidth } = column
774
+ const headOverflow = XEUtils.isUndefined(showHeaderOverflow) || XEUtils.isNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
775
+ const showEllipsis = headOverflow === 'ellipsis'
776
+ const showTitle = headOverflow === 'title'
777
+ const showTooltip = headOverflow === true || headOverflow === 'tooltip'
778
+ const hasEllipsis = showTitle || showTooltip || showEllipsis
779
+ const minTitleWidth = XEUtils.floor((XEUtils.toNumber(getComputedStyle(cell).fontSize) || 14) * 1.8)
780
+ const paddingLeftRight = getPaddingLeftRightSize(cell) + getPaddingLeftRightSize(queryElement(cell, '.vxe-cell'))
781
+ let mWidth = minTitleWidth + paddingLeftRight
782
+ // 默认最小宽处理
783
+ if (hasEllipsis) {
784
+ const dragIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--drag-handle'))
785
+ const checkboxIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--checkbox'))
786
+ const requiredIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--required-icon'))
787
+ const editIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--edit-icon'))
788
+ const prefixIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell-title-prefix-icon'))
789
+ const suffixIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell-title-suffix-icon'))
790
+ const sortIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--sort'))
791
+ const filterIconWidth = getElementMarginAndWidth(queryElement(cell, '.vxe-cell--filter'))
792
+ mWidth += dragIconWidth + checkboxIconWidth + requiredIconWidth + editIconWidth + prefixIconWidth + suffixIconWidth + filterIconWidth + sortIconWidth
793
+ }
794
+ // 如果设置最小宽
795
+ if (colMinWidth) {
796
+ const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
797
+ if (bodyScrollElem) {
798
+ if (isScale(colMinWidth)) {
799
+ const bodyWidth = bodyScrollElem.clientWidth - 1
800
+ const meanWidth = bodyWidth / 100
801
+ return Math.max(mWidth, Math.floor(XEUtils.toInteger(colMinWidth) * meanWidth))
802
+ } else if (isPx(colMinWidth)) {
803
+ return Math.max(mWidth, XEUtils.toInteger(colMinWidth))
804
+ }
805
+ }
806
+ }
807
+ return mWidth
808
+ }
809
+
810
+ export function getFirstChildColumn (column: VxeTableDefines.ColumnInfo): VxeTableDefines.ColumnInfo {
811
+ const { children } = column
812
+ if (children && children.length) {
813
+ return getFirstChildColumn(XEUtils.first(children))
814
+ }
815
+ return column
816
+ }
817
+
818
+ export function getLastChildColumn (column: VxeTableDefines.ColumnInfo): VxeTableDefines.ColumnInfo {
819
+ const { children } = column
820
+ if (children && children.length) {
821
+ return getFirstChildColumn(XEUtils.last(children))
822
+ }
823
+ return column
824
+ }
825
+
826
+ export function getCellValue (row: any, column: any) {
827
+ return XEUtils.get(row, column.field)
828
+ }
829
+
830
+ export function setCellValue (row: any, column:any, value: any) {
831
+ return XEUtils.set(row, column.field, value)
832
+ }
833
+
834
+ export function getRefElem (refEl: any) {
835
+ if (refEl) {
836
+ return (refEl.$el || refEl) as HTMLElement
837
+ }
838
+ return null
839
+ }
840
+
841
+ export function clearTableDefaultStatus ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) {
842
+ const props = $xeTable
843
+ const internalData = $xeTable as unknown as TableInternalData
844
+
845
+ internalData.initStatus = false
846
+ const actionList = [
847
+ $xeTable.clearSort(),
848
+ $xeTable.clearCurrentRow(),
849
+ $xeTable.clearCurrentColumn(),
850
+ $xeTable.clearRadioRow(),
851
+ $xeTable.clearRadioReserve(),
852
+ $xeTable.clearCheckboxRow(),
853
+ $xeTable.clearCheckboxReserve(),
854
+ $xeTable.clearRowExpand(),
855
+ $xeTable.clearTreeExpand(),
856
+ $xeTable.clearTreeExpandReserve(),
857
+ $xeTable.clearPendingRow()
858
+ ]
859
+ if ($xeTable.clearFilter) {
860
+ actionList.push(
861
+ $xeTable.clearFilter()
862
+ )
863
+ }
864
+ if ($xeTable.clearSelected && (props.keyboardConfig || props.mouseConfig)) {
865
+ actionList.push(
866
+ $xeTable.clearSelected()
867
+ )
868
+ }
869
+ if ($xeTable.clearCellAreas && props.mouseConfig) {
870
+ actionList.push(
871
+ $xeTable.clearCellAreas(),
872
+ $xeTable.clearCopyCellArea()
873
+ )
874
+ }
875
+ return Promise.all(actionList).then(() => {
876
+ return $xeTable.clearScroll()
877
+ })
878
+ }
879
+
880
+ export function clearTableAllStatus (_vm: any) {
881
+ if (_vm.clearFilter) {
882
+ _vm.clearFilter()
883
+ }
884
+ return clearTableDefaultStatus(_vm)
885
+ }
886
+
887
+ export function isColumnInfo (column: any) {
888
+ return column instanceof ColumnInfo
889
+ }
890
+
891
+ // 获取所有的列,排除分组
892
+ export function getColumnList (columns: VxeTableDefines.ColumnInfo[]) {
893
+ const result: VxeTableDefines.ColumnInfo[] = []
894
+ columns.forEach((column) => {
895
+ result.push(...(column.children && column.children.length ? getColumnList(column.children) : [column]))
896
+ })
897
+ return result
898
+ }
899
+
900
+ export function createColumn ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, options: any, renderOptions: any): any {
901
+ return isColumnInfo(options) ? options : new ColumnInfo($xeTable, options, renderOptions)
902
+ }
903
+
904
+ export function rowToVisible ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, row: any) {
905
+ const reactData = $xeTable as unknown as TableReactData
906
+ const internalData = $xeTable as unknown as TableInternalData
907
+
908
+ const { scrollYLoad, scrollYTop, isAllOverflow } = reactData
909
+ const { elemStore, afterFullData, fullAllDataRowIdData, isResizeCellHeight } = internalData
910
+ const rowOpts = $xeTable.computeRowOpts
911
+ const cellOpts = $xeTable.computeCellOpts
912
+ const defaultRowHeight = $xeTable.computeDefaultRowHeight
913
+ const leftFixedWidth = $xeTable.computeLeftFixedWidth
914
+ const rightFixedWidth = $xeTable.computeRightFixedWidth
915
+ const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
916
+ const rowid = getRowid($xeTable, row)
917
+ if (bodyScrollElem) {
918
+ const bodyHeight = bodyScrollElem.clientHeight
919
+ const bodyScrollTop = bodyScrollElem.scrollTop
920
+ const trElem: HTMLTableRowElement | null = bodyScrollElem.querySelector(`[rowid="${rowid}"]`)
921
+ if (trElem) {
922
+ const trOffsetTop = trElem.offsetTop + (scrollYLoad ? scrollYTop : 0)
923
+ const trHeight = trElem.clientHeight
924
+ // 检测行是否在可视区中
925
+ if (trOffsetTop < bodyScrollTop || trOffsetTop > bodyScrollTop + bodyHeight) {
926
+ return $xeTable.scrollTo(null, trOffsetTop)
927
+ } else if (trOffsetTop + trHeight >= bodyHeight + bodyScrollTop) {
928
+ return $xeTable.scrollTo(null, bodyScrollTop + trHeight)
929
+ }
930
+ } else {
931
+ // 如果是虚拟渲染滚动
932
+ if (scrollYLoad) {
933
+ const isCustomCellHeight = isResizeCellHeight || cellOpts.height || rowOpts.height
934
+ if (!isCustomCellHeight && isAllOverflow) {
935
+ return $xeTable.scrollTo(null, ($xeTable.findRowIndexOf(afterFullData, row) - 1) * defaultRowHeight)
936
+ }
937
+ const rowRest = fullAllDataRowIdData[rowid] || {}
938
+ const rHeight = rowRest.resizeHeight || cellOpts.height || rowOpts.height || rowRest.height || defaultRowHeight
939
+ const scrollTop = rowRest.oTop
940
+ if (scrollTop < bodyScrollTop) {
941
+ return $xeTable.scrollTo(null, scrollTop - leftFixedWidth - 1)
942
+ }
943
+ return $xeTable.scrollTo(null, (scrollTop + rHeight) - (bodyHeight - rightFixedWidth - 1))
944
+ }
945
+ }
946
+ }
947
+ return Promise.resolve()
948
+ }
949
+
950
+ export function colToVisible ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, isForce: boolean, column: VxeTableDefines.ColumnInfo, row?: any) {
951
+ const reactData = $xeTable as unknown as TableReactData
952
+ const internalData = $xeTable as unknown as TableInternalData
953
+
954
+ const { scrollXLoad, scrollXLeft } = reactData
955
+ const { elemStore, visibleColumn } = internalData
956
+ const leftFixedWidth = $xeTable.computeLeftFixedWidth
957
+ const rightFixedWidth = $xeTable.computeRightFixedWidth
958
+ const bodyScrollElem = getRefElem(elemStore['main-body-scroll'])
959
+ if (column.fixed) {
960
+ return Promise.resolve()
961
+ }
962
+ if (bodyScrollElem) {
963
+ const bodyWidth = bodyScrollElem.clientWidth
964
+ const bodyScrollLeft = bodyScrollElem.scrollLeft
965
+ let tdElem: HTMLTableCellElement | null = null
966
+ if (row) {
967
+ const rowid = getRowid($xeTable, row)
968
+ tdElem = bodyScrollElem.querySelector(`[rowid="${rowid}"] .${column.id}`)
969
+ }
970
+ if (!tdElem) {
971
+ tdElem = bodyScrollElem.querySelector(`.${column.id}`)
972
+ }
973
+ if (tdElem) {
974
+ const tdOffsetLeft = tdElem.offsetLeft + (scrollXLoad ? scrollXLeft : 0)
975
+ const cellWidth = tdElem.clientWidth
976
+ // 检测是否在可视区中
977
+ if (isForce || (
978
+ !(tdOffsetLeft <= (bodyScrollLeft + leftFixedWidth) && (tdOffsetLeft + cellWidth) > (bodyScrollLeft + leftFixedWidth)) &&
979
+ !(tdOffsetLeft >= (bodyScrollLeft + leftFixedWidth) && tdOffsetLeft < (bodyScrollLeft + bodyWidth - rightFixedWidth))
980
+ )) {
981
+ if (tdOffsetLeft < (bodyScrollLeft + leftFixedWidth)) {
982
+ return $xeTable.scrollTo(tdOffsetLeft - leftFixedWidth - 1)
983
+ } else if ((tdOffsetLeft + cellWidth - bodyScrollLeft) > (bodyWidth - rightFixedWidth)) {
984
+ return $xeTable.scrollTo((tdOffsetLeft + cellWidth) - (bodyWidth - rightFixedWidth - 1))
985
+ }
986
+ }
987
+ } else {
988
+ if (scrollXLoad) {
989
+ let tdOffsetLeft = 0
990
+ const cellWidth = column.renderWidth
991
+ for (let i = 0; i < visibleColumn.length; i++) {
992
+ const currCol = visibleColumn[i]
993
+ if (currCol === column || currCol.id === column.id) {
994
+ break
995
+ }
996
+ tdOffsetLeft += currCol.renderWidth
997
+ }
998
+ // 检测是否在可视区中
999
+ if (isForce || (
1000
+ !(tdOffsetLeft <= (bodyScrollLeft + leftFixedWidth) && (tdOffsetLeft + cellWidth) > (bodyScrollLeft + leftFixedWidth)) &&
1001
+ !(tdOffsetLeft >= (bodyScrollLeft + leftFixedWidth) && tdOffsetLeft < (bodyScrollLeft + bodyWidth - rightFixedWidth))
1002
+ )) {
1003
+ if (tdOffsetLeft < bodyScrollLeft) {
1004
+ return $xeTable.scrollTo(tdOffsetLeft - leftFixedWidth - 1)
1005
+ }
1006
+ return $xeTable.scrollTo((tdOffsetLeft + cellWidth) - (bodyWidth - rightFixedWidth - 1))
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+ return Promise.resolve()
1012
+ }