vxe-table 3.20.7 → 3.20.9

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 (144) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +106 -106
  3. package/es/index.esm.js +2 -1
  4. package/es/style.css +1 -1
  5. package/es/table/src/methods.js +81 -84
  6. package/es/table/src/table.js +20 -1
  7. package/es/table/src/util.js +6 -0
  8. package/es/table/style.css +18 -48
  9. package/es/ui/index.js +1 -1
  10. package/es/ui/src/dom.js +19 -20
  11. package/es/ui/src/log.js +1 -1
  12. package/es/vxe-table/style.css +18 -48
  13. package/lib/index.common.js +2 -1
  14. package/lib/index.umd.js +1985 -3291
  15. package/lib/index.umd.min.js +1 -1
  16. package/lib/style.css +1 -1
  17. package/lib/table/src/methods.js +17 -15
  18. package/lib/table/src/methods.min.js +1 -1
  19. package/lib/table/src/table.js +19 -1
  20. package/lib/table/src/table.min.js +1 -1
  21. package/lib/table/src/util.js +6 -0
  22. package/lib/table/src/util.min.js +1 -1
  23. package/lib/table/style/style.css +18 -48
  24. package/lib/ui/index.js +1 -1
  25. package/lib/ui/index.min.js +1 -1
  26. package/lib/ui/src/dom.js +21 -20
  27. package/lib/ui/src/dom.min.js +1 -1
  28. package/lib/ui/src/log.js +1 -1
  29. package/lib/ui/src/log.min.js +1 -1
  30. package/lib/v-x-e-table/index.js +2 -1
  31. package/lib/v-x-e-table/index.min.js +1 -1
  32. package/lib/vxe-colgroup/index.js +2 -1
  33. package/lib/vxe-colgroup/index.min.js +1 -1
  34. package/lib/vxe-column/index.js +2 -1
  35. package/lib/vxe-column/index.min.js +1 -1
  36. package/lib/vxe-grid/index.js +2 -1
  37. package/lib/vxe-grid/index.min.js +1 -1
  38. package/lib/vxe-table/index.js +2 -1
  39. package/lib/vxe-table/index.min.js +1 -1
  40. package/lib/vxe-table/style/style.css +18 -48
  41. package/lib/vxe-toolbar/index.js +2 -1
  42. package/lib/vxe-toolbar/index.min.js +1 -1
  43. package/lib/vxe-ui/index.js +2 -1
  44. package/lib/vxe-ui/index.min.js +1 -1
  45. package/lib/vxe-v-x-e-table/index.js +2 -1
  46. package/lib/vxe-v-x-e-table/index.min.js +1 -1
  47. package/package.json +93 -93
  48. package/packages/colgroup/index.ts +22 -22
  49. package/packages/column/index.ts +22 -22
  50. package/packages/components.ts +42 -42
  51. package/packages/grid/index.ts +22 -22
  52. package/packages/grid/src/grid.ts +1935 -1935
  53. package/packages/index.ts +4 -4
  54. package/packages/locale/lang/ar-EG.ts +832 -832
  55. package/packages/locale/lang/de-DE.ts +832 -832
  56. package/packages/locale/lang/en-US.ts +832 -832
  57. package/packages/locale/lang/es-ES.ts +832 -832
  58. package/packages/locale/lang/fr-FR.ts +832 -832
  59. package/packages/locale/lang/hu-HU.ts +832 -832
  60. package/packages/locale/lang/hy-AM.ts +832 -832
  61. package/packages/locale/lang/id-ID.ts +832 -832
  62. package/packages/locale/lang/it-IT.ts +832 -832
  63. package/packages/locale/lang/ja-JP.ts +832 -832
  64. package/packages/locale/lang/ko-KR.ts +832 -832
  65. package/packages/locale/lang/ms-MY.ts +832 -832
  66. package/packages/locale/lang/nb-NO.ts +832 -832
  67. package/packages/locale/lang/pt-BR.ts +832 -832
  68. package/packages/locale/lang/ru-RU.ts +832 -832
  69. package/packages/locale/lang/th-TH.ts +832 -832
  70. package/packages/locale/lang/ug-CN.ts +832 -832
  71. package/packages/locale/lang/uk-UA.ts +832 -832
  72. package/packages/locale/lang/uz-UZ.ts +832 -832
  73. package/packages/locale/lang/vi-VN.ts +832 -832
  74. package/packages/locale/lang/zh-CHT.ts +832 -832
  75. package/packages/locale/lang/zh-CN.ts +832 -832
  76. package/packages/locale/lang/zh-HK.ts +3 -3
  77. package/packages/locale/lang/zh-MO.ts +3 -3
  78. package/packages/locale/lang/zh-TC.ts +3 -3
  79. package/packages/locale/lang/zh-TW.ts +3 -3
  80. package/packages/table/index.ts +49 -49
  81. package/packages/table/module/custom/mixin.ts +369 -369
  82. package/packages/table/module/custom/panel.ts +1461 -1461
  83. package/packages/table/module/edit/mixin.ts +1123 -1123
  84. package/packages/table/module/export/export-panel.ts +658 -658
  85. package/packages/table/module/export/import-panel.ts +319 -319
  86. package/packages/table/module/export/mixin.ts +1693 -1693
  87. package/packages/table/module/export/util.ts +24 -24
  88. package/packages/table/module/filter/mixin.ts +507 -507
  89. package/packages/table/module/filter/panel.ts +329 -329
  90. package/packages/table/module/keyboard/mixin.ts +513 -513
  91. package/packages/table/module/menu/mixin.ts +329 -329
  92. package/packages/table/module/menu/panel.ts +212 -212
  93. package/packages/table/module/validator/mixin.ts +626 -626
  94. package/packages/table/render/index.ts +1456 -1456
  95. package/packages/table/src/body.ts +969 -969
  96. package/packages/table/src/cell.ts +1285 -1285
  97. package/packages/table/src/column.ts +205 -205
  98. package/packages/table/src/columnInfo.ts +228 -228
  99. package/packages/table/src/footer.ts +388 -388
  100. package/packages/table/src/group.ts +51 -51
  101. package/packages/table/src/header.ts +602 -602
  102. package/packages/table/src/methods.ts +12936 -12939
  103. package/packages/table/src/props.ts +311 -311
  104. package/packages/table/src/store.ts +15 -15
  105. package/packages/table/src/table.ts +2523 -2505
  106. package/packages/table/src/util.ts +1018 -1012
  107. package/packages/toolbar/index.ts +18 -18
  108. package/packages/toolbar/src/toolbar.ts +856 -856
  109. package/packages/ui/index.ts +530 -530
  110. package/packages/ui/src/anime.ts +52 -52
  111. package/packages/ui/src/comp.ts +3 -3
  112. package/packages/ui/src/dom.ts +237 -236
  113. package/packages/ui/src/log.ts +8 -8
  114. package/packages/ui/src/utils.ts +56 -56
  115. package/packages/ui/src/vn.ts +65 -65
  116. package/packages/v-x-e-table/index.ts +4 -4
  117. package/styles/all.scss +7 -7
  118. package/styles/base.scss +16 -16
  119. package/styles/components/grid.scss +89 -89
  120. package/styles/components/icon.scss +225 -225
  121. package/styles/components/old-icon.scss +715 -715
  122. package/styles/components/table-module/all.scss +6 -6
  123. package/styles/components/table-module/custom.scss +527 -527
  124. package/styles/components/table-module/export.scss +130 -130
  125. package/styles/components/table-module/filter.scss +130 -130
  126. package/styles/components/table-module/menu.scss +81 -81
  127. package/styles/components/table.scss +2679 -2679
  128. package/styles/components/toolbar.scss +119 -119
  129. package/styles/default.scss +2 -2
  130. package/styles/helpers/baseMixin.scss +95 -95
  131. package/styles/index.scss +3 -3
  132. package/styles/modules.scss +5 -5
  133. package/styles/theme/base.scss +93 -93
  134. package/styles/theme/dark.scss +49 -49
  135. package/styles/theme/light.scss +44 -44
  136. package/styles/variable.scss +43 -43
  137. package/types/all.d.ts +53 -53
  138. package/types/index.d.ts +4 -4
  139. /package/es/{iconfont.1773991883171.ttf → iconfont.1774420912543.ttf} +0 -0
  140. /package/es/{iconfont.1773991883171.woff → iconfont.1774420912543.woff} +0 -0
  141. /package/es/{iconfont.1773991883171.woff2 → iconfont.1774420912543.woff2} +0 -0
  142. /package/lib/{iconfont.1773991883171.ttf → iconfont.1774420912543.ttf} +0 -0
  143. /package/lib/{iconfont.1773991883171.woff → iconfont.1774420912543.woff} +0 -0
  144. /package/lib/{iconfont.1773991883171.woff2 → iconfont.1774420912543.woff2} +0 -0
