vxe-table 4.23.19 → 4.23.21

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 (127) hide show
  1. package/dist/all.esm.js +289 -253
  2. package/dist/all.esm.min.js +3 -3
  3. package/dist/style.css +4 -1
  4. package/dist/style.mini.css +1 -1
  5. package/es/components.d.ts +1 -3
  6. package/es/components.js +1 -2
  7. package/es/esm.index.d.ts +7 -0
  8. package/es/esm.index.js +8 -0
  9. package/es/style.css +4 -1
  10. package/es/style.mini.css +1 -1
  11. package/es/table/src/table.js +6 -2
  12. package/es/table/style.css +4 -1
  13. package/es/table/style.mini.css +1 -1
  14. package/es/ui/abandon.d.ts +82 -0
  15. package/es/ui/abandon.js +90 -0
  16. package/es/ui/index.d.ts +1 -83
  17. package/es/ui/index.js +2 -89
  18. package/es/ui/src/log.js +1 -1
  19. package/es/vxe-table/style.css +4 -1
  20. package/es/vxe-table/style.mini.css +1 -1
  21. package/lib/components.d.ts +1 -3
  22. package/lib/components.js +1 -2
  23. package/lib/esm.index.d.ts +7 -0
  24. package/lib/esm.index.js +39 -0
  25. package/lib/index.umd.js +254 -249
  26. package/lib/index.umd.min.js +3 -3
  27. package/lib/style.css +4 -1
  28. package/lib/style.mini.css +1 -1
  29. package/lib/table/src/table.js +6 -2
  30. package/lib/table/style/style.css +4 -1
  31. package/lib/table/style/style.mini.css +1 -1
  32. package/lib/ui/abandon.d.ts +82 -0
  33. package/lib/ui/abandon.js +110 -0
  34. package/lib/ui/index.d.ts +1 -83
  35. package/lib/ui/index.js +3 -89
  36. package/lib/ui/src/log.js +1 -1
  37. package/lib/vxe-table/style/style.css +4 -1
  38. package/lib/vxe-table/style/style.mini.css +1 -1
  39. package/package.json +1 -1
  40. package/packages/colgroup/index.ts +22 -22
  41. package/packages/column/index.ts +22 -22
  42. package/packages/components.ts +42 -45
  43. package/packages/esm.index.ts +10 -0
  44. package/packages/grid/index.ts +18 -18
  45. package/packages/grid/src/emits.ts +5 -5
  46. package/packages/grid/src/grid.ts +2220 -2220
  47. package/packages/grid/src/props.ts +22 -22
  48. package/packages/index.ts +13 -13
  49. package/packages/locale/lang/ar-EG.ts +914 -914
  50. package/packages/locale/lang/de-DE.ts +914 -914
  51. package/packages/locale/lang/en-US.ts +914 -914
  52. package/packages/locale/lang/es-ES.ts +914 -914
  53. package/packages/locale/lang/fr-FR.ts +914 -914
  54. package/packages/locale/lang/hu-HU.ts +914 -914
  55. package/packages/locale/lang/hy-AM.ts +914 -914
  56. package/packages/locale/lang/id-ID.ts +914 -914
  57. package/packages/locale/lang/it-IT.ts +914 -914
  58. package/packages/locale/lang/ja-JP.ts +914 -914
  59. package/packages/locale/lang/ko-KR.ts +914 -914
  60. package/packages/locale/lang/ms-MY.ts +914 -914
  61. package/packages/locale/lang/nb-NO.ts +914 -914
  62. package/packages/locale/lang/pt-BR.ts +914 -914
  63. package/packages/locale/lang/ru-RU.ts +914 -914
  64. package/packages/locale/lang/th-TH.ts +914 -914
  65. package/packages/locale/lang/ug-CN.ts +914 -914
  66. package/packages/locale/lang/uk-UA.ts +914 -914
  67. package/packages/locale/lang/uz-UZ.ts +914 -914
  68. package/packages/locale/lang/vi-VN.ts +914 -914
  69. package/packages/locale/lang/zh-CHT.ts +914 -914
  70. package/packages/locale/lang/zh-CN.ts +914 -914
  71. package/packages/locale/lang/zh-HK.ts +914 -914
  72. package/packages/locale/lang/zh-MO.ts +914 -914
  73. package/packages/locale/lang/zh-TC.ts +914 -914
  74. package/packages/locale/lang/zh-TW.ts +914 -914
  75. package/packages/table/index.ts +26 -26
  76. package/packages/table/module/custom/hook.ts +510 -510
  77. package/packages/table/module/custom/panel.ts +2002 -2002
  78. package/packages/table/module/edit/hook.ts +1232 -1232
  79. package/packages/table/module/export/export-panel.ts +697 -697
  80. package/packages/table/module/export/hook.ts +2158 -2158
  81. package/packages/table/module/export/import-panel.ts +319 -319
  82. package/packages/table/module/export/util.ts +25 -25
  83. package/packages/table/module/filter/hook.ts +505 -505
  84. package/packages/table/module/filter/panel.ts +368 -368
  85. package/packages/table/module/keyboard/hook.ts +498 -498
  86. package/packages/table/module/menu/hook.ts +330 -330
  87. package/packages/table/module/menu/panel.ts +272 -272
  88. package/packages/table/module/validator/hook.ts +653 -653
  89. package/packages/table/render/index.ts +1819 -1819
  90. package/packages/table/src/body.ts +1078 -1078
  91. package/packages/table/src/cell.ts +1524 -1524
  92. package/packages/table/src/column.ts +192 -192
  93. package/packages/table/src/columnInfo.ts +232 -232
  94. package/packages/table/src/emits.ts +134 -134
  95. package/packages/table/src/footer.ts +425 -425
  96. package/packages/table/src/group.ts +67 -67
  97. package/packages/table/src/header.ts +661 -661
  98. package/packages/table/src/props.ts +336 -336
  99. package/packages/table/src/store.ts +14 -14
  100. package/packages/table/src/table.ts +8 -3
  101. package/packages/table/src/use/cell-view.ts +41 -41
  102. package/packages/table/src/use/index.ts +1 -1
  103. package/packages/table/src/util.ts +1206 -1206
  104. package/packages/toolbar/index.ts +18 -18
  105. package/packages/toolbar/src/toolbar.ts +768 -768
  106. package/packages/ui/abandon.ts +136 -0
  107. package/packages/ui/index.ts +404 -524
  108. package/packages/ui/src/anime.ts +51 -51
  109. package/packages/ui/src/comp.ts +3 -3
  110. package/packages/ui/src/dom.ts +466 -466
  111. package/packages/ui/src/log.ts +19 -19
  112. package/packages/ui/src/utils.ts +66 -66
  113. package/packages/ui/src/vn.ts +55 -55
  114. package/packages/v-x-e-table/index.d.ts +3 -3
  115. package/packages/v-x-e-table/index.ts +3 -3
  116. package/styles/components/table.scss +2 -1
  117. package/types/all.d.ts +76 -76
  118. package/types/index.d.ts +4 -4
  119. /package/dist/{iconfont.1794474448348.ttf → iconfont.1794983806256.ttf} +0 -0
  120. /package/dist/{iconfont.1794474448348.woff → iconfont.1794983806256.woff} +0 -0
  121. /package/dist/{iconfont.1794474448348.woff2 → iconfont.1794983806256.woff2} +0 -0
  122. /package/es/{iconfont.1794474448348.ttf → iconfont.1794983806256.ttf} +0 -0
  123. /package/es/{iconfont.1794474448348.woff → iconfont.1794983806256.woff} +0 -0
  124. /package/es/{iconfont.1794474448348.woff2 → iconfont.1794983806256.woff2} +0 -0
  125. /package/lib/{iconfont.1794474448348.ttf → iconfont.1794983806256.ttf} +0 -0
  126. /package/lib/{iconfont.1794474448348.woff → iconfont.1794983806256.woff} +0 -0
  127. /package/lib/{iconfont.1794474448348.woff2 → iconfont.1794983806256.woff2} +0 -0
