vxe-table 4.19.0-beta.2 → 4.19.0-beta.3

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 (121) hide show
  1. package/LICENSE +20 -20
  2. package/README.en.md +118 -118
  3. package/README.ja-JP.md +117 -117
  4. package/README.md +268 -268
  5. package/README.zh-TW.md +117 -117
  6. package/es/style.css +1 -1
  7. package/es/table/render/index.js +1 -1
  8. package/es/ui/index.js +1 -1
  9. package/es/ui/src/log.js +1 -1
  10. package/lib/index.umd.js +2767 -2851
  11. package/lib/index.umd.min.js +1 -1
  12. package/lib/style.css +1 -1
  13. package/lib/table/render/index.js +1 -1
  14. package/lib/table/render/index.min.js +1 -1
  15. package/lib/ui/index.js +1 -1
  16. package/lib/ui/index.min.js +1 -1
  17. package/lib/ui/src/log.js +1 -1
  18. package/lib/ui/src/log.min.js +1 -1
  19. package/package.json +92 -92
  20. package/packages/colgroup/index.ts +22 -22
  21. package/packages/column/index.ts +22 -22
  22. package/packages/components.ts +43 -43
  23. package/packages/grid/index.ts +18 -18
  24. package/packages/grid/src/emits.ts +19 -19
  25. package/packages/grid/src/grid.ts +1768 -1768
  26. package/packages/grid/src/props.ts +23 -23
  27. package/packages/index.ts +4 -4
  28. package/packages/locale/lang/ar-EG.ts +840 -840
  29. package/packages/locale/lang/de-DE.ts +840 -840
  30. package/packages/locale/lang/en-US.ts +840 -840
  31. package/packages/locale/lang/es-ES.ts +840 -840
  32. package/packages/locale/lang/fr-FR.ts +840 -840
  33. package/packages/locale/lang/hu-HU.ts +840 -840
  34. package/packages/locale/lang/hy-AM.ts +840 -840
  35. package/packages/locale/lang/id-ID.ts +840 -840
  36. package/packages/locale/lang/it-IT.ts +840 -840
  37. package/packages/locale/lang/ja-JP.ts +840 -840
  38. package/packages/locale/lang/ko-KR.ts +840 -840
  39. package/packages/locale/lang/ms-MY.ts +840 -840
  40. package/packages/locale/lang/nb-NO.ts +840 -840
  41. package/packages/locale/lang/pt-BR.ts +840 -840
  42. package/packages/locale/lang/ru-RU.ts +840 -840
  43. package/packages/locale/lang/th-TH.ts +840 -840
  44. package/packages/locale/lang/ug-CN.ts +840 -840
  45. package/packages/locale/lang/uk-UA.ts +840 -840
  46. package/packages/locale/lang/uz-UZ.ts +840 -840
  47. package/packages/locale/lang/vi-VN.ts +840 -840
  48. package/packages/locale/lang/zh-CHT.ts +840 -840
  49. package/packages/locale/lang/zh-CN.ts +840 -840
  50. package/packages/locale/lang/zh-HK.ts +3 -3
  51. package/packages/locale/lang/zh-MO.ts +3 -3
  52. package/packages/locale/lang/zh-TC.ts +3 -3
  53. package/packages/locale/lang/zh-TW.ts +3 -3
  54. package/packages/table/index.ts +26 -26
  55. package/packages/table/module/custom/hook.ts +422 -422
  56. package/packages/table/module/custom/panel.ts +1512 -1512
  57. package/packages/table/module/edit/hook.ts +1064 -1064
  58. package/packages/table/module/export/export-panel.ts +567 -567
  59. package/packages/table/module/export/hook.ts +1654 -1654
  60. package/packages/table/module/export/import-panel.ts +266 -266
  61. package/packages/table/module/export/util.ts +24 -24
  62. package/packages/table/module/filter/hook.ts +468 -468
  63. package/packages/table/module/filter/panel.ts +301 -301
  64. package/packages/table/module/keyboard/hook.ts +494 -494
  65. package/packages/table/module/menu/hook.ts +325 -325
  66. package/packages/table/module/menu/panel.ts +201 -201
  67. package/packages/table/module/validator/hook.ts +631 -631
  68. package/packages/table/render/index.ts +1440 -1440
  69. package/packages/table/src/body.ts +935 -935
  70. package/packages/table/src/cell.ts +1290 -1290
  71. package/packages/table/src/column.ts +190 -190
  72. package/packages/table/src/columnInfo.ts +225 -225
  73. package/packages/table/src/emits.ts +125 -125
  74. package/packages/table/src/footer.ts +368 -368
  75. package/packages/table/src/group.ts +59 -59
  76. package/packages/table/src/header.ts +561 -561
  77. package/packages/table/src/props.ts +324 -324
  78. package/packages/table/src/store.ts +14 -14
  79. package/packages/table/src/table.ts +14274 -14274
  80. package/packages/table/src/use/cell-view.ts +44 -44
  81. package/packages/table/src/use/index.ts +1 -1
  82. package/packages/table/src/util.ts +1086 -1086
  83. package/packages/toolbar/index.ts +18 -18
  84. package/packages/toolbar/src/toolbar.ts +701 -701
  85. package/packages/ui/index.ts +532 -532
  86. package/packages/ui/src/anime.ts +52 -52
  87. package/packages/ui/src/comp.ts +3 -3
  88. package/packages/ui/src/dom.ts +264 -264
  89. package/packages/ui/src/log.ts +8 -8
  90. package/packages/ui/src/utils.ts +56 -56
  91. package/packages/ui/src/vn.ts +55 -55
  92. package/packages/v-x-e-table/index.d.ts +4 -4
  93. package/packages/v-x-e-table/index.ts +4 -4
  94. package/styles/all.scss +7 -7
  95. package/styles/base.scss +16 -16
  96. package/styles/components/grid.scss +89 -89
  97. package/styles/components/icon.scss +225 -225
  98. package/styles/components/old-icon.scss +715 -715
  99. package/styles/components/table-module/all.scss +6 -6
  100. package/styles/components/table-module/custom.scss +550 -550
  101. package/styles/components/table-module/export.scss +130 -130
  102. package/styles/components/table-module/filter.scss +130 -130
  103. package/styles/components/table-module/menu.scss +81 -81
  104. package/styles/components/table.scss +2679 -2679
  105. package/styles/components/toolbar.scss +119 -119
  106. package/styles/default.scss +2 -2
  107. package/styles/helpers/baseMixin.scss +95 -95
  108. package/styles/index.scss +4 -4
  109. package/styles/modules.scss +5 -5
  110. package/styles/theme/base.scss +93 -93
  111. package/styles/theme/dark.scss +49 -49
  112. package/styles/theme/light.scss +44 -44
  113. package/styles/variable.scss +43 -43
  114. package/types/all.d.ts +37 -37
  115. package/types/index.d.ts +4 -4
  116. /package/es/{iconfont.1778157083004.ttf → iconfont.1778318183872.ttf} +0 -0
  117. /package/es/{iconfont.1778157083004.woff → iconfont.1778318183872.woff} +0 -0
  118. /package/es/{iconfont.1778157083004.woff2 → iconfont.1778318183872.woff2} +0 -0
  119. /package/lib/{iconfont.1778157083004.ttf → iconfont.1778318183872.ttf} +0 -0
  120. /package/lib/{iconfont.1778157083004.woff → iconfont.1778318183872.woff} +0 -0
  121. /package/lib/{iconfont.1778157083004.woff2 → iconfont.1778318183872.woff2} +0 -0
