vxe-table 4.23.8 → 4.23.9

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