@@ -1,2220 +1,2220 @@
1
- import { h, ref, computed, provide, reactive, onBeforeUnmount, watch, nextTick, VNode, onMounted } from 'vue'
2
- import { VxeUI } from '@vxe-ui/core'
3
- import { defineVxeComponent } from '../../ui/src/comp'
4
- import XEUtils from 'xe-utils'
5
- import { getLastZIndex, nextZIndex, isEnableConf } from '../../ui/src/utils'
6
- import { getOffsetHeight, getPaddingTopBottomSize, getDomNode, toCssUnit, hasClass } from '../../ui/src/dom'
7
- import { gridComponeProps } from './props'
8
- import { gridComponeEmits } from './emits'
9
- import { getSlotVNs } from '../../ui/src/vn'
10
- import { createComponentLog } from '../../ui/src/log'
11
- import { tableComponenEmits } from '../../table/src/emits'
12
- import { tableComponenProps } from '../../table/src/props'
13
- import VxeTableComponent from '../../table'
14
- import VxeToolbarComponent from '../../toolbar'
15
-
16
- import type { ValueOf, VxeFormEvents, VxeFormInstance, VxePagerEvents, VxeFormItemProps, VxePagerInstance, VxeComponentStyleType } from 'vxe-pc-ui'
17
- import type {
18
- VxeTableMethods,
19
- VxeGridConstructor,
20
- VxeGridEmits,
21
- GridReactData,
22
- GridInternalData,
23
- VxeGridPropTypes,
24
- VxeToolbarPropTypes,
25
- GridMethods,
26
- GridPrivateMethods,
27
- VxeGridPrivateComputed,
28
- VxeGridPrivateMethods,
29
- VxeToolbarInstance,
30
- GridPrivateRef,
31
- VxeTableProps,
32
- VxeTableConstructor,
33
- VxeTablePrivateMethods,
34
- VxeTableEvents,
35
- VxeTableDefines,
36
- VxeTableEventProps,
37
- VxeGridProps,
38
- VxeGridDefines
39
- } from '../../../types'
40
-
41
- const { warnLog, errLog } = createComponentLog('grid')
42
-
43
- const { getConfig, getI18n, commands, hooks, useFns, createEvent, globalEvents, GLOBAL_EVENT_KEYS, renderEmptyElement } = VxeUI
44
-
45
- const tableComponentPropKeys = Object.keys(tableComponenProps) as (keyof VxeTableProps)[]
46
- const tableComponentMethodKeys: (keyof VxeTableMethods)[] = [
47
- 'clearAll',
48
- 'syncData',
49
- 'updateData',
50
- 'loadData',
51
- 'reloadData',
52
- 'reloadRow',
53
- 'loadColumn',
54
- 'reloadColumn',
55
- 'getRowNode',
56
- 'getColumnNode',
57
- 'getRowIndex',
58
- 'getVTRowIndex',
59
- 'getVMRowIndex',
60
- 'getColumnIndex',
61
- 'getVTColumnIndex',
62
- 'getVMColumnIndex',
63
- 'setRow',
64
- 'createData',
65
- 'createRow',
66
- 'revertData',
67
- 'clearData',
68
- 'isRemoveByRow',
69
- 'isInsertByRow',
70
- 'isUpdateByRow',
71
- 'getColumns',
72
- 'getColumnById',
73
- 'getColumnByField',
74
- 'getTableColumn',
75
- 'getFullColumns',
76
- 'getData',
77
- 'getCheckboxRecords',
78
- 'getParentRow',
79
- 'getTreeRowChildren',
80
- 'getTreeRowLevel',
81
- 'getTreeParentRow',
82
- 'getRowSeq',
83
- 'getRowById',
84
- 'getRowid',
85
- 'getTableData',
86
- 'getFullData',
87
- 'setColumnFixed',
88
- 'clearColumnFixed',
89
- 'setColumnWidth',
90
- 'getColumnWidth',
91
- 'recalcRowHeight',
92
- 'setRowHeightConf',
93
- 'getRowHeightConf',
94
- 'setRowHeight',
95
- 'getRowHeight',
96
- 'hideColumn',
97
- 'showColumn',
98
- 'resetColumn',
99
- 'refreshColumn',
100
- 'refreshScroll',
101
- 'recalculate',
102
- 'closeTooltip',
103
- 'isAllCheckboxChecked',
104
- 'isAllCheckboxIndeterminate',
105
- 'getCheckboxIndeterminateRecords',
106
- 'setCheckboxRow',
107
- 'setCheckboxRowKey',
108
- 'isCheckedByCheckboxRow',
109
- 'isCheckedByCheckboxRowKey',
110
- 'isIndeterminateByCheckboxRow',
111
- 'isIndeterminateByCheckboxRowKey',
112
- 'toggleCheckboxRow',
113
- 'setAllCheckboxRow',
114
- 'getRadioReserveRecord',
115
- 'clearRadioReserve',
116
- 'getCheckboxReserveRecords',
117
- 'clearCheckboxReserve',
118
- 'toggleAllCheckboxRow',
119
- 'clearCheckboxRow',
120
- 'setCurrentRow',
121
- 'isCheckedByRadioRow',
122
- 'isCheckedByRadioRowKey',
123
- 'setRadioRow',
124
- 'setRadioRowKey',
125
- 'clearCurrentRow',
126
- 'clearRadioRow',
127
- 'getCurrentRecord',
128
- 'getRadioRecord',
129
- 'getCurrentColumn',
130
- 'setCurrentColumn',
131
- 'clearCurrentColumn',
132
- 'setPendingRow',
133
- 'togglePendingRow',
134
- 'hasPendingByRow',
135
- 'isPendingByRow',
136
- 'getPendingRecords',
137
- 'clearPendingRow',
138
- 'setFilterByEvent',
139
- 'sort',
140
- 'setSort',
141
- 'setSortByEvent',
142
- 'clearSort',
143
- 'clearSortByEvent',
144
- 'isSort',
145
- 'getSortColumns',
146
- 'closeFilter',
147
- 'isFilter',
148
- 'clearFilterByEvent',
149
- 'isActiveFilterByColumn',
150
- 'isRowExpandLoaded',
151
- 'clearRowExpandLoaded',
152
- 'reloadRowExpand',
153
- 'reloadRowExpand',
154
- 'toggleRowExpand',
155
- 'setAllRowExpand',
156
- 'setRowExpand',
157
- 'isExpandByRow',
158
- 'isRowExpandByRow',
159
- 'clearRowExpand',
160
- 'clearRowExpandReserve',
161
- 'getRowExpandRecords',
162
- 'getTreeExpandRecords',
163
- 'isTreeExpandLoaded',
164
- 'clearTreeExpandLoaded',
165
- 'reloadTreeExpand',
166
- 'reloadTreeChilds',
167
- 'toggleTreeExpand',
168
- 'setAllTreeExpand',
169
- 'setTreeExpand',
170
- 'isTreeExpandByRow',
171
- 'clearTreeExpand',
172
- 'clearTreeExpandReserve',
173
- 'getScroll',
174
- 'getScrollData',
175
- 'scrollTo',
176
- 'scrollToStartRow',
177
- 'scrollToEndRow',
178
- 'scrollToRow',
179
- 'scrollToStartColumn',
180
- 'scrollToEndColumn',
181
- 'scrollToColumn',
182
- 'clearScroll',
183
- 'updateFooter',
184
- 'updateStatus',
185
- 'setMergeCells',
186
- 'removeInsertRow',
187
- 'removeMergeCells',
188
- 'getMergeCells',
189
- 'setMergeHeaderCells',
190
- 'removeMergeHeaderCells',
191
- 'getMergeHeaderCells',
192
- 'clearMergeHeaderCells',
193
- 'clearMergeCells',
194
- 'setMergeFooterItems',
195
- 'removeMergeFooterItems',
196
- 'getMergeFooterItems',
197
- 'clearMergeFooterItems',
198
- 'setCustomStoreData',
199
- 'getCustomStoreData',
200
- 'setRowGroupExpand',
201
- 'setRowGroupExpandByField',
202
- 'setAllRowGroupExpand',
203
- 'clearRowGroupExpand',
204
- 'isRowGroupExpandByRow',
205
- 'isRowGroupRecord',
206
- 'isAggregateRecord',
207
- 'isAggregateExpandByRow',
208
- 'getAggregateContentByRow',
209
- 'getAggregateRowChildren',
210
- 'setRowGroups',
211
- 'clearRowGroups',
212
- 'openTooltip',
213
- 'moveColumnTo',
214
- 'moveRowTo',
215
- 'getCellLabel',
216
- 'updateCellLabel',
217
- 'clearFormatterCache',
218
- 'getFooterCellLabel',
219
- 'updateFooterCellLabel',
220
- 'clearFooterFormatterCache',
221
- 'getUpdateCells',
222
- 'undo',
223
- 'redo',
224
- 'effectCellData',
225
- 'getCellElement',
226
- 'focus',
227
- 'blur',
228
- 'connect',
229
- 'connectToolbar'
230
- ]
231
-
232
- function createReactData(): GridReactData {
233
- return {
234
- tableLoading: false,
235
- proxyInited: false,
236
- isZMax: false,
237
- tableData: [],
238
- filterData: [],
239
- formData: {},
240
- sortData: [],
241
- footerData: [],
242
- tZindex: 0,
243
- tablePage: {
244
- total: 0,
245
- pageSize: getConfig().pager?.pageSize || 10,
246
- currentPage: 1
247
- }
248
- }
249
- }
250
-
251
- function createInternalData(): GridInternalData {
252
- return {
253
- uFoot: false
254
- }
255
- }
256
-
257
- export default /* define-vxe-component start */ defineVxeComponent({
258
- name: 'VxeGrid',
259
- props: gridComponeProps,
260
- emits: gridComponeEmits,
261
- setup(props, context) {
262
- const { slots, emit } = context
263
-
264
- const xID = XEUtils.uniqueId()
265
-
266
- // 使用已安装的组件,如果未安装则不渲染
267
- const VxeUIFormComponent = VxeUI.getComponent('VxeForm')
268
- const VxeUIPagerComponent = VxeUI.getComponent('VxePager')
269
-
270
- const defaultLayouts: VxeGridPropTypes.Layouts = [['Form'], ['Toolbar', 'Top', 'Table', 'Bottom', 'Pager']]
271
-
272
- const { computeSize } = useFns.useSize(props)
273
- const { computeIsVScrollbar } = useFns.useVScrollbar(props)
274
-
275
- const reactData = reactive(createReactData())
276
-
277
- const internalData = createInternalData()
278
-
279
- const refElem = ref<HTMLDivElement>()
280
- const refTable = ref<VxeTableConstructor & VxeTablePrivateMethods>()
281
- const refForm = ref<VxeFormInstance>()
282
- const refToolbar = ref<VxeToolbarInstance>()
283
- const refPager = ref<VxePagerInstance>()
284
-
285
- const refPopupContainerElem = ref<HTMLDivElement>()
286
-
287
- const refFormWrapper = ref<HTMLDivElement>()
288
- const refToolbarWrapper = ref<HTMLDivElement>()
289
- const refTopWrapper = ref<HTMLDivElement>()
290
- const refBottomWrapper = ref<HTMLDivElement>()
291
- const refPagerWrapper = ref<HTMLDivElement>()
292
-
293
- const extendTableMethods = <T>(methodKeys: T[]) => {
294
- const funcs: any = {}
295
- methodKeys.forEach((name) => {
296
- funcs[name] = (...args: any[]) => {
297
- const $xeTable: any = refTable.value
298
- if ($xeTable && $xeTable[name]) {
299
- return $xeTable[name](...args)
300
- }
301
- }
302
- })
303
- return funcs
304
- }
305
-
306
- const gridExtendTableMethods = extendTableMethods(tableComponentMethodKeys) as VxeTableMethods
307
-
308
- const computeProxyOpts = computed(() => {
309
- return XEUtils.merge({}, XEUtils.clone(getConfig().grid.proxyConfig, true), props.proxyConfig)
310
- })
311
-
312
- const computeIsRespMsg = computed(() => {
313
- const proxyOpts = computeProxyOpts.value
314
- return !!(XEUtils.isBoolean(proxyOpts.message) ? proxyOpts.message : proxyOpts.showResponseMsg)
315
- })
316
-
317
- const computeIsActiveMsg = computed(() => {
318
- const proxyOpts = computeProxyOpts.value
319
- return XEUtils.isBoolean(proxyOpts.showActionMsg) ? proxyOpts.showActionMsg : !!proxyOpts.showActiveMsg
320
- })
321
-
322
- const computePagerOpts = computed(() => {
323
- return Object.assign({}, getConfig().grid.pagerConfig, props.pagerConfig)
324
- })
325
-
326
- const computePagerProps = computed(() => {
327
- const pagerOpts = computePagerOpts.value
328
- return Object.assign({}, pagerOpts, { enabled: undefined, slots: undefined })
329
- })
330
-
331
- const computeFormOpts = computed(() => {
332
- return Object.assign({}, getConfig().grid.formConfig, props.formConfig)
333
- })
334
-
335
- const computeToolbarOpts = computed(() => {
336
- return Object.assign({}, getConfig().grid.toolbarConfig, props.toolbarConfig)
337
- })
338
-
339
- const computeZoomOpts = computed(() => {
340
- return Object.assign({}, getConfig().grid.zoomConfig, props.zoomConfig)
341
- })
342
-
343
- const computeStyles = computed(() => {
344
- const { height, maxHeight } = props
345
- const { isZMax, tZindex } = reactData
346
- const stys: VxeComponentStyleType = {}
347
- if (isZMax) {
348
- stys.zIndex = tZindex
349
- } else {
350
- if (height) {
351
- stys.height = height === 'auto' || height === '100%' ? '100%' : toCssUnit(height)
352
- }
353
- if (maxHeight) {
354
- stys.maxHeight = maxHeight === 'auto' || maxHeight === '100%' ? '100%' : toCssUnit(maxHeight)
355
- }
356
- }
357
- return stys
358
- })
359
-
360
- const computeTableExtendProps = computed(() => {
361
- const rest: Record<string, any> = {}
362
- tableComponentPropKeys.forEach((key) => {
363
- if (props[key] !== undefined) {
364
- rest[key] = props[key]
365
- }
366
- })
367
- return rest
368
- })
369
-
370
- const computeTableProps = computed(() => {
371
- const { showFooter, seqConfig, pagerConfig, editConfig, proxyConfig } = props
372
- const { isZMax, tablePage, footerData } = reactData
373
- const tableExtendProps = computeTableExtendProps.value
374
- const proxyOpts = computeProxyOpts.value
375
- const pagerOpts = computePagerOpts.value
376
- const isLoading = computeIsLoading.value
377
- const tProps = Object.assign({}, tableExtendProps)
378
- if (showFooter && !tProps.footerData) {
379
- // 如果未设置自己的标位数据,则使用代理的
380
- tProps.footerData = footerData
381
- } else if (proxyOpts.footer && footerData.length) {
382
- // 如果代理标为数据,且未请求到数据,则用自己的
383
- tProps.footerData = footerData
384
- }
385
- if (isZMax) {
386
- if (tProps.maxHeight) {
387
- tProps.maxHeight = '100%'
388
- } else {
389
- tProps.height = '100%'
390
- }
391
- }
392
- if (proxyConfig && isEnableConf(proxyOpts)) {
393
- tProps.loading = isLoading
394
- if (pagerConfig && proxyOpts.seq && isEnableConf(pagerOpts)) {
395
- tProps.seqConfig = Object.assign({}, seqConfig, { startIndex: (tablePage.currentPage - 1) * tablePage.pageSize })
396
- }
397
- }
398
- if (editConfig) {
399
- tProps.editConfig = Object.assign({}, editConfig)
400
- }
401
- return tProps
402
- })
403
-
404
- const computeCurrLayoutConf = computed(() => {
405
- const { layouts } = props
406
- let confs: VxeGridPropTypes.Layouts = []
407
- if (layouts && layouts.length) {
408
- confs = layouts
409
- } else {
410
- confs = getConfig().grid.layouts || defaultLayouts
411
- }
412
- let headKeys: VxeGridDefines.LayoutKey[] = []
413
- let bodyKeys: VxeGridDefines.LayoutKey[] = []
414
- let footKeys: VxeGridDefines.LayoutKey[] = []
415
- if (confs.length) {
416
- if (XEUtils.isArray(confs[0])) {
417
- headKeys = confs[0] as VxeGridDefines.LayoutKey[]
418
- bodyKeys = (confs[1] || []) as VxeGridDefines.LayoutKey[]
419
- footKeys = (confs[2] || []) as VxeGridDefines.LayoutKey[]
420
- } else {
421
- bodyKeys = confs as VxeGridDefines.LayoutKey[]
422
- }
423
- }
424
- return {
425
- headKeys,
426
- bodyKeys,
427
- footKeys
428
- }
429
- })
430
-
431
- const computeCustomCurrentPageFlag = computed(() => {
432
- const pagerOpts = computePagerOpts.value
433
- return pagerOpts.currentPage
434
- })
435
-
436
- const computeCustomPageSizeFlag = computed(() => {
437
- const pagerOpts = computePagerOpts.value
438
- return pagerOpts.pageSize
439
- })
440
-
441
- const computeCustomTotalFlag = computed(() => {
442
- const pagerOpts = computePagerOpts.value
443
- return pagerOpts.total
444
- })
445
-
446
- const computePageCount = computed(() => {
447
- const { tablePage } = reactData
448
- return Math.max(Math.ceil(tablePage.total / tablePage.pageSize), 1)
449
- })
450
-
451
- const computeIsLoading = computed(() => {
452
- const { loading, proxyConfig } = props
453
- const { tableLoading } = reactData
454
- const proxyOpts = computeProxyOpts.value
455
- const { showLoading } = proxyOpts
456
- return loading || (tableLoading && showLoading && proxyConfig && isEnableConf(proxyOpts))
457
- })
458
-
459
- const refMaps: GridPrivateRef = {
460
- refElem,
461
- refTable,
462
- refForm,
463
- refToolbar,
464
- refPager,
465
- refPopupContainerElem
466
- }
467
-
468
- const computeMaps: VxeGridPrivateComputed = {
469
- computeSize,
470
- computeIsVScrollbar,
471
- computeProxyOpts,
472
- computePagerOpts,
473
- computeFormOpts,
474
- computeToolbarOpts,
475
- computeZoomOpts
476
- }
477
-
478
- const $xeGrid = {
479
- xID,
480
- props: props as VxeGridProps,
481
- context,
482
- reactData,
483
- internalData,
484
- getRefMaps: () => refMaps,
485
- getComputeMaps: () => computeMaps
486
- } as VxeGridConstructor & VxeGridPrivateMethods
487
-
488
- const initToolbar = () => {
489
- const toolbarOpts = computeToolbarOpts.value
490
- if (props.toolbarConfig && isEnableConf(toolbarOpts)) {
491
- nextTick(() => {
492
- const $xeTable = refTable.value
493
- const $xeToolbar = refToolbar.value
494
- if ($xeTable && $xeToolbar) {
495
- $xeTable.connectToolbar($xeToolbar)
496
- }
497
- })
498
- }
499
- }
500
-
501
- const getFormData = () => {
502
- const { proxyConfig } = props
503
- const { formData } = reactData
504
- const proxyOpts = computeProxyOpts.value
505
- const formOpts = computeFormOpts.value
506
- return proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form ? formData : formOpts.data
507
- }
508
-
509
- const initPages = (propKey?: 'currentPage' | 'pageSize' | 'total') => {
510
- const { tablePage } = reactData
511
- const { pagerConfig } = props
512
- const pagerOpts = computePagerOpts.value
513
- if (pagerConfig && isEnableConf(pagerOpts)) {
514
- if (propKey) {
515
- if (pagerOpts[propKey]) {
516
- tablePage[propKey] = XEUtils.toNumber(pagerOpts[propKey])
517
- }
518
- } else {
519
- const { currentPage, pageSize, total } = pagerOpts
520
- if (currentPage) {
521
- tablePage.currentPage = currentPage
522
- }
523
- if (pageSize) {
524
- tablePage.pageSize = pageSize
525
- }
526
- if (total) {
527
- tablePage.total = total
528
- }
529
- }
530
- }
531
- }
532
-
533
- const triggerPendingEvent = (code: string) => {
534
- const isActiveMsg = computeIsActiveMsg.value
535
- const $xeTable = refTable.value
536
- const selectRecords = $xeTable ? $xeTable.getCheckboxRecords() : []
537
- if (selectRecords.length) {
538
- if ($xeTable) {
539
- $xeTable.togglePendingRow(selectRecords)
540
- }
541
- $xeGrid.clearCheckboxRow()
542
- } else {
543
- if (isActiveMsg) {
544
- if (VxeUI.modal) {
545
- VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
546
- }
547
- }
548
- }
549
- }
550
-
551
- const getRespMsg = (rest: any, defaultMsg: string) => {
552
- const proxyOpts = computeProxyOpts.value
553
- const resConfigs = proxyOpts.response || proxyOpts.props || {}
554
- const messageProp = resConfigs.message
555
- const $xeTable = refTable.value
556
- let msg
557
- if (rest && messageProp) {
558
- msg = XEUtils.isFunction(messageProp) ? messageProp({ data: rest, $table: $xeTable as VxeTableConstructor, $grid: $xeGrid, $gantt: null }) : XEUtils.get(rest, messageProp)
559
- }
560
- return msg || getI18n(defaultMsg)
561
- }
562
-
563
- const handleDeleteRow = (code: string, alertKey: string, callback: () => void): Promise<void> => {
564
- const isActiveMsg = computeIsActiveMsg.value
565
- const selectRecords = $xeGrid.getCheckboxRecords()
566
- if (isActiveMsg) {
567
- if (selectRecords.length) {
568
- if (VxeUI.modal) {
569
- return VxeUI.modal.confirm({ id: `cfm_${code}`, content: getI18n(alertKey), escClosable: true }).then((type) => {
570
- if (type === 'confirm') {
571
- return callback()
572
- }
573
- })
574
- }
575
- } else {
576
- if (VxeUI.modal) {
577
- VxeUI.modal.message({ id: `msg_${code}`, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
578
- }
579
- }
580
- } else {
581
- if (selectRecords.length) {
582
- callback()
583
- }
584
- }
585
- return Promise.resolve()
586
- }
587
-
588
- const pageChangeEvent: VxePagerEvents.PageChange = (params) => {
589
- const { proxyConfig } = props
590
- const { tablePage } = reactData
591
- const { $event, currentPage, pageSize } = params
592
- const proxyOpts = computeProxyOpts.value
593
- tablePage.currentPage = currentPage
594
- tablePage.pageSize = pageSize
595
- $xeGrid.dispatchEvent('page-change', params, $event)
596
- if (proxyConfig && isEnableConf(proxyOpts)) {
597
- $xeGrid.commitProxy('query').then((rest) => {
598
- $xeGrid.dispatchEvent('proxy-query', rest, $event)
599
- })
600
- }
601
- }
602
-
603
- const handleSortEvent: VxeTableEvents.SortChange | VxeTableEvents.ClearAllSort = (params) => {
604
- const $xeTable = refTable.value
605
- const { proxyConfig } = props
606
- if (!$xeTable) {
607
- return
608
- }
609
- const { computeSortOpts } = $xeTable.getComputeMaps()
610
- const proxyOpts = computeProxyOpts.value
611
- const sortOpts = computeSortOpts.value
612
- // 如果是服务端排序
613
- if (sortOpts.remote) {
614
- reactData.sortData = params.sortList
615
- if (proxyConfig && isEnableConf(proxyOpts)) {
616
- reactData.tablePage.currentPage = 1
617
- $xeGrid.commitProxy('query').then((rest) => {
618
- $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
619
- })
620
- }
621
- }
622
- }
623
-
624
- const sortChangeEvent: VxeTableEvents.SortChange = (params) => {
625
- handleSortEvent(params)
626
- $xeGrid.dispatchEvent('sort-change', params, params.$event)
627
- }
628
-
629
- const clearAllSortEvent: VxeTableEvents.ClearAllSort = (params) => {
630
- handleSortEvent(params)
631
- $xeGrid.dispatchEvent('clear-all-sort', params, params.$event)
632
- }
633
-
634
- const handleFilterEvent: VxeTableEvents.FilterChange | VxeTableEvents.ClearAllFilter = (params) => {
635
- const $xeTable = refTable.value
636
- const { proxyConfig } = props
637
- if (!$xeTable) {
638
- return
639
- }
640
- const { computeFilterOpts } = $xeTable.getComputeMaps()
641
- const proxyOpts = computeProxyOpts.value
642
- const filterOpts = computeFilterOpts.value
643
- // 如果是服务端过滤
644
- if (filterOpts.remote) {
645
- reactData.filterData = params.filterList
646
- if (proxyConfig && isEnableConf(proxyOpts)) {
647
- reactData.tablePage.currentPage = 1
648
- internalData.uFoot = true
649
- $xeGrid.commitProxy('query').then((rest) => {
650
- $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
651
- })
652
- internalData.uFoot = false
653
- updateQueryFooter()
654
- }
655
- }
656
- }
657
-
658
- const filterChangeEvent: VxeTableEvents.FilterChange = (params) => {
659
- handleFilterEvent(params)
660
- $xeGrid.dispatchEvent('filter-change', params, params.$event)
661
- }
662
-
663
- const clearAllFilterEvent: VxeTableEvents.ClearAllFilter = (params) => {
664
- handleFilterEvent(params)
665
- $xeGrid.dispatchEvent('clear-all-filter', params, params.$event)
666
- }
667
-
668
- const submitFormEvent: VxeFormEvents.Submit = (params) => {
669
- const { proxyConfig } = props
670
- const proxyOpts = computeProxyOpts.value
671
- const formOptions = proxyOpts.formOptions || {}
672
- if (reactData.tableLoading) {
673
- return
674
- }
675
- if (proxyConfig && isEnableConf(proxyOpts)) {
676
- $xeGrid.dispatchEvent('form-submit', params, params.$event)
677
- internalData.uFoot = true
678
- $xeGrid.commitProxy(formOptions.submitMode || 'reload').then((rest) => {
679
- $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, params.$event)
680
- })
681
- internalData.uFoot = false
682
- updateQueryFooter()
683
- } else {
684
- $xeGrid.dispatchEvent('form-submit', params, params.$event)
685
- }
686
- }
687
-
688
- const resetFormEvent: VxeFormEvents.Reset = (params) => {
689
- const $xeTable = refTable.value
690
- const { proxyConfig } = props
691
- const { $event } = params
692
- const proxyOpts = computeProxyOpts.value
693
- if (proxyConfig && isEnableConf(proxyOpts)) {
694
- const formOptions = proxyOpts.formOptions || {}
695
- $xeGrid.dispatchEvent('form-reset', params, $event)
696
- if ($xeTable) {
697
- $xeTable.clearScroll()
698
- }
699
- internalData.uFoot = true
700
- $xeGrid.commitProxy(formOptions.resetMode === 'reset_form' ? 'query' : 'reload').then((rest) => {
701
- $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, $event)
702
- })
703
- internalData.uFoot = false
704
- updateQueryFooter()
705
- } else {
706
- $xeGrid.dispatchEvent('form-reset', params, $event)
707
- }
708
- }
709
-
710
- const submitInvalidEvent: VxeFormEvents.SubmitInvalid = (params) => {
711
- $xeGrid.dispatchEvent('form-submit-invalid', params, params.$event)
712
- }
713
-
714
- const collapseEvent: VxeFormEvents.Collapse = (params) => {
715
- const { $event } = params
716
- $xeGrid.dispatchEvent('form-toggle-collapse', params, $event)
717
- $xeGrid.dispatchEvent('form-collapse', params, $event)
718
- }
719
-
720
- const handleZoom = (isMax?: boolean) => {
721
- const { isZMax } = reactData
722
- if (isMax ? !isZMax : isZMax) {
723
- reactData.isZMax = !isZMax
724
- if (reactData.tZindex < getLastZIndex()) {
725
- reactData.tZindex = nextZIndex()
726
- }
727
- }
728
- return nextTick()
729
- .then(() => $xeGrid.recalculate(true))
730
- .then(() => {
731
- setTimeout(() => $xeGrid.recalculate(true), 15)
732
- return reactData.isZMax
733
- })
734
- }
735
-
736
- const getFuncSlot = (optSlots: any, slotKey: string) => {
737
- const funcSlot = optSlots[slotKey]
738
- if (funcSlot) {
739
- if (XEUtils.isString(funcSlot)) {
740
- if (slots[funcSlot]) {
741
- return slots[funcSlot]
742
- } else {
743
- errLog('vxe.error.notSlot', [funcSlot])
744
- }
745
- } else {
746
- return funcSlot
747
- }
748
- }
749
- return null
750
- }
751
-
752
- const getConfigSlot = (slotConfigs?: Record<string, any>) => {
753
- const slotConf: Record<string, any> = {}
754
- XEUtils.objectMap(slotConfigs, (slotFunc, slotKey) => {
755
- if (slotFunc) {
756
- if (XEUtils.isString(slotFunc)) {
757
- if (slots[slotFunc]) {
758
- slotConf[slotKey] = slots[slotFunc]
759
- } else {
760
- errLog('vxe.error.notSlot', [slotFunc])
761
- }
762
- } else {
763
- slotConf[slotKey] = slotFunc
764
- }
765
- }
766
- })
767
- return slotConf
768
- }
769
-
770
- /**
771
- * 渲染表单
772
- */
773
- const renderForm = () => {
774
- const { formConfig, proxyConfig } = props
775
- const { formData } = reactData
776
- const proxyOpts = computeProxyOpts.value
777
- const formOpts = computeFormOpts.value
778
- if ((formConfig && isEnableConf(formOpts)) || slots.form) {
779
- let slotVNs: VNode[] = []
780
- if (slots.form) {
781
- slotVNs = slots.form({ $grid: $xeGrid, $gantt: null })
782
- } else {
783
- if (formOpts.items) {
784
- const formSlots: { [key: string]: () => VNode[] } = {}
785
- if (!(formOpts as any).inited) {
786
- ;(formOpts as any).inited = true
787
- const beforeItem = proxyOpts.beforeItem
788
- if (proxyOpts && beforeItem) {
789
- formOpts.items.forEach((item) => {
790
- beforeItem({ $grid: $xeGrid, $gantt: null, item })
791
- })
792
- }
793
- }
794
- // 处理插槽
795
- formOpts.items.forEach((item) => {
796
- XEUtils.each(item.slots, (func) => {
797
- if (func && !XEUtils.isFunction(func)) {
798
- if (slots[func]) {
799
- formSlots[func] = slots[func] as any
800
- }
801
- }
802
- })
803
- })
804
- if (VxeUIFormComponent) {
805
- slotVNs.push(
806
- h(
807
- VxeUIFormComponent,
808
- {
809
- ref: refForm,
810
- ...Object.assign({}, formOpts, {
811
- data: proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form ? formData : formOpts.data
812
- }),
813
- onSubmit: submitFormEvent,
814
- onReset: resetFormEvent,
815
- onSubmitInvalid: submitInvalidEvent,
816
- onCollapse: collapseEvent
817
- },
818
- formSlots
819
- )
820
- )
821
- }
822
- }
823
- }
824
- return h(
825
- 'div',
826
- {
827
- ref: refFormWrapper,
828
- key: 'form',
829
- class: 'vxe-grid--form-wrapper'
830
- },
831
- slotVNs
832
- )
833
- }
834
- return renderEmptyElement($xeGrid)
835
- }
836
-
837
- /**
838
- * 渲染工具栏
839
- */
840
- const renderToolbar = () => {
841
- const { toolbarConfig } = props
842
- const toolbarOpts = computeToolbarOpts.value
843
- const toolbarSlot = slots.toolbar
844
- if ((toolbarConfig && isEnableConf(toolbarOpts)) || toolbarSlot) {
845
- let slotVNs: VNode[] = []
846
- if (toolbarSlot) {
847
- slotVNs = toolbarSlot({ $grid: $xeGrid, $gantt: null })
848
- } else {
849
- const toolbarOptSlots = toolbarOpts.slots
850
- const toolbarSlots: {
851
- buttons?(params: any): any
852
- buttonPrefix?(params: any): any
853
- buttonSuffix?(params: any): any
854
- tools?(params: any): any
855
- toolPrefix?(params: any): any
856
- toolSuffix?(params: any): any
857
- } = {}
858
- if (toolbarOptSlots) {
859
- const buttonsSlot = getFuncSlot(toolbarOptSlots, 'buttons')
860
- const buttonPrefixSlot = getFuncSlot(toolbarOptSlots, 'buttonPrefix')
861
- const buttonSuffixSlot = getFuncSlot(toolbarOptSlots, 'buttonSuffix')
862
- const toolsSlot = getFuncSlot(toolbarOptSlots, 'tools')
863
- const toolPrefixSlot = getFuncSlot(toolbarOptSlots, 'toolPrefix')
864
- const toolSuffixSlot = getFuncSlot(toolbarOptSlots, 'toolSuffix')
865
- if (buttonsSlot) {
866
- toolbarSlots.buttons = buttonsSlot
867
- }
868
- if (buttonPrefixSlot) {
869
- toolbarSlots.buttonPrefix = buttonPrefixSlot
870
- }
871
- if (buttonSuffixSlot) {
872
- toolbarSlots.buttonSuffix = buttonSuffixSlot
873
- }
874
- if (toolsSlot) {
875
- toolbarSlots.tools = toolsSlot
876
- }
877
- if (toolPrefixSlot) {
878
- toolbarSlots.toolPrefix = toolPrefixSlot
879
- }
880
- if (toolSuffixSlot) {
881
- toolbarSlots.toolSuffix = toolSuffixSlot
882
- }
883
- }
884
- slotVNs.push(
885
- h(
886
- VxeToolbarComponent,
887
- {
888
- ref: refToolbar,
889
- ...toolbarOpts,
890
- slots: undefined
891
- },
892
- toolbarSlots
893
- )
894
- )
895
- }
896
- return h(
897
- 'div',
898
- {
899
- ref: refToolbarWrapper,
900
- key: 'toolbar',
901
- class: 'vxe-grid--toolbar-wrapper'
902
- },
903
- slotVNs
904
- )
905
- }
906
- return renderEmptyElement($xeGrid)
907
- }
908
-
909
- /**
910
- * 渲染表格顶部区域
911
- */
912
- const renderTop = () => {
913
- const topSlot = slots.top
914
- if (topSlot) {
915
- return h(
916
- 'div',
917
- {
918
- ref: refTopWrapper,
919
- key: 'top',
920
- class: 'vxe-grid--top-wrapper'
921
- },
922
- topSlot({ $grid: $xeGrid, $gantt: null })
923
- )
924
- }
925
- return renderEmptyElement($xeGrid)
926
- }
927
-
928
- const renderTableLeft = () => {
929
- const leftSlot = slots.left
930
- if (leftSlot) {
931
- return h(
932
- 'div',
933
- {
934
- class: 'vxe-grid--left-wrapper'
935
- },
936
- leftSlot({ $grid: $xeGrid, $gantt: null })
937
- )
938
- }
939
- return renderEmptyElement($xeGrid)
940
- }
941
-
942
- const renderTableRight = () => {
943
- const rightSlot = slots.right
944
- if (rightSlot) {
945
- return h(
946
- 'div',
947
- {
948
- class: 'vxe-grid--right-wrapper'
949
- },
950
- rightSlot({ $grid: $xeGrid, $gantt: null })
951
- )
952
- }
953
- return renderEmptyElement($xeGrid)
954
- }
955
-
956
- /**
957
- * 渲染表格
958
- */
959
- const renderTable = () => {
960
- const { proxyConfig } = props
961
- const tableProps = computeTableProps.value
962
- const proxyOpts = computeProxyOpts.value
963
- const tableOns = Object.assign({}, tableCompEvents)
964
- const emptySlot = slots.empty
965
- const loadingSlot = slots.loading
966
- const rowDragIconSlot = slots.rowDragIcon || slots['row-drag-icon']
967
- const columnDragIconSlot = slots.columnDragIcon || slots['column-drag-icon']
968
- const headerTooltipSlot = slots.headerTooltip || slots['header-tooltip']
969
- const tooltipSlot = slots.tooltip
970
- const footerTooltipSlot = slots.footerTooltip || slots['footer-tooltip']
971
- if (proxyConfig && isEnableConf(proxyOpts)) {
972
- if (proxyOpts.sort) {
973
- tableOns.onSortChange = sortChangeEvent
974
- tableOns.onClearAllSort = clearAllSortEvent
975
- }
976
- if (proxyOpts.filter) {
977
- tableOns.onFilterChange = filterChangeEvent
978
- tableOns.onClearAllFilter = clearAllFilterEvent
979
- }
980
- }
981
- const slotObj: {
982
- empty?(params: any): any
983
- loading?(params: any): any
984
- rowDragIcon?(params: any): any
985
- columnDragIcon?(params: any): any
986
- headerTooltip?(params: any): any
987
- tooltip?(params: any): any
988
- footerTooltip?(params: any): any
989
- } = {}
990
- if (emptySlot) {
991
- slotObj.empty = emptySlot
992
- }
993
- if (loadingSlot) {
994
- slotObj.loading = loadingSlot
995
- }
996
- if (rowDragIconSlot) {
997
- slotObj.rowDragIcon = rowDragIconSlot
998
- }
999
- if (columnDragIconSlot) {
1000
- slotObj.columnDragIcon = columnDragIconSlot
1001
- }
1002
- if (headerTooltipSlot) {
1003
- slotObj.headerTooltip = headerTooltipSlot
1004
- }
1005
- if (tooltipSlot) {
1006
- slotObj.tooltip = tooltipSlot
1007
- }
1008
- if (footerTooltipSlot) {
1009
- slotObj.footerTooltip = footerTooltipSlot
1010
- }
1011
- return h(
1012
- 'div',
1013
- {
1014
- class: 'vxe-grid--table-wrapper'
1015
- },
1016
- [
1017
- h(
1018
- VxeTableComponent,
1019
- {
1020
- ref: refTable,
1021
- ...tableProps,
1022
- ...tableOns
1023
- },
1024
- slotObj
1025
- )
1026
- ]
1027
- )
1028
- }
1029
-
1030
- /**
1031
- * 渲染表格底部区域
1032
- */
1033
- const renderBottom = () => {
1034
- if (slots.bottom) {
1035
- return h(
1036
- 'div',
1037
- {
1038
- ref: refBottomWrapper,
1039
- key: 'bottom',
1040
- class: 'vxe-grid--bottom-wrapper'
1041
- },
1042
- slots.bottom({ $grid: $xeGrid, $gantt: null })
1043
- )
1044
- }
1045
- return renderEmptyElement($xeGrid)
1046
- }
1047
-
1048
- /**
1049
- * 渲染分页
1050
- */
1051
- const renderPager = () => {
1052
- const { proxyConfig, pagerConfig } = props
1053
- const proxyOpts = computeProxyOpts.value
1054
- const pagerOpts = computePagerOpts.value
1055
- const pagerProps = computePagerProps.value
1056
- const pagerSlot = slots.pager
1057
- if ((pagerConfig && isEnableConf(pagerOpts)) || slots.pager) {
1058
- return h(
1059
- 'div',
1060
- {
1061
- ref: refPagerWrapper,
1062
- key: 'pager',
1063
- class: 'vxe-grid--pager-wrapper'
1064
- },
1065
- pagerSlot
1066
- ? pagerSlot({ $grid: $xeGrid, $gantt: null })
1067
- : [
1068
- VxeUIPagerComponent
1069
- ? h(
1070
- VxeUIPagerComponent,
1071
- {
1072
- ref: refPager,
1073
- ...pagerProps,
1074
- ...(proxyConfig && isEnableConf(proxyOpts) ? reactData.tablePage : {}),
1075
- onPageChange: pageChangeEvent
1076
- },
1077
- getConfigSlot(pagerOpts.slots)
1078
- )
1079
- : renderEmptyElement($xeGrid)
1080
- ]
1081
- )
1082
- }
1083
- return renderEmptyElement($xeGrid)
1084
- }
1085
-
1086
- const renderChildLayout = (layoutKeys: VxeGridDefines.LayoutKey[]) => {
1087
- const childVNs: VNode[] = []
1088
- layoutKeys.forEach((key) => {
1089
- switch (key) {
1090
- case 'Form':
1091
- childVNs.push(renderForm())
1092
- break
1093
- case 'Toolbar':
1094
- childVNs.push(renderToolbar())
1095
- break
1096
- case 'Top':
1097
- childVNs.push(renderTop())
1098
- break
1099
- case 'Table':
1100
- childVNs.push(
1101
- h(
1102
- 'div',
1103
- {
1104
- key: 'table',
1105
- class: 'vxe-grid--table-container'
1106
- },
1107
- [renderTableLeft(), renderTable(), renderTableRight()]
1108
- )
1109
- )
1110
- break
1111
- case 'Bottom':
1112
- childVNs.push(renderBottom())
1113
- break
1114
- case 'Pager':
1115
- childVNs.push(renderPager())
1116
- break
1117
- default:
1118
- errLog('vxe.error.notProp', [`layouts -> ${key}`])
1119
- break
1120
- }
1121
- })
1122
- return childVNs
1123
- }
1124
-
1125
- const renderLayout = () => {
1126
- const currLayoutConf = computeCurrLayoutConf.value
1127
- const { headKeys, bodyKeys, footKeys } = currLayoutConf
1128
- const asideLeftSlot = slots.asideLeft || slots['aside-left']
1129
- const asideRightSlot = slots.asideRight || slots['aside-right']
1130
- return [
1131
- h(
1132
- 'div',
1133
- {
1134
- class: 'vxe-grid--layout-header-wrapper'
1135
- },
1136
- renderChildLayout(headKeys)
1137
- ),
1138
- h(
1139
- 'div',
1140
- {
1141
- class: 'vxe-grid--layout-body-wrapper'
1142
- },
1143
- [
1144
- asideLeftSlot
1145
- ? h(
1146
- 'div',
1147
- {
1148
- class: 'vxe-grid--layout-aside-left-wrapper'
1149
- },
1150
- asideLeftSlot({})
1151
- )
1152
- : renderEmptyElement($xeGrid),
1153
- h(
1154
- 'div',
1155
- {
1156
- class: 'vxe-grid--layout-body-content-wrapper'
1157
- },
1158
- renderChildLayout(bodyKeys)
1159
- ),
1160
- asideRightSlot
1161
- ? h(
1162
- 'div',
1163
- {
1164
- class: 'vxe-grid--layout-aside-right-wrapper'
1165
- },
1166
- asideRightSlot({})
1167
- )
1168
- : renderEmptyElement($xeGrid)
1169
- ]
1170
- ),
1171
- h(
1172
- 'div',
1173
- {
1174
- class: 'vxe-grid--layout-footer-wrapper'
1175
- },
1176
- renderChildLayout(footKeys)
1177
- ),
1178
- h('div', {
1179
- ref: refPopupContainerElem
1180
- })
1181
- ]
1182
- }
1183
-
1184
- const tableCompEvents: VxeTableEventProps = {}
1185
- tableComponenEmits.forEach((name) => {
1186
- const type = XEUtils.camelCase(`on-${name}`) as keyof VxeTableEventProps
1187
- tableCompEvents[type] = (...args: any[]) => emit(name, ...args)
1188
- })
1189
-
1190
- const getDefaultFormData = () => {
1191
- const formOpts = computeFormOpts.value
1192
- if (formOpts.items) {
1193
- const fData: any = {}
1194
- formOpts.items.forEach((item) => {
1195
- const { field, itemRender } = item
1196
- if (field) {
1197
- let itemValue: any = null
1198
- if (itemRender) {
1199
- const { startField, endField, defaultValue } = itemRender
1200
- if (XEUtils.isFunction(defaultValue)) {
1201
- itemValue = defaultValue({ item })
1202
- } else if (!XEUtils.isUndefined(defaultValue)) {
1203
- itemValue = defaultValue
1204
- }
1205
- if (startField && endField) {
1206
- XEUtils.set(fData, startField, null)
1207
- XEUtils.set(fData, endField, null)
1208
- }
1209
- }
1210
- fData[field] = itemValue
1211
- }
1212
- })
1213
- return fData
1214
- }
1215
- return {}
1216
- }
1217
-
1218
- const initProxy = () => {
1219
- const { proxyConfig, formConfig } = props
1220
- const { proxyInited } = reactData
1221
- const proxyOpts = computeProxyOpts.value
1222
- const formOpts = computeFormOpts.value
1223
- if (proxyConfig && isEnableConf(proxyOpts)) {
1224
- if (formConfig && isEnableConf(formOpts) && proxyOpts.form && formOpts.items) {
1225
- reactData.formData = getDefaultFormData()
1226
- }
1227
- if (!proxyInited) {
1228
- reactData.proxyInited = true
1229
- if (proxyOpts.autoLoad !== false) {
1230
- nextTick()
1231
- .then(() => {
1232
- internalData.uFoot = true
1233
- const rest = $xeGrid.commitProxy('initial')
1234
- internalData.uFoot = false
1235
- updateQueryFooter()
1236
- return rest
1237
- })
1238
- .then((rest) => {
1239
- dispatchEvent('proxy-query', { ...rest, isInited: true }, new Event('initial'))
1240
- })
1241
- }
1242
- }
1243
- }
1244
- }
1245
-
1246
- const updateQueryFooter = () => {
1247
- const proxyOpts = computeProxyOpts.value
1248
- const { ajax } = proxyOpts
1249
- if (ajax && ajax.queryFooter) {
1250
- return $xeGrid.commitProxy('queryFooter')
1251
- }
1252
- }
1253
-
1254
- const handleGlobalKeydownEvent = (evnt: KeyboardEvent) => {
1255
- const zoomOpts = computeZoomOpts.value
1256
- const isEsc = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ESCAPE)
1257
- if (isEsc && reactData.isZMax && zoomOpts.escRestore !== false) {
1258
- $xeGrid.triggerZoomEvent(evnt)
1259
- }
1260
- }
1261
-
1262
- const dispatchEvent = (type: ValueOf<VxeGridEmits>, params: Record<string, any>, evnt: Event | null) => {
1263
- emit(type, createEvent(evnt, { $grid: $xeGrid, $gantt: null }, params))
1264
- }
1265
-
1266
- const gridMethods: GridMethods = {
1267
- dispatchEvent,
1268
- getEl() {
1269
- return refElem.value as HTMLDivElement
1270
- },
1271
- /**
1272
- * 提交指令,支持 code 或 button
1273
- * @param {String/Object} code 字符串或对象
1274
- */
1275
- commitProxy(proxyTarget: string | VxeToolbarPropTypes.ButtonConfig, ...args: any[]) {
1276
- const { showFooter, proxyConfig, toolbarConfig, pagerConfig, editRules, validConfig } = props
1277
- const { tablePage } = reactData
1278
- const isActiveMsg = computeIsActiveMsg.value
1279
- const isRespMsg = computeIsRespMsg.value
1280
- const proxyOpts = computeProxyOpts.value
1281
- const pagerOpts = computePagerOpts.value
1282
- const toolbarOpts = computeToolbarOpts.value
1283
- const { beforeQuery: oldBeforeQuery, afterQuery: oldAfterQuery, beforeQueryFooter: oldBeforeQueryFooter, afterQueryFooter: oldAfterQueryFooter, beforeDelete: oldBeforeDelete, afterDelete: oldAfterDelete, beforeSave: oldBeforeSave, afterSave: oldAfterSave, ajax = {} } = proxyOpts
1284
- const resConfigs = (proxyOpts.response || proxyOpts.props || {}) as VxeGridDefines.ProxyConfigResponseConfig
1285
- const $xeTable = refTable.value
1286
- if (!$xeTable) {
1287
- return nextTick()
1288
- }
1289
- let formData = getFormData()
1290
- let button: VxeToolbarPropTypes.ButtonConfig | null = null
1291
- let code: string | null = null
1292
- if (XEUtils.isString(proxyTarget)) {
1293
- const { buttons } = toolbarOpts
1294
- const matchObj = toolbarConfig && isEnableConf(toolbarOpts) && buttons ? XEUtils.findTree(buttons, (item) => item.code === proxyTarget, { children: 'dropdowns' }) : null
1295
- button = matchObj ? matchObj.item : null
1296
- code = proxyTarget
1297
- } else {
1298
- button = proxyTarget
1299
- code = button.code as string
1300
- }
1301
- const btnParams = button ? button.params : null
1302
- switch (code) {
1303
- case 'insert':
1304
- return $xeTable.insert({})
1305
- case 'insert_edit':
1306
- return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
1307
-
1308
- // 已废弃
1309
- case 'insert_actived':
1310
- return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
1311
- // 已废弃
1312
-
1313
- case 'mark_cancel':
1314
- triggerPendingEvent(code)
1315
- break
1316
- case 'remove':
1317
- return handleDeleteRow(code, 'vxe.grid.removeSelectRecord', () => $xeTable.removeCheckboxRow())
1318
- case 'import':
1319
- $xeTable.importData(btnParams)
1320
- break
1321
- case 'open_import':
1322
- $xeTable.openImport(btnParams)
1323
- break
1324
- case 'export':
1325
- $xeTable.exportData(btnParams)
1326
- break
1327
- case 'open_export':
1328
- $xeTable.openExport(btnParams)
1329
- break
1330
- case 'reset_custom':
1331
- return $xeTable.resetCustom(true)
1332
- case 'initial':
1333
- case 'reload':
1334
- case 'query': {
1335
- const bqMethod = ajax.beforeQuery
1336
- const qMethod = ajax.query
1337
- const aqMethod = ajax.afterQuery
1338
- const qsMethod = ajax.querySuccess
1339
- const qeMethod = ajax.queryError
1340
- if (qMethod) {
1341
- const isInited = code === 'initial'
1342
- const isReload = code === 'reload'
1343
- if (!isInited && reactData.tableLoading) {
1344
- return nextTick()
1345
- }
1346
- let operPromise = null
1347
- let sortList: any[] = []
1348
- let filterList: VxeTableDefines.FilterCheckedParams[] = []
1349
- let pageParams: any = {}
1350
- if (pagerConfig) {
1351
- if (isInited || isReload) {
1352
- // 重置分页
1353
- tablePage.currentPage = 1
1354
- }
1355
- if (isEnableConf(pagerOpts)) {
1356
- pageParams = { ...tablePage }
1357
- }
1358
- }
1359
- if (isInited) {
1360
- // 重置代理表单数据
1361
- if (proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form) {
1362
- formData = getDefaultFormData()
1363
- reactData.formData = formData
1364
- }
1365
- if ($xeTable) {
1366
- const tableInternalData = $xeTable.internalData
1367
- const { tableFullColumn, fullColumnFieldData } = tableInternalData
1368
- const { computeSortOpts } = $xeTable.getComputeMaps()
1369
- const sortOpts = computeSortOpts.value
1370
- let defaultSort = sortOpts.defaultSort
1371
- tableFullColumn.forEach((column) => {
1372
- column.order = null
1373
- })
1374
- // 如果使用默认排序
1375
- if (defaultSort) {
1376
- if (!XEUtils.isArray(defaultSort)) {
1377
- defaultSort = [defaultSort]
1378
- }
1379
- sortList = defaultSort.map((item) => {
1380
- const { field, order } = item
1381
- const colRest = fullColumnFieldData[field]
1382
- if (colRest) {
1383
- const column = colRest.column
1384
- if (column) {
1385
- column.order = order
1386
- }
1387
- }
1388
- return {
1389
- field,
1390
- property: field,
1391
- order
1392
- }
1393
- })
1394
- }
1395
- filterList = $xeTable.getCheckedFilters()
1396
- }
1397
- } else {
1398
- if ($xeTable) {
1399
- if (isReload) {
1400
- operPromise = $xeTable.clearAll()
1401
- } else {
1402
- sortList = $xeTable.getSortColumns()
1403
- filterList = $xeTable.getCheckedFilters()
1404
- }
1405
- }
1406
- }
1407
- const commitParams = {
1408
- $table: $xeTable,
1409
- $grid: $xeGrid,
1410
- $gantt: null,
1411
- code,
1412
- button,
1413
- isInited,
1414
- isReload,
1415
- page: pageParams,
1416
- sort: sortList.length ? sortList[0] : {},
1417
- sorts: sortList,
1418
- filters: filterList,
1419
- form: formData,
1420
- options: qMethod
1421
- }
1422
-
1423
- const handleQuery = () => {
1424
- reactData.sortData = sortList
1425
- reactData.filterData = filterList
1426
- reactData.tableLoading = true
1427
- return Promise.all([Promise.resolve((oldBeforeQuery || qMethod)(commitParams, ...args)), operPromise])
1428
- .then(([rest]) => {
1429
- reactData.tableLoading = false
1430
- if (aqMethod) {
1431
- aqMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1432
- } else {
1433
- let tableData: any[] = []
1434
- if (rest) {
1435
- const listProp = resConfigs.list
1436
- const resultProp = resConfigs.result
1437
- const reParams = { data: rest, $table: $xeTable, $grid: $xeGrid, $gantt: null }
1438
- if (pagerConfig && isEnableConf(pagerOpts)) {
1439
- const totalProp = resConfigs.total
1440
- const total = (XEUtils.isFunction(totalProp) ? totalProp(reParams) : XEUtils.get(rest, totalProp || 'page.total')) || 0
1441
- tablePage.total = XEUtils.toNumber(total)
1442
- tableData = (XEUtils.isFunction(resultProp) ? resultProp(reParams) : XEUtils.get(rest, resultProp || 'result')) || []
1443
- // 检验当前页码,不能超出当前最大页数
1444
- const pageCount = Math.max(Math.ceil(total / tablePage.pageSize), 1)
1445
- if (tablePage.currentPage > pageCount) {
1446
- tablePage.currentPage = pageCount
1447
- }
1448
- } else {
1449
- if (XEUtils.isArray(rest)) {
1450
- tableData = rest
1451
- } else if (listProp) {
1452
- tableData = (XEUtils.isFunction(listProp) ? listProp(reParams) : XEUtils.get(rest, listProp)) || []
1453
- }
1454
- }
1455
- if (showFooter) {
1456
- const fdProp = resConfigs.footerData
1457
- const footerList = fdProp ? (XEUtils.isFunction(fdProp) ? fdProp(reParams) : XEUtils.get(rest, fdProp)) : []
1458
- if (XEUtils.isArray(footerList)) {
1459
- reactData.footerData = footerList
1460
- }
1461
- }
1462
- }
1463
- if ($xeTable) {
1464
- $xeTable.loadData(tableData)
1465
- } else {
1466
- nextTick(() => {
1467
- const $xeTable = refTable.value
1468
- if ($xeTable) {
1469
- $xeTable.loadData(tableData)
1470
- }
1471
- })
1472
- }
1473
- if (oldAfterQuery) {
1474
- oldAfterQuery({ ...commitParams, response: rest }, ...args)
1475
- }
1476
- }
1477
-
1478
- if (qsMethod) {
1479
- qsMethod({ ...commitParams, response: rest })
1480
- }
1481
- return { status: true }
1482
- })
1483
- .catch((rest) => {
1484
- reactData.tableLoading = false
1485
- if (aqMethod) {
1486
- aqMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1487
- }
1488
- if (qeMethod) {
1489
- qeMethod({ ...commitParams, response: rest })
1490
- }
1491
- return { status: false }
1492
- })
1493
- }
1494
-
1495
- if (bqMethod) {
1496
- return Promise.resolve(bqMethod(commitParams, ...args)).then((status) => {
1497
- if (status !== false) {
1498
- return handleQuery()
1499
- }
1500
- })
1501
- }
1502
- return handleQuery()
1503
- } else {
1504
- errLog('vxe.error.notFunc', ['proxy-config.ajax.query'])
1505
- }
1506
- break
1507
- }
1508
- case 'queryFooter':
1509
- case 'query_footer': {
1510
- const bqfMethod = ajax.beforeQueryFooter
1511
- const qfMethod = ajax.queryFooter
1512
- const aqfMethod = ajax.afterQueryFooter
1513
- const qfSuccessMethod = ajax.queryFooterSuccess
1514
- const qfErrorMethod = ajax.queryFooterError
1515
- if (qfMethod) {
1516
- let filterList: VxeTableDefines.FilterCheckedParams[] = []
1517
- if ($xeTable) {
1518
- filterList = $xeTable.getCheckedFilters()
1519
- }
1520
- let pageParams: any = {}
1521
- if (pagerConfig) {
1522
- if (isEnableConf(pagerOpts)) {
1523
- pageParams = { ...tablePage }
1524
- }
1525
- }
1526
- const commitParams = {
1527
- $table: $xeTable,
1528
- $grid: $xeGrid,
1529
- $gantt: null,
1530
- code,
1531
- button,
1532
- page: pageParams,
1533
- filters: filterList,
1534
- form: formData,
1535
- options: qfMethod
1536
- }
1537
- const handleQueryFooter = () => {
1538
- return Promise.resolve((oldBeforeQueryFooter || qfMethod)(commitParams, ...args))
1539
- .then((rest) => {
1540
- if (aqfMethod) {
1541
- aqfMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1542
- } else {
1543
- reactData.footerData = XEUtils.isArray(rest) ? rest : []
1544
- if (oldAfterQueryFooter) {
1545
- oldAfterQueryFooter({ ...commitParams, response: rest }, ...args)
1546
- }
1547
- }
1548
- if (qfSuccessMethod) {
1549
- qfSuccessMethod({ ...commitParams, response: rest })
1550
- }
1551
- return { status: true }
1552
- })
1553
- .catch((rest) => {
1554
- if (aqfMethod) {
1555
- aqfMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1556
- }
1557
- if (qfErrorMethod) {
1558
- qfErrorMethod({ ...commitParams, response: rest })
1559
- }
1560
- return { status: false }
1561
- })
1562
- }
1563
- if (bqfMethod) {
1564
- return Promise.resolve(bqfMethod(commitParams, ...args)).then((status) => {
1565
- if (status !== false) {
1566
- return handleQueryFooter()
1567
- }
1568
- })
1569
- }
1570
- return handleQueryFooter()
1571
- } else {
1572
- errLog('vxe.error.notFunc', ['proxy-config.ajax.queryFooter'])
1573
- }
1574
- break
1575
- }
1576
- case 'delete': {
1577
- const bdMethod = ajax.beforeDelete
1578
- const dMethod = ajax.delete
1579
- const adMethod = ajax.afterDelete
1580
- const deleteSuccessMethods = ajax.deleteSuccess
1581
- const deleteErrorMethods = ajax.deleteError
1582
- if (dMethod) {
1583
- const selectRecords = $xeGrid.getCheckboxRecords()
1584
- const removeRecords = selectRecords.filter((row) => !$xeTable.isInsertByRow(row))
1585
- const body = { removeRecords }
1586
- const commitParams = {
1587
- $table: $xeTable,
1588
- $grid: $xeGrid,
1589
- $gantt: null,
1590
- code,
1591
- button,
1592
- body,
1593
- form: formData,
1594
- options: dMethod
1595
- }
1596
- if (selectRecords.length) {
1597
- return handleDeleteRow(code, 'vxe.grid.deleteSelectRecord', () => {
1598
- if (!removeRecords.length) {
1599
- return $xeTable.remove(selectRecords)
1600
- }
1601
-
1602
- const handleDelete = () => {
1603
- reactData.tableLoading = true
1604
- return Promise.resolve((oldBeforeDelete || dMethod)(commitParams, ...args))
1605
- .then((rest) => {
1606
- reactData.tableLoading = false
1607
- if (adMethod) {
1608
- adMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1609
- } else {
1610
- $xeTable.setPendingRow(removeRecords, false)
1611
- if (isRespMsg) {
1612
- if (VxeUI.modal) {
1613
- VxeUI.modal.message({ content: getRespMsg(rest, 'vxe.grid.delSuccess'), status: 'success' })
1614
- }
1615
- }
1616
- if (oldAfterDelete) {
1617
- oldAfterDelete({ ...commitParams, response: rest }, ...args)
1618
- } else {
1619
- internalData.uFoot = true
1620
- $xeGrid.commitProxy('query')
1621
- internalData.uFoot = false
1622
- updateQueryFooter()
1623
- }
1624
- }
1625
- if (deleteSuccessMethods) {
1626
- deleteSuccessMethods({ ...commitParams, response: rest })
1627
- }
1628
- return { status: true }
1629
- })
1630
- .catch((rest) => {
1631
- reactData.tableLoading = false
1632
- if (adMethod) {
1633
- adMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1634
- } else {
1635
- if (isRespMsg) {
1636
- if (VxeUI.modal) {
1637
- VxeUI.modal.message({ id: code, content: getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1638
- }
1639
- }
1640
- }
1641
- if (deleteErrorMethods) {
1642
- deleteErrorMethods({ ...commitParams, response: rest })
1643
- }
1644
- return { status: false }
1645
- })
1646
- }
1647
-
1648
- if (bdMethod) {
1649
- return Promise.resolve(bdMethod(commitParams, ...args)).then((status) => {
1650
- if (status !== false) {
1651
- return handleDelete()
1652
- }
1653
- })
1654
- }
1655
- return handleDelete()
1656
- })
1657
- } else {
1658
- if (isActiveMsg) {
1659
- if (VxeUI.modal) {
1660
- VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
1661
- }
1662
- }
1663
- }
1664
- } else {
1665
- errLog('vxe.error.notFunc', ['proxy-config.ajax.delete'])
1666
- }
1667
- break
1668
- }
1669
- case 'save': {
1670
- const bSaveMethod = ajax.beforeSave
1671
- const sMethod = ajax.save
1672
- const aSaveMethod = ajax.afterSave
1673
- const sSuccessMethod = ajax.saveSuccess
1674
- const sErrorMethod = ajax.saveError
1675
- if (sMethod) {
1676
- const body = $xeTable.getRecordset()
1677
- const { insertRecords, removeRecords, updateRecords, pendingRecords } = body
1678
- const commitParams = {
1679
- $table: $xeTable,
1680
- $grid: $xeGrid,
1681
- $gantt: null,
1682
- code,
1683
- button,
1684
- body,
1685
- form: formData,
1686
- options: sMethod
1687
- }
1688
- // 排除掉新增且标记为删除的数据
1689
- if (insertRecords.length) {
1690
- body.pendingRecords = pendingRecords.filter((row) => $xeTable.findRowIndexOf(insertRecords, row) === -1)
1691
- }
1692
- // 排除已标记为删除的数据
1693
- if (pendingRecords.length) {
1694
- body.insertRecords = insertRecords.filter((row) => $xeTable.findRowIndexOf(pendingRecords, row) === -1)
1695
- }
1696
- let restPromise: Promise<any> = Promise.resolve()
1697
- if (editRules) {
1698
- // 只校验新增和修改的数据
1699
- restPromise = $xeTable[validConfig && validConfig.msgMode === 'full' ? 'fullValidate' : 'validate'](body.insertRecords.concat(updateRecords))
1700
- }
1701
- return restPromise.then((errMap) => {
1702
- if (errMap) {
1703
- // 如果校验不通过
1704
- return
1705
- }
1706
- if (body.insertRecords.length || removeRecords.length || updateRecords.length || body.pendingRecords.length) {
1707
- const handleSave = () => {
1708
- reactData.tableLoading = true
1709
- return Promise.resolve((oldBeforeSave || sMethod)(commitParams, ...args))
1710
- .then((rest) => {
1711
- reactData.tableLoading = false
1712
- if (aSaveMethod) {
1713
- aSaveMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1714
- } else {
1715
- $xeTable.clearPendingRow()
1716
- if (isRespMsg) {
1717
- if (VxeUI.modal) {
1718
- VxeUI.modal.message({ content: getRespMsg(rest, 'vxe.grid.saveSuccess'), status: 'success' })
1719
- }
1720
- }
1721
- if (oldAfterSave) {
1722
- oldAfterSave({ ...commitParams, response: rest }, ...args)
1723
- } else {
1724
- internalData.uFoot = true
1725
- $xeGrid.commitProxy('query')
1726
- internalData.uFoot = false
1727
- updateQueryFooter()
1728
- }
1729
- }
1730
- if (sSuccessMethod) {
1731
- sSuccessMethod({ ...commitParams, response: rest })
1732
- }
1733
- return { status: true }
1734
- })
1735
- .catch((rest) => {
1736
- reactData.tableLoading = false
1737
- if (aSaveMethod) {
1738
- aSaveMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1739
- } else {
1740
- if (isRespMsg) {
1741
- if (VxeUI.modal) {
1742
- VxeUI.modal.message({ id: code, content: getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1743
- }
1744
- }
1745
- }
1746
- if (sErrorMethod) {
1747
- sErrorMethod({ ...commitParams, response: rest })
1748
- }
1749
- return { status: false }
1750
- })
1751
- }
1752
- if (bSaveMethod) {
1753
- return Promise.resolve(bSaveMethod(commitParams, ...args)).then((status) => {
1754
- if (status !== false) {
1755
- return handleSave()
1756
- }
1757
- })
1758
- }
1759
- return handleSave()
1760
- } else {
1761
- if (isActiveMsg) {
1762
- if (VxeUI.modal) {
1763
- VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.dataUnchanged'), status: 'info' })
1764
- }
1765
- }
1766
- }
1767
- })
1768
- } else {
1769
- errLog('vxe.error.notFunc', ['proxy-config.ajax.save'])
1770
- }
1771
- break
1772
- }
1773
- default: {
1774
- const gCommandOpts = commands.get(code)
1775
- if (gCommandOpts) {
1776
- const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
1777
- if (tCommandMethod) {
1778
- tCommandMethod({ code, button, $grid: $xeGrid, $table: $xeTable, $gantt: null }, ...args)
1779
- } else {
1780
- errLog('vxe.error.notCommands', [code])
1781
- }
1782
- }
1783
- }
1784
- }
1785
- return nextTick()
1786
- },
1787
- getParams() {
1788
- return props.params
1789
- },
1790
- zoom() {
1791
- if (reactData.isZMax) {
1792
- return $xeGrid.revert()
1793
- }
1794
- return $xeGrid.maximize()
1795
- },
1796
- isMaximized() {
1797
- return reactData.isZMax
1798
- },
1799
- maximize() {
1800
- return handleZoom(true)
1801
- },
1802
- revert() {
1803
- return handleZoom()
1804
- },
1805
- getFormData,
1806
- /**
1807
- * 已废弃,被 getFormFlatItems 替换
1808
- * @deprecated
1809
- */
1810
- getFormItems(itemIndex?: number): any {
1811
- const formOpts = computeFormOpts.value
1812
- const { formConfig } = props
1813
- const { items } = formOpts
1814
- const itemList: VxeFormItemProps[] = []
1815
- XEUtils.eachTree(
1816
- formConfig && isEnableConf(formOpts) && items ? items : [],
1817
- (item) => {
1818
- itemList.push(item)
1819
- },
1820
- { children: 'children' }
1821
- )
1822
- // errLog('vxe.error.delFunc', ['getFormItems', 'getFormFlatItems'])
1823
- return XEUtils.isUndefined(itemIndex) ? itemList : itemList[itemIndex]
1824
- },
1825
- getFormFlatItems() {
1826
- const $form = refForm.value
1827
- if ($form) {
1828
- return $form.getFlatItems()
1829
- }
1830
- return []
1831
- },
1832
- getFormNestedItems() {
1833
- const $form = refForm.value
1834
- if ($form) {
1835
- return $form.getNestedItems()
1836
- }
1837
- return []
1838
- },
1839
- getFormItemByField(field: string) {
1840
- const $form = refForm.value
1841
- if ($form) {
1842
- return $form.getItemByField(field)
1843
- }
1844
- return null
1845
- },
1846
- resetForm() {
1847
- const $form = refForm.value
1848
- if ($form) {
1849
- return $form.reset()
1850
- }
1851
- return nextTick()
1852
- },
1853
- validateForm() {
1854
- const $form = refForm.value
1855
- if ($form) {
1856
- return $form.validate()
1857
- }
1858
- return Promise.resolve()
1859
- },
1860
- validateFormField(field) {
1861
- const $form = refForm.value
1862
- if ($form) {
1863
- return $form.validateField(field)
1864
- }
1865
- return Promise.resolve()
1866
- },
1867
- clearFormValidate(field) {
1868
- const $form = refForm.value
1869
- if ($form) {
1870
- return $form.clearValidate(field)
1871
- }
1872
- return nextTick()
1873
- },
1874
- homePage() {
1875
- const { tablePage } = reactData
1876
- tablePage.currentPage = 1
1877
- return nextTick()
1878
- },
1879
- homePageByEvent(evnt) {
1880
- const $pager = refPager.value
1881
- if ($pager) {
1882
- $pager.homePageByEvent(evnt)
1883
- }
1884
- },
1885
- endPage() {
1886
- const { tablePage } = reactData
1887
- const pageCount = computePageCount.value
1888
- tablePage.currentPage = pageCount
1889
- return nextTick()
1890
- },
1891
- endPageByEvent(evnt) {
1892
- const $pager = refPager.value
1893
- if ($pager) {
1894
- $pager.endPageByEvent(evnt)
1895
- }
1896
- },
1897
- getCurrentPage() {
1898
- const { tablePage } = reactData
1899
- return tablePage.currentPage
1900
- },
1901
- setCurrentPage(currentPage) {
1902
- const { tablePage } = reactData
1903
- const pageCount = computePageCount.value
1904
- tablePage.currentPage = Math.min(pageCount, Math.max(1, XEUtils.toNumber(currentPage)))
1905
- return nextTick()
1906
- },
1907
- setCurrentPageByEvent(evnt, currentPage) {
1908
- const $pager = refPager.value
1909
- if ($pager) {
1910
- $pager.setCurrentPageByEvent(evnt, currentPage)
1911
- }
1912
- },
1913
- getPageSize() {
1914
- const { tablePage } = reactData
1915
- return tablePage.pageSize
1916
- },
1917
- setPageSize(pageSize) {
1918
- const { tablePage } = reactData
1919
- tablePage.pageSize = Math.max(1, XEUtils.toNumber(pageSize))
1920
- return nextTick()
1921
- },
1922
- setPageSizeByEvent(evnt, pageSize) {
1923
- const $pager = refPager.value
1924
- if ($pager) {
1925
- $pager.setPageSizeByEvent(evnt, pageSize)
1926
- }
1927
- },
1928
- getProxyInfo() {
1929
- const $xeTable = refTable.value
1930
- if (props.proxyConfig) {
1931
- const { sortData } = reactData
1932
- return {
1933
- data: $xeTable ? $xeTable.getFullData() : [],
1934
- filter: reactData.filterData,
1935
- form: getFormData(),
1936
- sort: sortData.length ? sortData[0] : {},
1937
- sorts: sortData,
1938
- pager: reactData.tablePage,
1939
- pendingRecords: $xeTable ? $xeTable.getPendingRecords() : []
1940
- }
1941
- }
1942
- return null
1943
- },
1944
- getCustomPagerData() {
1945
- const { pagerConfig } = props
1946
- const { tablePage } = reactData
1947
- const pagerOpts = computePagerOpts.value
1948
- if (pagerConfig && isEnableConf(pagerOpts)) {
1949
- return {
1950
- pSize: tablePage.pageSize
1951
- }
1952
- }
1953
- return {}
1954
- }
1955
- // setProxyInfo (options) {
1956
- // if (props.proxyConfig && options) {
1957
- // const { pager, form } = options
1958
- // const proxyOpts = computeProxyOpts.value
1959
- // if (pager) {
1960
- // if (pager.currentPage) {
1961
- // reactData.tablePage.currentPage = Number(pager.currentPage)
1962
- // }
1963
- // if (pager.pageSize) {
1964
- // reactData.tablePage.pageSize = Number(pager.pageSize)
1965
- // }
1966
- // }
1967
- // if (proxyOpts.form && form) {
1968
- // Object.assign(reactData.formData, form)
1969
- // }
1970
- // }
1971
- // return nextTick()
1972
- // }
1973
- }
1974
-
1975
- const gridPrivateMethods: GridPrivateMethods = {
1976
- extendTableMethods,
1977
- callSlot(slotFunc, params) {
1978
- if (slotFunc) {
1979
- if (XEUtils.isString(slotFunc)) {
1980
- slotFunc = slots[slotFunc] || null
1981
- }
1982
- if (XEUtils.isFunction(slotFunc)) {
1983
- return getSlotVNs(slotFunc(params))
1984
- }
1985
- }
1986
- return []
1987
- },
1988
- /**
1989
- * 获取需要排除的高度
1990
- */
1991
- getExcludeHeight() {
1992
- const { height } = props
1993
- const { isZMax } = reactData
1994
- const el = refElem.value
1995
- if (el) {
1996
- const formWrapper = refFormWrapper.value
1997
- const toolbarWrapper = refToolbarWrapper.value
1998
- const topWrapper = refTopWrapper.value
1999
- const bottomWrapper = refBottomWrapper.value
2000
- const pagerWrapper = refPagerWrapper.value
2001
- const parentEl = el.parentElement
2002
- let parentPaddingSize = 0
2003
- if (parentEl && (height === '100%' || height === 'auto')) {
2004
- parentPaddingSize = isZMax ? 0 : getPaddingTopBottomSize(parentEl)
2005
- }
2006
- return parentPaddingSize + getPaddingTopBottomSize(el) + getOffsetHeight(formWrapper) + getOffsetHeight(toolbarWrapper) + getOffsetHeight(topWrapper) + getOffsetHeight(bottomWrapper) + getOffsetHeight(pagerWrapper)
2007
- }
2008
- return 0
2009
- },
2010
- getParentElem() {
2011
- const el = refElem.value
2012
- if (!el) {
2013
- return null
2014
- }
2015
- let parentEl = el.parentElement
2016
- // 如果是虚拟滚动条
2017
- if (parentEl && hasClass(parentEl, 'vxe-scrollbar--view-inner')) {
2018
- parentEl = parentEl.parentElement
2019
- }
2020
- return parentEl
2021
- },
2022
- getParentHeight() {
2023
- const el = refElem.value
2024
- if (el) {
2025
- const parentEl = $xeGrid.getParentElem()
2026
- return (reactData.isZMax ? getDomNode().visibleHeight : parentEl ? XEUtils.toNumber(getComputedStyle(parentEl).height) : 0) - gridPrivateMethods.getExcludeHeight()
2027
- }
2028
- return 0
2029
- },
2030
- triggerToolbarCommitEvent(params, evnt) {
2031
- const { code } = params
2032
- if (code) {
2033
- const isUf = ['reload', 'delete', 'save'].includes(code)
2034
- if (isUf) {
2035
- internalData.uFoot = true
2036
- }
2037
- const rest = $xeGrid.commitProxy(params, evnt).then((rest) => {
2038
- if (rest && rest.status && ['query', 'reload', 'delete', 'save'].includes(code)) {
2039
- $xeGrid.dispatchEvent(code === 'delete' || code === 'save' ? `proxy-${code as 'delete' | 'save'}` : 'proxy-query', { ...rest, isReload: code === 'reload' }, evnt)
2040
- }
2041
- })
2042
- internalData.uFoot = false
2043
- if (isUf) {
2044
- updateQueryFooter()
2045
- }
2046
- return rest
2047
- }
2048
- return nextTick()
2049
- },
2050
- triggerToolbarBtnEvent(button, evnt) {
2051
- $xeGrid.triggerToolbarCommitEvent(button, evnt)
2052
- $xeGrid.dispatchEvent('toolbar-button-click', { code: button.code, button }, evnt)
2053
- },
2054
- triggerToolbarTolEvent(tool, evnt) {
2055
- $xeGrid.triggerToolbarCommitEvent(tool, evnt)
2056
- $xeGrid.dispatchEvent('toolbar-tool-click', { code: tool.code, tool }, evnt)
2057
- },
2058
- triggerZoomEvent(evnt) {
2059
- $xeGrid.zoom()
2060
- $xeGrid.dispatchEvent('zoom', { type: reactData.isZMax ? 'max' : 'revert' }, evnt)
2061
- }
2062
- }
2063
-
2064
- Object.assign($xeGrid, gridExtendTableMethods, gridMethods, gridPrivateMethods, {
2065
- // 检查插槽
2066
- loadColumn(columns: any[]) {
2067
- const $xeTable = refTable.value
2068
- XEUtils.eachTree(columns, (column) => {
2069
- if (column.slots) {
2070
- XEUtils.each(column.slots, (func) => {
2071
- if (func && !XEUtils.isFunction(func)) {
2072
- if (!slots[func]) {
2073
- errLog('vxe.error.notSlot', [func])
2074
- }
2075
- }
2076
- })
2077
- }
2078
- })
2079
- if ($xeTable) {
2080
- return $xeTable.loadColumn(columns)
2081
- }
2082
- return nextTick()
2083
- },
2084
- reloadColumn(columns: any[]) {
2085
- $xeGrid.clearAll()
2086
- return $xeGrid.loadColumn(columns)
2087
- }
2088
- })
2089
-
2090
- const renderVN = () => {
2091
- const vSize = computeSize.value
2092
- const styles = computeStyles.value
2093
- const isLoading = computeIsLoading.value
2094
- return h(
2095
- 'div',
2096
- {
2097
- ref: refElem,
2098
- class: [
2099
- 'vxe-grid',
2100
- {
2101
- [`size--${vSize}`]: vSize,
2102
- 'is--animat': !!props.animat,
2103
- 'is--round': props.round,
2104
- 'is--maximize': reactData.isZMax,
2105
- 'is--loading': isLoading
2106
- }
2107
- ],
2108
- style: styles
2109
- },
2110
- renderLayout()
2111
- )
2112
- }
2113
-
2114
- const columnFlag = ref(0)
2115
- watch(
2116
- () => (props.columns ? props.columns.length : -1),
2117
- () => {
2118
- columnFlag.value++
2119
- }
2120
- )
2121
- watch(
2122
- () => props.columns,
2123
- () => {
2124
- columnFlag.value++
2125
- }
2126
- )
2127
- watch(columnFlag, () => {
2128
- nextTick(() => $xeGrid.loadColumn(props.columns || []))
2129
- })
2130
-
2131
- watch(
2132
- () => props.toolbarConfig,
2133
- () => {
2134
- initToolbar()
2135
- }
2136
- )
2137
-
2138
- watch(computeCustomCurrentPageFlag, () => {
2139
- initPages('currentPage')
2140
- })
2141
-
2142
- watch(computeCustomPageSizeFlag, () => {
2143
- initPages('pageSize')
2144
- })
2145
-
2146
- watch(computeCustomTotalFlag, () => {
2147
- initPages('total')
2148
- })
2149
-
2150
- watch(
2151
- () => props.proxyConfig,
2152
- () => {
2153
- initProxy()
2154
- }
2155
- )
2156
-
2157
- hooks.forEach((options) => {
2158
- const { setupGrid } = options
2159
- if (setupGrid) {
2160
- const hookRest = setupGrid($xeGrid)
2161
- if (hookRest && XEUtils.isObject(hookRest)) {
2162
- Object.assign($xeGrid, hookRest)
2163
- }
2164
- }
2165
- })
2166
-
2167
- initPages()
2168
-
2169
- onMounted(() => {
2170
- nextTick(() => {
2171
- const { columns } = props
2172
- const proxyOpts = computeProxyOpts.value
2173
-
2174
- if (props.formConfig) {
2175
- if (!VxeUIFormComponent) {
2176
- errLog('vxe.error.reqComp', ['vxe-form'])
2177
- }
2178
- }
2179
- if (props.pagerConfig) {
2180
- if (!VxeUIPagerComponent) {
2181
- errLog('vxe.error.reqComp', ['vxe-pager'])
2182
- }
2183
- }
2184
-
2185
- // const { data, columns, proxyConfig } = props
2186
- // const formOpts = computeFormOpts.value
2187
- // if (isEnableConf(proxyConfig) && (data || (proxyOpts.form && formOpts.data))) {
2188
- // errLog('vxe.error.errConflicts', ['[grid] data', 'proxy-config'])
2189
- // }
2190
-
2191
- if (proxyOpts.props) {
2192
- warnLog('vxe.error.delProp', ['proxy-config.props', 'proxy-config.response'])
2193
- }
2194
-
2195
- if (columns && columns.length) {
2196
- $xeGrid.loadColumn(columns)
2197
- }
2198
- initToolbar()
2199
- initProxy()
2200
- })
2201
- globalEvents.on($xeGrid, 'keydown', handleGlobalKeydownEvent)
2202
- })
2203
-
2204
- onBeforeUnmount(() => {
2205
- globalEvents.off($xeGrid, 'keydown')
2206
- XEUtils.assign(reactData, createReactData())
2207
- XEUtils.assign(internalData, createInternalData())
2208
- })
2209
-
2210
- $xeGrid.renderVN = renderVN
2211
-
2212
- provide('$xeGrid', $xeGrid)
2213
- provide('$xeGantt', null)
2214
-
2215
- return $xeGrid
2216
- },
2217
- render() {
2218
- return this.renderVN()
2219
- }
2220
- }) /* define-vxe-component end */
1
+ import { h, ref, computed, provide, reactive, onBeforeUnmount, watch, nextTick, VNode, onMounted } from 'vue'
2
+ import { VxeUI } from '@vxe-ui/core'
3
+ import { defineVxeComponent } from '../../ui/src/comp'
4
+ import XEUtils from 'xe-utils'
5
+ import { getLastZIndex, nextZIndex, isEnableConf } from '../../ui/src/utils'
6
+ import { getOffsetHeight, getPaddingTopBottomSize, getDomNode, toCssUnit, hasClass } from '../../ui/src/dom'
7
+ import { gridComponeProps } from './props'
8
+ import { gridComponeEmits } from './emits'
9
+ import { getSlotVNs } from '../../ui/src/vn'
10
+ import { createComponentLog } from '../../ui/src/log'
11
+ import { tableComponenEmits } from '../../table/src/emits'
12
+ import { tableComponenProps } from '../../table/src/props'
13
+ import VxeTableComponent from '../../table'
14
+ import VxeToolbarComponent from '../../toolbar'
15
+
16
+ import type { ValueOf, VxeFormEvents, VxeFormInstance, VxePagerEvents, VxeFormItemProps, VxePagerInstance, VxeComponentStyleType } from 'vxe-pc-ui'
17
+ import type {
18
+ VxeTableMethods,
19
+ VxeGridConstructor,
20
+ VxeGridEmits,
21
+ GridReactData,
22
+ GridInternalData,
23
+ VxeGridPropTypes,
24
+ VxeToolbarPropTypes,
25
+ GridMethods,
26
+ GridPrivateMethods,
27
+ VxeGridPrivateComputed,
28
+ VxeGridPrivateMethods,
29
+ VxeToolbarInstance,
30
+ GridPrivateRef,
31
+ VxeTableProps,
32
+ VxeTableConstructor,
33
+ VxeTablePrivateMethods,
34
+ VxeTableEvents,
35
+ VxeTableDefines,
36
+ VxeTableEventProps,
37
+ VxeGridProps,
38
+ VxeGridDefines
39
+ } from '../../../types'
40
+
41
+ const { warnLog, errLog } = createComponentLog('grid')
42
+
43
+ const { getConfig, getI18n, commands, hooks, useFns, createEvent, globalEvents, GLOBAL_EVENT_KEYS, renderEmptyElement } = VxeUI
44
+
45
+ const tableComponentPropKeys = Object.keys(tableComponenProps) as (keyof VxeTableProps)[]
46
+ const tableComponentMethodKeys: (keyof VxeTableMethods)[] = [
47
+ 'clearAll',
48
+ 'syncData',
49
+ 'updateData',
50
+ 'loadData',
51
+ 'reloadData',
52
+ 'reloadRow',
53
+ 'loadColumn',
54
+ 'reloadColumn',
55
+ 'getRowNode',
56
+ 'getColumnNode',
57
+ 'getRowIndex',
58
+ 'getVTRowIndex',
59
+ 'getVMRowIndex',
60
+ 'getColumnIndex',
61
+ 'getVTColumnIndex',
62
+ 'getVMColumnIndex',
63
+ 'setRow',
64
+ 'createData',
65
+ 'createRow',
66
+ 'revertData',
67
+ 'clearData',
68
+ 'isRemoveByRow',
69
+ 'isInsertByRow',
70
+ 'isUpdateByRow',
71
+ 'getColumns',
72
+ 'getColumnById',
73
+ 'getColumnByField',
74
+ 'getTableColumn',
75
+ 'getFullColumns',
76
+ 'getData',
77
+ 'getCheckboxRecords',
78
+ 'getParentRow',
79
+ 'getTreeRowChildren',
80
+ 'getTreeRowLevel',
81
+ 'getTreeParentRow',
82
+ 'getRowSeq',
83
+ 'getRowById',
84
+ 'getRowid',
85
+ 'getTableData',
86
+ 'getFullData',
87
+ 'setColumnFixed',
88
+ 'clearColumnFixed',
89
+ 'setColumnWidth',
90
+ 'getColumnWidth',
91
+ 'recalcRowHeight',
92
+ 'setRowHeightConf',
93
+ 'getRowHeightConf',
94
+ 'setRowHeight',
95
+ 'getRowHeight',
96
+ 'hideColumn',
97
+ 'showColumn',
98
+ 'resetColumn',
99
+ 'refreshColumn',
100
+ 'refreshScroll',
101
+ 'recalculate',
102
+ 'closeTooltip',
103
+ 'isAllCheckboxChecked',
104
+ 'isAllCheckboxIndeterminate',
105
+ 'getCheckboxIndeterminateRecords',
106
+ 'setCheckboxRow',
107
+ 'setCheckboxRowKey',
108
+ 'isCheckedByCheckboxRow',
109
+ 'isCheckedByCheckboxRowKey',
110
+ 'isIndeterminateByCheckboxRow',
111
+ 'isIndeterminateByCheckboxRowKey',
112
+ 'toggleCheckboxRow',
113
+ 'setAllCheckboxRow',
114
+ 'getRadioReserveRecord',
115
+ 'clearRadioReserve',
116
+ 'getCheckboxReserveRecords',
117
+ 'clearCheckboxReserve',
118
+ 'toggleAllCheckboxRow',
119
+ 'clearCheckboxRow',
120
+ 'setCurrentRow',
121
+ 'isCheckedByRadioRow',
122
+ 'isCheckedByRadioRowKey',
123
+ 'setRadioRow',
124
+ 'setRadioRowKey',
125
+ 'clearCurrentRow',
126
+ 'clearRadioRow',
127
+ 'getCurrentRecord',
128
+ 'getRadioRecord',
129
+ 'getCurrentColumn',
130
+ 'setCurrentColumn',
131
+ 'clearCurrentColumn',
132
+ 'setPendingRow',
133
+ 'togglePendingRow',
134
+ 'hasPendingByRow',
135
+ 'isPendingByRow',
136
+ 'getPendingRecords',
137
+ 'clearPendingRow',
138
+ 'setFilterByEvent',
139
+ 'sort',
140
+ 'setSort',
141
+ 'setSortByEvent',
142
+ 'clearSort',
143
+ 'clearSortByEvent',
144
+ 'isSort',
145
+ 'getSortColumns',
146
+ 'closeFilter',
147
+ 'isFilter',
148
+ 'clearFilterByEvent',
149
+ 'isActiveFilterByColumn',
150
+ 'isRowExpandLoaded',
151
+ 'clearRowExpandLoaded',
152
+ 'reloadRowExpand',
153
+ 'reloadRowExpand',
154
+ 'toggleRowExpand',
155
+ 'setAllRowExpand',
156
+ 'setRowExpand',
157
+ 'isExpandByRow',
158
+ 'isRowExpandByRow',
159
+ 'clearRowExpand',
160
+ 'clearRowExpandReserve',
161
+ 'getRowExpandRecords',
162
+ 'getTreeExpandRecords',
163
+ 'isTreeExpandLoaded',
164
+ 'clearTreeExpandLoaded',
165
+ 'reloadTreeExpand',
166
+ 'reloadTreeChilds',
167
+ 'toggleTreeExpand',
168
+ 'setAllTreeExpand',
169
+ 'setTreeExpand',
170
+ 'isTreeExpandByRow',
171
+ 'clearTreeExpand',
172
+ 'clearTreeExpandReserve',
173
+ 'getScroll',
174
+ 'getScrollData',
175
+ 'scrollTo',
176
+ 'scrollToStartRow',
177
+ 'scrollToEndRow',
178
+ 'scrollToRow',
179
+ 'scrollToStartColumn',
180
+ 'scrollToEndColumn',
181
+ 'scrollToColumn',
182
+ 'clearScroll',
183
+ 'updateFooter',
184
+ 'updateStatus',
185
+ 'setMergeCells',
186
+ 'removeInsertRow',
187
+ 'removeMergeCells',
188
+ 'getMergeCells',
189
+ 'setMergeHeaderCells',
190
+ 'removeMergeHeaderCells',
191
+ 'getMergeHeaderCells',
192
+ 'clearMergeHeaderCells',
193
+ 'clearMergeCells',
194
+ 'setMergeFooterItems',
195
+ 'removeMergeFooterItems',
196
+ 'getMergeFooterItems',
197
+ 'clearMergeFooterItems',
198
+ 'setCustomStoreData',
199
+ 'getCustomStoreData',
200
+ 'setRowGroupExpand',
201
+ 'setRowGroupExpandByField',
202
+ 'setAllRowGroupExpand',
203
+ 'clearRowGroupExpand',
204
+ 'isRowGroupExpandByRow',
205
+ 'isRowGroupRecord',
206
+ 'isAggregateRecord',
207
+ 'isAggregateExpandByRow',
208
+ 'getAggregateContentByRow',
209
+ 'getAggregateRowChildren',
210
+ 'setRowGroups',
211
+ 'clearRowGroups',
212
+ 'openTooltip',
213
+ 'moveColumnTo',
214
+ 'moveRowTo',
215
+ 'getCellLabel',
216
+ 'updateCellLabel',
217
+ 'clearFormatterCache',
218
+ 'getFooterCellLabel',
219
+ 'updateFooterCellLabel',
220
+ 'clearFooterFormatterCache',
221
+ 'getUpdateCells',
222
+ 'undo',
223
+ 'redo',
224
+ 'effectCellData',
225
+ 'getCellElement',
226
+ 'focus',
227
+ 'blur',
228
+ 'connect',
229
+ 'connectToolbar'
230
+ ]
231
+
232
+ function createReactData(): GridReactData {
233
+ return {
234
+ tableLoading: false,
235
+ proxyInited: false,
236
+ isZMax: false,
237
+ tableData: [],
238
+ filterData: [],
239
+ formData: {},
240
+ sortData: [],
241
+ footerData: [],
242
+ tZindex: 0,
243
+ tablePage: {
244
+ total: 0,
245
+ pageSize: getConfig().pager?.pageSize || 10,
246
+ currentPage: 1
247
+ }
248
+ }
249
+ }
250
+
251
+ function createInternalData(): GridInternalData {
252
+ return {
253
+ uFoot: false
254
+ }
255
+ }
256
+
257
+ export default /* define-vxe-component start */ defineVxeComponent({
258
+ name: 'VxeGrid',
259
+ props: gridComponeProps,
260
+ emits: gridComponeEmits,
261
+ setup(props, context) {
262
+ const { slots, emit } = context
263
+
264
+ const xID = XEUtils.uniqueId()
265
+
266
+ // 使用已安装的组件,如果未安装则不渲染
267
+ const VxeUIFormComponent = VxeUI.getComponent('VxeForm')
268
+ const VxeUIPagerComponent = VxeUI.getComponent('VxePager')
269
+
270
+ const defaultLayouts: VxeGridPropTypes.Layouts = [['Form'], ['Toolbar', 'Top', 'Table', 'Bottom', 'Pager']]
271
+
272
+ const { computeSize } = useFns.useSize(props)
273
+ const { computeIsVScrollbar } = useFns.useVScrollbar(props)
274
+
275
+ const reactData = reactive(createReactData())
276
+
277
+ const internalData = createInternalData()
278
+
279
+ const refElem = ref<HTMLDivElement>()
280
+ const refTable = ref<VxeTableConstructor & VxeTablePrivateMethods>()
281
+ const refForm = ref<VxeFormInstance>()
282
+ const refToolbar = ref<VxeToolbarInstance>()
283
+ const refPager = ref<VxePagerInstance>()
284
+
285
+ const refPopupContainerElem = ref<HTMLDivElement>()
286
+
287
+ const refFormWrapper = ref<HTMLDivElement>()
288
+ const refToolbarWrapper = ref<HTMLDivElement>()
289
+ const refTopWrapper = ref<HTMLDivElement>()
290
+ const refBottomWrapper = ref<HTMLDivElement>()
291
+ const refPagerWrapper = ref<HTMLDivElement>()
292
+
293
+ const extendTableMethods = <T>(methodKeys: T[]) => {
294
+ const funcs: any = {}
295
+ methodKeys.forEach((name) => {
296
+ funcs[name] = (...args: any[]) => {
297
+ const $xeTable: any = refTable.value
298
+ if ($xeTable && $xeTable[name]) {
299
+ return $xeTable[name](...args)
300
+ }
301
+ }
302
+ })
303
+ return funcs
304
+ }
305
+
306
+ const gridExtendTableMethods = extendTableMethods(tableComponentMethodKeys) as VxeTableMethods
307
+
308
+ const computeProxyOpts = computed(() => {
309
+ return XEUtils.merge({}, XEUtils.clone(getConfig().grid.proxyConfig, true), props.proxyConfig)
310
+ })
311
+
312
+ const computeIsRespMsg = computed(() => {
313
+ const proxyOpts = computeProxyOpts.value
314
+ return !!(XEUtils.isBoolean(proxyOpts.message) ? proxyOpts.message : proxyOpts.showResponseMsg)
315
+ })
316
+
317
+ const computeIsActiveMsg = computed(() => {
318
+ const proxyOpts = computeProxyOpts.value
319
+ return XEUtils.isBoolean(proxyOpts.showActionMsg) ? proxyOpts.showActionMsg : !!proxyOpts.showActiveMsg
320
+ })
321
+
322
+ const computePagerOpts = computed(() => {
323
+ return Object.assign({}, getConfig().grid.pagerConfig, props.pagerConfig)
324
+ })
325
+
326
+ const computePagerProps = computed(() => {
327
+ const pagerOpts = computePagerOpts.value
328
+ return Object.assign({}, pagerOpts, { enabled: undefined, slots: undefined })
329
+ })
330
+
331
+ const computeFormOpts = computed(() => {
332
+ return Object.assign({}, getConfig().grid.formConfig, props.formConfig)
333
+ })
334
+
335
+ const computeToolbarOpts = computed(() => {
336
+ return Object.assign({}, getConfig().grid.toolbarConfig, props.toolbarConfig)
337
+ })
338
+
339
+ const computeZoomOpts = computed(() => {
340
+ return Object.assign({}, getConfig().grid.zoomConfig, props.zoomConfig)
341
+ })
342
+
343
+ const computeStyles = computed(() => {
344
+ const { height, maxHeight } = props
345
+ const { isZMax, tZindex } = reactData
346
+ const stys: VxeComponentStyleType = {}
347
+ if (isZMax) {
348
+ stys.zIndex = tZindex
349
+ } else {
350
+ if (height) {
351
+ stys.height = height === 'auto' || height === '100%' ? '100%' : toCssUnit(height)
352
+ }
353
+ if (maxHeight) {
354
+ stys.maxHeight = maxHeight === 'auto' || maxHeight === '100%' ? '100%' : toCssUnit(maxHeight)
355
+ }
356
+ }
357
+ return stys
358
+ })
359
+
360
+ const computeTableExtendProps = computed(() => {
361
+ const rest: Record<string, any> = {}
362
+ tableComponentPropKeys.forEach((key) => {
363
+ if (props[key] !== undefined) {
364
+ rest[key] = props[key]
365
+ }
366
+ })
367
+ return rest
368
+ })
369
+
370
+ const computeTableProps = computed(() => {
371
+ const { showFooter, seqConfig, pagerConfig, editConfig, proxyConfig } = props
372
+ const { isZMax, tablePage, footerData } = reactData
373
+ const tableExtendProps = computeTableExtendProps.value
374
+ const proxyOpts = computeProxyOpts.value
375
+ const pagerOpts = computePagerOpts.value
376
+ const isLoading = computeIsLoading.value
377
+ const tProps = Object.assign({}, tableExtendProps)
378
+ if (showFooter && !tProps.footerData) {
379
+ // 如果未设置自己的标位数据,则使用代理的
380
+ tProps.footerData = footerData
381
+ } else if (proxyOpts.footer && footerData.length) {
382
+ // 如果代理标为数据,且未请求到数据,则用自己的
383
+ tProps.footerData = footerData
384
+ }
385
+ if (isZMax) {
386
+ if (tProps.maxHeight) {
387
+ tProps.maxHeight = '100%'
388
+ } else {
389
+ tProps.height = '100%'
390
+ }
391
+ }
392
+ if (proxyConfig && isEnableConf(proxyOpts)) {
393
+ tProps.loading = isLoading
394
+ if (pagerConfig && proxyOpts.seq && isEnableConf(pagerOpts)) {
395
+ tProps.seqConfig = Object.assign({}, seqConfig, { startIndex: (tablePage.currentPage - 1) * tablePage.pageSize })
396
+ }
397
+ }
398
+ if (editConfig) {
399
+ tProps.editConfig = Object.assign({}, editConfig)
400
+ }
401
+ return tProps
402
+ })
403
+
404
+ const computeCurrLayoutConf = computed(() => {
405
+ const { layouts } = props
406
+ let confs: VxeGridPropTypes.Layouts = []
407
+ if (layouts && layouts.length) {
408
+ confs = layouts
409
+ } else {
410
+ confs = getConfig().grid.layouts || defaultLayouts
411
+ }
412
+ let headKeys: VxeGridDefines.LayoutKey[] = []
413
+ let bodyKeys: VxeGridDefines.LayoutKey[] = []
414
+ let footKeys: VxeGridDefines.LayoutKey[] = []
415
+ if (confs.length) {
416
+ if (XEUtils.isArray(confs[0])) {
417
+ headKeys = confs[0] as VxeGridDefines.LayoutKey[]
418
+ bodyKeys = (confs[1] || []) as VxeGridDefines.LayoutKey[]
419
+ footKeys = (confs[2] || []) as VxeGridDefines.LayoutKey[]
420
+ } else {
421
+ bodyKeys = confs as VxeGridDefines.LayoutKey[]
422
+ }
423
+ }
424
+ return {
425
+ headKeys,
426
+ bodyKeys,
427
+ footKeys
428
+ }
429
+ })
430
+
431
+ const computeCustomCurrentPageFlag = computed(() => {
432
+ const pagerOpts = computePagerOpts.value
433
+ return pagerOpts.currentPage
434
+ })
435
+
436
+ const computeCustomPageSizeFlag = computed(() => {
437
+ const pagerOpts = computePagerOpts.value
438
+ return pagerOpts.pageSize
439
+ })
440
+
441
+ const computeCustomTotalFlag = computed(() => {
442
+ const pagerOpts = computePagerOpts.value
443
+ return pagerOpts.total
444
+ })
445
+
446
+ const computePageCount = computed(() => {
447
+ const { tablePage } = reactData
448
+ return Math.max(Math.ceil(tablePage.total / tablePage.pageSize), 1)
449
+ })
450
+
451
+ const computeIsLoading = computed(() => {
452
+ const { loading, proxyConfig } = props
453
+ const { tableLoading } = reactData
454
+ const proxyOpts = computeProxyOpts.value
455
+ const { showLoading } = proxyOpts
456
+ return loading || (tableLoading && showLoading && proxyConfig && isEnableConf(proxyOpts))
457
+ })
458
+
459
+ const refMaps: GridPrivateRef = {
460
+ refElem,
461
+ refTable,
462
+ refForm,
463
+ refToolbar,
464
+ refPager,
465
+ refPopupContainerElem
466
+ }
467
+
468
+ const computeMaps: VxeGridPrivateComputed = {
469
+ computeSize,
470
+ computeIsVScrollbar,
471
+ computeProxyOpts,
472
+ computePagerOpts,
473
+ computeFormOpts,
474
+ computeToolbarOpts,
475
+ computeZoomOpts
476
+ }
477
+
478
+ const $xeGrid = {
479
+ xID,
480
+ props: props as VxeGridProps,
481
+ context,
482
+ reactData,
483
+ internalData,
484
+ getRefMaps: () => refMaps,
485
+ getComputeMaps: () => computeMaps
486
+ } as VxeGridConstructor & VxeGridPrivateMethods
487
+
488
+ const initToolbar = () => {
489
+ const toolbarOpts = computeToolbarOpts.value
490
+ if (props.toolbarConfig && isEnableConf(toolbarOpts)) {
491
+ nextTick(() => {
492
+ const $xeTable = refTable.value
493
+ const $xeToolbar = refToolbar.value
494
+ if ($xeTable && $xeToolbar) {
495
+ $xeTable.connectToolbar($xeToolbar)
496
+ }
497
+ })
498
+ }
499
+ }
500
+
501
+ const getFormData = () => {
502
+ const { proxyConfig } = props
503
+ const { formData } = reactData
504
+ const proxyOpts = computeProxyOpts.value
505
+ const formOpts = computeFormOpts.value
506
+ return proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form ? formData : formOpts.data
507
+ }
508
+
509
+ const initPages = (propKey?: 'currentPage' | 'pageSize' | 'total') => {
510
+ const { tablePage } = reactData
511
+ const { pagerConfig } = props
512
+ const pagerOpts = computePagerOpts.value
513
+ if (pagerConfig && isEnableConf(pagerOpts)) {
514
+ if (propKey) {
515
+ if (pagerOpts[propKey]) {
516
+ tablePage[propKey] = XEUtils.toNumber(pagerOpts[propKey])
517
+ }
518
+ } else {
519
+ const { currentPage, pageSize, total } = pagerOpts
520
+ if (currentPage) {
521
+ tablePage.currentPage = currentPage
522
+ }
523
+ if (pageSize) {
524
+ tablePage.pageSize = pageSize
525
+ }
526
+ if (total) {
527
+ tablePage.total = total
528
+ }
529
+ }
530
+ }
531
+ }
532
+
533
+ const triggerPendingEvent = (code: string) => {
534
+ const isActiveMsg = computeIsActiveMsg.value
535
+ const $xeTable = refTable.value
536
+ const selectRecords = $xeTable ? $xeTable.getCheckboxRecords() : []
537
+ if (selectRecords.length) {
538
+ if ($xeTable) {
539
+ $xeTable.togglePendingRow(selectRecords)
540
+ }
541
+ $xeGrid.clearCheckboxRow()
542
+ } else {
543
+ if (isActiveMsg) {
544
+ if (VxeUI.modal) {
545
+ VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
546
+ }
547
+ }
548
+ }
549
+ }
550
+
551
+ const getRespMsg = (rest: any, defaultMsg: string) => {
552
+ const proxyOpts = computeProxyOpts.value
553
+ const resConfigs = proxyOpts.response || proxyOpts.props || {}
554
+ const messageProp = resConfigs.message
555
+ const $xeTable = refTable.value
556
+ let msg
557
+ if (rest && messageProp) {
558
+ msg = XEUtils.isFunction(messageProp) ? messageProp({ data: rest, $table: $xeTable as VxeTableConstructor, $grid: $xeGrid, $gantt: null }) : XEUtils.get(rest, messageProp)
559
+ }
560
+ return msg || getI18n(defaultMsg)
561
+ }
562
+
563
+ const handleDeleteRow = (code: string, alertKey: string, callback: () => void): Promise<void> => {
564
+ const isActiveMsg = computeIsActiveMsg.value
565
+ const selectRecords = $xeGrid.getCheckboxRecords()
566
+ if (isActiveMsg) {
567
+ if (selectRecords.length) {
568
+ if (VxeUI.modal) {
569
+ return VxeUI.modal.confirm({ id: `cfm_${code}`, content: getI18n(alertKey), escClosable: true }).then((type) => {
570
+ if (type === 'confirm') {
571
+ return callback()
572
+ }
573
+ })
574
+ }
575
+ } else {
576
+ if (VxeUI.modal) {
577
+ VxeUI.modal.message({ id: `msg_${code}`, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
578
+ }
579
+ }
580
+ } else {
581
+ if (selectRecords.length) {
582
+ callback()
583
+ }
584
+ }
585
+ return Promise.resolve()
586
+ }
587
+
588
+ const pageChangeEvent: VxePagerEvents.PageChange = (params) => {
589
+ const { proxyConfig } = props
590
+ const { tablePage } = reactData
591
+ const { $event, currentPage, pageSize } = params
592
+ const proxyOpts = computeProxyOpts.value
593
+ tablePage.currentPage = currentPage
594
+ tablePage.pageSize = pageSize
595
+ $xeGrid.dispatchEvent('page-change', params, $event)
596
+ if (proxyConfig && isEnableConf(proxyOpts)) {
597
+ $xeGrid.commitProxy('query').then((rest) => {
598
+ $xeGrid.dispatchEvent('proxy-query', rest, $event)
599
+ })
600
+ }
601
+ }
602
+
603
+ const handleSortEvent: VxeTableEvents.SortChange | VxeTableEvents.ClearAllSort = (params) => {
604
+ const $xeTable = refTable.value
605
+ const { proxyConfig } = props
606
+ if (!$xeTable) {
607
+ return
608
+ }
609
+ const { computeSortOpts } = $xeTable.getComputeMaps()
610
+ const proxyOpts = computeProxyOpts.value
611
+ const sortOpts = computeSortOpts.value
612
+ // 如果是服务端排序
613
+ if (sortOpts.remote) {
614
+ reactData.sortData = params.sortList
615
+ if (proxyConfig && isEnableConf(proxyOpts)) {
616
+ reactData.tablePage.currentPage = 1
617
+ $xeGrid.commitProxy('query').then((rest) => {
618
+ $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
619
+ })
620
+ }
621
+ }
622
+ }
623
+
624
+ const sortChangeEvent: VxeTableEvents.SortChange = (params) => {
625
+ handleSortEvent(params)
626
+ $xeGrid.dispatchEvent('sort-change', params, params.$event)
627
+ }
628
+
629
+ const clearAllSortEvent: VxeTableEvents.ClearAllSort = (params) => {
630
+ handleSortEvent(params)
631
+ $xeGrid.dispatchEvent('clear-all-sort', params, params.$event)
632
+ }
633
+
634
+ const handleFilterEvent: VxeTableEvents.FilterChange | VxeTableEvents.ClearAllFilter = (params) => {
635
+ const $xeTable = refTable.value
636
+ const { proxyConfig } = props
637
+ if (!$xeTable) {
638
+ return
639
+ }
640
+ const { computeFilterOpts } = $xeTable.getComputeMaps()
641
+ const proxyOpts = computeProxyOpts.value
642
+ const filterOpts = computeFilterOpts.value
643
+ // 如果是服务端过滤
644
+ if (filterOpts.remote) {
645
+ reactData.filterData = params.filterList
646
+ if (proxyConfig && isEnableConf(proxyOpts)) {
647
+ reactData.tablePage.currentPage = 1
648
+ internalData.uFoot = true
649
+ $xeGrid.commitProxy('query').then((rest) => {
650
+ $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
651
+ })
652
+ internalData.uFoot = false
653
+ updateQueryFooter()
654
+ }
655
+ }
656
+ }
657
+
658
+ const filterChangeEvent: VxeTableEvents.FilterChange = (params) => {
659
+ handleFilterEvent(params)
660
+ $xeGrid.dispatchEvent('filter-change', params, params.$event)
661
+ }
662
+
663
+ const clearAllFilterEvent: VxeTableEvents.ClearAllFilter = (params) => {
664
+ handleFilterEvent(params)
665
+ $xeGrid.dispatchEvent('clear-all-filter', params, params.$event)
666
+ }
667
+
668
+ const submitFormEvent: VxeFormEvents.Submit = (params) => {
669
+ const { proxyConfig } = props
670
+ const proxyOpts = computeProxyOpts.value
671
+ const formOptions = proxyOpts.formOptions || {}
672
+ if (reactData.tableLoading) {
673
+ return
674
+ }
675
+ if (proxyConfig && isEnableConf(proxyOpts)) {
676
+ $xeGrid.dispatchEvent('form-submit', params, params.$event)
677
+ internalData.uFoot = true
678
+ $xeGrid.commitProxy(formOptions.submitMode || 'reload').then((rest) => {
679
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, params.$event)
680
+ })
681
+ internalData.uFoot = false
682
+ updateQueryFooter()
683
+ } else {
684
+ $xeGrid.dispatchEvent('form-submit', params, params.$event)
685
+ }
686
+ }
687
+
688
+ const resetFormEvent: VxeFormEvents.Reset = (params) => {
689
+ const $xeTable = refTable.value
690
+ const { proxyConfig } = props
691
+ const { $event } = params
692
+ const proxyOpts = computeProxyOpts.value
693
+ if (proxyConfig && isEnableConf(proxyOpts)) {
694
+ const formOptions = proxyOpts.formOptions || {}
695
+ $xeGrid.dispatchEvent('form-reset', params, $event)
696
+ if ($xeTable) {
697
+ $xeTable.clearScroll()
698
+ }
699
+ internalData.uFoot = true
700
+ $xeGrid.commitProxy(formOptions.resetMode === 'reset_form' ? 'query' : 'reload').then((rest) => {
701
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, $event)
702
+ })
703
+ internalData.uFoot = false
704
+ updateQueryFooter()
705
+ } else {
706
+ $xeGrid.dispatchEvent('form-reset', params, $event)
707
+ }
708
+ }
709
+
710
+ const submitInvalidEvent: VxeFormEvents.SubmitInvalid = (params) => {
711
+ $xeGrid.dispatchEvent('form-submit-invalid', params, params.$event)
712
+ }
713
+
714
+ const collapseEvent: VxeFormEvents.Collapse = (params) => {
715
+ const { $event } = params
716
+ $xeGrid.dispatchEvent('form-toggle-collapse', params, $event)
717
+ $xeGrid.dispatchEvent('form-collapse', params, $event)
718
+ }
719
+
720
+ const handleZoom = (isMax?: boolean) => {
721
+ const { isZMax } = reactData
722
+ if (isMax ? !isZMax : isZMax) {
723
+ reactData.isZMax = !isZMax
724
+ if (reactData.tZindex < getLastZIndex()) {
725
+ reactData.tZindex = nextZIndex()
726
+ }
727
+ }
728
+ return nextTick()
729
+ .then(() => $xeGrid.recalculate(true))
730
+ .then(() => {
731
+ setTimeout(() => $xeGrid.recalculate(true), 15)
732
+ return reactData.isZMax
733
+ })
734
+ }
735
+
736
+ const getFuncSlot = (optSlots: any, slotKey: string) => {
737
+ const funcSlot = optSlots[slotKey]
738
+ if (funcSlot) {
739
+ if (XEUtils.isString(funcSlot)) {
740
+ if (slots[funcSlot]) {
741
+ return slots[funcSlot]
742
+ } else {
743
+ errLog('vxe.error.notSlot', [funcSlot])
744
+ }
745
+ } else {
746
+ return funcSlot
747
+ }
748
+ }
749
+ return null
750
+ }
751
+
752
+ const getConfigSlot = (slotConfigs?: Record<string, any>) => {
753
+ const slotConf: Record<string, any> = {}
754
+ XEUtils.objectMap(slotConfigs, (slotFunc, slotKey) => {
755
+ if (slotFunc) {
756
+ if (XEUtils.isString(slotFunc)) {
757
+ if (slots[slotFunc]) {
758
+ slotConf[slotKey] = slots[slotFunc]
759
+ } else {
760
+ errLog('vxe.error.notSlot', [slotFunc])
761
+ }
762
+ } else {
763
+ slotConf[slotKey] = slotFunc
764
+ }
765
+ }
766
+ })
767
+ return slotConf
768
+ }
769
+
770
+ /**
771
+ * 渲染表单
772
+ */
773
+ const renderForm = () => {
774
+ const { formConfig, proxyConfig } = props
775
+ const { formData } = reactData
776
+ const proxyOpts = computeProxyOpts.value
777
+ const formOpts = computeFormOpts.value
778
+ if ((formConfig && isEnableConf(formOpts)) || slots.form) {
779
+ let slotVNs: VNode[] = []
780
+ if (slots.form) {
781
+ slotVNs = slots.form({ $grid: $xeGrid, $gantt: null })
782
+ } else {
783
+ if (formOpts.items) {
784
+ const formSlots: { [key: string]: () => VNode[] } = {}
785
+ if (!(formOpts as any).inited) {
786
+ ;(formOpts as any).inited = true
787
+ const beforeItem = proxyOpts.beforeItem
788
+ if (proxyOpts && beforeItem) {
789
+ formOpts.items.forEach((item) => {
790
+ beforeItem({ $grid: $xeGrid, $gantt: null, item })
791
+ })
792
+ }
793
+ }
794
+ // 处理插槽
795
+ formOpts.items.forEach((item) => {
796
+ XEUtils.each(item.slots, (func) => {
797
+ if (func && !XEUtils.isFunction(func)) {
798
+ if (slots[func]) {
799
+ formSlots[func] = slots[func] as any
800
+ }
801
+ }
802
+ })
803
+ })
804
+ if (VxeUIFormComponent) {
805
+ slotVNs.push(
806
+ h(
807
+ VxeUIFormComponent,
808
+ {
809
+ ref: refForm,
810
+ ...Object.assign({}, formOpts, {
811
+ data: proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form ? formData : formOpts.data
812
+ }),
813
+ onSubmit: submitFormEvent,
814
+ onReset: resetFormEvent,
815
+ onSubmitInvalid: submitInvalidEvent,
816
+ onCollapse: collapseEvent
817
+ },
818
+ formSlots
819
+ )
820
+ )
821
+ }
822
+ }
823
+ }
824
+ return h(
825
+ 'div',
826
+ {
827
+ ref: refFormWrapper,
828
+ key: 'form',
829
+ class: 'vxe-grid--form-wrapper'
830
+ },
831
+ slotVNs
832
+ )
833
+ }
834
+ return renderEmptyElement($xeGrid)
835
+ }
836
+
837
+ /**
838
+ * 渲染工具栏
839
+ */
840
+ const renderToolbar = () => {
841
+ const { toolbarConfig } = props
842
+ const toolbarOpts = computeToolbarOpts.value
843
+ const toolbarSlot = slots.toolbar
844
+ if ((toolbarConfig && isEnableConf(toolbarOpts)) || toolbarSlot) {
845
+ let slotVNs: VNode[] = []
846
+ if (toolbarSlot) {
847
+ slotVNs = toolbarSlot({ $grid: $xeGrid, $gantt: null })
848
+ } else {
849
+ const toolbarOptSlots = toolbarOpts.slots
850
+ const toolbarSlots: {
851
+ buttons?(params: any): any
852
+ buttonPrefix?(params: any): any
853
+ buttonSuffix?(params: any): any
854
+ tools?(params: any): any
855
+ toolPrefix?(params: any): any
856
+ toolSuffix?(params: any): any
857
+ } = {}
858
+ if (toolbarOptSlots) {
859
+ const buttonsSlot = getFuncSlot(toolbarOptSlots, 'buttons')
860
+ const buttonPrefixSlot = getFuncSlot(toolbarOptSlots, 'buttonPrefix')
861
+ const buttonSuffixSlot = getFuncSlot(toolbarOptSlots, 'buttonSuffix')
862
+ const toolsSlot = getFuncSlot(toolbarOptSlots, 'tools')
863
+ const toolPrefixSlot = getFuncSlot(toolbarOptSlots, 'toolPrefix')
864
+ const toolSuffixSlot = getFuncSlot(toolbarOptSlots, 'toolSuffix')
865
+ if (buttonsSlot) {
866
+ toolbarSlots.buttons = buttonsSlot
867
+ }
868
+ if (buttonPrefixSlot) {
869
+ toolbarSlots.buttonPrefix = buttonPrefixSlot
870
+ }
871
+ if (buttonSuffixSlot) {
872
+ toolbarSlots.buttonSuffix = buttonSuffixSlot
873
+ }
874
+ if (toolsSlot) {
875
+ toolbarSlots.tools = toolsSlot
876
+ }
877
+ if (toolPrefixSlot) {
878
+ toolbarSlots.toolPrefix = toolPrefixSlot
879
+ }
880
+ if (toolSuffixSlot) {
881
+ toolbarSlots.toolSuffix = toolSuffixSlot
882
+ }
883
+ }
884
+ slotVNs.push(
885
+ h(
886
+ VxeToolbarComponent,
887
+ {
888
+ ref: refToolbar,
889
+ ...toolbarOpts,
890
+ slots: undefined
891
+ },
892
+ toolbarSlots
893
+ )
894
+ )
895
+ }
896
+ return h(
897
+ 'div',
898
+ {
899
+ ref: refToolbarWrapper,
900
+ key: 'toolbar',
901
+ class: 'vxe-grid--toolbar-wrapper'
902
+ },
903
+ slotVNs
904
+ )
905
+ }
906
+ return renderEmptyElement($xeGrid)
907
+ }
908
+
909
+ /**
910
+ * 渲染表格顶部区域
911
+ */
912
+ const renderTop = () => {
913
+ const topSlot = slots.top
914
+ if (topSlot) {
915
+ return h(
916
+ 'div',
917
+ {
918
+ ref: refTopWrapper,
919
+ key: 'top',
920
+ class: 'vxe-grid--top-wrapper'
921
+ },
922
+ topSlot({ $grid: $xeGrid, $gantt: null })
923
+ )
924
+ }
925
+ return renderEmptyElement($xeGrid)
926
+ }
927
+
928
+ const renderTableLeft = () => {
929
+ const leftSlot = slots.left
930
+ if (leftSlot) {
931
+ return h(
932
+ 'div',
933
+ {
934
+ class: 'vxe-grid--left-wrapper'
935
+ },
936
+ leftSlot({ $grid: $xeGrid, $gantt: null })
937
+ )
938
+ }
939
+ return renderEmptyElement($xeGrid)
940
+ }
941
+
942
+ const renderTableRight = () => {
943
+ const rightSlot = slots.right
944
+ if (rightSlot) {
945
+ return h(
946
+ 'div',
947
+ {
948
+ class: 'vxe-grid--right-wrapper'
949
+ },
950
+ rightSlot({ $grid: $xeGrid, $gantt: null })
951
+ )
952
+ }
953
+ return renderEmptyElement($xeGrid)
954
+ }
955
+
956
+ /**
957
+ * 渲染表格
958
+ */
959
+ const renderTable = () => {
960
+ const { proxyConfig } = props
961
+ const tableProps = computeTableProps.value
962
+ const proxyOpts = computeProxyOpts.value
963
+ const tableOns = Object.assign({}, tableCompEvents)
964
+ const emptySlot = slots.empty
965
+ const loadingSlot = slots.loading
966
+ const rowDragIconSlot = slots.rowDragIcon || slots['row-drag-icon']
967
+ const columnDragIconSlot = slots.columnDragIcon || slots['column-drag-icon']
968
+ const headerTooltipSlot = slots.headerTooltip || slots['header-tooltip']
969
+ const tooltipSlot = slots.tooltip
970
+ const footerTooltipSlot = slots.footerTooltip || slots['footer-tooltip']
971
+ if (proxyConfig && isEnableConf(proxyOpts)) {
972
+ if (proxyOpts.sort) {
973
+ tableOns.onSortChange = sortChangeEvent
974
+ tableOns.onClearAllSort = clearAllSortEvent
975
+ }
976
+ if (proxyOpts.filter) {
977
+ tableOns.onFilterChange = filterChangeEvent
978
+ tableOns.onClearAllFilter = clearAllFilterEvent
979
+ }
980
+ }
981
+ const slotObj: {
982
+ empty?(params: any): any
983
+ loading?(params: any): any
984
+ rowDragIcon?(params: any): any
985
+ columnDragIcon?(params: any): any
986
+ headerTooltip?(params: any): any
987
+ tooltip?(params: any): any
988
+ footerTooltip?(params: any): any
989
+ } = {}
990
+ if (emptySlot) {
991
+ slotObj.empty = emptySlot
992
+ }
993
+ if (loadingSlot) {
994
+ slotObj.loading = loadingSlot
995
+ }
996
+ if (rowDragIconSlot) {
997
+ slotObj.rowDragIcon = rowDragIconSlot
998
+ }
999
+ if (columnDragIconSlot) {
1000
+ slotObj.columnDragIcon = columnDragIconSlot
1001
+ }
1002
+ if (headerTooltipSlot) {
1003
+ slotObj.headerTooltip = headerTooltipSlot
1004
+ }
1005
+ if (tooltipSlot) {
1006
+ slotObj.tooltip = tooltipSlot
1007
+ }
1008
+ if (footerTooltipSlot) {
1009
+ slotObj.footerTooltip = footerTooltipSlot
1010
+ }
1011
+ return h(
1012
+ 'div',
1013
+ {
1014
+ class: 'vxe-grid--table-wrapper'
1015
+ },
1016
+ [
1017
+ h(
1018
+ VxeTableComponent,
1019
+ {
1020
+ ref: refTable,
1021
+ ...tableProps,
1022
+ ...tableOns
1023
+ },
1024
+ slotObj
1025
+ )
1026
+ ]
1027
+ )
1028
+ }
1029
+
1030
+ /**
1031
+ * 渲染表格底部区域
1032
+ */
1033
+ const renderBottom = () => {
1034
+ if (slots.bottom) {
1035
+ return h(
1036
+ 'div',
1037
+ {
1038
+ ref: refBottomWrapper,
1039
+ key: 'bottom',
1040
+ class: 'vxe-grid--bottom-wrapper'
1041
+ },
1042
+ slots.bottom({ $grid: $xeGrid, $gantt: null })
1043
+ )
1044
+ }
1045
+ return renderEmptyElement($xeGrid)
1046
+ }
1047
+
1048
+ /**
1049
+ * 渲染分页
1050
+ */
1051
+ const renderPager = () => {
1052
+ const { proxyConfig, pagerConfig } = props
1053
+ const proxyOpts = computeProxyOpts.value
1054
+ const pagerOpts = computePagerOpts.value
1055
+ const pagerProps = computePagerProps.value
1056
+ const pagerSlot = slots.pager
1057
+ if ((pagerConfig && isEnableConf(pagerOpts)) || slots.pager) {
1058
+ return h(
1059
+ 'div',
1060
+ {
1061
+ ref: refPagerWrapper,
1062
+ key: 'pager',
1063
+ class: 'vxe-grid--pager-wrapper'
1064
+ },
1065
+ pagerSlot
1066
+ ? pagerSlot({ $grid: $xeGrid, $gantt: null })
1067
+ : [
1068
+ VxeUIPagerComponent
1069
+ ? h(
1070
+ VxeUIPagerComponent,
1071
+ {
1072
+ ref: refPager,
1073
+ ...pagerProps,
1074
+ ...(proxyConfig && isEnableConf(proxyOpts) ? reactData.tablePage : {}),
1075
+ onPageChange: pageChangeEvent
1076
+ },
1077
+ getConfigSlot(pagerOpts.slots)
1078
+ )
1079
+ : renderEmptyElement($xeGrid)
1080
+ ]
1081
+ )
1082
+ }
1083
+ return renderEmptyElement($xeGrid)
1084
+ }
1085
+
1086
+ const renderChildLayout = (layoutKeys: VxeGridDefines.LayoutKey[]) => {
1087
+ const childVNs: VNode[] = []
1088
+ layoutKeys.forEach((key) => {
1089
+ switch (key) {
1090
+ case 'Form':
1091
+ childVNs.push(renderForm())
1092
+ break
1093
+ case 'Toolbar':
1094
+ childVNs.push(renderToolbar())
1095
+ break
1096
+ case 'Top':
1097
+ childVNs.push(renderTop())
1098
+ break
1099
+ case 'Table':
1100
+ childVNs.push(
1101
+ h(
1102
+ 'div',
1103
+ {
1104
+ key: 'table',
1105
+ class: 'vxe-grid--table-container'
1106
+ },
1107
+ [renderTableLeft(), renderTable(), renderTableRight()]
1108
+ )
1109
+ )
1110
+ break
1111
+ case 'Bottom':
1112
+ childVNs.push(renderBottom())
1113
+ break
1114
+ case 'Pager':
1115
+ childVNs.push(renderPager())
1116
+ break
1117
+ default:
1118
+ errLog('vxe.error.notProp', [`layouts -> ${key}`])
1119
+ break
1120
+ }
1121
+ })
1122
+ return childVNs
1123
+ }
1124
+
1125
+ const renderLayout = () => {
1126
+ const currLayoutConf = computeCurrLayoutConf.value
1127
+ const { headKeys, bodyKeys, footKeys } = currLayoutConf
1128
+ const asideLeftSlot = slots.asideLeft || slots['aside-left']
1129
+ const asideRightSlot = slots.asideRight || slots['aside-right']
1130
+ return [
1131
+ h(
1132
+ 'div',
1133
+ {
1134
+ class: 'vxe-grid--layout-header-wrapper'
1135
+ },
1136
+ renderChildLayout(headKeys)
1137
+ ),
1138
+ h(
1139
+ 'div',
1140
+ {
1141
+ class: 'vxe-grid--layout-body-wrapper'
1142
+ },
1143
+ [
1144
+ asideLeftSlot
1145
+ ? h(
1146
+ 'div',
1147
+ {
1148
+ class: 'vxe-grid--layout-aside-left-wrapper'
1149
+ },
1150
+ asideLeftSlot({})
1151
+ )
1152
+ : renderEmptyElement($xeGrid),
1153
+ h(
1154
+ 'div',
1155
+ {
1156
+ class: 'vxe-grid--layout-body-content-wrapper'
1157
+ },
1158
+ renderChildLayout(bodyKeys)
1159
+ ),
1160
+ asideRightSlot
1161
+ ? h(
1162
+ 'div',
1163
+ {
1164
+ class: 'vxe-grid--layout-aside-right-wrapper'
1165
+ },
1166
+ asideRightSlot({})
1167
+ )
1168
+ : renderEmptyElement($xeGrid)
1169
+ ]
1170
+ ),
1171
+ h(
1172
+ 'div',
1173
+ {
1174
+ class: 'vxe-grid--layout-footer-wrapper'
1175
+ },
1176
+ renderChildLayout(footKeys)
1177
+ ),
1178
+ h('div', {
1179
+ ref: refPopupContainerElem
1180
+ })
1181
+ ]
1182
+ }
1183
+
1184
+ const tableCompEvents: VxeTableEventProps = {}
1185
+ tableComponenEmits.forEach((name) => {
1186
+ const type = XEUtils.camelCase(`on-${name}`) as keyof VxeTableEventProps
1187
+ tableCompEvents[type] = (...args: any[]) => emit(name, ...args)
1188
+ })
1189
+
1190
+ const getDefaultFormData = () => {
1191
+ const formOpts = computeFormOpts.value
1192
+ if (formOpts.items) {
1193
+ const fData: any = {}
1194
+ formOpts.items.forEach((item) => {
1195
+ const { field, itemRender } = item
1196
+ if (field) {
1197
+ let itemValue: any = null
1198
+ if (itemRender) {
1199
+ const { startField, endField, defaultValue } = itemRender
1200
+ if (XEUtils.isFunction(defaultValue)) {
1201
+ itemValue = defaultValue({ item })
1202
+ } else if (!XEUtils.isUndefined(defaultValue)) {
1203
+ itemValue = defaultValue
1204
+ }
1205
+ if (startField && endField) {
1206
+ XEUtils.set(fData, startField, null)
1207
+ XEUtils.set(fData, endField, null)
1208
+ }
1209
+ }
1210
+ fData[field] = itemValue
1211
+ }
1212
+ })
1213
+ return fData
1214
+ }
1215
+ return {}
1216
+ }
1217
+
1218
+ const initProxy = () => {
1219
+ const { proxyConfig, formConfig } = props
1220
+ const { proxyInited } = reactData
1221
+ const proxyOpts = computeProxyOpts.value
1222
+ const formOpts = computeFormOpts.value
1223
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1224
+ if (formConfig && isEnableConf(formOpts) && proxyOpts.form && formOpts.items) {
1225
+ reactData.formData = getDefaultFormData()
1226
+ }
1227
+ if (!proxyInited) {
1228
+ reactData.proxyInited = true
1229
+ if (proxyOpts.autoLoad !== false) {
1230
+ nextTick()
1231
+ .then(() => {
1232
+ internalData.uFoot = true
1233
+ const rest = $xeGrid.commitProxy('initial')
1234
+ internalData.uFoot = false
1235
+ updateQueryFooter()
1236
+ return rest
1237
+ })
1238
+ .then((rest) => {
1239
+ dispatchEvent('proxy-query', { ...rest, isInited: true }, new Event('initial'))
1240
+ })
1241
+ }
1242
+ }
1243
+ }
1244
+ }
1245
+
1246
+ const updateQueryFooter = () => {
1247
+ const proxyOpts = computeProxyOpts.value
1248
+ const { ajax } = proxyOpts
1249
+ if (ajax && ajax.queryFooter) {
1250
+ return $xeGrid.commitProxy('queryFooter')
1251
+ }
1252
+ }
1253
+
1254
+ const handleGlobalKeydownEvent = (evnt: KeyboardEvent) => {
1255
+ const zoomOpts = computeZoomOpts.value
1256
+ const isEsc = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ESCAPE)
1257
+ if (isEsc && reactData.isZMax && zoomOpts.escRestore !== false) {
1258
+ $xeGrid.triggerZoomEvent(evnt)
1259
+ }
1260
+ }
1261
+
1262
+ const dispatchEvent = (type: ValueOf<VxeGridEmits>, params: Record<string, any>, evnt: Event | null) => {
1263
+ emit(type, createEvent(evnt, { $grid: $xeGrid, $gantt: null }, params))
1264
+ }
1265
+
1266
+ const gridMethods: GridMethods = {
1267
+ dispatchEvent,
1268
+ getEl() {
1269
+ return refElem.value as HTMLDivElement
1270
+ },
1271
+ /**
1272
+ * 提交指令,支持 code 或 button
1273
+ * @param {String/Object} code 字符串或对象
1274
+ */
1275
+ commitProxy(proxyTarget: string | VxeToolbarPropTypes.ButtonConfig, ...args: any[]) {
1276
+ const { showFooter, proxyConfig, toolbarConfig, pagerConfig, editRules, validConfig } = props
1277
+ const { tablePage } = reactData
1278
+ const isActiveMsg = computeIsActiveMsg.value
1279
+ const isRespMsg = computeIsRespMsg.value
1280
+ const proxyOpts = computeProxyOpts.value
1281
+ const pagerOpts = computePagerOpts.value
1282
+ const toolbarOpts = computeToolbarOpts.value
1283
+ const { beforeQuery: oldBeforeQuery, afterQuery: oldAfterQuery, beforeQueryFooter: oldBeforeQueryFooter, afterQueryFooter: oldAfterQueryFooter, beforeDelete: oldBeforeDelete, afterDelete: oldAfterDelete, beforeSave: oldBeforeSave, afterSave: oldAfterSave, ajax = {} } = proxyOpts
1284
+ const resConfigs = (proxyOpts.response || proxyOpts.props || {}) as VxeGridDefines.ProxyConfigResponseConfig
1285
+ const $xeTable = refTable.value
1286
+ if (!$xeTable) {
1287
+ return nextTick()
1288
+ }
1289
+ let formData = getFormData()
1290
+ let button: VxeToolbarPropTypes.ButtonConfig | null = null
1291
+ let code: string | null = null
1292
+ if (XEUtils.isString(proxyTarget)) {
1293
+ const { buttons } = toolbarOpts
1294
+ const matchObj = toolbarConfig && isEnableConf(toolbarOpts) && buttons ? XEUtils.findTree(buttons, (item) => item.code === proxyTarget, { children: 'dropdowns' }) : null
1295
+ button = matchObj ? matchObj.item : null
1296
+ code = proxyTarget
1297
+ } else {
1298
+ button = proxyTarget
1299
+ code = button.code as string
1300
+ }
1301
+ const btnParams = button ? button.params : null
1302
+ switch (code) {
1303
+ case 'insert':
1304
+ return $xeTable.insert({})
1305
+ case 'insert_edit':
1306
+ return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
1307
+
1308
+ // 已废弃
1309
+ case 'insert_actived':
1310
+ return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
1311
+ // 已废弃
1312
+
1313
+ case 'mark_cancel':
1314
+ triggerPendingEvent(code)
1315
+ break
1316
+ case 'remove':
1317
+ return handleDeleteRow(code, 'vxe.grid.removeSelectRecord', () => $xeTable.removeCheckboxRow())
1318
+ case 'import':
1319
+ $xeTable.importData(btnParams)
1320
+ break
1321
+ case 'open_import':
1322
+ $xeTable.openImport(btnParams)
1323
+ break
1324
+ case 'export':
1325
+ $xeTable.exportData(btnParams)
1326
+ break
1327
+ case 'open_export':
1328
+ $xeTable.openExport(btnParams)
1329
+ break
1330
+ case 'reset_custom':
1331
+ return $xeTable.resetCustom(true)
1332
+ case 'initial':
1333
+ case 'reload':
1334
+ case 'query': {
1335
+ const bqMethod = ajax.beforeQuery
1336
+ const qMethod = ajax.query
1337
+ const aqMethod = ajax.afterQuery
1338
+ const qsMethod = ajax.querySuccess
1339
+ const qeMethod = ajax.queryError
1340
+ if (qMethod) {
1341
+ const isInited = code === 'initial'
1342
+ const isReload = code === 'reload'
1343
+ if (!isInited && reactData.tableLoading) {
1344
+ return nextTick()
1345
+ }
1346
+ let operPromise = null
1347
+ let sortList: any[] = []
1348
+ let filterList: VxeTableDefines.FilterCheckedParams[] = []
1349
+ let pageParams: any = {}
1350
+ if (pagerConfig) {
1351
+ if (isInited || isReload) {
1352
+ // 重置分页
1353
+ tablePage.currentPage = 1
1354
+ }
1355
+ if (isEnableConf(pagerOpts)) {
1356
+ pageParams = { ...tablePage }
1357
+ }
1358
+ }
1359
+ if (isInited) {
1360
+ // 重置代理表单数据
1361
+ if (proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form) {
1362
+ formData = getDefaultFormData()
1363
+ reactData.formData = formData
1364
+ }
1365
+ if ($xeTable) {
1366
+ const tableInternalData = $xeTable.internalData
1367
+ const { tableFullColumn, fullColumnFieldData } = tableInternalData
1368
+ const { computeSortOpts } = $xeTable.getComputeMaps()
1369
+ const sortOpts = computeSortOpts.value
1370
+ let defaultSort = sortOpts.defaultSort
1371
+ tableFullColumn.forEach((column) => {
1372
+ column.order = null
1373
+ })
1374
+ // 如果使用默认排序
1375
+ if (defaultSort) {
1376
+ if (!XEUtils.isArray(defaultSort)) {
1377
+ defaultSort = [defaultSort]
1378
+ }
1379
+ sortList = defaultSort.map((item) => {
1380
+ const { field, order } = item
1381
+ const colRest = fullColumnFieldData[field]
1382
+ if (colRest) {
1383
+ const column = colRest.column
1384
+ if (column) {
1385
+ column.order = order
1386
+ }
1387
+ }
1388
+ return {
1389
+ field,
1390
+ property: field,
1391
+ order
1392
+ }
1393
+ })
1394
+ }
1395
+ filterList = $xeTable.getCheckedFilters()
1396
+ }
1397
+ } else {
1398
+ if ($xeTable) {
1399
+ if (isReload) {
1400
+ operPromise = $xeTable.clearAll()
1401
+ } else {
1402
+ sortList = $xeTable.getSortColumns()
1403
+ filterList = $xeTable.getCheckedFilters()
1404
+ }
1405
+ }
1406
+ }
1407
+ const commitParams = {
1408
+ $table: $xeTable,
1409
+ $grid: $xeGrid,
1410
+ $gantt: null,
1411
+ code,
1412
+ button,
1413
+ isInited,
1414
+ isReload,
1415
+ page: pageParams,
1416
+ sort: sortList.length ? sortList[0] : {},
1417
+ sorts: sortList,
1418
+ filters: filterList,
1419
+ form: formData,
1420
+ options: qMethod
1421
+ }
1422
+
1423
+ const handleQuery = () => {
1424
+ reactData.sortData = sortList
1425
+ reactData.filterData = filterList
1426
+ reactData.tableLoading = true
1427
+ return Promise.all([Promise.resolve((oldBeforeQuery || qMethod)(commitParams, ...args)), operPromise])
1428
+ .then(([rest]) => {
1429
+ reactData.tableLoading = false
1430
+ if (aqMethod) {
1431
+ aqMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1432
+ } else {
1433
+ let tableData: any[] = []
1434
+ if (rest) {
1435
+ const listProp = resConfigs.list
1436
+ const resultProp = resConfigs.result
1437
+ const reParams = { data: rest, $table: $xeTable, $grid: $xeGrid, $gantt: null }
1438
+ if (pagerConfig && isEnableConf(pagerOpts)) {
1439
+ const totalProp = resConfigs.total
1440
+ const total = (XEUtils.isFunction(totalProp) ? totalProp(reParams) : XEUtils.get(rest, totalProp || 'page.total')) || 0
1441
+ tablePage.total = XEUtils.toNumber(total)
1442
+ tableData = (XEUtils.isFunction(resultProp) ? resultProp(reParams) : XEUtils.get(rest, resultProp || 'result')) || []
1443
+ // 检验当前页码,不能超出当前最大页数
1444
+ const pageCount = Math.max(Math.ceil(total / tablePage.pageSize), 1)
1445
+ if (tablePage.currentPage > pageCount) {
1446
+ tablePage.currentPage = pageCount
1447
+ }
1448
+ } else {
1449
+ if (XEUtils.isArray(rest)) {
1450
+ tableData = rest
1451
+ } else if (listProp) {
1452
+ tableData = (XEUtils.isFunction(listProp) ? listProp(reParams) : XEUtils.get(rest, listProp)) || []
1453
+ }
1454
+ }
1455
+ if (showFooter) {
1456
+ const fdProp = resConfigs.footerData
1457
+ const footerList = fdProp ? (XEUtils.isFunction(fdProp) ? fdProp(reParams) : XEUtils.get(rest, fdProp)) : []
1458
+ if (XEUtils.isArray(footerList)) {
1459
+ reactData.footerData = footerList
1460
+ }
1461
+ }
1462
+ }
1463
+ if ($xeTable) {
1464
+ $xeTable.loadData(tableData)
1465
+ } else {
1466
+ nextTick(() => {
1467
+ const $xeTable = refTable.value
1468
+ if ($xeTable) {
1469
+ $xeTable.loadData(tableData)
1470
+ }
1471
+ })
1472
+ }
1473
+ if (oldAfterQuery) {
1474
+ oldAfterQuery({ ...commitParams, response: rest }, ...args)
1475
+ }
1476
+ }
1477
+
1478
+ if (qsMethod) {
1479
+ qsMethod({ ...commitParams, response: rest })
1480
+ }
1481
+ return { status: true }
1482
+ })
1483
+ .catch((rest) => {
1484
+ reactData.tableLoading = false
1485
+ if (aqMethod) {
1486
+ aqMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1487
+ }
1488
+ if (qeMethod) {
1489
+ qeMethod({ ...commitParams, response: rest })
1490
+ }
1491
+ return { status: false }
1492
+ })
1493
+ }
1494
+
1495
+ if (bqMethod) {
1496
+ return Promise.resolve(bqMethod(commitParams, ...args)).then((status) => {
1497
+ if (status !== false) {
1498
+ return handleQuery()
1499
+ }
1500
+ })
1501
+ }
1502
+ return handleQuery()
1503
+ } else {
1504
+ errLog('vxe.error.notFunc', ['proxy-config.ajax.query'])
1505
+ }
1506
+ break
1507
+ }
1508
+ case 'queryFooter':
1509
+ case 'query_footer': {
1510
+ const bqfMethod = ajax.beforeQueryFooter
1511
+ const qfMethod = ajax.queryFooter
1512
+ const aqfMethod = ajax.afterQueryFooter
1513
+ const qfSuccessMethod = ajax.queryFooterSuccess
1514
+ const qfErrorMethod = ajax.queryFooterError
1515
+ if (qfMethod) {
1516
+ let filterList: VxeTableDefines.FilterCheckedParams[] = []
1517
+ if ($xeTable) {
1518
+ filterList = $xeTable.getCheckedFilters()
1519
+ }
1520
+ let pageParams: any = {}
1521
+ if (pagerConfig) {
1522
+ if (isEnableConf(pagerOpts)) {
1523
+ pageParams = { ...tablePage }
1524
+ }
1525
+ }
1526
+ const commitParams = {
1527
+ $table: $xeTable,
1528
+ $grid: $xeGrid,
1529
+ $gantt: null,
1530
+ code,
1531
+ button,
1532
+ page: pageParams,
1533
+ filters: filterList,
1534
+ form: formData,
1535
+ options: qfMethod
1536
+ }
1537
+ const handleQueryFooter = () => {
1538
+ return Promise.resolve((oldBeforeQueryFooter || qfMethod)(commitParams, ...args))
1539
+ .then((rest) => {
1540
+ if (aqfMethod) {
1541
+ aqfMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1542
+ } else {
1543
+ reactData.footerData = XEUtils.isArray(rest) ? rest : []
1544
+ if (oldAfterQueryFooter) {
1545
+ oldAfterQueryFooter({ ...commitParams, response: rest }, ...args)
1546
+ }
1547
+ }
1548
+ if (qfSuccessMethod) {
1549
+ qfSuccessMethod({ ...commitParams, response: rest })
1550
+ }
1551
+ return { status: true }
1552
+ })
1553
+ .catch((rest) => {
1554
+ if (aqfMethod) {
1555
+ aqfMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1556
+ }
1557
+ if (qfErrorMethod) {
1558
+ qfErrorMethod({ ...commitParams, response: rest })
1559
+ }
1560
+ return { status: false }
1561
+ })
1562
+ }
1563
+ if (bqfMethod) {
1564
+ return Promise.resolve(bqfMethod(commitParams, ...args)).then((status) => {
1565
+ if (status !== false) {
1566
+ return handleQueryFooter()
1567
+ }
1568
+ })
1569
+ }
1570
+ return handleQueryFooter()
1571
+ } else {
1572
+ errLog('vxe.error.notFunc', ['proxy-config.ajax.queryFooter'])
1573
+ }
1574
+ break
1575
+ }
1576
+ case 'delete': {
1577
+ const bdMethod = ajax.beforeDelete
1578
+ const dMethod = ajax.delete
1579
+ const adMethod = ajax.afterDelete
1580
+ const deleteSuccessMethods = ajax.deleteSuccess
1581
+ const deleteErrorMethods = ajax.deleteError
1582
+ if (dMethod) {
1583
+ const selectRecords = $xeGrid.getCheckboxRecords()
1584
+ const removeRecords = selectRecords.filter((row) => !$xeTable.isInsertByRow(row))
1585
+ const body = { removeRecords }
1586
+ const commitParams = {
1587
+ $table: $xeTable,
1588
+ $grid: $xeGrid,
1589
+ $gantt: null,
1590
+ code,
1591
+ button,
1592
+ body,
1593
+ form: formData,
1594
+ options: dMethod
1595
+ }
1596
+ if (selectRecords.length) {
1597
+ return handleDeleteRow(code, 'vxe.grid.deleteSelectRecord', () => {
1598
+ if (!removeRecords.length) {
1599
+ return $xeTable.remove(selectRecords)
1600
+ }
1601
+
1602
+ const handleDelete = () => {
1603
+ reactData.tableLoading = true
1604
+ return Promise.resolve((oldBeforeDelete || dMethod)(commitParams, ...args))
1605
+ .then((rest) => {
1606
+ reactData.tableLoading = false
1607
+ if (adMethod) {
1608
+ adMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1609
+ } else {
1610
+ $xeTable.setPendingRow(removeRecords, false)
1611
+ if (isRespMsg) {
1612
+ if (VxeUI.modal) {
1613
+ VxeUI.modal.message({ content: getRespMsg(rest, 'vxe.grid.delSuccess'), status: 'success' })
1614
+ }
1615
+ }
1616
+ if (oldAfterDelete) {
1617
+ oldAfterDelete({ ...commitParams, response: rest }, ...args)
1618
+ } else {
1619
+ internalData.uFoot = true
1620
+ $xeGrid.commitProxy('query')
1621
+ internalData.uFoot = false
1622
+ updateQueryFooter()
1623
+ }
1624
+ }
1625
+ if (deleteSuccessMethods) {
1626
+ deleteSuccessMethods({ ...commitParams, response: rest })
1627
+ }
1628
+ return { status: true }
1629
+ })
1630
+ .catch((rest) => {
1631
+ reactData.tableLoading = false
1632
+ if (adMethod) {
1633
+ adMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1634
+ } else {
1635
+ if (isRespMsg) {
1636
+ if (VxeUI.modal) {
1637
+ VxeUI.modal.message({ id: code, content: getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1638
+ }
1639
+ }
1640
+ }
1641
+ if (deleteErrorMethods) {
1642
+ deleteErrorMethods({ ...commitParams, response: rest })
1643
+ }
1644
+ return { status: false }
1645
+ })
1646
+ }
1647
+
1648
+ if (bdMethod) {
1649
+ return Promise.resolve(bdMethod(commitParams, ...args)).then((status) => {
1650
+ if (status !== false) {
1651
+ return handleDelete()
1652
+ }
1653
+ })
1654
+ }
1655
+ return handleDelete()
1656
+ })
1657
+ } else {
1658
+ if (isActiveMsg) {
1659
+ if (VxeUI.modal) {
1660
+ VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
1661
+ }
1662
+ }
1663
+ }
1664
+ } else {
1665
+ errLog('vxe.error.notFunc', ['proxy-config.ajax.delete'])
1666
+ }
1667
+ break
1668
+ }
1669
+ case 'save': {
1670
+ const bSaveMethod = ajax.beforeSave
1671
+ const sMethod = ajax.save
1672
+ const aSaveMethod = ajax.afterSave
1673
+ const sSuccessMethod = ajax.saveSuccess
1674
+ const sErrorMethod = ajax.saveError
1675
+ if (sMethod) {
1676
+ const body = $xeTable.getRecordset()
1677
+ const { insertRecords, removeRecords, updateRecords, pendingRecords } = body
1678
+ const commitParams = {
1679
+ $table: $xeTable,
1680
+ $grid: $xeGrid,
1681
+ $gantt: null,
1682
+ code,
1683
+ button,
1684
+ body,
1685
+ form: formData,
1686
+ options: sMethod
1687
+ }
1688
+ // 排除掉新增且标记为删除的数据
1689
+ if (insertRecords.length) {
1690
+ body.pendingRecords = pendingRecords.filter((row) => $xeTable.findRowIndexOf(insertRecords, row) === -1)
1691
+ }
1692
+ // 排除已标记为删除的数据
1693
+ if (pendingRecords.length) {
1694
+ body.insertRecords = insertRecords.filter((row) => $xeTable.findRowIndexOf(pendingRecords, row) === -1)
1695
+ }
1696
+ let restPromise: Promise<any> = Promise.resolve()
1697
+ if (editRules) {
1698
+ // 只校验新增和修改的数据
1699
+ restPromise = $xeTable[validConfig && validConfig.msgMode === 'full' ? 'fullValidate' : 'validate'](body.insertRecords.concat(updateRecords))
1700
+ }
1701
+ return restPromise.then((errMap) => {
1702
+ if (errMap) {
1703
+ // 如果校验不通过
1704
+ return
1705
+ }
1706
+ if (body.insertRecords.length || removeRecords.length || updateRecords.length || body.pendingRecords.length) {
1707
+ const handleSave = () => {
1708
+ reactData.tableLoading = true
1709
+ return Promise.resolve((oldBeforeSave || sMethod)(commitParams, ...args))
1710
+ .then((rest) => {
1711
+ reactData.tableLoading = false
1712
+ if (aSaveMethod) {
1713
+ aSaveMethod({ ...commitParams, response: rest, status: 'success' }, ...args)
1714
+ } else {
1715
+ $xeTable.clearPendingRow()
1716
+ if (isRespMsg) {
1717
+ if (VxeUI.modal) {
1718
+ VxeUI.modal.message({ content: getRespMsg(rest, 'vxe.grid.saveSuccess'), status: 'success' })
1719
+ }
1720
+ }
1721
+ if (oldAfterSave) {
1722
+ oldAfterSave({ ...commitParams, response: rest }, ...args)
1723
+ } else {
1724
+ internalData.uFoot = true
1725
+ $xeGrid.commitProxy('query')
1726
+ internalData.uFoot = false
1727
+ updateQueryFooter()
1728
+ }
1729
+ }
1730
+ if (sSuccessMethod) {
1731
+ sSuccessMethod({ ...commitParams, response: rest })
1732
+ }
1733
+ return { status: true }
1734
+ })
1735
+ .catch((rest) => {
1736
+ reactData.tableLoading = false
1737
+ if (aSaveMethod) {
1738
+ aSaveMethod({ ...commitParams, response: rest, status: 'error' }, ...args)
1739
+ } else {
1740
+ if (isRespMsg) {
1741
+ if (VxeUI.modal) {
1742
+ VxeUI.modal.message({ id: code, content: getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1743
+ }
1744
+ }
1745
+ }
1746
+ if (sErrorMethod) {
1747
+ sErrorMethod({ ...commitParams, response: rest })
1748
+ }
1749
+ return { status: false }
1750
+ })
1751
+ }
1752
+ if (bSaveMethod) {
1753
+ return Promise.resolve(bSaveMethod(commitParams, ...args)).then((status) => {
1754
+ if (status !== false) {
1755
+ return handleSave()
1756
+ }
1757
+ })
1758
+ }
1759
+ return handleSave()
1760
+ } else {
1761
+ if (isActiveMsg) {
1762
+ if (VxeUI.modal) {
1763
+ VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.dataUnchanged'), status: 'info' })
1764
+ }
1765
+ }
1766
+ }
1767
+ })
1768
+ } else {
1769
+ errLog('vxe.error.notFunc', ['proxy-config.ajax.save'])
1770
+ }
1771
+ break
1772
+ }
1773
+ default: {
1774
+ const gCommandOpts = commands.get(code)
1775
+ if (gCommandOpts) {
1776
+ const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
1777
+ if (tCommandMethod) {
1778
+ tCommandMethod({ code, button, $grid: $xeGrid, $table: $xeTable, $gantt: null }, ...args)
1779
+ } else {
1780
+ errLog('vxe.error.notCommands', [code])
1781
+ }
1782
+ }
1783
+ }
1784
+ }
1785
+ return nextTick()
1786
+ },
1787
+ getParams() {
1788
+ return props.params
1789
+ },
1790
+ zoom() {
1791
+ if (reactData.isZMax) {
1792
+ return $xeGrid.revert()
1793
+ }
1794
+ return $xeGrid.maximize()
1795
+ },
1796
+ isMaximized() {
1797
+ return reactData.isZMax
1798
+ },
1799
+ maximize() {
1800
+ return handleZoom(true)
1801
+ },
1802
+ revert() {
1803
+ return handleZoom()
1804
+ },
1805
+ getFormData,
1806
+ /**
1807
+ * 已废弃,被 getFormFlatItems 替换
1808
+ * @deprecated
1809
+ */
1810
+ getFormItems(itemIndex?: number): any {
1811
+ const formOpts = computeFormOpts.value
1812
+ const { formConfig } = props
1813
+ const { items } = formOpts
1814
+ const itemList: VxeFormItemProps[] = []
1815
+ XEUtils.eachTree(
1816
+ formConfig && isEnableConf(formOpts) && items ? items : [],
1817
+ (item) => {
1818
+ itemList.push(item)
1819
+ },
1820
+ { children: 'children' }
1821
+ )
1822
+ // errLog('vxe.error.delFunc', ['getFormItems', 'getFormFlatItems'])
1823
+ return XEUtils.isUndefined(itemIndex) ? itemList : itemList[itemIndex]
1824
+ },
1825
+ getFormFlatItems() {
1826
+ const $form = refForm.value
1827
+ if ($form) {
1828
+ return $form.getFlatItems()
1829
+ }
1830
+ return []
1831
+ },
1832
+ getFormNestedItems() {
1833
+ const $form = refForm.value
1834
+ if ($form) {
1835
+ return $form.getNestedItems()
1836
+ }
1837
+ return []
1838
+ },
1839
+ getFormItemByField(field: string) {
1840
+ const $form = refForm.value
1841
+ if ($form) {
1842
+ return $form.getItemByField(field)
1843
+ }
1844
+ return null
1845
+ },
1846
+ resetForm() {
1847
+ const $form = refForm.value
1848
+ if ($form) {
1849
+ return $form.reset()
1850
+ }
1851
+ return nextTick()
1852
+ },
1853
+ validateForm() {
1854
+ const $form = refForm.value
1855
+ if ($form) {
1856
+ return $form.validate()
1857
+ }
1858
+ return Promise.resolve()
1859
+ },
1860
+ validateFormField(field) {
1861
+ const $form = refForm.value
1862
+ if ($form) {
1863
+ return $form.validateField(field)
1864
+ }
1865
+ return Promise.resolve()
1866
+ },
1867
+ clearFormValidate(field) {
1868
+ const $form = refForm.value
1869
+ if ($form) {
1870
+ return $form.clearValidate(field)
1871
+ }
1872
+ return nextTick()
1873
+ },
1874
+ homePage() {
1875
+ const { tablePage } = reactData
1876
+ tablePage.currentPage = 1
1877
+ return nextTick()
1878
+ },
1879
+ homePageByEvent(evnt) {
1880
+ const $pager = refPager.value
1881
+ if ($pager) {
1882
+ $pager.homePageByEvent(evnt)
1883
+ }
1884
+ },
1885
+ endPage() {
1886
+ const { tablePage } = reactData
1887
+ const pageCount = computePageCount.value
1888
+ tablePage.currentPage = pageCount
1889
+ return nextTick()
1890
+ },
1891
+ endPageByEvent(evnt) {
1892
+ const $pager = refPager.value
1893
+ if ($pager) {
1894
+ $pager.endPageByEvent(evnt)
1895
+ }
1896
+ },
1897
+ getCurrentPage() {
1898
+ const { tablePage } = reactData
1899
+ return tablePage.currentPage
1900
+ },
1901
+ setCurrentPage(currentPage) {
1902
+ const { tablePage } = reactData
1903
+ const pageCount = computePageCount.value
1904
+ tablePage.currentPage = Math.min(pageCount, Math.max(1, XEUtils.toNumber(currentPage)))
1905
+ return nextTick()
1906
+ },
1907
+ setCurrentPageByEvent(evnt, currentPage) {
1908
+ const $pager = refPager.value
1909
+ if ($pager) {
1910
+ $pager.setCurrentPageByEvent(evnt, currentPage)
1911
+ }
1912
+ },
1913
+ getPageSize() {
1914
+ const { tablePage } = reactData
1915
+ return tablePage.pageSize
1916
+ },
1917
+ setPageSize(pageSize) {
1918
+ const { tablePage } = reactData
1919
+ tablePage.pageSize = Math.max(1, XEUtils.toNumber(pageSize))
1920
+ return nextTick()
1921
+ },
1922
+ setPageSizeByEvent(evnt, pageSize) {
1923
+ const $pager = refPager.value
1924
+ if ($pager) {
1925
+ $pager.setPageSizeByEvent(evnt, pageSize)
1926
+ }
1927
+ },
1928
+ getProxyInfo() {
1929
+ const $xeTable = refTable.value
1930
+ if (props.proxyConfig) {
1931
+ const { sortData } = reactData
1932
+ return {
1933
+ data: $xeTable ? $xeTable.getFullData() : [],
1934
+ filter: reactData.filterData,
1935
+ form: getFormData(),
1936
+ sort: sortData.length ? sortData[0] : {},
1937
+ sorts: sortData,
1938
+ pager: reactData.tablePage,
1939
+ pendingRecords: $xeTable ? $xeTable.getPendingRecords() : []
1940
+ }
1941
+ }
1942
+ return null
1943
+ },
1944
+ getCustomPagerData() {
1945
+ const { pagerConfig } = props
1946
+ const { tablePage } = reactData
1947
+ const pagerOpts = computePagerOpts.value
1948
+ if (pagerConfig && isEnableConf(pagerOpts)) {
1949
+ return {
1950
+ pSize: tablePage.pageSize
1951
+ }
1952
+ }
1953
+ return {}
1954
+ }
1955
+ // setProxyInfo (options) {
1956
+ // if (props.proxyConfig && options) {
1957
+ // const { pager, form } = options
1958
+ // const proxyOpts = computeProxyOpts.value
1959
+ // if (pager) {
1960
+ // if (pager.currentPage) {
1961
+ // reactData.tablePage.currentPage = Number(pager.currentPage)
1962
+ // }
1963
+ // if (pager.pageSize) {
1964
+ // reactData.tablePage.pageSize = Number(pager.pageSize)
1965
+ // }
1966
+ // }
1967
+ // if (proxyOpts.form && form) {
1968
+ // Object.assign(reactData.formData, form)
1969
+ // }
1970
+ // }
1971
+ // return nextTick()
1972
+ // }
1973
+ }
1974
+
1975
+ const gridPrivateMethods: GridPrivateMethods = {
1976
+ extendTableMethods,
1977
+ callSlot(slotFunc, params) {
1978
+ if (slotFunc) {
1979
+ if (XEUtils.isString(slotFunc)) {
1980
+ slotFunc = slots[slotFunc] || null
1981
+ }
1982
+ if (XEUtils.isFunction(slotFunc)) {
1983
+ return getSlotVNs(slotFunc(params))
1984
+ }
1985
+ }
1986
+ return []
1987
+ },
1988
+ /**
1989
+ * 获取需要排除的高度
1990
+ */
1991
+ getExcludeHeight() {
1992
+ const { height } = props
1993
+ const { isZMax } = reactData
1994
+ const el = refElem.value
1995
+ if (el) {
1996
+ const formWrapper = refFormWrapper.value
1997
+ const toolbarWrapper = refToolbarWrapper.value
1998
+ const topWrapper = refTopWrapper.value
1999
+ const bottomWrapper = refBottomWrapper.value
2000
+ const pagerWrapper = refPagerWrapper.value
2001
+ const parentEl = el.parentElement
2002
+ let parentPaddingSize = 0
2003
+ if (parentEl && (height === '100%' || height === 'auto')) {
2004
+ parentPaddingSize = isZMax ? 0 : getPaddingTopBottomSize(parentEl)
2005
+ }
2006
+ return parentPaddingSize + getPaddingTopBottomSize(el) + getOffsetHeight(formWrapper) + getOffsetHeight(toolbarWrapper) + getOffsetHeight(topWrapper) + getOffsetHeight(bottomWrapper) + getOffsetHeight(pagerWrapper)
2007
+ }
2008
+ return 0
2009
+ },
2010
+ getParentElem() {
2011
+ const el = refElem.value
2012
+ if (!el) {
2013
+ return null
2014
+ }
2015
+ let parentEl = el.parentElement
2016
+ // 如果是虚拟滚动条
2017
+ if (parentEl && hasClass(parentEl, 'vxe-scrollbar--view-inner')) {
2018
+ parentEl = parentEl.parentElement
2019
+ }
2020
+ return parentEl
2021
+ },
2022
+ getParentHeight() {
2023
+ const el = refElem.value
2024
+ if (el) {
2025
+ const parentEl = $xeGrid.getParentElem()
2026
+ return (reactData.isZMax ? getDomNode().visibleHeight : parentEl ? XEUtils.toNumber(getComputedStyle(parentEl).height) : 0) - gridPrivateMethods.getExcludeHeight()
2027
+ }
2028
+ return 0
2029
+ },
2030
+ triggerToolbarCommitEvent(params, evnt) {
2031
+ const { code } = params
2032
+ if (code) {
2033
+ const isUf = ['reload', 'delete', 'save'].includes(code)
2034
+ if (isUf) {
2035
+ internalData.uFoot = true
2036
+ }
2037
+ const rest = $xeGrid.commitProxy(params, evnt).then((rest) => {
2038
+ if (rest && rest.status && ['query', 'reload', 'delete', 'save'].includes(code)) {
2039
+ $xeGrid.dispatchEvent(code === 'delete' || code === 'save' ? `proxy-${code as 'delete' | 'save'}` : 'proxy-query', { ...rest, isReload: code === 'reload' }, evnt)
2040
+ }
2041
+ })
2042
+ internalData.uFoot = false
2043
+ if (isUf) {
2044
+ updateQueryFooter()
2045
+ }
2046
+ return rest
2047
+ }
2048
+ return nextTick()
2049
+ },
2050
+ triggerToolbarBtnEvent(button, evnt) {
2051
+ $xeGrid.triggerToolbarCommitEvent(button, evnt)
2052
+ $xeGrid.dispatchEvent('toolbar-button-click', { code: button.code, button }, evnt)
2053
+ },
2054
+ triggerToolbarTolEvent(tool, evnt) {
2055
+ $xeGrid.triggerToolbarCommitEvent(tool, evnt)
2056
+ $xeGrid.dispatchEvent('toolbar-tool-click', { code: tool.code, tool }, evnt)
2057
+ },
2058
+ triggerZoomEvent(evnt) {
2059
+ $xeGrid.zoom()
2060
+ $xeGrid.dispatchEvent('zoom', { type: reactData.isZMax ? 'max' : 'revert' }, evnt)
2061
+ }
2062
+ }
2063
+
2064
+ Object.assign($xeGrid, gridExtendTableMethods, gridMethods, gridPrivateMethods, {
2065
+ // 检查插槽
2066
+ loadColumn(columns: any[]) {
2067
+ const $xeTable = refTable.value
2068
+ XEUtils.eachTree(columns, (column) => {
2069
+ if (column.slots) {
2070
+ XEUtils.each(column.slots, (func) => {
2071
+ if (func && !XEUtils.isFunction(func)) {
2072
+ if (!slots[func]) {
2073
+ errLog('vxe.error.notSlot', [func])
2074
+ }
2075
+ }
2076
+ })
2077
+ }
2078
+ })
2079
+ if ($xeTable) {
2080
+ return $xeTable.loadColumn(columns)
2081
+ }
2082
+ return nextTick()
2083
+ },
2084
+ reloadColumn(columns: any[]) {
2085
+ $xeGrid.clearAll()
2086
+ return $xeGrid.loadColumn(columns)
2087
+ }
2088
+ })
2089
+
2090
+ const renderVN = () => {
2091
+ const vSize = computeSize.value
2092
+ const styles = computeStyles.value
2093
+ const isLoading = computeIsLoading.value
2094
+ return h(
2095
+ 'div',
2096
+ {
2097
+ ref: refElem,
2098
+ class: [
2099
+ 'vxe-grid',
2100
+ {
2101
+ [`size--${vSize}`]: vSize,
2102
+ 'is--animat': !!props.animat,
2103
+ 'is--round': props.round,
2104
+ 'is--maximize': reactData.isZMax,
2105
+ 'is--loading': isLoading
2106
+ }
2107
+ ],
2108
+ style: styles
2109
+ },
2110
+ renderLayout()
2111
+ )
2112
+ }
2113
+
2114
+ const columnFlag = ref(0)
2115
+ watch(
2116
+ () => (props.columns ? props.columns.length : -1),
2117
+ () => {
2118
+ columnFlag.value++
2119
+ }
2120
+ )
2121
+ watch(
2122
+ () => props.columns,
2123
+ () => {
2124
+ columnFlag.value++
2125
+ }
2126
+ )
2127
+ watch(columnFlag, () => {
2128
+ nextTick(() => $xeGrid.loadColumn(props.columns || []))
2129
+ })
2130
+
2131
+ watch(
2132
+ () => props.toolbarConfig,
2133
+ () => {
2134
+ initToolbar()
2135
+ }
2136
+ )
2137
+
2138
+ watch(computeCustomCurrentPageFlag, () => {
2139
+ initPages('currentPage')
2140
+ })
2141
+
2142
+ watch(computeCustomPageSizeFlag, () => {
2143
+ initPages('pageSize')
2144
+ })
2145
+
2146
+ watch(computeCustomTotalFlag, () => {
2147
+ initPages('total')
2148
+ })
2149
+
2150
+ watch(
2151
+ () => props.proxyConfig,
2152
+ () => {
2153
+ initProxy()
2154
+ }
2155
+ )
2156
+
2157
+ hooks.forEach((options) => {
2158
+ const { setupGrid } = options
2159
+ if (setupGrid) {
2160
+ const hookRest = setupGrid($xeGrid)
2161
+ if (hookRest && XEUtils.isObject(hookRest)) {
2162
+ Object.assign($xeGrid, hookRest)
2163
+ }
2164
+ }
2165
+ })
2166
+
2167
+ initPages()
2168
+
2169
+ onMounted(() => {
2170
+ nextTick(() => {
2171
+ const { columns } = props
2172
+ const proxyOpts = computeProxyOpts.value
2173
+
2174
+ if (props.formConfig) {
2175
+ if (!VxeUIFormComponent) {
2176
+ errLog('vxe.error.reqComp', ['vxe-form'])
2177
+ }
2178
+ }
2179
+ if (props.pagerConfig) {
2180
+ if (!VxeUIPagerComponent) {
2181
+ errLog('vxe.error.reqComp', ['vxe-pager'])
2182
+ }
2183
+ }
2184
+
2185
+ // const { data, columns, proxyConfig } = props
2186
+ // const formOpts = computeFormOpts.value
2187
+ // if (isEnableConf(proxyConfig) && (data || (proxyOpts.form && formOpts.data))) {
2188
+ // errLog('vxe.error.errConflicts', ['[grid] data', 'proxy-config'])
2189
+ // }
2190
+
2191
+ if (proxyOpts.props) {
2192
+ warnLog('vxe.error.delProp', ['proxy-config.props', 'proxy-config.response'])
2193
+ }
2194
+
2195
+ if (columns && columns.length) {
2196
+ $xeGrid.loadColumn(columns)
2197
+ }
2198
+ initToolbar()
2199
+ initProxy()
2200
+ })
2201
+ globalEvents.on($xeGrid, 'keydown', handleGlobalKeydownEvent)
2202
+ })
2203
+
2204
+ onBeforeUnmount(() => {
2205
+ globalEvents.off($xeGrid, 'keydown')
2206
+ XEUtils.assign(reactData, createReactData())
2207
+ XEUtils.assign(internalData, createInternalData())
2208
+ })
2209
+
2210
+ $xeGrid.renderVN = renderVN
2211
+
2212
+ provide('$xeGrid', $xeGrid)
2213
+ provide('$xeGantt', null)
2214
+
2215
+ return $xeGrid
2216
+ },
2217
+ render() {
2218
+ return this.renderVN()
2219
+ }
2220
+ }) /* define-vxe-component end */