@@ -1,422 +1,422 @@
1
- import { nextTick } from 'vue'
2
- import { VxeUI } from '../../../ui'
3
- import XEUtils from 'xe-utils'
4
- import { getColumnList } from '../../src/util'
5
- import { toCssUnit } from '../../../ui/src/dom'
6
-
7
- import type { TableCustomMethods, TableCustomPrivateMethods, VxeColumnPropTypes, VxeTableDefines, VxeComponentStyleType } from '../../../../types'
8
-
9
- const tableCustomMethodKeys: (keyof TableCustomMethods)[] = ['openCustom', 'closeCustom', 'getCustomVisible', 'toggleCustom', 'saveCustom', 'cancelCustom', 'resetCustom', 'toggleCustomAllCheckbox', 'setCustomAllCheckbox']
10
-
11
- VxeUI.hooks.add('tableCustomModule', {
12
- setupTable ($xeTable) {
13
- const { reactData, internalData } = $xeTable
14
- const { computeCustomOpts, computeRowGroupFields, computeCustomSimpleMode } = $xeTable.getComputeMaps()
15
- const { refElem } = $xeTable.getRefMaps()
16
-
17
- const $xeGrid = $xeTable.xeGrid
18
- const $xeGantt = $xeTable.xeGantt
19
- const $xeGGWrapper = $xeGrid || $xeGantt
20
-
21
- const updatePopupStyle = () => {
22
- const { customStore } = reactData
23
- const customOpts = computeCustomOpts.value
24
- const { mode, placement, popupOptions } = customOpts
25
- const showSimple = !(mode === 'modal' || mode === 'drawer')
26
- const { transfer, maxHeight } = popupOptions || {}
27
- const customSimpleMode = computeCustomSimpleMode.value
28
- const showCustomSimpleOutside = customSimpleMode === 'outside'
29
- const bodyEl = document.documentElement
30
- let wrapperEl = refElem.value
31
- let popupTop = 0
32
- let popupMaxHeight: string | number = 0
33
- const popupStys: VxeComponentStyleType = {}
34
- if ($xeGantt) {
35
- const { refGanttContainerElem } = $xeGantt.getRefMaps()
36
- const ganttContainerElem = refGanttContainerElem.value
37
- if (ganttContainerElem) {
38
- wrapperEl = ganttContainerElem
39
- }
40
- }
41
- const tableRect = wrapperEl.getBoundingClientRect()
42
- // 多种模式,指定元素插入
43
- if (showSimple && transfer) {
44
- popupTop = tableRect.top + bodyEl.scrollTop
45
- popupMaxHeight = XEUtils.eqNull(maxHeight) ? 360 : maxHeight
46
- } else if (showCustomSimpleOutside) {
47
- if ($xeGGWrapper && wrapperEl) {
48
- popupTop = wrapperEl.offsetTop
49
- }
50
- popupMaxHeight = XEUtils.eqNull(maxHeight) ? 360 : maxHeight
51
- } else {
52
- // 判断面板不能大于表格高度
53
- if (wrapperEl) {
54
- popupMaxHeight = wrapperEl.clientHeight - 22
55
- }
56
- popupMaxHeight = Math.max(88, popupMaxHeight)
57
- }
58
- let popupMxHeight: string | number = 0
59
- if (!(placement === 'left' || placement === 'right')) {
60
- popupMxHeight = XEUtils.eqNull(maxHeight) ? popupMaxHeight : maxHeight
61
- }
62
- if (!placement || !(['left', 'right', 'bottom-left', 'bottom-right'].includes(placement))) {
63
- if (popupTop) {
64
- popupStys.top = toCssUnit(popupTop)
65
- }
66
- }
67
-
68
- if (showSimple && transfer) {
69
- if (placement === 'bottom-left' || placement === 'bottom-right') {
70
- popupStys.bottom = toCssUnit(bodyEl.scrollHeight - tableRect.top - tableRect.height + 1)
71
- }
72
- if (placement === 'top-left' || placement === 'bottom-left') {
73
- popupStys.left = toCssUnit(tableRect.left)
74
- } else if (!placement || placement === 'top-right' || placement === 'bottom-right') {
75
- popupStys.right = toCssUnit(bodyEl.scrollWidth - tableRect.left - tableRect.width + 1)
76
- }
77
- }
78
-
79
- if (popupMxHeight) {
80
- popupStys.maxHeight = toCssUnit(popupMxHeight)
81
- }
82
- customStore.popupStyle = popupStys
83
- customStore.maxHeight = popupMxHeight
84
- return nextTick()
85
- }
86
-
87
- const openCustom = () => {
88
- const { initStore, customStore } = reactData
89
- const customOpts = computeCustomOpts.value
90
- const { mode, popupOptions } = customOpts
91
- const showSimple = !(mode === 'modal' || mode === 'drawer')
92
- const { transfer } = popupOptions || {}
93
- const customSimpleMode = computeCustomSimpleMode.value
94
- const showCustomSimpleOutside = customSimpleMode === 'outside'
95
- let cpToElem = null
96
- // 多种模式,指定元素插入
97
- if (showSimple && transfer) {
98
- cpToElem = document.body
99
- } else {
100
- if (showCustomSimpleOutside && $xeGGWrapper) {
101
- const { refPopupContainerElem } = $xeGGWrapper.getRefMaps()
102
- const popupContainerElem = refPopupContainerElem.value
103
- if (popupContainerElem) {
104
- cpToElem = popupContainerElem
105
- }
106
- }
107
- }
108
- if (internalData.customPopupToElem !== cpToElem) {
109
- reactData.ctPopupFlag++
110
- }
111
- internalData.customPopupToElem = cpToElem
112
- customStore.visible = true
113
- initStore.custom = true
114
- handleUpdateCustomColumn()
115
- checkCustomStatus()
116
- updatePopupStyle()
117
- return nextTick().then(() => updatePopupStyle())
118
- }
119
-
120
- const handleUpdateCustomColumn = () => {
121
- const { customStore } = reactData
122
- const { collectColumn } = internalData
123
- if (customStore.visible) {
124
- const sortMaps: Record<string, number> = {}
125
- const fixedMaps: Record<string, VxeColumnPropTypes.Fixed> = {}
126
- const visibleMaps: Record<string, boolean> = {}
127
- XEUtils.eachTree(collectColumn, column => {
128
- const colid = column.getKey()
129
- column.renderFixed = column.fixed
130
- column.renderVisible = column.visible
131
- column.renderResizeWidth = column.renderWidth
132
- sortMaps[colid] = column.renderSortNumber
133
- fixedMaps[colid] = column.fixed
134
- visibleMaps[colid] = column.visible
135
- })
136
- customStore.oldSortMaps = sortMaps
137
- customStore.oldFixedMaps = fixedMaps
138
- customStore.oldVisibleMaps = visibleMaps
139
- reactData.customColumnList = collectColumn.slice(0)
140
- }
141
- }
142
-
143
- const closeCustom = () => {
144
- const { customStore } = reactData
145
- const customOpts = computeCustomOpts.value
146
- if (customStore.visible) {
147
- customStore.visible = false
148
- if (!customOpts.immediate) {
149
- $xeTable.handleCustom()
150
- }
151
- }
152
- return nextTick()
153
- }
154
-
155
- const toggleCustom = () => {
156
- const { customStore } = reactData
157
- if (customStore.visible) {
158
- return closeCustom()
159
- }
160
- return openCustom()
161
- }
162
-
163
- const saveCustom = () => {
164
- const { customColumnList, aggHandleFields, rowGroupList } = reactData
165
- const customOpts = computeCustomOpts.value
166
- const { allowVisible, allowSort, allowFixed, allowResizable, allowGroup, allowValues } = customOpts
167
- XEUtils.eachTree(customColumnList, (column, index, items, path, parentColumn) => {
168
- if (parentColumn) {
169
- // 更新子列信息
170
- column.fixed = parentColumn.fixed
171
- } else {
172
- if (allowSort) {
173
- const sortIndex = index + 1
174
- column.renderSortNumber = sortIndex
175
- }
176
- if (allowFixed) {
177
- column.fixed = column.renderFixed
178
- }
179
- }
180
- if (allowResizable) {
181
- if (column.renderVisible && (!column.children || !column.children.length)) {
182
- if (column.renderResizeWidth !== column.renderWidth) {
183
- column.resizeWidth = column.renderResizeWidth
184
- column.renderWidth = column.renderResizeWidth
185
- }
186
- }
187
- }
188
- if (allowVisible) {
189
- column.visible = column.renderVisible
190
- }
191
- if (allowGroup && allowValues) {
192
- column.aggFunc = column.renderAggFn
193
- }
194
- })
195
- reactData.isCustomStatus = true
196
- if (allowGroup && !!$xeTable.handlePivotTableAggregateData) {
197
- if (rowGroupList.length !== aggHandleFields.length || rowGroupList.some((conf, i) => conf.field !== aggHandleFields[i])) {
198
- // 更新数据分组
199
- if (aggHandleFields.length) {
200
- $xeTable.setRowGroups(aggHandleFields)
201
- } else {
202
- $xeTable.clearRowGroups()
203
- }
204
- } else if (allowValues) {
205
- // 更新聚合函数
206
- $xeTable.handleUpdateAggData()
207
- }
208
- }
209
- if (allowSort) {
210
- internalData.collectColumn = customColumnList
211
- }
212
- return $xeTable.saveCustomStore('confirm')
213
- }
214
-
215
- const cancelCustom = () => {
216
- const { customColumnList, customStore } = reactData
217
- const { oldSortMaps, oldFixedMaps, oldVisibleMaps } = customStore
218
- const customOpts = computeCustomOpts.value
219
- const { allowVisible, allowSort, allowFixed, allowResizable } = customOpts
220
- XEUtils.eachTree(customColumnList, column => {
221
- const colid = column.getKey()
222
- const visible = !!oldVisibleMaps[colid]
223
- const fixed = oldFixedMaps[colid] || ''
224
- if (allowVisible) {
225
- column.renderVisible = visible
226
- column.visible = visible
227
- }
228
- if (allowFixed) {
229
- column.renderFixed = fixed
230
- column.fixed = fixed
231
- }
232
- if (allowSort) {
233
- column.renderSortNumber = oldSortMaps[colid] || 0
234
- }
235
- if (allowResizable) {
236
- column.renderResizeWidth = column.renderWidth
237
- }
238
- }, { children: 'children' })
239
- return nextTick()
240
- }
241
-
242
- const setCustomAllCheckbox = (checked: boolean) => {
243
- const { customStore } = reactData
244
- const { customColumnList } = reactData
245
- const customOpts = computeCustomOpts.value
246
- const { checkMethod, visibleMethod } = customOpts
247
- const isAll = !!checked
248
- if (customOpts.immediate) {
249
- XEUtils.eachTree(customColumnList, (column) => {
250
- if (visibleMethod && !visibleMethod({ $table: $xeTable, column })) {
251
- return
252
- }
253
- if (checkMethod && !checkMethod({ $table: $xeTable, column })) {
254
- return
255
- }
256
- column.visible = isAll
257
- column.renderVisible = isAll
258
- column.halfVisible = false
259
- })
260
- customStore.isAll = isAll
261
- reactData.isCustomStatus = true
262
- $xeTable.handleCustom()
263
- $xeTable.saveCustomStore('update:visible')
264
- } else {
265
- XEUtils.eachTree(customColumnList, (column) => {
266
- if (visibleMethod && !visibleMethod({ $table: $xeTable, column })) {
267
- return
268
- }
269
- if (checkMethod && !checkMethod({ $table: $xeTable, column })) {
270
- return
271
- }
272
- column.renderVisible = isAll
273
- column.halfVisible = false
274
- })
275
- customStore.isAll = isAll
276
- }
277
- $xeTable.checkCustomStatus()
278
- return nextTick()
279
- }
280
-
281
- const customMethods: TableCustomMethods = {
282
- getCustomVisible () {
283
- const { customStore } = reactData
284
- return customStore.visible
285
- },
286
- openCustom,
287
- closeCustom,
288
- toggleCustom,
289
- saveCustom,
290
- cancelCustom,
291
- resetCustom (options) {
292
- const { rowGroupList } = reactData
293
- const { collectColumn } = internalData
294
- const customOpts = computeCustomOpts.value
295
- const { checkMethod } = customOpts
296
- const opts: VxeTableDefines.VxeTableCustomStorageObj = Object.assign({
297
- visible: true,
298
- resizable: options === true,
299
- fixed: options === true,
300
- sort: options === true,
301
- aggFunc: options === true
302
- }, options)
303
- const allCols: VxeTableDefines.ColumnInfo[] = []
304
- XEUtils.eachTree(collectColumn, (column) => {
305
- if (opts.resizable) {
306
- column.resizeWidth = 0
307
- }
308
- if (opts.fixed) {
309
- column.fixed = column.defaultFixed
310
- }
311
- if (opts.sort) {
312
- column.renderSortNumber = column.sortNumber
313
- column.parentId = column.defaultParentId
314
- }
315
- if (!checkMethod || checkMethod({ $table: $xeTable, column })) {
316
- column.visible = column.defaultVisible
317
- }
318
- if (opts.aggFunc) {
319
- column.aggFunc = column.defaultAggFunc
320
- column.renderAggFn = column.defaultAggFunc
321
- }
322
- column.renderResizeWidth = column.renderWidth
323
- allCols.push(column)
324
- })
325
- if (opts.sort) {
326
- const newCollectCols = XEUtils.toArrayTree(XEUtils.orderBy(allCols, 'renderSortNumber'), { key: 'id', parentKey: 'parentId', children: 'children' })
327
- internalData.collectColumn = newCollectCols
328
- internalData.tableFullColumn = getColumnList(newCollectCols)
329
- }
330
- reactData.isCustomStatus = false
331
- return $xeTable.handleCustom().then(() => {
332
- if (opts.aggFunc && ($xeTable as any).handlePivotTableAggregateData) {
333
- const rowGroupFields = computeRowGroupFields.value
334
- if (rowGroupFields ? rowGroupFields.length : rowGroupList.length) {
335
- if (rowGroupFields && rowGroupFields.length) {
336
- $xeTable.setRowGroups(rowGroupFields)
337
- } else {
338
- $xeTable.clearRowGroups()
339
- }
340
- } else {
341
- $xeTable.handleUpdateAggData()
342
- }
343
- }
344
- $xeTable.saveCustomStore('reset')
345
- })
346
- },
347
- toggleCustomAllCheckbox () {
348
- const { customStore } = reactData
349
- const isAll = !customStore.isAll
350
- return setCustomAllCheckbox(isAll)
351
- },
352
- setCustomAllCheckbox
353
- }
354
-
355
- const checkCustomStatus = () => {
356
- const { customStore } = reactData
357
- const { collectColumn } = internalData
358
- const customOpts = computeCustomOpts.value
359
- const { checkMethod } = customOpts
360
- customStore.isAll = collectColumn.every((column) => (checkMethod ? !checkMethod({ $table: $xeTable, column }) : false) || column.renderVisible)
361
- customStore.isIndeterminate = !customStore.isAll && collectColumn.some((column) => (!checkMethod || checkMethod({ $table: $xeTable, column })) && (column.renderVisible || column.halfVisible))
362
- }
363
-
364
- const emitCustomEvent = (type: VxeTableDefines.CustomType, evnt: Event) => {
365
- $xeTable.dispatchEvent('custom', { type }, evnt)
366
- }
367
-
368
- const customPrivateMethods: TableCustomPrivateMethods = {
369
- checkCustomStatus,
370
- emitCustomEvent,
371
- triggerCustomEvent (evnt) {
372
- const reactData = $xeTable.reactData
373
-
374
- const { customStore } = reactData
375
- if (customStore.visible) {
376
- closeCustom()
377
- emitCustomEvent('close', evnt)
378
- } else {
379
- customStore.btnEl = evnt.target as HTMLDivElement
380
- openCustom()
381
- emitCustomEvent('open', evnt)
382
- }
383
- },
384
- customOpenEvent (evnt) {
385
- const reactData = $xeTable.reactData
386
-
387
- const { customStore } = reactData
388
- if (!customStore.visible) {
389
- customStore.activeBtn = true
390
- customStore.btnEl = evnt.target as HTMLDivElement
391
- $xeTable.openCustom()
392
- $xeTable.emitCustomEvent('open', evnt)
393
- }
394
- },
395
- customCloseEvent (evnt) {
396
- const reactData = $xeTable.reactData
397
-
398
- const { customStore } = reactData
399
- if (customStore.visible) {
400
- customStore.activeBtn = false
401
- $xeTable.closeCustom()
402
- $xeTable.emitCustomEvent('close', evnt)
403
- }
404
- },
405
- handleUpdateCustomColumn,
406
- handleCustomStyle () {
407
- const reactData = $xeTable.reactData
408
-
409
- reactData.isCustomDragStatus = false
410
- return updatePopupStyle()
411
- }
412
- }
413
-
414
- return { ...customMethods, ...customPrivateMethods }
415
- },
416
- setupGrid ($xeGrid) {
417
- return $xeGrid.extendTableMethods(tableCustomMethodKeys)
418
- },
419
- setupGantt ($xeGantt) {
420
- return $xeGantt.extendTableMethods(tableCustomMethodKeys)
421
- }
422
- })
1
+ import { nextTick } from 'vue'
2
+ import { VxeUI } from '../../../ui'
3
+ import XEUtils from 'xe-utils'
4
+ import { getColumnList } from '../../src/util'
5
+ import { toCssUnit } from '../../../ui/src/dom'
6
+
7
+ import type { TableCustomMethods, TableCustomPrivateMethods, VxeColumnPropTypes, VxeTableDefines, VxeComponentStyleType } from '../../../../types'
8
+
9
+ const tableCustomMethodKeys: (keyof TableCustomMethods)[] = ['openCustom', 'closeCustom', 'getCustomVisible', 'toggleCustom', 'saveCustom', 'cancelCustom', 'resetCustom', 'toggleCustomAllCheckbox', 'setCustomAllCheckbox']
10
+
11
+ VxeUI.hooks.add('tableCustomModule', {
12
+ setupTable ($xeTable) {
13
+ const { reactData, internalData } = $xeTable
14
+ const { computeCustomOpts, computeRowGroupFields, computeCustomSimpleMode } = $xeTable.getComputeMaps()
15
+ const { refElem } = $xeTable.getRefMaps()
16
+
17
+ const $xeGrid = $xeTable.xeGrid
18
+ const $xeGantt = $xeTable.xeGantt
19
+ const $xeGGWrapper = $xeGrid || $xeGantt
20
+
21
+ const updatePopupStyle = () => {
22
+ const { customStore } = reactData
23
+ const customOpts = computeCustomOpts.value
24
+ const { mode, placement, popupOptions } = customOpts
25
+ const showSimple = !(mode === 'modal' || mode === 'drawer')
26
+ const { transfer, maxHeight } = popupOptions || {}
27
+ const customSimpleMode = computeCustomSimpleMode.value
28
+ const showCustomSimpleOutside = customSimpleMode === 'outside'
29
+ const bodyEl = document.documentElement
30
+ let wrapperEl = refElem.value
31
+ let popupTop = 0
32
+ let popupMaxHeight: string | number = 0
33
+ const popupStys: VxeComponentStyleType = {}
34
+ if ($xeGantt) {
35
+ const { refGanttContainerElem } = $xeGantt.getRefMaps()
36
+ const ganttContainerElem = refGanttContainerElem.value
37
+ if (ganttContainerElem) {
38
+ wrapperEl = ganttContainerElem
39
+ }
40
+ }
41
+ const tableRect = wrapperEl.getBoundingClientRect()
42
+ // 多种模式,指定元素插入
43
+ if (showSimple && transfer) {
44
+ popupTop = tableRect.top + bodyEl.scrollTop
45
+ popupMaxHeight = XEUtils.eqNull(maxHeight) ? 360 : maxHeight
46
+ } else if (showCustomSimpleOutside) {
47
+ if ($xeGGWrapper && wrapperEl) {
48
+ popupTop = wrapperEl.offsetTop
49
+ }
50
+ popupMaxHeight = XEUtils.eqNull(maxHeight) ? 360 : maxHeight
51
+ } else {
52
+ // 判断面板不能大于表格高度
53
+ if (wrapperEl) {
54
+ popupMaxHeight = wrapperEl.clientHeight - 22
55
+ }
56
+ popupMaxHeight = Math.max(88, popupMaxHeight)
57
+ }
58
+ let popupMxHeight: string | number = 0
59
+ if (!(placement === 'left' || placement === 'right')) {
60
+ popupMxHeight = XEUtils.eqNull(maxHeight) ? popupMaxHeight : maxHeight
61
+ }
62
+ if (!placement || !(['left', 'right', 'bottom-left', 'bottom-right'].includes(placement))) {
63
+ if (popupTop) {
64
+ popupStys.top = toCssUnit(popupTop)
65
+ }
66
+ }
67
+
68
+ if (showSimple && transfer) {
69
+ if (placement === 'bottom-left' || placement === 'bottom-right') {
70
+ popupStys.bottom = toCssUnit(bodyEl.scrollHeight - tableRect.top - tableRect.height + 1)
71
+ }
72
+ if (placement === 'top-left' || placement === 'bottom-left') {
73
+ popupStys.left = toCssUnit(tableRect.left)
74
+ } else if (!placement || placement === 'top-right' || placement === 'bottom-right') {
75
+ popupStys.right = toCssUnit(bodyEl.scrollWidth - tableRect.left - tableRect.width + 1)
76
+ }
77
+ }
78
+
79
+ if (popupMxHeight) {
80
+ popupStys.maxHeight = toCssUnit(popupMxHeight)
81
+ }
82
+ customStore.popupStyle = popupStys
83
+ customStore.maxHeight = popupMxHeight
84
+ return nextTick()
85
+ }
86
+
87
+ const openCustom = () => {
88
+ const { initStore, customStore } = reactData
89
+ const customOpts = computeCustomOpts.value
90
+ const { mode, popupOptions } = customOpts
91
+ const showSimple = !(mode === 'modal' || mode === 'drawer')
92
+ const { transfer } = popupOptions || {}
93
+ const customSimpleMode = computeCustomSimpleMode.value
94
+ const showCustomSimpleOutside = customSimpleMode === 'outside'
95
+ let cpToElem = null
96
+ // 多种模式,指定元素插入
97
+ if (showSimple && transfer) {
98
+ cpToElem = document.body
99
+ } else {
100
+ if (showCustomSimpleOutside && $xeGGWrapper) {
101
+ const { refPopupContainerElem } = $xeGGWrapper.getRefMaps()
102
+ const popupContainerElem = refPopupContainerElem.value
103
+ if (popupContainerElem) {
104
+ cpToElem = popupContainerElem
105
+ }
106
+ }
107
+ }
108
+ if (internalData.customPopupToElem !== cpToElem) {
109
+ reactData.ctPopupFlag++
110
+ }
111
+ internalData.customPopupToElem = cpToElem
112
+ customStore.visible = true
113
+ initStore.custom = true
114
+ handleUpdateCustomColumn()
115
+ checkCustomStatus()
116
+ updatePopupStyle()
117
+ return nextTick().then(() => updatePopupStyle())
118
+ }
119
+
120
+ const handleUpdateCustomColumn = () => {
121
+ const { customStore } = reactData
122
+ const { collectColumn } = internalData
123
+ if (customStore.visible) {
124
+ const sortMaps: Record<string, number> = {}
125
+ const fixedMaps: Record<string, VxeColumnPropTypes.Fixed> = {}
126
+ const visibleMaps: Record<string, boolean> = {}
127
+ XEUtils.eachTree(collectColumn, column => {
128
+ const colid = column.getKey()
129
+ column.renderFixed = column.fixed
130
+ column.renderVisible = column.visible
131
+ column.renderResizeWidth = column.renderWidth
132
+ sortMaps[colid] = column.renderSortNumber
133
+ fixedMaps[colid] = column.fixed
134
+ visibleMaps[colid] = column.visible
135
+ })
136
+ customStore.oldSortMaps = sortMaps
137
+ customStore.oldFixedMaps = fixedMaps
138
+ customStore.oldVisibleMaps = visibleMaps
139
+ reactData.customColumnList = collectColumn.slice(0)
140
+ }
141
+ }
142
+
143
+ const closeCustom = () => {
144
+ const { customStore } = reactData
145
+ const customOpts = computeCustomOpts.value
146
+ if (customStore.visible) {
147
+ customStore.visible = false
148
+ if (!customOpts.immediate) {
149
+ $xeTable.handleCustom()
150
+ }
151
+ }
152
+ return nextTick()
153
+ }
154
+
155
+ const toggleCustom = () => {
156
+ const { customStore } = reactData
157
+ if (customStore.visible) {
158
+ return closeCustom()
159
+ }
160
+ return openCustom()
161
+ }
162
+
163
+ const saveCustom = () => {
164
+ const { customColumnList, aggHandleFields, rowGroupList } = reactData
165
+ const customOpts = computeCustomOpts.value
166
+ const { allowVisible, allowSort, allowFixed, allowResizable, allowGroup, allowValues } = customOpts
167
+ XEUtils.eachTree(customColumnList, (column, index, items, path, parentColumn) => {
168
+ if (parentColumn) {
169
+ // 更新子列信息
170
+ column.fixed = parentColumn.fixed
171
+ } else {
172
+ if (allowSort) {
173
+ const sortIndex = index + 1
174
+ column.renderSortNumber = sortIndex
175
+ }
176
+ if (allowFixed) {
177
+ column.fixed = column.renderFixed
178
+ }
179
+ }
180
+ if (allowResizable) {
181
+ if (column.renderVisible && (!column.children || !column.children.length)) {
182
+ if (column.renderResizeWidth !== column.renderWidth) {
183
+ column.resizeWidth = column.renderResizeWidth
184
+ column.renderWidth = column.renderResizeWidth
185
+ }
186
+ }
187
+ }
188
+ if (allowVisible) {
189
+ column.visible = column.renderVisible
190
+ }
191
+ if (allowGroup && allowValues) {
192
+ column.aggFunc = column.renderAggFn
193
+ }
194
+ })
195
+ reactData.isCustomStatus = true
196
+ if (allowGroup && !!$xeTable.handlePivotTableAggregateData) {
197
+ if (rowGroupList.length !== aggHandleFields.length || rowGroupList.some((conf, i) => conf.field !== aggHandleFields[i])) {
198
+ // 更新数据分组
199
+ if (aggHandleFields.length) {
200
+ $xeTable.setRowGroups(aggHandleFields)
201
+ } else {
202
+ $xeTable.clearRowGroups()
203
+ }
204
+ } else if (allowValues) {
205
+ // 更新聚合函数
206
+ $xeTable.handleUpdateAggData()
207
+ }
208
+ }
209
+ if (allowSort) {
210
+ internalData.collectColumn = customColumnList
211
+ }
212
+ return $xeTable.saveCustomStore('confirm')
213
+ }
214
+
215
+ const cancelCustom = () => {
216
+ const { customColumnList, customStore } = reactData
217
+ const { oldSortMaps, oldFixedMaps, oldVisibleMaps } = customStore
218
+ const customOpts = computeCustomOpts.value
219
+ const { allowVisible, allowSort, allowFixed, allowResizable } = customOpts
220
+ XEUtils.eachTree(customColumnList, column => {
221
+ const colid = column.getKey()
222
+ const visible = !!oldVisibleMaps[colid]
223
+ const fixed = oldFixedMaps[colid] || ''
224
+ if (allowVisible) {
225
+ column.renderVisible = visible
226
+ column.visible = visible
227
+ }
228
+ if (allowFixed) {
229
+ column.renderFixed = fixed
230
+ column.fixed = fixed
231
+ }
232
+ if (allowSort) {
233
+ column.renderSortNumber = oldSortMaps[colid] || 0
234
+ }
235
+ if (allowResizable) {
236
+ column.renderResizeWidth = column.renderWidth
237
+ }
238
+ }, { children: 'children' })
239
+ return nextTick()
240
+ }
241
+
242
+ const setCustomAllCheckbox = (checked: boolean) => {
243
+ const { customStore } = reactData
244
+ const { customColumnList } = reactData
245
+ const customOpts = computeCustomOpts.value
246
+ const { checkMethod, visibleMethod } = customOpts
247
+ const isAll = !!checked
248
+ if (customOpts.immediate) {
249
+ XEUtils.eachTree(customColumnList, (column) => {
250
+ if (visibleMethod && !visibleMethod({ $table: $xeTable, column })) {
251
+ return
252
+ }
253
+ if (checkMethod && !checkMethod({ $table: $xeTable, column })) {
254
+ return
255
+ }
256
+ column.visible = isAll
257
+ column.renderVisible = isAll
258
+ column.halfVisible = false
259
+ })
260
+ customStore.isAll = isAll
261
+ reactData.isCustomStatus = true
262
+ $xeTable.handleCustom()
263
+ $xeTable.saveCustomStore('update:visible')
264
+ } else {
265
+ XEUtils.eachTree(customColumnList, (column) => {
266
+ if (visibleMethod && !visibleMethod({ $table: $xeTable, column })) {
267
+ return
268
+ }
269
+ if (checkMethod && !checkMethod({ $table: $xeTable, column })) {
270
+ return
271
+ }
272
+ column.renderVisible = isAll
273
+ column.halfVisible = false
274
+ })
275
+ customStore.isAll = isAll
276
+ }
277
+ $xeTable.checkCustomStatus()
278
+ return nextTick()
279
+ }
280
+
281
+ const customMethods: TableCustomMethods = {
282
+ getCustomVisible () {
283
+ const { customStore } = reactData
284
+ return customStore.visible
285
+ },
286
+ openCustom,
287
+ closeCustom,
288
+ toggleCustom,
289
+ saveCustom,
290
+ cancelCustom,
291
+ resetCustom (options) {
292
+ const { rowGroupList } = reactData
293
+ const { collectColumn } = internalData
294
+ const customOpts = computeCustomOpts.value
295
+ const { checkMethod } = customOpts
296
+ const opts: VxeTableDefines.VxeTableCustomStorageObj = Object.assign({
297
+ visible: true,
298
+ resizable: options === true,
299
+ fixed: options === true,
300
+ sort: options === true,
301
+ aggFunc: options === true
302
+ }, options)
303
+ const allCols: VxeTableDefines.ColumnInfo[] = []
304
+ XEUtils.eachTree(collectColumn, (column) => {
305
+ if (opts.resizable) {
306
+ column.resizeWidth = 0
307
+ }
308
+ if (opts.fixed) {
309
+ column.fixed = column.defaultFixed
310
+ }
311
+ if (opts.sort) {
312
+ column.renderSortNumber = column.sortNumber
313
+ column.parentId = column.defaultParentId
314
+ }
315
+ if (!checkMethod || checkMethod({ $table: $xeTable, column })) {
316
+ column.visible = column.defaultVisible
317
+ }
318
+ if (opts.aggFunc) {
319
+ column.aggFunc = column.defaultAggFunc
320
+ column.renderAggFn = column.defaultAggFunc
321
+ }
322
+ column.renderResizeWidth = column.renderWidth
323
+ allCols.push(column)
324
+ })
325
+ if (opts.sort) {
326
+ const newCollectCols = XEUtils.toArrayTree(XEUtils.orderBy(allCols, 'renderSortNumber'), { key: 'id', parentKey: 'parentId', children: 'children' })
327
+ internalData.collectColumn = newCollectCols
328
+ internalData.tableFullColumn = getColumnList(newCollectCols)
329
+ }
330
+ reactData.isCustomStatus = false
331
+ return $xeTable.handleCustom().then(() => {
332
+ if (opts.aggFunc && ($xeTable as any).handlePivotTableAggregateData) {
333
+ const rowGroupFields = computeRowGroupFields.value
334
+ if (rowGroupFields ? rowGroupFields.length : rowGroupList.length) {
335
+ if (rowGroupFields && rowGroupFields.length) {
336
+ $xeTable.setRowGroups(rowGroupFields)
337
+ } else {
338
+ $xeTable.clearRowGroups()
339
+ }
340
+ } else {
341
+ $xeTable.handleUpdateAggData()
342
+ }
343
+ }
344
+ $xeTable.saveCustomStore('reset')
345
+ })
346
+ },
347
+ toggleCustomAllCheckbox () {
348
+ const { customStore } = reactData
349
+ const isAll = !customStore.isAll
350
+ return setCustomAllCheckbox(isAll)
351
+ },
352
+ setCustomAllCheckbox
353
+ }
354
+
355
+ const checkCustomStatus = () => {
356
+ const { customStore } = reactData
357
+ const { collectColumn } = internalData
358
+ const customOpts = computeCustomOpts.value
359
+ const { checkMethod } = customOpts
360
+ customStore.isAll = collectColumn.every((column) => (checkMethod ? !checkMethod({ $table: $xeTable, column }) : false) || column.renderVisible)
361
+ customStore.isIndeterminate = !customStore.isAll && collectColumn.some((column) => (!checkMethod || checkMethod({ $table: $xeTable, column })) && (column.renderVisible || column.halfVisible))
362
+ }
363
+
364
+ const emitCustomEvent = (type: VxeTableDefines.CustomType, evnt: Event) => {
365
+ $xeTable.dispatchEvent('custom', { type }, evnt)
366
+ }
367
+
368
+ const customPrivateMethods: TableCustomPrivateMethods = {
369
+ checkCustomStatus,
370
+ emitCustomEvent,
371
+ triggerCustomEvent (evnt) {
372
+ const reactData = $xeTable.reactData
373
+
374
+ const { customStore } = reactData
375
+ if (customStore.visible) {
376
+ closeCustom()
377
+ emitCustomEvent('close', evnt)
378
+ } else {
379
+ customStore.btnEl = evnt.target as HTMLDivElement
380
+ openCustom()
381
+ emitCustomEvent('open', evnt)
382
+ }
383
+ },
384
+ customOpenEvent (evnt) {
385
+ const reactData = $xeTable.reactData
386
+
387
+ const { customStore } = reactData
388
+ if (!customStore.visible) {
389
+ customStore.activeBtn = true
390
+ customStore.btnEl = evnt.target as HTMLDivElement
391
+ $xeTable.openCustom()
392
+ $xeTable.emitCustomEvent('open', evnt)
393
+ }
394
+ },
395
+ customCloseEvent (evnt) {
396
+ const reactData = $xeTable.reactData
397
+
398
+ const { customStore } = reactData
399
+ if (customStore.visible) {
400
+ customStore.activeBtn = false
401
+ $xeTable.closeCustom()
402
+ $xeTable.emitCustomEvent('close', evnt)
403
+ }
404
+ },
405
+ handleUpdateCustomColumn,
406
+ handleCustomStyle () {
407
+ const reactData = $xeTable.reactData
408
+
409
+ reactData.isCustomDragStatus = false
410
+ return updatePopupStyle()
411
+ }
412
+ }
413
+
414
+ return { ...customMethods, ...customPrivateMethods }
415
+ },
416
+ setupGrid ($xeGrid) {
417
+ return $xeGrid.extendTableMethods(tableCustomMethodKeys)
418
+ },
419
+ setupGantt ($xeGantt) {
420
+ return $xeGantt.extendTableMethods(tableCustomMethodKeys)
421
+ }
422
+ })