@@ -1,602 +1,602 @@
1
- import { PropType, CreateElement } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import { VxeUI } from '../../ui'
4
- import { isEnableConf, getClass } from '../../ui/src/utils'
5
- import { getCalcHeight, convertHeaderColumnToRows, convertHeaderToGridRows } from './util'
6
- import { getSlotVNs } from '../../ui/src/vn'
7
-
8
- import type { VxeTableDefines, VxeTableConstructor, VxeTablePrivateMethods, VxeColumnPropTypes, TableReactData, TableInternalData, VxeComponentStyleType, VxeGlobalRendererHandles } from '../../../types'
9
-
10
- const { renderer, renderEmptyElement } = VxeUI
11
-
12
- const sourceType = 'table'
13
- const renderType = 'header'
14
-
15
- function renderRows (h: CreateElement, _vm: any, isGroup: boolean, isOptimizeMode: boolean, headerGroups: VxeTableDefines.ColumnInfo[][], $rowIndex: number, cols: VxeTableDefines.ColumnInfo[]) {
16
- const props = _vm
17
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
18
- const $xeGrid = $xeTable.$xeGrid
19
- const $xeGantt = $xeTable.$xeGantt
20
- const tableProps = $xeTable
21
- const tableReactData = $xeTable as unknown as TableReactData
22
- const tableInternalData = $xeTable as unknown as TableInternalData
23
-
24
- const { fixedType } = props
25
- const { resizable: allResizable, columnKey, showCustomHeader, headerCellClassName, headerCellStyle, showHeaderOverflow: allColumnHeaderOverflow, headerAlign: allHeaderAlign, align: allAlign, mouseConfig } = tableProps
26
- const { currentColumn, dragCol, scrollXLoad, scrollYLoad, overflowX, mergeHeadFlag, tableColumn } = tableReactData
27
- const { fullColumnIdData, scrollXStore, mergeHeaderList, mergeHeaderCellMaps } = tableInternalData
28
- const virtualXOpts = $xeTable.computeVirtualXOpts
29
- const columnOpts = $xeTable.computeColumnOpts
30
- const columnDragOpts = $xeTable.computeColumnDragOpts
31
- const cellOpts = $xeTable.computeCellOpts
32
- const defaultRowHeight = $xeTable.computeDefaultRowHeight
33
- const headerCellOpts = $xeTable.computeHeaderCellOpts
34
- const currCellHeight = getCalcHeight(headerCellOpts.height) || defaultRowHeight
35
- const { disabledMethod: dragDisabledMethod, isCrossDrag, isPeerDrag } = columnDragOpts
36
- const isLastRow = $rowIndex === headerGroups.length - 1
37
-
38
- return cols.map((column, $columnIndex) => {
39
- const { type, showHeaderOverflow, headerAlign, align, filters, headerClassName, editRender, cellRender } = column
40
- // const { enabled } = tooltipOpts
41
- const colid = column.id
42
- const colRest = fullColumnIdData[colid] || {}
43
- const renderOpts = editRender || cellRender
44
- const compConf = renderOpts ? renderer.get(renderOpts.name) : null
45
- const isColGroup = column.children && column.children.length
46
- const fixedHiddenColumn = overflowX && !isColGroup && (fixedType ? column.fixed !== fixedType : !!column.fixed)
47
- const isPadding = XEUtils.isBoolean(headerCellOpts.padding) ? headerCellOpts.padding : cellOpts.padding
48
- const headOverflow = XEUtils.isUndefined(showHeaderOverflow) || XEUtils.isNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
49
- const headAlign = headerAlign || (compConf ? compConf.tableHeaderCellAlign : '') || allHeaderAlign || align || (compConf ? compConf.tableCellAlign : '') || allAlign
50
- const showEllipsis = headOverflow === 'ellipsis'
51
- const showTitle = headOverflow === 'title'
52
- const showTooltip = headOverflow === true || headOverflow === 'tooltip'
53
- const hasEllipsis = showTitle || showTooltip || showEllipsis
54
- let hasFilter = false
55
- let firstFilterOption: VxeColumnPropTypes.FilterItem | null = null
56
- if (filters) {
57
- firstFilterOption = filters[0]
58
- hasFilter = filters.some((item: VxeColumnPropTypes.FilterItem) => item.checked)
59
- }
60
- const columnIndex = colRest.index
61
- const _columnIndex = showCustomHeader ? $columnIndex : colRest._index
62
- const cellParams: VxeTableDefines.CellRenderHeaderParams & {
63
- $table: VxeTableConstructor & VxeTablePrivateMethods
64
- } = {
65
- $table: $xeTable,
66
- $grid: $xeGrid,
67
- $gantt: $xeGantt,
68
- $rowIndex,
69
- column,
70
- columnIndex,
71
- $columnIndex,
72
- _columnIndex,
73
- firstFilterOption: firstFilterOption as VxeTableDefines.FilterOption,
74
- fixed: fixedType,
75
- source: sourceType,
76
- type: renderType,
77
- isHidden: fixedHiddenColumn,
78
- hasFilter
79
- }
80
- const thAttrs: Record<string, string | number | null> = {
81
- colid
82
- }
83
- let isMergeCell = false
84
- // 合并行或列
85
- if (!showCustomHeader) {
86
- thAttrs.colspan = column.colSpan > 1 ? column.colSpan : null
87
- thAttrs.rowspan = column.rowSpan > 1 ? column.rowSpan : null
88
- }
89
- if (mergeHeadFlag && mergeHeaderList.length && (showCustomHeader || isLastRow)) {
90
- const spanRest = mergeHeaderCellMaps[`${$rowIndex}:${showCustomHeader ? $columnIndex : _columnIndex}`]
91
- if (spanRest) {
92
- const { rowspan, colspan } = spanRest
93
- if (!rowspan || !colspan) {
94
- return null
95
- }
96
- if (rowspan > 1) {
97
- isMergeCell = true
98
- thAttrs.rowspan = rowspan
99
- }
100
- if (colspan > 1) {
101
- isMergeCell = true
102
- thAttrs.colspan = colspan
103
- }
104
- }
105
- }
106
- const thOns: any = {
107
- click: (evnt: MouseEvent) => $xeTable.triggerHeaderCellClickEvent(evnt, cellParams),
108
- dblclick: (evnt: MouseEvent) => $xeTable.triggerHeaderCellDblclickEvent(evnt, cellParams)
109
- }
110
- const isColDragCell = columnOpts.drag && columnDragOpts.trigger === 'cell'
111
- let isDisabledDrag = false
112
- if (isColDragCell) {
113
- isDisabledDrag = !!(dragDisabledMethod && dragDisabledMethod(cellParams))
114
- }
115
- // 按下事件处理
116
- if (mouseConfig || isColDragCell) {
117
- thOns.mousedown = (evnt: any) => $xeTable.triggerHeaderCellMousedownEvent(evnt, cellParams)
118
- }
119
- // 拖拽列事件
120
- if (columnOpts.drag) {
121
- thOns.dragstart = $xeTable.handleHeaderCellDragDragstartEvent
122
- thOns.dragend = $xeTable.handleHeaderCellDragDragendEvent
123
- thOns.dragover = $xeTable.handleHeaderCellDragDragoverEvent
124
- if (isColDragCell) {
125
- thOns.mouseup = $xeTable.handleHeaderCellDragMouseupEvent
126
- }
127
- }
128
- const isLastColumn = $columnIndex === cols.length - 1
129
- const showResizable = (XEUtils.isBoolean(column.resizable) ? column.resizable : (columnOpts.resizable || allResizable))
130
- const isAutoCellWidth = !column.resizeWidth && (column.minWidth === 'auto' || column.width === 'auto')
131
-
132
- let isVNPreEmptyStatus = false
133
- if (isOptimizeMode && overflowX && !isGroup && !isMergeCell) {
134
- if (!dragCol || dragCol.id !== colid) {
135
- if (scrollXLoad && tableColumn.length > 10 && !column.fixed && !virtualXOpts.immediate && (_columnIndex < scrollXStore.visibleStartIndex - scrollXStore.preloadSize || _columnIndex > scrollXStore.visibleEndIndex + scrollXStore.preloadSize)) {
136
- isVNPreEmptyStatus = true
137
- }
138
- }
139
- }
140
-
141
- const tcStyle: Record<string, string> = {}
142
- if (hasEllipsis) {
143
- tcStyle.height = `${currCellHeight}px`
144
- } else {
145
- tcStyle.minHeight = `${currCellHeight}px`
146
- }
147
-
148
- if (showCustomHeader) {
149
- // custom
150
- } else if (isColGroup && !isLastRow) {
151
- let childWidth = 0
152
- XEUtils.eachTree(column.children, (childRow) => {
153
- if (childRow.visible && (!childRow.children || !childRow.children.length)) {
154
- childWidth += childRow.renderWidth
155
- }
156
- })
157
- tcStyle.width = `${childWidth}px`
158
- }
159
-
160
- return h('th', {
161
- class: ['vxe-table--column vxe-header--column', colid, fixedHiddenColumn ? 'fixed--hidden' : 'fixed--visible', {
162
- [`col--${headAlign}`]: headAlign,
163
- [`col--${type}`]: type,
164
- 'col--last': isLastColumn,
165
- 'col--fixed': column.fixed,
166
- 'col--group': isColGroup,
167
- 'col--ellipsis': hasEllipsis,
168
- 'fixed--width': !isAutoCellWidth,
169
- 'is--padding': isPadding,
170
- 'is--sortable': column.sortable,
171
- 'col--filter': !!filters,
172
- 'is--filter-active': hasFilter,
173
- 'is--drag-active': columnOpts.drag && !column.fixed && !isDisabledDrag && (isCrossDrag || isPeerDrag || !column.parentId),
174
- 'is--drag-disabled': columnOpts.drag && isDisabledDrag,
175
- 'col--current': currentColumn === column
176
- }, getClass(headerClassName, cellParams), getClass(headerCellClassName, cellParams)],
177
- attrs: thAttrs,
178
- style: headerCellStyle ? (XEUtils.isFunction(headerCellStyle) ? headerCellStyle(cellParams) : headerCellStyle) as VxeComponentStyleType : undefined,
179
- on: thOns,
180
- key: showCustomHeader ? `${colid}${$columnIndex}` : (columnKey || scrollXLoad || scrollYLoad || columnOpts.useKey || columnOpts.drag || isColGroup ? colid : $columnIndex)
181
- }, [
182
- h('div', {
183
- class: ['vxe-cell', {
184
- 'c--title': showTitle,
185
- 'c--tooltip': showTooltip,
186
- 'c--ellipsis': showEllipsis
187
- }],
188
- style: tcStyle
189
- }, isVNPreEmptyStatus || (isOptimizeMode && fixedHiddenColumn)
190
- ? []
191
- : [
192
- h('div', {
193
- attrs: {
194
- colid
195
- },
196
- class: 'vxe-cell--wrapper vxe-header-cell--wrapper'
197
- }, column.renderHeader(h, cellParams))
198
- ]),
199
- /**
200
- * 列宽拖动
201
- */
202
- !fixedHiddenColumn && showResizable && (!showCustomHeader || isLastRow)
203
- ? h('div', {
204
- class: 'vxe-cell--col-resizable',
205
- on: {
206
- mousedown: (evnt: MouseEvent) => $xeTable.handleColResizeMousedownEvent(evnt, fixedType, cellParams),
207
- dblclick: (evnt: MouseEvent) => $xeTable.handleColResizeDblclickEvent(evnt, cellParams)
208
- }
209
- })
210
- : renderEmptyElement($xeTable)
211
- ])
212
- })
213
- }
214
-
215
- function renderFilterRows (h: CreateElement, _vm: any, isOptimizeMode: boolean, cols: VxeTableDefines.ColumnInfo[]) {
216
- const props = _vm
217
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
218
- const $xeGrid = $xeTable.$xeGrid
219
- const $xeGantt = $xeTable.$xeGantt
220
- const tableProps = $xeTable
221
- const tableReactData = $xeTable as unknown as TableReactData
222
- const tableInternalData = $xeTable as unknown as TableInternalData
223
-
224
- const { fixedType } = props
225
- const { showHeaderOverflow: allColumnHeaderOverflow, headerAlign: allHeaderAlign, align: allAlign } = tableProps
226
- const { currentColumn, overflowX } = tableReactData
227
- const { fullColumnIdData } = tableInternalData
228
- const cellOpts = $xeTable.computeCellOpts
229
- const defaultRowHeight = $xeTable.computeDefaultRowHeight
230
- const headerCellOpts = $xeTable.computeHeaderCellOpts
231
- const currCellHeight = getCalcHeight(headerCellOpts.height) || defaultRowHeight
232
-
233
- return cols.map((column, $columnIndex) => {
234
- const { type, showHeaderOverflow, headerAlign, align, filters, editRender, cellRender, floatingFilters, filterRender, slots } = column
235
- const colid = column.id
236
- const colRest = fullColumnIdData[colid] || {}
237
- const renderOpts = editRender || cellRender
238
- const compConf = renderOpts ? renderer.get(renderOpts.name) : null
239
- const flCompConf = isEnableConf(filterRender) ? renderer.get(filterRender.name) : null
240
- const rtFloatingFilter = flCompConf ? flCompConf.renderTableFloatingFilter : null
241
- const flSlot = slots ? (slots.floatingFilter || slots['floating-filter']) : null
242
- const fixedHiddenColumn = overflowX && (fixedType ? column.fixed !== fixedType : !!column.fixed)
243
- const isPadding = XEUtils.isBoolean(headerCellOpts.padding) ? headerCellOpts.padding : cellOpts.padding
244
- const headOverflow = XEUtils.eqNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
245
- const headAlign = headerAlign || (compConf ? compConf.tableHeaderCellAlign : '') || allHeaderAlign || align || (compConf ? compConf.tableCellAlign : '') || allAlign
246
- const showEllipsis = headOverflow === 'ellipsis'
247
- const showTitle = headOverflow === 'title'
248
- const showTooltip = headOverflow === true || headOverflow === 'tooltip'
249
- const hasEllipsis = showTitle || showTooltip || showEllipsis
250
- let hasFilter = false
251
- let firstFilterOption: VxeTableDefines.FilterOption | null = null
252
- if (filters) {
253
- firstFilterOption = filters[0] as VxeTableDefines.FilterOption
254
- hasFilter = filters.some((item) => item.checked)
255
- }
256
- const columnIndex = colRest.index
257
- const _columnIndex = colRest._index
258
- const cellParams: VxeTableDefines.CellFloatingFilterParams & {
259
- $table: VxeTableConstructor & VxeTablePrivateMethods
260
- } = {
261
- $table: $xeTable,
262
- $grid: $xeGrid,
263
- $gantt: $xeGantt,
264
- column: column,
265
- columnIndex,
266
- $columnIndex,
267
- _columnIndex,
268
- option: firstFilterOption as VxeTableDefines.FilterOption,
269
- fixed: fixedType,
270
- source: sourceType,
271
- type: renderType,
272
- isHidden: fixedHiddenColumn,
273
- hasFilter
274
- }
275
- const thAttrs: Record<string, string | number | null> = {
276
- colid
277
- }
278
-
279
- const isLastColumn = $columnIndex === cols.length - 1
280
- const isAutoCellWidth = !column.resizeWidth && (column.minWidth === 'auto' || column.width === 'auto')
281
-
282
- const tcStyle: Record<string, string> = {}
283
- if (hasEllipsis) {
284
- tcStyle.height = `${currCellHeight}px`
285
- } else {
286
- tcStyle.minHeight = `${currCellHeight}px`
287
- }
288
-
289
- return h('th', {
290
- class: ['vxe-table--column vxe-header--column', colid, fixedHiddenColumn ? 'fixed--hidden' : 'fixed--visible', {
291
- [`col--${headAlign}`]: headAlign,
292
- [`col--${type}`]: type,
293
- 'col--last': isLastColumn,
294
- 'col--fixed': column.fixed,
295
- 'col--ellipsis': hasEllipsis,
296
- 'fixed--width': !isAutoCellWidth,
297
- 'is--padding': isPadding,
298
- 'is--sortable': column.sortable,
299
- 'col--current': currentColumn === column
300
- }
301
- ],
302
- key: colid,
303
- attrs: thAttrs
304
- }, [
305
- h('div', {
306
- class: ['vxe-cell', {
307
- 'c--title': showTitle,
308
- 'c--tooltip': showTooltip,
309
- 'c--ellipsis': showEllipsis
310
- }],
311
- style: tcStyle
312
- }, isOptimizeMode && fixedHiddenColumn && !floatingFilters
313
- ? []
314
- : [
315
- h('div', {
316
- attrs: {
317
- colid
318
- },
319
- class: 'vxe-cell--wrapper vxe-header-cell--wrapper'
320
- }, flSlot
321
- ? $xeTable.callSlot(flSlot, cellParams, h)
322
- : (rtFloatingFilter && firstFilterOption
323
- ? getSlotVNs(rtFloatingFilter.call($xeTable, h, filterRender, cellParams as unknown as VxeGlobalRendererHandles.RenderTableFloatingFilterParams))
324
- : []))
325
- ])
326
- ])
327
- })
328
- }
329
-
330
- function renderHeads (h: CreateElement, _vm: any, isGroup: boolean, isOptimizeMode: boolean, headerGroups: VxeTableDefines.ColumnInfo[][], renderColumnList: VxeTableDefines.ColumnInfo[]) {
331
- const props = _vm
332
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
333
- const tableProps = $xeTable
334
-
335
- const { fixedType } = props
336
-
337
- const { headerRowClassName, headerRowStyle } = tableProps
338
- const floatingFilterOpts = $xeTable.computeFloatingFilterOpts
339
- const rowVNs = headerGroups.map((cols, $rowIndex) => {
340
- const params = { $table: $xeTable, $rowIndex, fixed: fixedType, type: renderType }
341
- return h('tr', {
342
- key: $rowIndex,
343
- class: [
344
- 'vxe-header--row',
345
- headerRowClassName ? XEUtils.isFunction(headerRowClassName) ? headerRowClassName(params) : headerRowClassName : ''
346
- ],
347
- style: headerRowStyle ? (XEUtils.isFunction(headerRowStyle) ? headerRowStyle(params) : headerRowStyle) as VxeComponentStyleType : undefined
348
- }, renderRows(h, _vm, isGroup, isOptimizeMode, headerGroups, $rowIndex, cols))
349
- })
350
-
351
- if (floatingFilterOpts.enabled) {
352
- rowVNs.push(
353
- h('tr', {
354
- key: 'ff',
355
- class: [
356
- 'vxe-header--row'
357
- ]
358
- }, renderFilterRows(h, _vm, isOptimizeMode, renderColumnList))
359
- )
360
- }
361
-
362
- return rowVNs
363
- }
364
-
365
- export default {
366
- name: 'VxeTableHeader',
367
- props: {
368
- tableData: Array as PropType<any[]>,
369
- tableColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
370
- tableGroupColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
371
- fixedColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
372
- fixedType: {
373
- type: String as PropType<'right' | 'left' | ''>,
374
- default: null
375
- }
376
- },
377
- data () {
378
- return {
379
- headerColumn: []
380
- }
381
- },
382
- watch: {
383
- tableColumn () {
384
- const _vm = this as any
385
-
386
- _vm.uploadColumn()
387
- }
388
- },
389
- created () {
390
- const _vm = this as any
391
- _vm.uploadColumn()
392
- },
393
- mounted () {
394
- const _vm = this as any
395
- const props = _vm
396
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
397
- const internalData = $xeTable as unknown as TableInternalData
398
-
399
- const { fixedType } = props
400
- const { elemStore } = internalData
401
- const prefix = `${fixedType || 'main'}-header-`
402
- elemStore[`${prefix}wrapper`] = _vm.$refs.refElem
403
- elemStore[`${prefix}scroll`] = _vm.$refs.refHeaderScroll
404
- elemStore[`${prefix}table`] = _vm.$refs.refHeaderTable
405
- elemStore[`${prefix}colgroup`] = _vm.$refs.refHeaderColgroup
406
- elemStore[`${prefix}list`] = _vm.$refs.refHeaderTHead
407
- elemStore[`${prefix}xSpace`] = _vm.$refs.refHeaderXSpace
408
- elemStore[`${prefix}repair`] = _vm.$refs.refHeaderBorderRepair
409
- },
410
- destroyed () {
411
- const _vm = this as any
412
- const props = _vm
413
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
414
- const internalData = $xeTable as unknown as TableInternalData
415
-
416
- const { fixedType } = props
417
- const { elemStore } = internalData
418
- const prefix = `${fixedType || 'main'}-header-`
419
- elemStore[`${prefix}wrapper`] = null
420
- elemStore[`${prefix}scroll`] = null
421
- elemStore[`${prefix}table`] = null
422
- elemStore[`${prefix}colgroup`] = null
423
- elemStore[`${prefix}list`] = null
424
- elemStore[`${prefix}xSpace`] = null
425
- elemStore[`${prefix}repair`] = null
426
- },
427
- render (h: CreateElement) {
428
- const _vm = this as any
429
- const props = _vm
430
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
431
- const tableProps = $xeTable
432
- const tableReactData = $xeTable as unknown as TableReactData
433
- const tableInternalData = $xeTable as unknown as TableInternalData
434
-
435
- const { xID } = $xeTable
436
- const { fixedType, fixedColumn, tableColumn } = props
437
- const { headerColumn } = _vm
438
-
439
- const { mouseConfig } = tableProps
440
- const { isGroup, isColLoading, overflowX, scrollXLoad, dragCol } = tableReactData
441
- const { visibleColumn, fullColumnIdData } = tableInternalData
442
-
443
- const mouseOpts = $xeTable.computeMouseOpts
444
- const isHeaderRenderOptimize = $xeTable.computeIsHeaderRenderOptimize
445
- let renderHeaderList = headerColumn as VxeTableDefines.ColumnInfo[][]
446
- let renderColumnList = tableColumn as VxeTableDefines.ColumnInfo[]
447
- const isOptimizeMode = isHeaderRenderOptimize
448
-
449
- if (isGroup) {
450
- renderColumnList = visibleColumn
451
- } else {
452
- if (!isOptimizeMode || (!isColLoading && (fixedType || !overflowX))) {
453
- renderColumnList = visibleColumn
454
- }
455
-
456
- if (fixedType) {
457
- // 如果是使用优化模式
458
- if (isOptimizeMode) {
459
- renderColumnList = fixedColumn || []
460
- }
461
- }
462
- renderHeaderList = [renderColumnList]
463
- }
464
-
465
- if (!fixedType && !isGroup) {
466
- // 列拖拽
467
- if (scrollXLoad && dragCol) {
468
- if (renderColumnList.length > 2) {
469
- const dCowRest = fullColumnIdData[dragCol.id]
470
- if (dCowRest) {
471
- const dcIndex = dCowRest._index
472
- const firstCol = renderColumnList[0]
473
- const lastCol = renderColumnList[renderColumnList.length - 1]
474
- const firstColRest = fullColumnIdData[firstCol.id]
475
- const lastColRest = fullColumnIdData[lastCol.id]
476
- if (firstColRest && lastColRest) {
477
- const fcIndex = firstColRest._index
478
- const lcIndex = lastColRest._index
479
- if (dcIndex < fcIndex) {
480
- renderColumnList = [dragCol].concat(renderColumnList)
481
- renderHeaderList = [[dragCol].concat(renderHeaderList[0])].concat(renderHeaderList.slice(1))
482
- } else if (dcIndex > lcIndex) {
483
- renderColumnList = renderColumnList.concat([dragCol])
484
- renderHeaderList = [renderHeaderList[0].concat([dragCol])].concat(renderHeaderList.slice(1))
485
- }
486
- }
487
- }
488
- }
489
- }
490
- }
491
-
492
- return h('div', {
493
- ref: 'refElem',
494
- class: ['vxe-table--header-wrapper', fixedType ? `fixed-${fixedType}--wrapper` : 'body--wrapper'],
495
- attrs: {
496
- xid: xID
497
- }
498
- }, [
499
- h('div', {
500
- ref: 'refHeaderScroll',
501
- class: 'vxe-table--header-inner-wrapper',
502
- on: {
503
- scroll (evnt: Event) {
504
- $xeTable.triggerHeaderScrollEvent(evnt, fixedType)
505
- }
506
- }
507
- }, [
508
- fixedType
509
- ? renderEmptyElement($xeTable)
510
- : h('div', {
511
- ref: 'refHeaderXSpace',
512
- class: 'vxe-body--x-space'
513
- }),
514
- h('table', {
515
- ref: 'refHeaderTable',
516
- class: 'vxe-table--header',
517
- attrs: {
518
- xid: xID,
519
- cellspacing: 0,
520
- cellpadding: 0,
521
- border: 0,
522
- xvm: isOptimizeMode ? '1' : null
523
- }
524
- }, [
525
- /**
526
- * 列宽
527
- */
528
- h('colgroup', {
529
- ref: 'refHeaderColgroup'
530
- }, renderColumnList.map((column, $columnIndex) => {
531
- return h('col', {
532
- attrs: {
533
- name: column.id
534
- },
535
- key: $columnIndex,
536
- style: {
537
- width: `${column.renderWidth}px`
538
- }
539
- })
540
- })),
541
- /**
542
- * 头部
543
- */
544
- h('thead', {
545
- ref: 'refHeaderTHead'
546
- }, renderHeads(h, _vm, isGroup, isOptimizeMode, renderHeaderList, renderColumnList))
547
- ]),
548
- mouseConfig && mouseOpts.area
549
- ? h('div', {
550
- class: 'vxe-table--cell-area',
551
- attrs: {
552
- xid: xID
553
- }
554
- }, [
555
- h('span', {
556
- class: 'vxe-table--cell-main-area'
557
- }),
558
- h('span', {
559
- class: 'vxe-table--cell-clip-area'
560
- }),
561
- h('span', {
562
- class: 'vxe-table--cell-extend-area'
563
- }),
564
- h('span', {
565
- class: 'vxe-table--cell-multi-area'
566
- }),
567
- h('span', {
568
- class: 'vxe-table--cell-active-area'
569
- }),
570
- h('span', {
571
- class: 'vxe-table--cell-col-status-area'
572
- })
573
- ])
574
- : renderEmptyElement($xeTable)
575
- ])
576
- ])
577
- },
578
- methods: {
579
- uploadColumn () {
580
- const _vm = this as any
581
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
582
- const tableProps = $xeTable
583
- const tableReactData = $xeTable as unknown as TableReactData
584
- const tableInternalData = $xeTable as unknown as TableInternalData
585
-
586
- const props = _vm
587
-
588
- const { showCustomHeader } = tableProps
589
- const { collectColumn, visibleColumn } = tableInternalData
590
- const { tableGroupColumn } = props
591
- const { isGroup } = tableReactData
592
- let spanColumns: VxeTableDefines.ColumnInfo[][] = isGroup ? convertHeaderColumnToRows(tableGroupColumn) : []
593
- let visibleColgroups: VxeTableDefines.ColumnInfo[][] = []
594
- if (showCustomHeader && spanColumns.length > 1) {
595
- visibleColgroups = convertHeaderToGridRows(spanColumns)
596
- spanColumns = visibleColgroups
597
- }
598
- _vm.headerColumn = spanColumns
599
- $xeTable.dispatchEvent('columns-change', { visibleColgroups, collectColumn, visibleColumn }, null)
600
- }
601
- }
602
- }
1
+ import { PropType, CreateElement } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import { VxeUI } from '../../ui'
4
+ import { isEnableConf, getClass } from '../../ui/src/utils'
5
+ import { getCalcHeight, convertHeaderColumnToRows, convertHeaderToGridRows } from './util'
6
+ import { getSlotVNs } from '../../ui/src/vn'
7
+
8
+ import type { VxeTableDefines, VxeTableConstructor, VxeTablePrivateMethods, VxeColumnPropTypes, TableReactData, TableInternalData, VxeComponentStyleType, VxeGlobalRendererHandles } from '../../../types'
9
+
10
+ const { renderer, renderEmptyElement } = VxeUI
11
+
12
+ const sourceType = 'table'
13
+ const renderType = 'header'
14
+
15
+ function renderRows (h: CreateElement, _vm: any, isGroup: boolean, isOptimizeMode: boolean, headerGroups: VxeTableDefines.ColumnInfo[][], $rowIndex: number, cols: VxeTableDefines.ColumnInfo[]) {
16
+ const props = _vm
17
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
18
+ const $xeGrid = $xeTable.$xeGrid
19
+ const $xeGantt = $xeTable.$xeGantt
20
+ const tableProps = $xeTable
21
+ const tableReactData = $xeTable as unknown as TableReactData
22
+ const tableInternalData = $xeTable as unknown as TableInternalData
23
+
24
+ const { fixedType } = props
25
+ const { resizable: allResizable, columnKey, showCustomHeader, headerCellClassName, headerCellStyle, showHeaderOverflow: allColumnHeaderOverflow, headerAlign: allHeaderAlign, align: allAlign, mouseConfig } = tableProps
26
+ const { currentColumn, dragCol, scrollXLoad, scrollYLoad, overflowX, mergeHeadFlag, tableColumn } = tableReactData
27
+ const { fullColumnIdData, scrollXStore, mergeHeaderList, mergeHeaderCellMaps } = tableInternalData
28
+ const virtualXOpts = $xeTable.computeVirtualXOpts
29
+ const columnOpts = $xeTable.computeColumnOpts
30
+ const columnDragOpts = $xeTable.computeColumnDragOpts
31
+ const cellOpts = $xeTable.computeCellOpts
32
+ const defaultRowHeight = $xeTable.computeDefaultRowHeight
33
+ const headerCellOpts = $xeTable.computeHeaderCellOpts
34
+ const currCellHeight = getCalcHeight(headerCellOpts.height) || defaultRowHeight
35
+ const { disabledMethod: dragDisabledMethod, isCrossDrag, isPeerDrag } = columnDragOpts
36
+ const isLastRow = $rowIndex === headerGroups.length - 1
37
+
38
+ return cols.map((column, $columnIndex) => {
39
+ const { type, showHeaderOverflow, headerAlign, align, filters, headerClassName, editRender, cellRender } = column
40
+ // const { enabled } = tooltipOpts
41
+ const colid = column.id
42
+ const colRest = fullColumnIdData[colid] || {}
43
+ const renderOpts = editRender || cellRender
44
+ const compConf = renderOpts ? renderer.get(renderOpts.name) : null
45
+ const isColGroup = column.children && column.children.length
46
+ const fixedHiddenColumn = overflowX && !isColGroup && (fixedType ? column.fixed !== fixedType : !!column.fixed)
47
+ const isPadding = XEUtils.isBoolean(headerCellOpts.padding) ? headerCellOpts.padding : cellOpts.padding
48
+ const headOverflow = XEUtils.isUndefined(showHeaderOverflow) || XEUtils.isNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
49
+ const headAlign = headerAlign || (compConf ? compConf.tableHeaderCellAlign : '') || allHeaderAlign || align || (compConf ? compConf.tableCellAlign : '') || allAlign
50
+ const showEllipsis = headOverflow === 'ellipsis'
51
+ const showTitle = headOverflow === 'title'
52
+ const showTooltip = headOverflow === true || headOverflow === 'tooltip'
53
+ const hasEllipsis = showTitle || showTooltip || showEllipsis
54
+ let hasFilter = false
55
+ let firstFilterOption: VxeColumnPropTypes.FilterItem | null = null
56
+ if (filters) {
57
+ firstFilterOption = filters[0]
58
+ hasFilter = filters.some((item: VxeColumnPropTypes.FilterItem) => item.checked)
59
+ }
60
+ const columnIndex = colRest.index
61
+ const _columnIndex = showCustomHeader ? $columnIndex : colRest._index
62
+ const cellParams: VxeTableDefines.CellRenderHeaderParams & {
63
+ $table: VxeTableConstructor & VxeTablePrivateMethods
64
+ } = {
65
+ $table: $xeTable,
66
+ $grid: $xeGrid,
67
+ $gantt: $xeGantt,
68
+ $rowIndex,
69
+ column,
70
+ columnIndex,
71
+ $columnIndex,
72
+ _columnIndex,
73
+ firstFilterOption: firstFilterOption as VxeTableDefines.FilterOption,
74
+ fixed: fixedType,
75
+ source: sourceType,
76
+ type: renderType,
77
+ isHidden: fixedHiddenColumn,
78
+ hasFilter
79
+ }
80
+ const thAttrs: Record<string, string | number | null> = {
81
+ colid
82
+ }
83
+ let isMergeCell = false
84
+ // 合并行或列
85
+ if (!showCustomHeader) {
86
+ thAttrs.colspan = column.colSpan > 1 ? column.colSpan : null
87
+ thAttrs.rowspan = column.rowSpan > 1 ? column.rowSpan : null
88
+ }
89
+ if (mergeHeadFlag && mergeHeaderList.length && (showCustomHeader || isLastRow)) {
90
+ const spanRest = mergeHeaderCellMaps[`${$rowIndex}:${showCustomHeader ? $columnIndex : _columnIndex}`]
91
+ if (spanRest) {
92
+ const { rowspan, colspan } = spanRest
93
+ if (!rowspan || !colspan) {
94
+ return null
95
+ }
96
+ if (rowspan > 1) {
97
+ isMergeCell = true
98
+ thAttrs.rowspan = rowspan
99
+ }
100
+ if (colspan > 1) {
101
+ isMergeCell = true
102
+ thAttrs.colspan = colspan
103
+ }
104
+ }
105
+ }
106
+ const thOns: any = {
107
+ click: (evnt: MouseEvent) => $xeTable.triggerHeaderCellClickEvent(evnt, cellParams),
108
+ dblclick: (evnt: MouseEvent) => $xeTable.triggerHeaderCellDblclickEvent(evnt, cellParams)
109
+ }
110
+ const isColDragCell = columnOpts.drag && columnDragOpts.trigger === 'cell'
111
+ let isDisabledDrag = false
112
+ if (isColDragCell) {
113
+ isDisabledDrag = !!(dragDisabledMethod && dragDisabledMethod(cellParams))
114
+ }
115
+ // 按下事件处理
116
+ if (mouseConfig || isColDragCell) {
117
+ thOns.mousedown = (evnt: any) => $xeTable.triggerHeaderCellMousedownEvent(evnt, cellParams)
118
+ }
119
+ // 拖拽列事件
120
+ if (columnOpts.drag) {
121
+ thOns.dragstart = $xeTable.handleHeaderCellDragDragstartEvent
122
+ thOns.dragend = $xeTable.handleHeaderCellDragDragendEvent
123
+ thOns.dragover = $xeTable.handleHeaderCellDragDragoverEvent
124
+ if (isColDragCell) {
125
+ thOns.mouseup = $xeTable.handleHeaderCellDragMouseupEvent
126
+ }
127
+ }
128
+ const isLastColumn = $columnIndex === cols.length - 1
129
+ const showResizable = (XEUtils.isBoolean(column.resizable) ? column.resizable : (columnOpts.resizable || allResizable))
130
+ const isAutoCellWidth = !column.resizeWidth && (column.minWidth === 'auto' || column.width === 'auto')
131
+
132
+ let isVNPreEmptyStatus = false
133
+ if (isOptimizeMode && overflowX && !isGroup && !isMergeCell) {
134
+ if (!dragCol || dragCol.id !== colid) {
135
+ if (scrollXLoad && tableColumn.length > 10 && !column.fixed && !virtualXOpts.immediate && (_columnIndex < scrollXStore.visibleStartIndex - scrollXStore.preloadSize || _columnIndex > scrollXStore.visibleEndIndex + scrollXStore.preloadSize)) {
136
+ isVNPreEmptyStatus = true
137
+ }
138
+ }
139
+ }
140
+
141
+ const tcStyle: Record<string, string> = {}
142
+ if (hasEllipsis) {
143
+ tcStyle.height = `${currCellHeight}px`
144
+ } else {
145
+ tcStyle.minHeight = `${currCellHeight}px`
146
+ }
147
+
148
+ if (showCustomHeader) {
149
+ // custom
150
+ } else if (isColGroup && !isLastRow) {
151
+ let childWidth = 0
152
+ XEUtils.eachTree(column.children, (childRow) => {
153
+ if (childRow.visible && (!childRow.children || !childRow.children.length)) {
154
+ childWidth += childRow.renderWidth
155
+ }
156
+ })
157
+ tcStyle.width = `${childWidth}px`
158
+ }
159
+
160
+ return h('th', {
161
+ class: ['vxe-table--column vxe-header--column', colid, fixedHiddenColumn ? 'fixed--hidden' : 'fixed--visible', {
162
+ [`col--${headAlign}`]: headAlign,
163
+ [`col--${type}`]: type,
164
+ 'col--last': isLastColumn,
165
+ 'col--fixed': column.fixed,
166
+ 'col--group': isColGroup,
167
+ 'col--ellipsis': hasEllipsis,
168
+ 'fixed--width': !isAutoCellWidth,
169
+ 'is--padding': isPadding,
170
+ 'is--sortable': column.sortable,
171
+ 'col--filter': !!filters,
172
+ 'is--filter-active': hasFilter,
173
+ 'is--drag-active': columnOpts.drag && !column.fixed && !isDisabledDrag && (isCrossDrag || isPeerDrag || !column.parentId),
174
+ 'is--drag-disabled': columnOpts.drag && isDisabledDrag,
175
+ 'col--current': currentColumn === column
176
+ }, getClass(headerClassName, cellParams), getClass(headerCellClassName, cellParams)],
177
+ attrs: thAttrs,
178
+ style: headerCellStyle ? (XEUtils.isFunction(headerCellStyle) ? headerCellStyle(cellParams) : headerCellStyle) as VxeComponentStyleType : undefined,
179
+ on: thOns,
180
+ key: showCustomHeader ? `${colid}${$columnIndex}` : (columnKey || scrollXLoad || scrollYLoad || columnOpts.useKey || columnOpts.drag || isColGroup ? colid : $columnIndex)
181
+ }, [
182
+ h('div', {
183
+ class: ['vxe-cell', {
184
+ 'c--title': showTitle,
185
+ 'c--tooltip': showTooltip,
186
+ 'c--ellipsis': showEllipsis
187
+ }],
188
+ style: tcStyle
189
+ }, isVNPreEmptyStatus || (isOptimizeMode && fixedHiddenColumn)
190
+ ? []
191
+ : [
192
+ h('div', {
193
+ attrs: {
194
+ colid
195
+ },
196
+ class: 'vxe-cell--wrapper vxe-header-cell--wrapper'
197
+ }, column.renderHeader(h, cellParams))
198
+ ]),
199
+ /**
200
+ * 列宽拖动
201
+ */
202
+ !fixedHiddenColumn && showResizable && (!showCustomHeader || isLastRow)
203
+ ? h('div', {
204
+ class: 'vxe-cell--col-resizable',
205
+ on: {
206
+ mousedown: (evnt: MouseEvent) => $xeTable.handleColResizeMousedownEvent(evnt, fixedType, cellParams),
207
+ dblclick: (evnt: MouseEvent) => $xeTable.handleColResizeDblclickEvent(evnt, cellParams)
208
+ }
209
+ })
210
+ : renderEmptyElement($xeTable)
211
+ ])
212
+ })
213
+ }
214
+
215
+ function renderFilterRows (h: CreateElement, _vm: any, isOptimizeMode: boolean, cols: VxeTableDefines.ColumnInfo[]) {
216
+ const props = _vm
217
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
218
+ const $xeGrid = $xeTable.$xeGrid
219
+ const $xeGantt = $xeTable.$xeGantt
220
+ const tableProps = $xeTable
221
+ const tableReactData = $xeTable as unknown as TableReactData
222
+ const tableInternalData = $xeTable as unknown as TableInternalData
223
+
224
+ const { fixedType } = props
225
+ const { showHeaderOverflow: allColumnHeaderOverflow, headerAlign: allHeaderAlign, align: allAlign } = tableProps
226
+ const { currentColumn, overflowX } = tableReactData
227
+ const { fullColumnIdData } = tableInternalData
228
+ const cellOpts = $xeTable.computeCellOpts
229
+ const defaultRowHeight = $xeTable.computeDefaultRowHeight
230
+ const headerCellOpts = $xeTable.computeHeaderCellOpts
231
+ const currCellHeight = getCalcHeight(headerCellOpts.height) || defaultRowHeight
232
+
233
+ return cols.map((column, $columnIndex) => {
234
+ const { type, showHeaderOverflow, headerAlign, align, filters, editRender, cellRender, floatingFilters, filterRender, slots } = column
235
+ const colid = column.id
236
+ const colRest = fullColumnIdData[colid] || {}
237
+ const renderOpts = editRender || cellRender
238
+ const compConf = renderOpts ? renderer.get(renderOpts.name) : null
239
+ const flCompConf = isEnableConf(filterRender) ? renderer.get(filterRender.name) : null
240
+ const rtFloatingFilter = flCompConf ? flCompConf.renderTableFloatingFilter : null
241
+ const flSlot = slots ? (slots.floatingFilter || slots['floating-filter']) : null
242
+ const fixedHiddenColumn = overflowX && (fixedType ? column.fixed !== fixedType : !!column.fixed)
243
+ const isPadding = XEUtils.isBoolean(headerCellOpts.padding) ? headerCellOpts.padding : cellOpts.padding
244
+ const headOverflow = XEUtils.eqNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
245
+ const headAlign = headerAlign || (compConf ? compConf.tableHeaderCellAlign : '') || allHeaderAlign || align || (compConf ? compConf.tableCellAlign : '') || allAlign
246
+ const showEllipsis = headOverflow === 'ellipsis'
247
+ const showTitle = headOverflow === 'title'
248
+ const showTooltip = headOverflow === true || headOverflow === 'tooltip'
249
+ const hasEllipsis = showTitle || showTooltip || showEllipsis
250
+ let hasFilter = false
251
+ let firstFilterOption: VxeTableDefines.FilterOption | null = null
252
+ if (filters) {
253
+ firstFilterOption = filters[0] as VxeTableDefines.FilterOption
254
+ hasFilter = filters.some((item) => item.checked)
255
+ }
256
+ const columnIndex = colRest.index
257
+ const _columnIndex = colRest._index
258
+ const cellParams: VxeTableDefines.CellFloatingFilterParams & {
259
+ $table: VxeTableConstructor & VxeTablePrivateMethods
260
+ } = {
261
+ $table: $xeTable,
262
+ $grid: $xeGrid,
263
+ $gantt: $xeGantt,
264
+ column: column,
265
+ columnIndex,
266
+ $columnIndex,
267
+ _columnIndex,
268
+ option: firstFilterOption as VxeTableDefines.FilterOption,
269
+ fixed: fixedType,
270
+ source: sourceType,
271
+ type: renderType,
272
+ isHidden: fixedHiddenColumn,
273
+ hasFilter
274
+ }
275
+ const thAttrs: Record<string, string | number | null> = {
276
+ colid
277
+ }
278
+
279
+ const isLastColumn = $columnIndex === cols.length - 1
280
+ const isAutoCellWidth = !column.resizeWidth && (column.minWidth === 'auto' || column.width === 'auto')
281
+
282
+ const tcStyle: Record<string, string> = {}
283
+ if (hasEllipsis) {
284
+ tcStyle.height = `${currCellHeight}px`
285
+ } else {
286
+ tcStyle.minHeight = `${currCellHeight}px`
287
+ }
288
+
289
+ return h('th', {
290
+ class: ['vxe-table--column vxe-header--column', colid, fixedHiddenColumn ? 'fixed--hidden' : 'fixed--visible', {
291
+ [`col--${headAlign}`]: headAlign,
292
+ [`col--${type}`]: type,
293
+ 'col--last': isLastColumn,
294
+ 'col--fixed': column.fixed,
295
+ 'col--ellipsis': hasEllipsis,
296
+ 'fixed--width': !isAutoCellWidth,
297
+ 'is--padding': isPadding,
298
+ 'is--sortable': column.sortable,
299
+ 'col--current': currentColumn === column
300
+ }
301
+ ],
302
+ key: colid,
303
+ attrs: thAttrs
304
+ }, [
305
+ h('div', {
306
+ class: ['vxe-cell', {
307
+ 'c--title': showTitle,
308
+ 'c--tooltip': showTooltip,
309
+ 'c--ellipsis': showEllipsis
310
+ }],
311
+ style: tcStyle
312
+ }, isOptimizeMode && fixedHiddenColumn && !floatingFilters
313
+ ? []
314
+ : [
315
+ h('div', {
316
+ attrs: {
317
+ colid
318
+ },
319
+ class: 'vxe-cell--wrapper vxe-header-cell--wrapper'
320
+ }, flSlot
321
+ ? $xeTable.callSlot(flSlot, cellParams, h)
322
+ : (rtFloatingFilter && firstFilterOption
323
+ ? getSlotVNs(rtFloatingFilter.call($xeTable, h, filterRender, cellParams as unknown as VxeGlobalRendererHandles.RenderTableFloatingFilterParams))
324
+ : []))
325
+ ])
326
+ ])
327
+ })
328
+ }
329
+
330
+ function renderHeads (h: CreateElement, _vm: any, isGroup: boolean, isOptimizeMode: boolean, headerGroups: VxeTableDefines.ColumnInfo[][], renderColumnList: VxeTableDefines.ColumnInfo[]) {
331
+ const props = _vm
332
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
333
+ const tableProps = $xeTable
334
+
335
+ const { fixedType } = props
336
+
337
+ const { headerRowClassName, headerRowStyle } = tableProps
338
+ const floatingFilterOpts = $xeTable.computeFloatingFilterOpts
339
+ const rowVNs = headerGroups.map((cols, $rowIndex) => {
340
+ const params = { $table: $xeTable, $rowIndex, fixed: fixedType, type: renderType }
341
+ return h('tr', {
342
+ key: $rowIndex,
343
+ class: [
344
+ 'vxe-header--row',
345
+ headerRowClassName ? XEUtils.isFunction(headerRowClassName) ? headerRowClassName(params) : headerRowClassName : ''
346
+ ],
347
+ style: headerRowStyle ? (XEUtils.isFunction(headerRowStyle) ? headerRowStyle(params) : headerRowStyle) as VxeComponentStyleType : undefined
348
+ }, renderRows(h, _vm, isGroup, isOptimizeMode, headerGroups, $rowIndex, cols))
349
+ })
350
+
351
+ if (floatingFilterOpts.enabled) {
352
+ rowVNs.push(
353
+ h('tr', {
354
+ key: 'ff',
355
+ class: [
356
+ 'vxe-header--row'
357
+ ]
358
+ }, renderFilterRows(h, _vm, isOptimizeMode, renderColumnList))
359
+ )
360
+ }
361
+
362
+ return rowVNs
363
+ }
364
+
365
+ export default {
366
+ name: 'VxeTableHeader',
367
+ props: {
368
+ tableData: Array as PropType<any[]>,
369
+ tableColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
370
+ tableGroupColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
371
+ fixedColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
372
+ fixedType: {
373
+ type: String as PropType<'right' | 'left' | ''>,
374
+ default: null
375
+ }
376
+ },
377
+ data () {
378
+ return {
379
+ headerColumn: []
380
+ }
381
+ },
382
+ watch: {
383
+ tableColumn () {
384
+ const _vm = this as any
385
+
386
+ _vm.uploadColumn()
387
+ }
388
+ },
389
+ created () {
390
+ const _vm = this as any
391
+ _vm.uploadColumn()
392
+ },
393
+ mounted () {
394
+ const _vm = this as any
395
+ const props = _vm
396
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
397
+ const internalData = $xeTable as unknown as TableInternalData
398
+
399
+ const { fixedType } = props
400
+ const { elemStore } = internalData
401
+ const prefix = `${fixedType || 'main'}-header-`
402
+ elemStore[`${prefix}wrapper`] = _vm.$refs.refElem
403
+ elemStore[`${prefix}scroll`] = _vm.$refs.refHeaderScroll
404
+ elemStore[`${prefix}table`] = _vm.$refs.refHeaderTable
405
+ elemStore[`${prefix}colgroup`] = _vm.$refs.refHeaderColgroup
406
+ elemStore[`${prefix}list`] = _vm.$refs.refHeaderTHead
407
+ elemStore[`${prefix}xSpace`] = _vm.$refs.refHeaderXSpace
408
+ elemStore[`${prefix}repair`] = _vm.$refs.refHeaderBorderRepair
409
+ },
410
+ destroyed () {
411
+ const _vm = this as any
412
+ const props = _vm
413
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
414
+ const internalData = $xeTable as unknown as TableInternalData
415
+
416
+ const { fixedType } = props
417
+ const { elemStore } = internalData
418
+ const prefix = `${fixedType || 'main'}-header-`
419
+ elemStore[`${prefix}wrapper`] = null
420
+ elemStore[`${prefix}scroll`] = null
421
+ elemStore[`${prefix}table`] = null
422
+ elemStore[`${prefix}colgroup`] = null
423
+ elemStore[`${prefix}list`] = null
424
+ elemStore[`${prefix}xSpace`] = null
425
+ elemStore[`${prefix}repair`] = null
426
+ },
427
+ render (h: CreateElement) {
428
+ const _vm = this as any
429
+ const props = _vm
430
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
431
+ const tableProps = $xeTable
432
+ const tableReactData = $xeTable as unknown as TableReactData
433
+ const tableInternalData = $xeTable as unknown as TableInternalData
434
+
435
+ const { xID } = $xeTable
436
+ const { fixedType, fixedColumn, tableColumn } = props
437
+ const { headerColumn } = _vm
438
+
439
+ const { mouseConfig } = tableProps
440
+ const { isGroup, isColLoading, overflowX, scrollXLoad, dragCol } = tableReactData
441
+ const { visibleColumn, fullColumnIdData } = tableInternalData
442
+
443
+ const mouseOpts = $xeTable.computeMouseOpts
444
+ const isHeaderRenderOptimize = $xeTable.computeIsHeaderRenderOptimize
445
+ let renderHeaderList = headerColumn as VxeTableDefines.ColumnInfo[][]
446
+ let renderColumnList = tableColumn as VxeTableDefines.ColumnInfo[]
447
+ const isOptimizeMode = isHeaderRenderOptimize
448
+
449
+ if (isGroup) {
450
+ renderColumnList = visibleColumn
451
+ } else {
452
+ if (!isOptimizeMode || (!isColLoading && (fixedType || !overflowX))) {
453
+ renderColumnList = visibleColumn
454
+ }
455
+
456
+ if (fixedType) {
457
+ // 如果是使用优化模式
458
+ if (isOptimizeMode) {
459
+ renderColumnList = fixedColumn || []
460
+ }
461
+ }
462
+ renderHeaderList = [renderColumnList]
463
+ }
464
+
465
+ if (!fixedType && !isGroup) {
466
+ // 列拖拽
467
+ if (scrollXLoad && dragCol) {
468
+ if (renderColumnList.length > 2) {
469
+ const dCowRest = fullColumnIdData[dragCol.id]
470
+ if (dCowRest) {
471
+ const dcIndex = dCowRest._index
472
+ const firstCol = renderColumnList[0]
473
+ const lastCol = renderColumnList[renderColumnList.length - 1]
474
+ const firstColRest = fullColumnIdData[firstCol.id]
475
+ const lastColRest = fullColumnIdData[lastCol.id]
476
+ if (firstColRest && lastColRest) {
477
+ const fcIndex = firstColRest._index
478
+ const lcIndex = lastColRest._index
479
+ if (dcIndex < fcIndex) {
480
+ renderColumnList = [dragCol].concat(renderColumnList)
481
+ renderHeaderList = [[dragCol].concat(renderHeaderList[0])].concat(renderHeaderList.slice(1))
482
+ } else if (dcIndex > lcIndex) {
483
+ renderColumnList = renderColumnList.concat([dragCol])
484
+ renderHeaderList = [renderHeaderList[0].concat([dragCol])].concat(renderHeaderList.slice(1))
485
+ }
486
+ }
487
+ }
488
+ }
489
+ }
490
+ }
491
+
492
+ return h('div', {
493
+ ref: 'refElem',
494
+ class: ['vxe-table--header-wrapper', fixedType ? `fixed-${fixedType}--wrapper` : 'body--wrapper'],
495
+ attrs: {
496
+ xid: xID
497
+ }
498
+ }, [
499
+ h('div', {
500
+ ref: 'refHeaderScroll',
501
+ class: 'vxe-table--header-inner-wrapper',
502
+ on: {
503
+ scroll (evnt: Event) {
504
+ $xeTable.triggerHeaderScrollEvent(evnt, fixedType)
505
+ }
506
+ }
507
+ }, [
508
+ fixedType
509
+ ? renderEmptyElement($xeTable)
510
+ : h('div', {
511
+ ref: 'refHeaderXSpace',
512
+ class: 'vxe-body--x-space'
513
+ }),
514
+ h('table', {
515
+ ref: 'refHeaderTable',
516
+ class: 'vxe-table--header',
517
+ attrs: {
518
+ xid: xID,
519
+ cellspacing: 0,
520
+ cellpadding: 0,
521
+ border: 0,
522
+ xvm: isOptimizeMode ? '1' : null
523
+ }
524
+ }, [
525
+ /**
526
+ * 列宽
527
+ */
528
+ h('colgroup', {
529
+ ref: 'refHeaderColgroup'
530
+ }, renderColumnList.map((column, $columnIndex) => {
531
+ return h('col', {
532
+ attrs: {
533
+ name: column.id
534
+ },
535
+ key: $columnIndex,
536
+ style: {
537
+ width: `${column.renderWidth}px`
538
+ }
539
+ })
540
+ })),
541
+ /**
542
+ * 头部
543
+ */
544
+ h('thead', {
545
+ ref: 'refHeaderTHead'
546
+ }, renderHeads(h, _vm, isGroup, isOptimizeMode, renderHeaderList, renderColumnList))
547
+ ]),
548
+ mouseConfig && mouseOpts.area
549
+ ? h('div', {
550
+ class: 'vxe-table--cell-area',
551
+ attrs: {
552
+ xid: xID
553
+ }
554
+ }, [
555
+ h('span', {
556
+ class: 'vxe-table--cell-main-area'
557
+ }),
558
+ h('span', {
559
+ class: 'vxe-table--cell-clip-area'
560
+ }),
561
+ h('span', {
562
+ class: 'vxe-table--cell-extend-area'
563
+ }),
564
+ h('span', {
565
+ class: 'vxe-table--cell-multi-area'
566
+ }),
567
+ h('span', {
568
+ class: 'vxe-table--cell-active-area'
569
+ }),
570
+ h('span', {
571
+ class: 'vxe-table--cell-col-status-area'
572
+ })
573
+ ])
574
+ : renderEmptyElement($xeTable)
575
+ ])
576
+ ])
577
+ },
578
+ methods: {
579
+ uploadColumn () {
580
+ const _vm = this as any
581
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
582
+ const tableProps = $xeTable
583
+ const tableReactData = $xeTable as unknown as TableReactData
584
+ const tableInternalData = $xeTable as unknown as TableInternalData
585
+
586
+ const props = _vm
587
+
588
+ const { showCustomHeader } = tableProps
589
+ const { collectColumn, visibleColumn } = tableInternalData
590
+ const { tableGroupColumn } = props
591
+ const { isGroup } = tableReactData
592
+ let spanColumns: VxeTableDefines.ColumnInfo[][] = isGroup ? convertHeaderColumnToRows(tableGroupColumn) : []
593
+ let visibleColgroups: VxeTableDefines.ColumnInfo[][] = []
594
+ if (showCustomHeader && spanColumns.length > 1) {
595
+ visibleColgroups = convertHeaderToGridRows(spanColumns)
596
+ spanColumns = visibleColgroups
597
+ }
598
+ _vm.headerColumn = spanColumns
599
+ $xeTable.dispatchEvent('columns-change', { visibleColgroups, collectColumn, visibleColumn }, null)
600
+ }
601
+ }
602
+ }