vxe-table 3.20.4 → 3.20.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +106 -106
  3. package/es/grid/style.css +4 -0
  4. package/es/grid/style.min.css +1 -1
  5. package/es/index.css +1 -1
  6. package/es/index.esm.js +1 -2
  7. package/es/index.min.css +1 -1
  8. package/es/style.css +1 -1
  9. package/es/style.min.css +1 -1
  10. package/es/table/src/methods.js +51 -22
  11. package/es/table/src/table.js +36 -0
  12. package/es/table/src/util.js +3 -4
  13. package/es/table/style.css +48 -18
  14. package/es/ui/index.js +1 -1
  15. package/es/ui/src/log.js +1 -1
  16. package/es/vxe-grid/style.css +4 -0
  17. package/es/vxe-grid/style.min.css +1 -1
  18. package/es/vxe-table/style.css +48 -18
  19. package/lib/grid/style/style.css +4 -0
  20. package/lib/grid/style/style.min.css +1 -1
  21. package/lib/index.common.js +1 -2
  22. package/lib/index.css +1 -1
  23. package/lib/index.min.css +1 -1
  24. package/lib/index.umd.js +3252 -1877
  25. package/lib/index.umd.min.js +1 -1
  26. package/lib/style.css +1 -1
  27. package/lib/style.min.css +1 -1
  28. package/lib/table/src/methods.js +4 -3
  29. package/lib/table/src/methods.min.js +1 -1
  30. package/lib/table/src/table.js +44 -0
  31. package/lib/table/src/table.min.js +1 -1
  32. package/lib/table/src/util.js +4 -6
  33. package/lib/table/src/util.min.js +1 -1
  34. package/lib/table/style/style.css +48 -18
  35. package/lib/ui/index.js +1 -1
  36. package/lib/ui/index.min.js +1 -1
  37. package/lib/ui/src/log.js +1 -1
  38. package/lib/ui/src/log.min.js +1 -1
  39. package/lib/v-x-e-table/index.js +1 -2
  40. package/lib/v-x-e-table/index.min.js +1 -1
  41. package/lib/vxe-colgroup/index.js +1 -2
  42. package/lib/vxe-colgroup/index.min.js +1 -1
  43. package/lib/vxe-column/index.js +1 -2
  44. package/lib/vxe-column/index.min.js +1 -1
  45. package/lib/vxe-grid/index.js +1 -2
  46. package/lib/vxe-grid/index.min.js +1 -1
  47. package/lib/vxe-grid/style/style.css +4 -0
  48. package/lib/vxe-grid/style/style.min.css +1 -1
  49. package/lib/vxe-table/index.js +1 -2
  50. package/lib/vxe-table/index.min.js +1 -1
  51. package/lib/vxe-table/style/style.css +48 -18
  52. package/lib/vxe-toolbar/index.js +1 -2
  53. package/lib/vxe-toolbar/index.min.js +1 -1
  54. package/lib/vxe-ui/index.js +1 -2
  55. package/lib/vxe-ui/index.min.js +1 -1
  56. package/lib/vxe-v-x-e-table/index.js +1 -2
  57. package/lib/vxe-v-x-e-table/index.min.js +1 -1
  58. package/package.json +93 -93
  59. package/packages/colgroup/index.ts +22 -22
  60. package/packages/column/index.ts +22 -22
  61. package/packages/components.ts +42 -42
  62. package/packages/grid/index.ts +22 -22
  63. package/packages/grid/src/grid.ts +1935 -1935
  64. package/packages/index.ts +4 -4
  65. package/packages/locale/lang/ar-EG.ts +832 -832
  66. package/packages/locale/lang/de-DE.ts +832 -832
  67. package/packages/locale/lang/en-US.ts +832 -832
  68. package/packages/locale/lang/es-ES.ts +832 -832
  69. package/packages/locale/lang/fr-FR.ts +832 -832
  70. package/packages/locale/lang/hu-HU.ts +832 -832
  71. package/packages/locale/lang/hy-AM.ts +832 -832
  72. package/packages/locale/lang/id-ID.ts +832 -832
  73. package/packages/locale/lang/it-IT.ts +832 -832
  74. package/packages/locale/lang/ja-JP.ts +832 -832
  75. package/packages/locale/lang/ko-KR.ts +832 -832
  76. package/packages/locale/lang/ms-MY.ts +832 -832
  77. package/packages/locale/lang/nb-NO.ts +832 -832
  78. package/packages/locale/lang/pt-BR.ts +832 -832
  79. package/packages/locale/lang/ru-RU.ts +832 -832
  80. package/packages/locale/lang/th-TH.ts +832 -832
  81. package/packages/locale/lang/ug-CN.ts +832 -832
  82. package/packages/locale/lang/uk-UA.ts +832 -832
  83. package/packages/locale/lang/uz-UZ.ts +832 -832
  84. package/packages/locale/lang/vi-VN.ts +832 -832
  85. package/packages/locale/lang/zh-CHT.ts +832 -832
  86. package/packages/locale/lang/zh-CN.ts +832 -832
  87. package/packages/locale/lang/zh-HK.ts +3 -3
  88. package/packages/locale/lang/zh-MO.ts +3 -3
  89. package/packages/locale/lang/zh-TC.ts +3 -3
  90. package/packages/locale/lang/zh-TW.ts +3 -3
  91. package/packages/table/index.ts +49 -49
  92. package/packages/table/module/custom/mixin.ts +369 -369
  93. package/packages/table/module/custom/panel.ts +1461 -1461
  94. package/packages/table/module/edit/mixin.ts +1123 -1123
  95. package/packages/table/module/export/export-panel.ts +658 -658
  96. package/packages/table/module/export/import-panel.ts +319 -319
  97. package/packages/table/module/export/mixin.ts +1693 -1693
  98. package/packages/table/module/export/util.ts +24 -24
  99. package/packages/table/module/filter/mixin.ts +507 -507
  100. package/packages/table/module/filter/panel.ts +329 -329
  101. package/packages/table/module/keyboard/mixin.ts +513 -513
  102. package/packages/table/module/menu/mixin.ts +329 -329
  103. package/packages/table/module/menu/panel.ts +212 -212
  104. package/packages/table/module/validator/mixin.ts +626 -626
  105. package/packages/table/render/index.ts +1456 -1456
  106. package/packages/table/src/body.ts +969 -969
  107. package/packages/table/src/cell.ts +1285 -1285
  108. package/packages/table/src/column.ts +205 -205
  109. package/packages/table/src/columnInfo.ts +228 -228
  110. package/packages/table/src/footer.ts +388 -388
  111. package/packages/table/src/group.ts +51 -51
  112. package/packages/table/src/header.ts +602 -602
  113. package/packages/table/src/methods.ts +12939 -12912
  114. package/packages/table/src/props.ts +311 -311
  115. package/packages/table/src/store.ts +15 -15
  116. package/packages/table/src/table.ts +2502 -2460
  117. package/packages/table/src/util.ts +1012 -1012
  118. package/packages/toolbar/index.ts +18 -18
  119. package/packages/toolbar/src/toolbar.ts +856 -856
  120. package/packages/ui/index.ts +530 -530
  121. package/packages/ui/src/anime.ts +52 -52
  122. package/packages/ui/src/comp.ts +3 -3
  123. package/packages/ui/src/dom.ts +236 -236
  124. package/packages/ui/src/log.ts +8 -8
  125. package/packages/ui/src/utils.ts +56 -56
  126. package/packages/ui/src/vn.ts +65 -65
  127. package/packages/v-x-e-table/index.ts +4 -4
  128. package/styles/all.scss +7 -7
  129. package/styles/base.scss +16 -16
  130. package/styles/components/grid.scss +89 -85
  131. package/styles/components/icon.scss +225 -225
  132. package/styles/components/old-icon.scss +715 -715
  133. package/styles/components/table-module/all.scss +6 -6
  134. package/styles/components/table-module/custom.scss +527 -527
  135. package/styles/components/table-module/export.scss +130 -130
  136. package/styles/components/table-module/filter.scss +130 -130
  137. package/styles/components/table-module/menu.scss +81 -81
  138. package/styles/components/table.scss +2679 -2679
  139. package/styles/components/toolbar.scss +119 -119
  140. package/styles/default.scss +2 -2
  141. package/styles/helpers/baseMixin.scss +95 -95
  142. package/styles/index.scss +3 -3
  143. package/styles/modules.scss +5 -5
  144. package/styles/theme/base.scss +93 -93
  145. package/styles/theme/dark.scss +49 -49
  146. package/styles/theme/light.scss +44 -44
  147. package/styles/variable.scss +43 -43
  148. package/types/all.d.ts +53 -53
  149. package/types/index.d.ts +4 -4
  150. /package/es/{iconfont.1773644050430.ttf → iconfont.1773972972913.ttf} +0 -0
  151. /package/es/{iconfont.1773644050430.woff → iconfont.1773972972913.woff} +0 -0
  152. /package/es/{iconfont.1773644050430.woff2 → iconfont.1773972972913.woff2} +0 -0
  153. /package/lib/{iconfont.1773644050430.ttf → iconfont.1773972972913.ttf} +0 -0
  154. /package/lib/{iconfont.1773644050430.woff → iconfont.1773972972913.woff} +0 -0
  155. /package/lib/{iconfont.1773644050430.woff2 → iconfont.1773972972913.woff2} +0 -0
@@ -1,1935 +1,1935 @@
1
- import { CreateElement, VNode, PropType } from 'vue'
2
- import { defineVxeComponent } from '../../ui/src/comp'
3
- import XEUtils from 'xe-utils'
4
- import { getLastZIndex, nextZIndex, isEnableConf } from '../../ui/src/utils'
5
- import { getOffsetHeight, getPaddingTopBottomSize, getDomNode, toCssUnit } from '../../ui/src/dom'
6
- import { VxeUI } from '../../ui'
7
- import { getSlotVNs } from '../../ui/src/vn'
8
- import { warnLog, errLog } from '../../ui/src/log'
9
- import { tableProps } from '../../table/src/props'
10
- import VxeTableComponent from '../../table/src/table'
11
- import VxeToolbarComponent from '../../toolbar/src/toolbar'
12
-
13
- import type { VxeFormItemProps, VxeFormDefines, VxeComponentStyleType, VxeComponentSizeType, ValueOf, VxeFormInstance, VxeFormItemPropTypes, VxePagerInstance } from 'vxe-pc-ui'
14
- import type { GridReactData, VxeTablePropTypes, VxeGridConstructor, VxeToolbarPropTypes, VxeToolbarInstance, VxeGridPropTypes, VxeTableMethods, GridInternalData, VxeGridEmits, VxePagerDefines, VxeTableConstructor, VxeTableDefines, VxeTablePrivateMethods, TableInternalData, VxeTableProps, VxeGridDefines } from '../../../types'
15
-
16
- const { getConfig, getI18n, commands, globalEvents, globalMixins, createEvent, GLOBAL_EVENT_KEYS, renderEmptyElement } = VxeUI
17
-
18
- const tableMethods: VxeTableMethods = {} as VxeTableMethods
19
- const propKeys = Object.keys(tableProps) as (keyof VxeTableProps)[]
20
-
21
- const defaultLayouts: VxeGridPropTypes.Layouts = [['Form'], ['Toolbar', 'Top', 'Table', 'Bottom', 'Pager']]
22
-
23
- function getTableOns (_vm: any) {
24
- const { $listeners, proxyConfig, proxyOpts } = _vm
25
- const ons: any = {}
26
- XEUtils.each($listeners, (cb: any, type: any) => {
27
- ons[type] = (...args: any[]) => {
28
- _vm.$emit(type, ...args)
29
- }
30
- })
31
- if (proxyConfig) {
32
- if (proxyOpts.sort) {
33
- ons['sort-change'] = _vm.sortChangeEvent
34
- ons['clear-all-sort'] = _vm.clearAllSortEvent
35
- }
36
- if (proxyOpts.filter) {
37
- ons['filter-change'] = _vm.filterChangeEvent
38
- ons['clear-all-filter'] = _vm.clearAllFilterEvent
39
- }
40
- }
41
- return ons
42
- }
43
-
44
- XEUtils.each(VxeTableComponent.methods, (fn, name) => {
45
- tableMethods[name as keyof VxeTableMethods] = function (this: any, ...args: any[]) {
46
- const $xeGrid = this
47
- const $xeTable = $xeGrid.$refs.refTable
48
-
49
- return $xeTable && $xeTable[name](...args)
50
- }
51
- })
52
-
53
- function createReactData (): GridReactData {
54
- return {
55
- tableLoading: false,
56
- proxyInited: false,
57
- isZMax: false,
58
- tableData: [],
59
- filterData: [],
60
- formData: {},
61
- sortData: [],
62
- footerData: [],
63
- tZindex: 0,
64
- tablePage: {
65
- total: 0,
66
- pageSize: getConfig().pager?.pageSize || 10,
67
- currentPage: 1
68
- }
69
- }
70
- }
71
-
72
- function createInternalData (): GridInternalData {
73
- return {
74
- uFoot: false
75
- }
76
- }
77
-
78
- export default /* define-vxe-component start */ defineVxeComponent({
79
- name: 'VxeGrid',
80
- mixins: [
81
- globalMixins.sizeMixin
82
- ],
83
- props: {
84
- ...(tableProps as unknown as {
85
- border: PropType<VxeTablePropTypes.Border>
86
- round: PropType<VxeTablePropTypes.Round>
87
- loading: PropType<VxeTablePropTypes.Loading>
88
- height: PropType<VxeTablePropTypes.Height>
89
- minHeight: PropType<VxeTablePropTypes.MinHeight>
90
- maxHeight: PropType<VxeTablePropTypes.MaxHeight>
91
- seqConfig: PropType<VxeTablePropTypes.SeqConfig>
92
- editConfig: PropType<VxeTablePropTypes.EditConfig>
93
- sortConfig: PropType<VxeTablePropTypes.SortConfig>
94
- filterConfig: PropType<VxeTablePropTypes.FilterConfig>
95
- validConfig: PropType<VxeTablePropTypes.ValidConfig>
96
- editRules: PropType<VxeTablePropTypes.EditRules>
97
- animat: PropType<VxeTablePropTypes.Animat>
98
- scrollbarConfig: PropType<VxeTablePropTypes.ScrollbarConfig>
99
- showFooter: PropType<VxeTablePropTypes.ShowFooter>
100
- params: PropType<VxeTablePropTypes.Params>
101
- }),
102
-
103
- layouts: Array as PropType<VxeGridPropTypes.Layouts>,
104
- columns: Array as PropType<VxeGridPropTypes.Columns<any>>,
105
- pagerConfig: Object as PropType<VxeGridPropTypes.PagerConfig>,
106
- proxyConfig: Object as PropType<VxeGridPropTypes.ProxyConfig<any>>,
107
- toolbarConfig: Object as PropType<VxeGridPropTypes.ToolbarConfig>,
108
- formConfig: Object as PropType<VxeGridPropTypes.FormConfig>,
109
- zoomConfig: Object as PropType<VxeGridPropTypes.ZoomConfig>,
110
- size: {
111
- type: String as PropType<VxeGridPropTypes.Size>,
112
- default: () => getConfig().grid.size || getConfig().size
113
- }
114
- },
115
- provide () {
116
- const $xeGrid = this
117
- const $xeGantt = null
118
-
119
- return {
120
- $xeGrid,
121
- $xeGantt
122
- }
123
- },
124
- data () {
125
- const xID = XEUtils.uniqueId()
126
-
127
- const reactData = createReactData()
128
- const internalData = createInternalData()
129
-
130
- return {
131
- xID,
132
- reactData,
133
- internalData
134
- }
135
- },
136
- computed: {
137
- ...({} as {
138
- computeSize(): VxeComponentSizeType
139
- }),
140
- isRespMsg () {
141
- const $xeGrid = this
142
-
143
- return $xeGrid.computeIsRespMsg
144
- },
145
- computeIsRespMsg () {
146
- const $xeGrid = this
147
-
148
- const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
149
- return !!(XEUtils.isBoolean(proxyOpts.message) ? proxyOpts.message : proxyOpts.showResponseMsg)
150
- },
151
- isActiveMsg () {
152
- const $xeGrid = this
153
-
154
- return $xeGrid.computeIsActiveMsg
155
- },
156
- computeIsActiveMsg () {
157
- const $xeGrid = this
158
-
159
- const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
160
- return XEUtils.isBoolean(proxyOpts.showActionMsg) ? proxyOpts.showActionMsg : !!proxyOpts.showActiveMsg
161
- },
162
- proxyOpts () {
163
- const $xeGrid = this
164
-
165
- return $xeGrid.computeProxyOpts
166
- },
167
- computeProxyOpts () {
168
- const $xeGrid = this
169
- const props = $xeGrid
170
-
171
- return XEUtils.merge({}, XEUtils.clone(getConfig().grid.proxyConfig, true), props.proxyConfig) as VxeGridPropTypes.ProxyConfig
172
- },
173
- pagerOpts () {
174
- const $xeGrid = this
175
-
176
- return $xeGrid.computePagerOpts
177
- },
178
- computePagerOpts () {
179
- const $xeGrid = this
180
- const props = $xeGrid
181
-
182
- return Object.assign({}, getConfig().grid.pagerConfig, props.pagerConfig)
183
- },
184
- formOpts () {
185
- const $xeGrid = this
186
-
187
- return $xeGrid.computeFormOpts
188
- },
189
- computeFormOpts () {
190
- const $xeGrid = this
191
- const props = $xeGrid
192
-
193
- return Object.assign({}, getConfig().grid.formConfig, props.formConfig)
194
- },
195
- toolbarOpts () {
196
- const $xeGrid = this
197
-
198
- return $xeGrid.computeToolbarOpts
199
- },
200
- computeToolbarOpts () {
201
- const $xeGrid = this
202
- const props = $xeGrid
203
-
204
- return Object.assign({}, getConfig().grid.toolbarConfig, props.toolbarConfig)
205
- },
206
- zoomOpts () {
207
- const $xeGrid = this
208
-
209
- return $xeGrid.computeZoomOpts
210
- },
211
- computeZoomOpts () {
212
- const $xeGrid = this
213
- const props = $xeGrid
214
-
215
- return Object.assign({}, getConfig().grid.zoomConfig, props.zoomConfig)
216
- },
217
- computeStyles () {
218
- const $xeGrid = this
219
- const props = $xeGrid
220
- const reactData = $xeGrid.reactData
221
-
222
- const { height, maxHeight } = props
223
- const { isZMax, tZindex } = reactData
224
- const stys: VxeComponentStyleType = {}
225
- if (isZMax) {
226
- stys.zIndex = tZindex
227
- } else {
228
- if (height) {
229
- stys.height = height === 'auto' || height === '100%' ? '100%' : toCssUnit(height)
230
- }
231
- if (maxHeight) {
232
- stys.maxHeight = maxHeight === 'auto' || maxHeight === '100%' ? '100%' : toCssUnit(maxHeight)
233
- }
234
- }
235
- return stys
236
- },
237
- computeTableExtendProps () {
238
- const $xeGrid = this
239
- const props = $xeGrid
240
-
241
- const rest: any = {}
242
- const gridProps: any = props
243
- propKeys.forEach(key => {
244
- if (gridProps[key] !== undefined) {
245
- rest[key] = gridProps[key]
246
- }
247
- })
248
- return rest
249
- },
250
- computeTableProps () {
251
- const $xeGrid = this
252
- const props = $xeGrid
253
- const reactData = $xeGrid.reactData
254
-
255
- const { showFooter, seqConfig, pagerConfig, editConfig, proxyConfig } = props
256
- const { isZMax, tablePage, footerData } = reactData
257
- const tableExtendProps = $xeGrid.computeTableExtendProps as any
258
- const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
259
- const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
260
- const isLoading = $xeGrid.computeIsLoading as boolean
261
- const tProps = Object.assign({}, tableExtendProps)
262
- if (showFooter && !tProps.footerData) {
263
- // 如果未设置自己的标位数据,则使用代理的
264
- tProps.footerData = footerData
265
- } else if (proxyOpts.footer && footerData.length) {
266
- // 如果代理标为数据,且未请求到数据,则用自己的
267
- tProps.footerData = footerData
268
- }
269
- if (isZMax) {
270
- if (tProps.maxHeight) {
271
- tProps.maxHeight = '100%'
272
- } else {
273
- tProps.height = '100%'
274
- }
275
- }
276
- if (proxyConfig && isEnableConf(proxyOpts)) {
277
- tProps.loading = isLoading
278
- if (pagerConfig && proxyOpts.seq && isEnableConf(pagerOpts)) {
279
- tProps.seqConfig = Object.assign({}, seqConfig, { startIndex: (tablePage.currentPage - 1) * tablePage.pageSize })
280
- }
281
- }
282
- if (editConfig) {
283
- tProps.editConfig = Object.assign({}, editConfig)
284
- }
285
- return tProps
286
- },
287
- tableProps () {
288
- const $xeGrid = this
289
-
290
- return $xeGrid.computeTableProps
291
- },
292
- computeCurrLayoutConf () {
293
- const $xeGrid = this
294
- const props = $xeGrid
295
-
296
- const { layouts } = props
297
- let confs: VxeGridPropTypes.Layouts = []
298
- if (layouts && layouts.length) {
299
- confs = layouts
300
- } else {
301
- confs = getConfig().grid.layouts || defaultLayouts
302
- }
303
- let headKeys: VxeGridDefines.LayoutKey[] = []
304
- let bodyKeys: VxeGridDefines.LayoutKey[] = []
305
- let footKeys: VxeGridDefines.LayoutKey[] = []
306
- if (confs.length) {
307
- if (XEUtils.isArray(confs[0])) {
308
- headKeys = confs[0] as VxeGridDefines.LayoutKey[]
309
- bodyKeys = (confs[1] || []) as VxeGridDefines.LayoutKey[]
310
- footKeys = (confs[2] || []) as VxeGridDefines.LayoutKey[]
311
- } else {
312
- bodyKeys = confs as VxeGridDefines.LayoutKey[]
313
- }
314
- }
315
- return {
316
- headKeys,
317
- bodyKeys,
318
- footKeys
319
- }
320
- },
321
- computeCustomCurrentPageFlag () {
322
- const $xeGrid = this
323
-
324
- const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
325
- return pagerOpts.currentPage
326
- },
327
- computeCustomPageSizeFlag () {
328
- const $xeGrid = this
329
-
330
- const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
331
- return pagerOpts.pageSize
332
- },
333
- computeCustomTotalFlag () {
334
- const $xeGrid = this
335
-
336
- const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
337
- return pagerOpts.total
338
- },
339
- computePageCount () {
340
- const $xeGrid = this
341
- const reactData = ($xeGrid as any).reactData as GridReactData
342
-
343
- const { tablePage } = reactData
344
- return Math.max(Math.ceil(tablePage.total / tablePage.pageSize), 1)
345
- },
346
- computeIsLoading () {
347
- const $xeGrid = this
348
- const props = $xeGrid
349
- const reactData = ($xeGrid as any).reactData as GridReactData
350
-
351
- const { loading, proxyConfig } = props
352
- const { tableLoading } = reactData
353
- const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
354
- const { showLoading } = proxyOpts
355
- return loading || (tableLoading && showLoading && proxyConfig && isEnableConf(proxyOpts))
356
- }
357
- },
358
- watch: {
359
- columns (value: any) {
360
- const $xeGrid = this
361
-
362
- $xeGrid.$nextTick(() => $xeGrid.loadColumn(value))
363
- },
364
- toolbar (value: any) {
365
- const $xeGrid = this
366
-
367
- if (value) {
368
- $xeGrid.initToolbar()
369
- }
370
- },
371
- toolbarConfig (value: any) {
372
- const $xeGrid = this
373
-
374
- if (value) {
375
- $xeGrid.initToolbar()
376
- }
377
- },
378
- proxyConfig () {
379
- const $xeGrid = this
380
-
381
- $xeGrid.initProxy()
382
- },
383
- computeCustomCurrentPageFlag () {
384
- const $xeGrid = this
385
-
386
- $xeGrid.initPages('currentPage')
387
- },
388
- computeCustomPageSizeFlag () {
389
- const $xeGrid = this
390
-
391
- $xeGrid.initPages('pageSize')
392
- },
393
- computeCustomTotalFlag () {
394
- const $xeGrid = this
395
-
396
- $xeGrid.initPages('total')
397
- }
398
- },
399
- methods: {
400
- ...tableMethods,
401
- dispatchEvent (type: ValueOf<VxeGridEmits>, params: Record<string, any>, evnt: Event | null) {
402
- const $xeGrid = this
403
- $xeGrid.$emit(type, createEvent(evnt, { $grid: $xeGrid, $gantt: null }, params))
404
- },
405
- initPages (propKey?: 'currentPage' | 'pageSize' | 'total') {
406
- const $xeGrid = this
407
- const props = $xeGrid
408
- const reactData = $xeGrid.reactData
409
-
410
- const { tablePage } = reactData
411
- const { pagerConfig } = props
412
- const pagerOpts = $xeGrid.computePagerOpts
413
- if (pagerConfig && isEnableConf(pagerOpts)) {
414
- if (propKey) {
415
- if (pagerOpts[propKey]) {
416
- tablePage[propKey] = XEUtils.toNumber(pagerOpts[propKey])
417
- }
418
- } else {
419
- const { currentPage, pageSize, total } = pagerOpts
420
- if (currentPage) {
421
- tablePage.currentPage = currentPage
422
- }
423
- if (pageSize) {
424
- tablePage.pageSize = pageSize
425
- }
426
- if (total) {
427
- tablePage.total = total
428
- }
429
- }
430
- }
431
- },
432
- callSlot (slotFunc: any, params: any, h: CreateElement) {
433
- const $xeGrid = this
434
- const slots = $xeGrid.$scopedSlots
435
-
436
- if (slotFunc) {
437
- if (XEUtils.isString(slotFunc)) {
438
- slotFunc = slots[slotFunc] || null
439
- }
440
- if (XEUtils.isFunction(slotFunc)) {
441
- return getSlotVNs(slotFunc.call(this, params, h))
442
- }
443
- }
444
- return []
445
- },
446
- getEl () {
447
- const $xeGrid = this
448
-
449
- return $xeGrid.$refs.refElem as HTMLDivElement
450
- },
451
- /**
452
- * 获取需要排除的高度
453
- */
454
- getExcludeHeight () {
455
- const $xeGrid = this
456
- const props = $xeGrid
457
- const reactData = $xeGrid.reactData
458
-
459
- const { height } = props
460
- const { isZMax } = reactData
461
- const el = $xeGrid.$refs.refElem as HTMLDivElement
462
- if (el) {
463
- const formWrapper = $xeGrid.$refs.refFormWrapper as HTMLDivElement
464
- const toolbarWrapper = $xeGrid.$refs.refToolbarWrapper as HTMLDivElement
465
- const topWrapper = $xeGrid.$refs.refTopWrapper as HTMLDivElement
466
- const bottomWrapper = $xeGrid.$refs.refBottomWrapper as HTMLDivElement
467
- const pagerWrapper = $xeGrid.$refs.refPagerWrapper as HTMLDivElement
468
- const parentEl = el.parentElement as HTMLElement
469
- let parentPaddingSize = 0
470
- if (parentEl && (height === '100%' || height === 'auto')) {
471
- parentPaddingSize = isZMax ? 0 : getPaddingTopBottomSize(parentEl)
472
- }
473
- return parentPaddingSize + getPaddingTopBottomSize(el) + getOffsetHeight(formWrapper) + getOffsetHeight(toolbarWrapper) + getOffsetHeight(topWrapper) + getOffsetHeight(bottomWrapper) + getOffsetHeight(pagerWrapper)
474
- }
475
- return 0
476
- },
477
- getParentHeight () {
478
- const $xeGrid = this
479
- const reactData = $xeGrid.reactData
480
-
481
- const el = $xeGrid.$refs.refElem as HTMLDivElement
482
- if (el) {
483
- const parentEl = el.parentElement as HTMLElement
484
- return (reactData.isZMax ? getDomNode().visibleHeight : (parentEl ? XEUtils.toNumber(getComputedStyle(parentEl).height) : 0)) - $xeGrid.getExcludeHeight()
485
- }
486
- return 0
487
- },
488
- initToolbar () {
489
- const $xeGrid = this
490
-
491
- $xeGrid.$nextTick(() => {
492
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
493
- const $xeToolbar = $xeGrid.$refs.refToolbar as VxeToolbarInstance
494
- if ($xeTable && $xeToolbar) {
495
- $xeTable.connectToolbar($xeToolbar)
496
- }
497
- })
498
- },
499
- getDefaultFormData () {
500
- const $xeGrid = this
501
-
502
- const formOpts = $xeGrid.computeFormOpts
503
- if (formOpts.items) {
504
- const fData: any = {}
505
- formOpts.items.forEach(item => {
506
- const { field, itemRender } = item
507
- if (field) {
508
- let itemValue: any = null
509
- if (itemRender) {
510
- const { startField, endField, defaultValue } = itemRender
511
- if (XEUtils.isFunction(defaultValue)) {
512
- itemValue = defaultValue({ item })
513
- } else if (!XEUtils.isUndefined(defaultValue)) {
514
- itemValue = defaultValue
515
- }
516
- if (startField && endField) {
517
- XEUtils.set(fData, startField, null)
518
- XEUtils.set(fData, endField, null)
519
- }
520
- }
521
- fData[field] = itemValue
522
- }
523
- })
524
- return fData
525
- }
526
- return {}
527
- },
528
- initProxy () {
529
- const $xeGrid = this
530
- const props = $xeGrid
531
- const reactData = $xeGrid.reactData
532
- const internalData = $xeGrid.internalData
533
-
534
- const { proxyConfig, formConfig } = props
535
- const { proxyInited } = reactData
536
- const proxyOpts = $xeGrid.computeProxyOpts
537
- const formOpts = $xeGrid.computeFormOpts
538
- if (proxyConfig) {
539
- if (isEnableConf(formConfig) && proxyOpts.form && formOpts.items) {
540
- reactData.formData = $xeGrid.getDefaultFormData()
541
- }
542
- if (!proxyInited) {
543
- reactData.proxyInited = true
544
- if (proxyOpts.autoLoad !== false) {
545
- $xeGrid.$nextTick().then(() => {
546
- internalData.uFoot = true
547
- const rest = $xeGrid.commitProxy('initial')
548
- internalData.uFoot = false
549
- $xeGrid.updateQueryFooter()
550
- return rest
551
- }).then((rest) => {
552
- $xeGrid.dispatchEvent('proxy-query', { ...rest, isInited: true }, new Event('initial'))
553
- })
554
- }
555
- }
556
- }
557
- },
558
- updateQueryFooter () {
559
- const $xeGrid = this
560
-
561
- const proxyOpts = $xeGrid.computeProxyOpts
562
- const { ajax } = proxyOpts
563
- if (ajax && ajax.queryFooter) {
564
- return $xeGrid.commitProxy('queryFooter')
565
- }
566
- },
567
- handleGlobalKeydownEvent (evnt: KeyboardEvent) {
568
- const $xeGrid = this
569
- const reactData = $xeGrid.reactData
570
-
571
- const zoomOpts = $xeGrid.computeZoomOpts
572
- const isEsc = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ESCAPE)
573
- if (isEsc && reactData.isZMax && zoomOpts.escRestore !== false) {
574
- $xeGrid.triggerZoomEvent(evnt)
575
- }
576
- },
577
- getRespMsg (rest: any, defaultMsg: string) {
578
- const $xeGrid = this
579
-
580
- const proxyOpts = $xeGrid.computeProxyOpts
581
- const resConfigs = proxyOpts.response || proxyOpts.props || {}
582
- const messageProp = resConfigs.message
583
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
584
- let msg
585
- if (rest && messageProp) {
586
- msg = XEUtils.isFunction(messageProp) ? messageProp({ data: rest, $table: $xeTable, $grid: $xeGrid as VxeGridConstructor, $gantt: null }) : XEUtils.get(rest, messageProp)
587
- }
588
- return msg || getI18n(defaultMsg)
589
- },
590
- handleDeleteRow (code: string, alertKey: string, callback: () => void): Promise<void> {
591
- const $xeGrid = this
592
-
593
- const isActiveMsg = $xeGrid.computeIsActiveMsg
594
- const selectRecords = $xeGrid.getCheckboxRecords()
595
- if (isActiveMsg) {
596
- if (selectRecords.length) {
597
- if (VxeUI.modal) {
598
- return VxeUI.modal.confirm({ id: `cfm_${code}`, content: getI18n(alertKey), escClosable: true }).then((type) => {
599
- if (type === 'confirm') {
600
- return callback()
601
- }
602
- })
603
- }
604
- } else {
605
- if (VxeUI.modal) {
606
- VxeUI.modal.message({ id: `msg_${code}`, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
607
- }
608
- }
609
- } else {
610
- if (selectRecords.length) {
611
- callback()
612
- }
613
- }
614
- return Promise.resolve()
615
- },
616
- triggerPendingEvent (code: string) {
617
- const $xeGrid = this
618
-
619
- const isActiveMsg = $xeGrid.computeIsActiveMsg
620
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
621
- const selectRecords = $xeTable.getCheckboxRecords()
622
- if (selectRecords.length) {
623
- $xeTable.togglePendingRow(selectRecords)
624
- $xeGrid.clearCheckboxRow()
625
- } else {
626
- if (isActiveMsg) {
627
- if (VxeUI.modal) {
628
- VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
629
- }
630
- }
631
- }
632
- },
633
- /**
634
- * 提交指令,支持 code 或 button
635
- * @param {String/Object} code 字符串或对象
636
- */
637
- commitProxy (proxyTarget: string | VxeToolbarPropTypes.ButtonConfig, ...args: any[]): Promise<any> {
638
- const $xeGrid = this
639
- const props = $xeGrid
640
- const reactData = $xeGrid.reactData
641
- const internalData = $xeGrid.internalData
642
-
643
- /**
644
- * 已废弃
645
- * @deprecated
646
- */
647
- const toolbar = (props as any).toolbar
648
-
649
- const { showFooter, proxyConfig, toolbarConfig, pagerConfig, editRules, validConfig } = props
650
- const { tablePage } = reactData
651
- const isActiveMsg = $xeGrid.computeIsActiveMsg
652
- const isRespMsg = $xeGrid.computeIsRespMsg
653
- const proxyOpts = $xeGrid.computeProxyOpts
654
- const pagerOpts = $xeGrid.computePagerOpts
655
- const toolbarOpts = $xeGrid.computeToolbarOpts
656
- const { beforeQuery, afterQuery, beforeQueryFooter, afterQueryFooter, beforeDelete, afterDelete, beforeSave, afterSave, ajax = {} } = proxyOpts
657
- const resConfigs = (proxyOpts.response || proxyOpts.props || {}) as VxeGridDefines.ProxyConfigResponseConfig
658
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
659
- let formData = $xeGrid.getFormData()
660
- let button: VxeToolbarPropTypes.ButtonConfig | null = null
661
- let code: string | null = null
662
- if (XEUtils.isString(proxyTarget)) {
663
- const { buttons } = toolbarOpts
664
- const matchObj = (toolbarConfig || toolbar) && isEnableConf(toolbarOpts) && buttons ? XEUtils.findTree(buttons, (item) => item.code === proxyTarget, { children: 'dropdowns' }) : null
665
- button = matchObj ? matchObj.item as any : null
666
- code = proxyTarget
667
- } else {
668
- button = proxyTarget
669
- code = button.code as string
670
- }
671
- const btnParams = button ? button.params : null
672
- switch (code) {
673
- case 'insert':
674
- return $xeTable.insert({})
675
- case 'insert_edit':
676
- return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
677
-
678
- // 已废弃
679
- case 'insert_actived':
680
- return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
681
- // 已废弃
682
-
683
- case 'mark_cancel':
684
- $xeGrid.triggerPendingEvent(code)
685
- break
686
- case 'remove':
687
- return $xeGrid.handleDeleteRow(code, 'vxe.grid.removeSelectRecord', () => $xeTable.removeCheckboxRow())
688
- case 'import':
689
- $xeTable.importData(btnParams)
690
- break
691
- case 'open_import':
692
- $xeTable.openImport(btnParams)
693
- break
694
- case 'export':
695
- $xeTable.exportData(btnParams)
696
- break
697
- case 'open_export':
698
- $xeTable.openExport(btnParams)
699
- break
700
- case 'reset_custom':
701
- $xeTable.resetCustom(true)
702
- break
703
- case 'initial':
704
- case 'reload':
705
- case 'query': {
706
- const qMethods = ajax.query
707
- const qsMethods = ajax.querySuccess
708
- const qeMethods = ajax.queryError
709
- if (qMethods) {
710
- const isInited = code === 'initial'
711
- const isReload = code === 'reload'
712
- if (!isInited && reactData.tableLoading) {
713
- return $xeGrid.$nextTick()
714
- }
715
- let operPromise = null
716
- let sortList: any[] = []
717
- let filterList: VxeTableDefines.FilterCheckedParams[] = []
718
- let pageParams: any = {}
719
- if (pagerConfig) {
720
- if (isInited || isReload) {
721
- tablePage.currentPage = 1
722
- }
723
- if (isEnableConf(pagerConfig)) {
724
- pageParams = { ...tablePage }
725
- }
726
- }
727
- if (isInited) {
728
- // 重置代理表单数据
729
- if (proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form) {
730
- formData = $xeGrid.getDefaultFormData()
731
- reactData.formData = formData
732
- }
733
- if ($xeTable) {
734
- const tableInternalData = $xeTable as unknown as TableInternalData
735
- const { tableFullColumn, fullColumnFieldData } = tableInternalData
736
- const sortOpts = $xeTable.computeSortOpts
737
- let defaultSort = sortOpts.defaultSort
738
- tableFullColumn.forEach((column) => {
739
- column.order = null
740
- })
741
- // 如果使用默认排序
742
- if (defaultSort) {
743
- if (!XEUtils.isArray(defaultSort)) {
744
- defaultSort = [defaultSort]
745
- }
746
- sortList = defaultSort.map((item) => {
747
- const { field, order } = item
748
- const colRest = fullColumnFieldData[field]
749
- if (colRest) {
750
- const column = colRest.column
751
- if (column) {
752
- column.order = order
753
- }
754
- }
755
- return {
756
- field,
757
- property: field,
758
- order
759
- }
760
- })
761
- }
762
- filterList = $xeTable.getCheckedFilters()
763
- }
764
- } else {
765
- if ($xeTable) {
766
- if (isReload) {
767
- operPromise = $xeTable.clearAll()
768
- } else {
769
- sortList = $xeTable.getSortColumns()
770
- filterList = $xeTable.getCheckedFilters()
771
- }
772
- }
773
- }
774
- const commitParams = {
775
- $table: $xeTable,
776
- $grid: $xeGrid as VxeGridConstructor,
777
- $gantt: null,
778
- code,
779
- button,
780
- isInited,
781
- isReload,
782
- page: pageParams,
783
- sort: sortList.length ? sortList[0] : {},
784
- sorts: sortList,
785
- filters: filterList,
786
- form: formData,
787
- options: qMethods
788
- }
789
- reactData.sortData = sortList
790
- reactData.filterData = filterList
791
- reactData.tableLoading = true
792
- return Promise.all([
793
- Promise.resolve((beforeQuery || qMethods)(commitParams, ...args)),
794
- operPromise
795
- ]).then(([rest]) => {
796
- let tableData: any[] = []
797
- reactData.tableLoading = false
798
- if (rest) {
799
- const reParams = { data: rest, $table: $xeTable, $grid: $xeGrid as VxeGridConstructor, $gantt: null }
800
- if (pagerConfig && isEnableConf(pagerOpts)) {
801
- const totalProp = resConfigs.total
802
- const total = (XEUtils.isFunction(totalProp) ? totalProp(reParams) : XEUtils.get(rest, totalProp || 'page.total')) || 0
803
- tablePage.total = XEUtils.toNumber(total)
804
- const resultProp = resConfigs.result
805
- tableData = (XEUtils.isFunction(resultProp) ? resultProp(reParams) : XEUtils.get(rest, resultProp || 'result')) || []
806
- // 检验当前页码,不能超出当前最大页数
807
- const pageCount = Math.max(Math.ceil(total / tablePage.pageSize), 1)
808
- if (tablePage.currentPage > pageCount) {
809
- tablePage.currentPage = pageCount
810
- }
811
- } else {
812
- const listProp = resConfigs.list
813
- if (XEUtils.isArray(rest)) {
814
- tableData = rest
815
- } else if (listProp) {
816
- tableData = (XEUtils.isFunction(listProp) ? listProp(reParams) : XEUtils.get(rest, listProp)) || []
817
- }
818
- }
819
- if (showFooter) {
820
- const fdProp = resConfigs.footerData
821
- const footerList = fdProp ? (XEUtils.isFunction(fdProp) ? fdProp(reParams) : XEUtils.get(rest, fdProp)) : []
822
- if (XEUtils.isArray(footerList)) {
823
- reactData.footerData = footerList
824
- }
825
- }
826
- }
827
- if ($xeTable) {
828
- $xeTable.loadData(tableData)
829
- } else {
830
- $xeGrid.$nextTick(() => {
831
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
832
- if ($xeTable) {
833
- $xeTable.loadData(tableData)
834
- }
835
- })
836
- }
837
- if (afterQuery) {
838
- afterQuery(commitParams, ...args)
839
- }
840
- if (qsMethods) {
841
- qsMethods({ ...commitParams, response: rest })
842
- }
843
- return { status: true }
844
- }).catch((rest) => {
845
- reactData.tableLoading = false
846
- if (qeMethods) {
847
- qeMethods({ ...commitParams, response: rest })
848
- }
849
- return { status: false }
850
- })
851
- } else {
852
- errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.query'])
853
- }
854
- break
855
- }
856
- case 'queryFooter': {
857
- const qfMethods = ajax.queryFooter
858
- const qfSuccessMethods = ajax.queryFooterSuccess
859
- const qfErrorMethods = ajax.queryFooterError
860
- if (qfMethods) {
861
- let filterList: VxeTableDefines.FilterCheckedParams[] = []
862
- if ($xeTable) {
863
- filterList = $xeTable.getCheckedFilters()
864
- }
865
- const commitParams = {
866
- $table: $xeTable,
867
- $grid: $xeGrid,
868
- $gantt: null,
869
- code,
870
- button,
871
- filters: filterList,
872
- form: formData,
873
- options: qfMethods
874
- }
875
- return Promise.resolve((beforeQueryFooter || qfMethods)(commitParams, ...args)).then(rest => {
876
- reactData.footerData = XEUtils.isArray(rest) ? rest : []
877
- if (afterQueryFooter) {
878
- afterQueryFooter(commitParams, ...args)
879
- }
880
- if (qfSuccessMethods) {
881
- qfSuccessMethods({ ...commitParams, response: rest })
882
- }
883
- return { status: true }
884
- }).catch((rest) => {
885
- if (qfErrorMethods) {
886
- qfErrorMethods({ ...commitParams, response: rest })
887
- }
888
- return { status: false }
889
- })
890
- } else {
891
- errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.queryFooter'])
892
- }
893
- break
894
- }
895
- case 'delete': {
896
- const dMethods = ajax.delete
897
- const deleteSuccessMethods = ajax.deleteSuccess
898
- const deleteErrorMethods = ajax.deleteError
899
- if (dMethods) {
900
- const selectRecords = $xeTable.getCheckboxRecords()
901
- const removeRecords = selectRecords.filter((row) => !$xeTable.isInsertByRow(row))
902
- const body = { removeRecords }
903
- const commitParams = {
904
- $table: $xeTable,
905
- $grid: $xeGrid as VxeGridConstructor,
906
- $gantt: null,
907
- code,
908
- button,
909
- body,
910
- form: formData,
911
- options: dMethods
912
- }
913
- const applyArgs = [commitParams].concat(args)
914
- if (selectRecords.length) {
915
- return $xeGrid.handleDeleteRow(code, 'vxe.grid.deleteSelectRecord', () => {
916
- if (!removeRecords.length) {
917
- return $xeTable.remove(selectRecords)
918
- }
919
- reactData.tableLoading = true
920
- return Promise.resolve((beforeDelete || dMethods)(...applyArgs))
921
- .then(rest => {
922
- reactData.tableLoading = false
923
- $xeTable.setPendingRow(removeRecords, false)
924
- if (isRespMsg) {
925
- if (VxeUI.modal) {
926
- VxeUI.modal.message({ content: $xeGrid.getRespMsg(rest, 'vxe.grid.delSuccess'), status: 'success' })
927
- }
928
- }
929
- if (afterDelete) {
930
- afterDelete(...applyArgs)
931
- } else {
932
- internalData.uFoot = true
933
- $xeGrid.commitProxy('query')
934
- internalData.uFoot = false
935
- $xeGrid.updateQueryFooter()
936
- }
937
- if (deleteSuccessMethods) {
938
- deleteSuccessMethods({ ...commitParams, response: rest })
939
- }
940
- return { status: true }
941
- })
942
- .catch(rest => {
943
- reactData.tableLoading = false
944
- if (isRespMsg) {
945
- if (VxeUI.modal) {
946
- VxeUI.modal.message({ id: code, content: $xeGrid.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
947
- }
948
- }
949
- if (deleteErrorMethods) {
950
- deleteErrorMethods({ ...commitParams, response: rest })
951
- }
952
- return { status: false }
953
- })
954
- })
955
- } else {
956
- if (isActiveMsg) {
957
- if (VxeUI.modal) {
958
- VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
959
- }
960
- }
961
- }
962
- } else {
963
- errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.delete'])
964
- }
965
- break
966
- }
967
- case 'save': {
968
- const ajaxMethods = ajax.save
969
- const saveSuccessMethods = ajax.saveSuccess
970
- const saveErrorMethods = ajax.saveError
971
- if (ajaxMethods) {
972
- const body = $xeGrid.getRecordset()
973
- const { insertRecords, removeRecords, updateRecords, pendingRecords } = body
974
- const commitParams = {
975
- $table: $xeTable,
976
- $grid: $xeGrid as VxeGridConstructor,
977
- $gantt: null,
978
- code,
979
- button,
980
- body,
981
- form: formData,
982
- options: ajaxMethods
983
- }
984
- const applyArgs = [commitParams].concat(args)
985
- // 排除掉新增且标记为删除的数据
986
- if (insertRecords.length) {
987
- body.pendingRecords = pendingRecords.filter((row) => insertRecords.indexOf(row) === -1)
988
- }
989
- // 排除已标记为删除的数据
990
- if (pendingRecords.length) {
991
- body.insertRecords = insertRecords.filter((row) => pendingRecords.indexOf(row) === -1)
992
- }
993
- let restPromise: Promise<any> = Promise.resolve()
994
- if (editRules) {
995
- // 只校验新增和修改的数据
996
- restPromise = $xeGrid[validConfig && validConfig.msgMode === 'full' ? 'fullValidate' : 'validate'](body.insertRecords.concat(updateRecords))
997
- }
998
- return restPromise.then((errMap: any) => {
999
- if (errMap) {
1000
- // 如果校验不通过
1001
- return
1002
- }
1003
- if (body.insertRecords.length || removeRecords.length || updateRecords.length || body.pendingRecords.length) {
1004
- reactData.tableLoading = true
1005
- return Promise.resolve((beforeSave || ajaxMethods)(...applyArgs))
1006
- .then(rest => {
1007
- reactData.tableLoading = false
1008
- $xeTable.clearPendingRow()
1009
- if (isRespMsg) {
1010
- if (VxeUI.modal) {
1011
- VxeUI.modal.message({ content: $xeGrid.getRespMsg(rest, 'vxe.grid.saveSuccess'), status: 'success' })
1012
- }
1013
- }
1014
- if (afterSave) {
1015
- afterSave(...applyArgs)
1016
- } else {
1017
- internalData.uFoot = true
1018
- $xeGrid.commitProxy('query')
1019
- internalData.uFoot = false
1020
- $xeGrid.updateQueryFooter()
1021
- }
1022
- if (saveSuccessMethods) {
1023
- saveSuccessMethods({ ...commitParams, response: rest })
1024
- }
1025
- return { status: true }
1026
- })
1027
- .catch(rest => {
1028
- reactData.tableLoading = false
1029
- if (isRespMsg) {
1030
- if (VxeUI.modal) {
1031
- VxeUI.modal.message({ id: code, content: $xeGrid.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1032
- }
1033
- }
1034
- if (saveErrorMethods) {
1035
- saveErrorMethods({ ...commitParams, response: rest })
1036
- }
1037
- return { status: false }
1038
- })
1039
- } else {
1040
- if (isActiveMsg) {
1041
- if (VxeUI.modal) {
1042
- VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.dataUnchanged'), status: 'info' })
1043
- }
1044
- }
1045
- }
1046
- })
1047
- } else {
1048
- errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.save'])
1049
- }
1050
- break
1051
- }
1052
- default: {
1053
- const gCommandOpts = commands.get(code)
1054
- if (gCommandOpts) {
1055
- const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
1056
- if (tCommandMethod) {
1057
- tCommandMethod({ code, button, $grid: $xeGrid as VxeGridConstructor, $table: $xeTable, $gantt: null }, ...args)
1058
- } else {
1059
- errLog('vxe.error.notCommands', [`[grid] ${code}`])
1060
- }
1061
- }
1062
- }
1063
- }
1064
- return $xeGrid.$nextTick()
1065
- },
1066
- getFormData () {
1067
- const $xeGrid = this
1068
- const props = $xeGrid
1069
- const reactData = $xeGrid.reactData
1070
-
1071
- const { proxyConfig } = props
1072
- const { formData } = reactData
1073
- const proxyOpts = $xeGrid.computeProxyOpts
1074
- const formOpts = $xeGrid.computeFormOpts
1075
- return proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form ? formData : formOpts.data
1076
- },
1077
- getFormItems (itemIndex?: number): any {
1078
- const $xeGrid = this
1079
- const props = $xeGrid
1080
-
1081
- const formOpts = $xeGrid.computeFormOpts
1082
- const { formConfig } = props
1083
- const { items } = formOpts
1084
- const itemList: VxeFormItemProps[] = []
1085
- XEUtils.eachTree(formConfig && isEnableConf(formOpts) && items ? items : [], item => {
1086
- itemList.push(item)
1087
- }, { children: 'children' })
1088
- return XEUtils.isUndefined(itemIndex) ? itemList : itemList[itemIndex]
1089
- },
1090
- resetForm () {
1091
- const $xeGrid = this
1092
-
1093
- const $form = $xeGrid.$refs.refForm as VxeFormInstance
1094
- if ($form) {
1095
- return $form.reset()
1096
- }
1097
- return $xeGrid.$nextTick()
1098
- },
1099
- validateForm () {
1100
- const $xeGrid = this
1101
-
1102
- const $form = $xeGrid.$refs.refForm as VxeFormInstance
1103
- if ($form) {
1104
- return $form.validate()
1105
- }
1106
- return $xeGrid.$nextTick() as unknown as Promise<VxeFormDefines.ValidateErrorMapParams>
1107
- },
1108
- validateFormField (field: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null) {
1109
- const $xeGrid = this
1110
-
1111
- const $form = $xeGrid.$refs.refForm as VxeFormInstance
1112
- if ($form) {
1113
- return $form.validateField(field)
1114
- }
1115
- return $xeGrid.$nextTick() as unknown as Promise<VxeFormDefines.ValidateErrorMapParams>
1116
- },
1117
- clearFormValidate (field?: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null) {
1118
- const $xeGrid = this
1119
-
1120
- const $form = $xeGrid.$refs.refForm as VxeFormInstance
1121
- if ($form) {
1122
- return $form.clearValidate(field)
1123
- }
1124
- return $xeGrid.$nextTick()
1125
- },
1126
- homePage () {
1127
- const $xeGrid = this
1128
- const reactData = $xeGrid.reactData
1129
-
1130
- const { tablePage } = reactData
1131
- tablePage.currentPage = 1
1132
- return $xeGrid.$nextTick()
1133
- },
1134
- homePageByEvent (evnt: Event) {
1135
- const $xeGrid = this
1136
-
1137
- const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1138
- if ($pager) {
1139
- $pager.homePageByEvent(evnt)
1140
- }
1141
- },
1142
- endPage () {
1143
- const $xeGrid = this
1144
- const reactData = $xeGrid.reactData
1145
-
1146
- const { tablePage } = reactData
1147
- const pageCount = $xeGrid.computePageCount
1148
- tablePage.currentPage = pageCount
1149
- return $xeGrid.$nextTick()
1150
- },
1151
- endPageByEvent (evnt: Event) {
1152
- const $xeGrid = this
1153
-
1154
- const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1155
- if ($pager) {
1156
- $pager.endPageByEvent(evnt)
1157
- }
1158
- },
1159
- getCurrentPage () {
1160
- const $xeGrid = this
1161
- const reactData = $xeGrid.reactData
1162
-
1163
- const { tablePage } = reactData
1164
- return tablePage.currentPage
1165
- },
1166
- setCurrentPage (currentPage: number | string | null | undefined) {
1167
- const $xeGrid = this
1168
- const reactData = $xeGrid.reactData
1169
-
1170
- const { tablePage } = reactData
1171
- const pageCount = $xeGrid.computePageCount
1172
- tablePage.currentPage = Math.min(pageCount, Math.max(1, XEUtils.toNumber(currentPage)))
1173
- return $xeGrid.$nextTick()
1174
- },
1175
- setCurrentPageByEvent (evnt: Event, currentPage: number | string | null | undefined) {
1176
- const $xeGrid = this
1177
-
1178
- const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1179
- if ($pager) {
1180
- $pager.setCurrentPageByEvent(evnt, currentPage)
1181
- }
1182
- },
1183
- getPageSize () {
1184
- const $xeGrid = this
1185
- const reactData = $xeGrid.reactData
1186
-
1187
- const { tablePage } = reactData
1188
- return tablePage.pageSize
1189
- },
1190
- setPageSize (pageSize: number | string | null | undefined) {
1191
- const $xeGrid = this
1192
- const reactData = $xeGrid.reactData
1193
-
1194
- const { tablePage } = reactData
1195
- tablePage.pageSize = Math.max(1, XEUtils.toNumber(pageSize))
1196
- return $xeGrid.$nextTick()
1197
- },
1198
- setPageSizeByEvent (evnt: Event, pageSize: number | string | null | undefined) {
1199
- const $xeGrid = this
1200
-
1201
- const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1202
- if ($pager) {
1203
- $pager.setPageSizeByEvent(evnt, pageSize)
1204
- }
1205
- },
1206
- triggerToolbarCommitEvent (params: any, evnt: any) {
1207
- const $xeGrid = this
1208
- const internalData = $xeGrid.internalData
1209
-
1210
- const { code } = params
1211
- if (code) {
1212
- const isUf = ['reload', 'delete', 'save'].includes(code)
1213
- if (isUf) {
1214
- internalData.uFoot = true
1215
- }
1216
- const rest = $xeGrid.commitProxy(params, evnt).then((rest) => {
1217
- if (code && rest && rest.status && ['query', 'reload', 'delete', 'save'].includes(code)) {
1218
- $xeGrid.dispatchEvent(code === 'delete' || code === 'save' ? `proxy-${code as 'delete' | 'save'}` : 'proxy-query', { ...rest, isReload: code === 'reload' }, evnt)
1219
- }
1220
- })
1221
- if (isUf) {
1222
- $xeGrid.updateQueryFooter()
1223
- }
1224
- internalData.uFoot = false
1225
- return rest
1226
- }
1227
- return $xeGrid.$nextTick()
1228
- },
1229
- triggerToolbarBtnEvent (button: any, evnt: any) {
1230
- const $xeGrid = this
1231
-
1232
- $xeGrid.triggerToolbarCommitEvent(button, evnt)
1233
- $xeGrid.dispatchEvent('toolbar-button-click', { code: button.code, button }, evnt)
1234
- },
1235
- triggerToolbarTolEvent (tool: any, evnt: any) {
1236
- const $xeGrid = this
1237
-
1238
- $xeGrid.triggerToolbarCommitEvent(tool, evnt)
1239
- $xeGrid.dispatchEvent('toolbar-tool-click', { code: tool.code, tool }, evnt)
1240
- },
1241
- pageChangeEvent (params: VxePagerDefines.PageChangeEventParams) {
1242
- const $xeGrid = this
1243
- const props = $xeGrid
1244
- const reactData = $xeGrid.reactData
1245
-
1246
- const { proxyConfig } = props
1247
- const { tablePage } = reactData
1248
- const { $event, currentPage, pageSize } = params
1249
- const proxyOpts = $xeGrid.computeProxyOpts
1250
- tablePage.currentPage = currentPage
1251
- tablePage.pageSize = pageSize
1252
- $xeGrid.dispatchEvent('page-change', params, $event)
1253
- if (proxyConfig && isEnableConf(proxyOpts)) {
1254
- $xeGrid.commitProxy('query').then((rest) => {
1255
- $xeGrid.dispatchEvent('proxy-query', rest, $event)
1256
- })
1257
- }
1258
- },
1259
- handleSortEvent (params: VxeTableDefines.SortChangeEventParams) {
1260
- const $xeGrid = this
1261
- const props = $xeGrid
1262
- const reactData = $xeGrid.reactData
1263
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1264
-
1265
- const { proxyConfig } = props
1266
- const proxyOpts = $xeGrid.computeProxyOpts
1267
- const sortOpts = $xeTable.computeSortOpts
1268
- // 如果是服务端排序
1269
- if (sortOpts.remote) {
1270
- reactData.sortData = params.sortList
1271
- if (proxyConfig && isEnableConf(proxyOpts)) {
1272
- reactData.tablePage.currentPage = 1
1273
- $xeGrid.commitProxy('query').then((rest) => {
1274
- $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
1275
- })
1276
- }
1277
- }
1278
- },
1279
- sortChangeEvent (params: VxeTableDefines.SortChangeEventParams) {
1280
- const $xeGrid = this
1281
-
1282
- $xeGrid.handleSortEvent(params)
1283
- $xeGrid.dispatchEvent('sort-change', params, params.$event)
1284
- },
1285
- clearAllSortEvent (params: VxeTableDefines.SortChangeEventParams) {
1286
- const $xeGrid = this
1287
-
1288
- $xeGrid.handleSortEvent(params)
1289
- $xeGrid.dispatchEvent('clear-all-sort', params, params.$event)
1290
- },
1291
- handleFilterEvent (params: VxeTableDefines.ClearAllFilterEventParams) {
1292
- const $xeGrid = this
1293
- const props = $xeGrid
1294
- const reactData = $xeGrid.reactData
1295
- const internalData = $xeGrid.internalData
1296
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1297
-
1298
- const { proxyConfig } = props
1299
- const proxyOpts = $xeGrid.computeProxyOpts
1300
- const filterOpts = $xeTable.computeFilterOpts
1301
- // 如果是服务端过滤
1302
- if (filterOpts.remote) {
1303
- reactData.filterData = params.filterList
1304
- if (proxyConfig && isEnableConf(proxyOpts)) {
1305
- reactData.tablePage.currentPage = 1
1306
- internalData.uFoot = true
1307
- $xeGrid.commitProxy('query').then((rest) => {
1308
- $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
1309
- })
1310
- internalData.uFoot = false
1311
- $xeGrid.updateQueryFooter()
1312
- }
1313
- }
1314
- },
1315
- filterChangeEvent (params: VxeTableDefines.ClearAllFilterEventParams) {
1316
- const $xeGrid = this
1317
-
1318
- $xeGrid.handleFilterEvent(params)
1319
- $xeGrid.dispatchEvent('filter-change', params, params.$event)
1320
- },
1321
- clearAllFilterEvent (params: VxeTableDefines.ClearAllFilterEventParams) {
1322
- const $xeGrid = this
1323
-
1324
- $xeGrid.handleFilterEvent(params)
1325
- $xeGrid.dispatchEvent('clear-all-filter', params, params.$event)
1326
- },
1327
- submitFormEvent (params: VxeFormDefines.SubmitEventParams) {
1328
- const $xeGrid = this
1329
- const props = $xeGrid
1330
- const reactData = $xeGrid.reactData
1331
- const internalData = $xeGrid.internalData
1332
-
1333
- const { proxyConfig } = props
1334
- const proxyOpts = $xeGrid.computeProxyOpts
1335
- if (reactData.tableLoading) {
1336
- return
1337
- }
1338
- if (proxyConfig && isEnableConf(proxyOpts)) {
1339
- internalData.uFoot = true
1340
- $xeGrid.commitProxy('reload').then((rest) => {
1341
- $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, params.$event)
1342
- })
1343
- internalData.uFoot = false
1344
- $xeGrid.updateQueryFooter()
1345
- }
1346
- $xeGrid.dispatchEvent('form-submit', params, params.$event)
1347
- },
1348
- resetFormEvent (params: VxeFormDefines.ResetEventParams) {
1349
- const $xeGrid = this
1350
- const props = $xeGrid
1351
- const internalData = $xeGrid.internalData
1352
-
1353
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1354
- const { proxyConfig } = props
1355
- const { $event } = params
1356
- const proxyOpts = $xeGrid.computeProxyOpts
1357
- if (proxyConfig && isEnableConf(proxyOpts)) {
1358
- $xeTable.clearScroll()
1359
- internalData.uFoot = true
1360
- $xeGrid.commitProxy('reload').then((rest) => {
1361
- $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, $event)
1362
- })
1363
- internalData.uFoot = false
1364
- $xeGrid.updateQueryFooter()
1365
- }
1366
- $xeGrid.dispatchEvent('form-reset', params, $event)
1367
- },
1368
- submitInvalidEvent (params: VxeFormDefines.SubmitInvalidEventParams) {
1369
- const $xeGrid = this
1370
-
1371
- $xeGrid.dispatchEvent('form-submit-invalid', params, params.$event)
1372
- },
1373
- collapseEvent (params: VxeFormDefines.CollapseEventParams) {
1374
- const $xeGrid = this
1375
-
1376
- const { $event } = params
1377
- $xeGrid.dispatchEvent('form-toggle-collapse', params, $event)
1378
- $xeGrid.dispatchEvent('form-collapse', params, $event)
1379
- },
1380
- triggerZoomEvent (evnt: Event) {
1381
- const $xeGrid = this
1382
- const reactData = $xeGrid.reactData
1383
-
1384
- $xeGrid.zoom()
1385
- $xeGrid.dispatchEvent('zoom', { type: reactData.isZMax ? 'max' : 'revert' }, evnt)
1386
- },
1387
- getParams () {
1388
- const $xeGrid = this
1389
- const props = $xeGrid
1390
-
1391
- return (props as any).params
1392
- },
1393
- zoom () {
1394
- const $xeGrid = this
1395
- const reactData = $xeGrid.reactData
1396
-
1397
- if (reactData.isZMax) {
1398
- return $xeGrid.revert()
1399
- }
1400
- return $xeGrid.maximize()
1401
- },
1402
- isMaximized () {
1403
- const $xeGrid = this
1404
- const reactData = $xeGrid.reactData
1405
-
1406
- return reactData.isZMax
1407
- },
1408
- maximize () {
1409
- const $xeGrid = this
1410
-
1411
- return $xeGrid.handleZoom(true)
1412
- },
1413
- revert () {
1414
- const $xeGrid = this
1415
-
1416
- return $xeGrid.handleZoom()
1417
- },
1418
- handleZoom (isMax?: boolean) {
1419
- const $xeGrid = this
1420
- const reactData = $xeGrid.reactData
1421
-
1422
- const { isZMax } = reactData
1423
- if (isMax ? !isZMax : isZMax) {
1424
- reactData.isZMax = !isZMax
1425
- if (reactData.tZindex < getLastZIndex()) {
1426
- reactData.tZindex = nextZIndex()
1427
- }
1428
- }
1429
- return $xeGrid.$nextTick()
1430
- .then(() => $xeGrid.recalculate(true))
1431
- .then(() => {
1432
- setTimeout(() => $xeGrid.recalculate(true), 15)
1433
- return reactData.isZMax
1434
- })
1435
- },
1436
- getProxyInfo () {
1437
- const $xeGrid = this
1438
- const props = $xeGrid
1439
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1440
- const reactData = $xeGrid.reactData
1441
-
1442
- if (props.proxyConfig) {
1443
- const { sortData } = reactData
1444
- return {
1445
- data: $xeTable ? $xeTable.getFullData() : [],
1446
- filter: reactData.filterData,
1447
- form: $xeGrid.getFormData(),
1448
- sort: sortData.length ? sortData[0] : {},
1449
- sorts: sortData,
1450
- pager: reactData.tablePage,
1451
- pendingRecords: $xeTable ? $xeTable.getPendingRecords() : []
1452
- }
1453
- }
1454
- return null
1455
- },
1456
- loadColumn (columns: any[]) {
1457
- const $xeGrid = this
1458
- const slots = $xeGrid.$scopedSlots
1459
- const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1460
-
1461
- XEUtils.eachTree(columns, column => {
1462
- if (column.slots) {
1463
- XEUtils.each(column.slots, (func) => {
1464
- if (!XEUtils.isFunction(func)) {
1465
- if (!slots[func]) {
1466
- errLog('vxe.error.notSlot', [`[grid] ${func}`])
1467
- }
1468
- }
1469
- })
1470
- }
1471
- })
1472
- return $xeTable.loadColumn(columns)
1473
- },
1474
- reloadColumn (columns: any[]) {
1475
- const $xeGrid = this
1476
-
1477
- $xeGrid.clearAll()
1478
- return $xeGrid.loadColumn(columns)
1479
- },
1480
- getConfigSlot (slotConfigs?: Record<string, any>) {
1481
- const $xeGrid = this
1482
- const slots = $xeGrid.$scopedSlots
1483
-
1484
- const slotConf: Record<string, any> = {}
1485
- XEUtils.objectMap(slotConfigs, (slotFunc, slotKey) => {
1486
- if (slotFunc) {
1487
- if (XEUtils.isString(slotFunc)) {
1488
- if (slots[slotFunc]) {
1489
- slotConf[slotKey] = slots[slotFunc]
1490
- } else {
1491
- errLog('vxe.error.notSlot', [`[grid] ${slotFunc}`])
1492
- }
1493
- } else {
1494
- slotConf[slotKey] = slotFunc
1495
- }
1496
- }
1497
- })
1498
- return slotConf
1499
- },
1500
- getToolbarSlots () {
1501
- const $xeGrid = this
1502
- const slots = $xeGrid.$scopedSlots
1503
-
1504
- const toolbarOpts = $xeGrid.computeToolbarOpts
1505
- const toolbarOptSlots = toolbarOpts.slots
1506
- const toolbarSlots: {
1507
- buttons?(params: any): any
1508
- buttonPrefix?(params: any): any
1509
- buttonSuffix?(params: any): any
1510
- tools?(params: any): any
1511
- toolPrefix?(params: any): any
1512
- toolSuffix?(params: any): any
1513
- } = {}
1514
- if (slots.buttons && (!toolbarOptSlots || toolbarOptSlots.buttons !== 'buttons')) {
1515
- warnLog('vxe.error.reqProp', ['[grid] toolbar-config.slots.buttons'])
1516
- }
1517
- if (slots.tools && (!toolbarOptSlots || toolbarOptSlots.tools !== 'tools')) {
1518
- warnLog('vxe.error.reqProp', ['[grid] toolbar-config.slots.tools'])
1519
- }
1520
- if (toolbarOptSlots) {
1521
- const buttonsSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttons')
1522
- const buttonPrefixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttonPrefix')
1523
- const buttonSuffixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttonSuffix')
1524
- const toolsSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'tools')
1525
- const toolPrefixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'toolPrefix')
1526
- const toolSuffixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'toolSuffix')
1527
- if (buttonsSlot) {
1528
- toolbarSlots.buttons = buttonsSlot
1529
- }
1530
- if (buttonPrefixSlot) {
1531
- toolbarSlots.buttonPrefix = buttonPrefixSlot
1532
- }
1533
- if (buttonSuffixSlot) {
1534
- toolbarSlots.buttonSuffix = buttonSuffixSlot
1535
- }
1536
- if (toolsSlot) {
1537
- toolbarSlots.tools = toolsSlot
1538
- }
1539
- if (toolPrefixSlot) {
1540
- toolbarSlots.toolPrefix = toolPrefixSlot
1541
- }
1542
- if (toolSuffixSlot) {
1543
- toolbarSlots.toolSuffix = toolSuffixSlot
1544
- }
1545
- }
1546
- return toolbarSlots
1547
- },
1548
- getFuncSlot (optSlots: any, slotKey: any) {
1549
- const $xeGrid = this
1550
- const slots = $xeGrid.$scopedSlots
1551
-
1552
- const funcSlot = optSlots[slotKey]
1553
- if (funcSlot) {
1554
- if (XEUtils.isString(funcSlot)) {
1555
- if (slots[funcSlot]) {
1556
- return slots[funcSlot]
1557
- } else {
1558
- errLog('vxe.error.notSlot', [`[grid] ${funcSlot}`])
1559
- }
1560
- } else {
1561
- return funcSlot
1562
- }
1563
- }
1564
- return null
1565
- },
1566
-
1567
- //
1568
- // Render
1569
- //
1570
- renderDefaultForm (h: CreateElement) {
1571
- const VxeUIFormComponent = VxeUI.getComponent('VxeForm')
1572
-
1573
- const $xeGrid = this
1574
- const props = $xeGrid
1575
- const slots = $xeGrid.$scopedSlots
1576
- const reactData = $xeGrid.reactData
1577
-
1578
- const { proxyConfig, formConfig } = props
1579
- const { formData } = reactData
1580
- const proxyOpts = $xeGrid.computeProxyOpts
1581
- const formOpts = $xeGrid.computeFormOpts
1582
- if (isEnableConf(formConfig) && formOpts.items && formOpts.items.length) {
1583
- const formSlots: any = {}
1584
- if (!(formOpts as any).inited) {
1585
- (formOpts as any).inited = true
1586
- const beforeItem = proxyOpts.beforeItem
1587
- if (proxyOpts && beforeItem) {
1588
- formOpts.items.forEach((item) => {
1589
- beforeItem.call($xeGrid, { $grid: $xeGrid, $gantt: null, item })
1590
- })
1591
- }
1592
- }
1593
- // 处理插槽
1594
- formOpts.items.forEach((item) => {
1595
- XEUtils.each(item.slots, (func) => {
1596
- if (!XEUtils.isFunction(func)) {
1597
- if (slots[func]) {
1598
- formSlots[func] = slots[func]
1599
- }
1600
- }
1601
- })
1602
- })
1603
- return [
1604
- VxeUIFormComponent
1605
- ? h(VxeUIFormComponent, {
1606
- ref: 'refForm',
1607
- props: Object.assign({}, formOpts, {
1608
- data: proxyConfig && proxyOpts.form ? formData : formOpts.data
1609
- }),
1610
- on: {
1611
- submit: $xeGrid.submitFormEvent,
1612
- reset: $xeGrid.resetFormEvent,
1613
- collapse: $xeGrid.collapseEvent,
1614
- 'submit-invalid': $xeGrid.submitInvalidEvent
1615
- },
1616
- scopedSlots: formSlots
1617
- })
1618
- : renderEmptyElement($xeGrid)
1619
- ]
1620
- }
1621
- return []
1622
- },
1623
- renderForm (h: CreateElement) {
1624
- const $xeGrid = this
1625
- const props = $xeGrid
1626
- const slots = $xeGrid.$scopedSlots
1627
-
1628
- const { formConfig } = props
1629
- const formSlot = slots.form
1630
- const hasForm = !!(formSlot || isEnableConf(formConfig))
1631
-
1632
- if (hasForm) {
1633
- return h('div', {
1634
- key: 'form',
1635
- ref: 'refFormWrapper',
1636
- class: 'vxe-grid--form-wrapper'
1637
- }, formSlot ? formSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null }) : $xeGrid.renderDefaultForm(h))
1638
- }
1639
- return renderEmptyElement($xeGrid)
1640
- },
1641
- renderToolbar (h: CreateElement) {
1642
- const $xeGrid = this
1643
- const props = $xeGrid
1644
- const slots = $xeGrid.$scopedSlots
1645
-
1646
- const { toolbarConfig } = props
1647
- const toolbarSlot = slots.toolbar
1648
- const toolbarOpts = $xeGrid.computeToolbarOpts
1649
-
1650
- if ((toolbarConfig && isEnableConf(toolbarOpts)) || toolbarSlot) {
1651
- return h('div', {
1652
- key: 'toolbar',
1653
- ref: 'refToolbarWrapper',
1654
- class: 'vxe-grid--toolbar-wrapper'
1655
- }, toolbarSlot
1656
- ? toolbarSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null })
1657
- : [
1658
- h(VxeToolbarComponent, {
1659
- props: Object.assign({}, toolbarOpts, { slots: undefined }),
1660
- ref: 'refToolbar',
1661
- scopedSlots: $xeGrid.getToolbarSlots()
1662
- })
1663
- ]
1664
- )
1665
- }
1666
- return renderEmptyElement($xeGrid)
1667
- },
1668
- renderTop (h: CreateElement) {
1669
- const $xeGrid = this
1670
- const slots = $xeGrid.$scopedSlots
1671
-
1672
- const topSlot = slots.top
1673
- return topSlot
1674
- ? h('div', {
1675
- key: 'top',
1676
- ref: 'refTopWrapper',
1677
- class: 'vxe-grid--top-wrapper'
1678
- }, topSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null }))
1679
- : renderEmptyElement($xeGrid)
1680
- },
1681
- renderTableLeft (h: CreateElement) {
1682
- const $xeGrid = this
1683
- const slots = $xeGrid.$scopedSlots
1684
-
1685
- const leftSlot = slots.left
1686
- if (leftSlot) {
1687
- return h('div', {
1688
- class: 'vxe-grid--left-wrapper'
1689
- }, leftSlot({ $grid: $xeGrid, $gantt: null }))
1690
- }
1691
- return renderEmptyElement($xeGrid)
1692
- },
1693
- renderTableRight (h: CreateElement) {
1694
- const $xeGrid = this
1695
- const slots = $xeGrid.$scopedSlots
1696
-
1697
- const rightSlot = slots.right
1698
- if (rightSlot) {
1699
- return h('div', {
1700
- class: 'vxe-grid--right-wrapper'
1701
- }, rightSlot({ $grid: $xeGrid, $gantt: null }))
1702
- }
1703
- return renderEmptyElement($xeGrid)
1704
- },
1705
- renderTable (h: CreateElement) {
1706
- const $xeGrid = this
1707
- const slots = $xeGrid.$scopedSlots
1708
-
1709
- const tableProps = $xeGrid.computeTableProps
1710
- return h('div', {
1711
- class: 'vxe-grid--table-wrapper'
1712
- }, [
1713
- h(VxeTableComponent, {
1714
- key: 'table',
1715
- props: tableProps,
1716
- on: getTableOns($xeGrid),
1717
- scopedSlots: slots,
1718
- ref: 'refTable'
1719
- })
1720
- ])
1721
- },
1722
- renderBottom (h: CreateElement) {
1723
- const $xeGrid = this
1724
- const slots = $xeGrid.$scopedSlots
1725
-
1726
- const bottomSlot = slots.bottom
1727
- return bottomSlot
1728
- ? h('div', {
1729
- key: 'bottom',
1730
- ref: 'refBottomWrapper',
1731
- class: 'vxe-grid--bottom-wrapper'
1732
- }, bottomSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null }))
1733
- : renderEmptyElement($xeGrid)
1734
- },
1735
- renderPager (h: CreateElement) {
1736
- const VxeUIPagerComponent = VxeUI.getComponent('VxePager')
1737
-
1738
- const $xeGrid = this
1739
- const props = $xeGrid
1740
- const slots = $xeGrid.$scopedSlots
1741
- const reactData = $xeGrid.reactData
1742
-
1743
- const { proxyConfig, pagerConfig } = props
1744
- const proxyOpts = $xeGrid.computeProxyOpts
1745
- const pagerOpts = $xeGrid.computePagerOpts
1746
- const pagerSlot = slots.pager
1747
- if ((pagerConfig && isEnableConf(pagerOpts)) || slots.pager) {
1748
- return h('div', {
1749
- ref: 'refPagerWrapper',
1750
- key: 'pager',
1751
- class: 'vxe-grid--pager-wrapper'
1752
- }, pagerSlot
1753
- ? pagerSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null })
1754
- : [
1755
- VxeUIPagerComponent
1756
- ? h(VxeUIPagerComponent, {
1757
- ref: 'refPager',
1758
- props: {
1759
- ...pagerOpts,
1760
- ...(proxyConfig && isEnableConf(proxyOpts) ? reactData.tablePage : {})
1761
- },
1762
- on: {
1763
- 'page-change': $xeGrid.pageChangeEvent
1764
- },
1765
- scopedSlots: $xeGrid.getConfigSlot(pagerOpts.slots)
1766
- })
1767
- : renderEmptyElement($xeGrid)
1768
- ])
1769
- }
1770
- return renderEmptyElement($xeGrid)
1771
- },
1772
- renderChildLayout (h: CreateElement, layoutKeys: VxeGridDefines.LayoutKey[]) {
1773
- const $xeGrid = this
1774
-
1775
- const childVNs: VNode[] = []
1776
- layoutKeys.forEach(key => {
1777
- switch (key) {
1778
- case 'Form':
1779
- childVNs.push($xeGrid.renderForm(h))
1780
- break
1781
- case 'Toolbar':
1782
- childVNs.push($xeGrid.renderToolbar(h))
1783
- break
1784
- case 'Top':
1785
- childVNs.push($xeGrid.renderTop(h))
1786
- break
1787
- case 'Table':
1788
- childVNs.push(
1789
- h('div', {
1790
- key: 'table',
1791
- class: 'vxe-grid--table-container'
1792
- }, [
1793
- $xeGrid.renderTableLeft(h),
1794
- $xeGrid.renderTable(h),
1795
- $xeGrid.renderTableRight(h)
1796
- ])
1797
- )
1798
- break
1799
- case 'Bottom':
1800
- childVNs.push($xeGrid.renderBottom(h))
1801
- break
1802
- case 'Pager':
1803
- childVNs.push($xeGrid.renderPager(h))
1804
- break
1805
- default:
1806
- errLog('vxe.error.notProp', [`[grid] layouts -> ${key}`])
1807
- break
1808
- }
1809
- })
1810
- return childVNs
1811
- },
1812
- renderLayout (h: CreateElement) {
1813
- const $xeGrid = this
1814
- const slots = $xeGrid.$scopedSlots
1815
-
1816
- const currLayoutConf = $xeGrid.computeCurrLayoutConf
1817
- const { headKeys, bodyKeys, footKeys } = currLayoutConf
1818
- const asideLeftSlot = slots.asideLeft || slots['aside-left']
1819
- const asideRightSlot = slots.asideRight || slots['aside-right']
1820
- return [
1821
- h('div', {
1822
- class: 'vxe-grid--layout-header-wrapper'
1823
- }, $xeGrid.renderChildLayout(h, headKeys)),
1824
- h('div', {
1825
- class: 'vxe-grid--layout-body-wrapper'
1826
- }, [
1827
- asideLeftSlot
1828
- ? h('div', {
1829
- class: 'vxe-grid--layout-aside-left-wrapper'
1830
- }, asideLeftSlot({}))
1831
- : renderEmptyElement($xeGrid),
1832
- h('div', {
1833
- class: 'vxe-grid--layout-body-content-wrapper'
1834
- }, $xeGrid.renderChildLayout(h, bodyKeys)),
1835
- asideRightSlot
1836
- ? h('div', {
1837
- class: 'vxe-grid--layout-aside-right-wrapper'
1838
- }, asideRightSlot({}))
1839
- : renderEmptyElement($xeGrid)
1840
- ]),
1841
- h('div', {
1842
- class: 'vxe-grid--layout-footer-wrapper'
1843
- }, $xeGrid.renderChildLayout(h, footKeys)),
1844
- h('div', {
1845
- ref: 'refPopupContainerElem'
1846
- })
1847
- ]
1848
- },
1849
- renderVN (h: CreateElement): VNode {
1850
- const $xeGrid = this
1851
- const props = $xeGrid
1852
- const reactData = $xeGrid.reactData
1853
-
1854
- const vSize = $xeGrid.computeSize
1855
- const styles = $xeGrid.computeStyles
1856
- const isLoading = $xeGrid.computeIsLoading
1857
- return h('div', {
1858
- ref: 'refElem',
1859
- class: ['vxe-grid', {
1860
- [`size--${vSize}`]: vSize,
1861
- 'is--animat': !!props.animat,
1862
- 'is--round': props.round,
1863
- 'is--maximize': reactData.isZMax,
1864
- 'is--loading': isLoading
1865
- }],
1866
- style: styles
1867
- }, $xeGrid.renderLayout(h))
1868
- }
1869
- },
1870
- created () {
1871
- // 使用已安装的组件,如果未安装则不渲染
1872
- const VxeUIFormComponent = VxeUI.getComponent('VxeForm')
1873
- const VxeUIPagerComponent = VxeUI.getComponent('VxePager')
1874
-
1875
- const $xeGrid = this
1876
- const props = $xeGrid
1877
-
1878
- const proxyOpts = $xeGrid.computeProxyOpts
1879
-
1880
- // const { data, formOpts, proxyOpts, proxyConfig } = this
1881
- // if (proxyConfig && (data || (proxyOpts.form && formOpts.data))) {
1882
- // errLog('vxe.error.errConflicts', ['[grid] data', 'proxy-config'])
1883
- // }
1884
-
1885
- if ((props as any).toolbar) {
1886
- errLog('vxe.error.delProp', ['[grid] toolbar', 'toolbar-config'])
1887
- }
1888
- if (props.toolbarConfig && !XEUtils.isObject(props.toolbarConfig)) {
1889
- errLog('vxe.error.errProp', [`[grid] toolbar-config=${props.toolbarConfig}`, 'toolbar-config={}'])
1890
- }
1891
- if (proxyOpts.props) {
1892
- warnLog('vxe.error.delProp', ['[grid] proxy-config.props', 'proxy-config.response'])
1893
- }
1894
-
1895
- $xeGrid.$nextTick(() => {
1896
- if (props.formConfig) {
1897
- if (!VxeUIFormComponent) {
1898
- errLog('vxe.error.reqComp', ['vxe-form'])
1899
- }
1900
- }
1901
- if (props.pagerConfig) {
1902
- if (!VxeUIPagerComponent) {
1903
- errLog('vxe.error.reqComp', ['vxe-pager'])
1904
- }
1905
- }
1906
- })
1907
-
1908
- $xeGrid.initPages()
1909
- globalEvents.on($xeGrid, 'keydown', $xeGrid.handleGlobalKeydownEvent)
1910
- },
1911
- mounted () {
1912
- const $xeGrid = this
1913
- const props = $xeGrid
1914
-
1915
- const { columns } = props
1916
- if (columns && columns.length) {
1917
- $xeGrid.loadColumn(columns)
1918
- }
1919
- $xeGrid.initToolbar()
1920
- $xeGrid.initProxy()
1921
- },
1922
- beforeDestroy () {
1923
- const $xeGrid = this
1924
- const reactData = $xeGrid.reactData
1925
- const internalData = $xeGrid.internalData
1926
-
1927
- globalEvents.off($xeGrid, 'keydown')
1928
-
1929
- XEUtils.assign(reactData, createReactData())
1930
- XEUtils.assign(internalData, createInternalData())
1931
- },
1932
- render (this: any, h) {
1933
- return this.renderVN(h)
1934
- }
1935
- }) /* define-vxe-component end */
1
+ import { CreateElement, VNode, PropType } from 'vue'
2
+ import { defineVxeComponent } from '../../ui/src/comp'
3
+ import XEUtils from 'xe-utils'
4
+ import { getLastZIndex, nextZIndex, isEnableConf } from '../../ui/src/utils'
5
+ import { getOffsetHeight, getPaddingTopBottomSize, getDomNode, toCssUnit } from '../../ui/src/dom'
6
+ import { VxeUI } from '../../ui'
7
+ import { getSlotVNs } from '../../ui/src/vn'
8
+ import { warnLog, errLog } from '../../ui/src/log'
9
+ import { tableProps } from '../../table/src/props'
10
+ import VxeTableComponent from '../../table/src/table'
11
+ import VxeToolbarComponent from '../../toolbar/src/toolbar'
12
+
13
+ import type { VxeFormItemProps, VxeFormDefines, VxeComponentStyleType, VxeComponentSizeType, ValueOf, VxeFormInstance, VxeFormItemPropTypes, VxePagerInstance } from 'vxe-pc-ui'
14
+ import type { GridReactData, VxeTablePropTypes, VxeGridConstructor, VxeToolbarPropTypes, VxeToolbarInstance, VxeGridPropTypes, VxeTableMethods, GridInternalData, VxeGridEmits, VxePagerDefines, VxeTableConstructor, VxeTableDefines, VxeTablePrivateMethods, TableInternalData, VxeTableProps, VxeGridDefines } from '../../../types'
15
+
16
+ const { getConfig, getI18n, commands, globalEvents, globalMixins, createEvent, GLOBAL_EVENT_KEYS, renderEmptyElement } = VxeUI
17
+
18
+ const tableMethods: VxeTableMethods = {} as VxeTableMethods
19
+ const propKeys = Object.keys(tableProps) as (keyof VxeTableProps)[]
20
+
21
+ const defaultLayouts: VxeGridPropTypes.Layouts = [['Form'], ['Toolbar', 'Top', 'Table', 'Bottom', 'Pager']]
22
+
23
+ function getTableOns (_vm: any) {
24
+ const { $listeners, proxyConfig, proxyOpts } = _vm
25
+ const ons: any = {}
26
+ XEUtils.each($listeners, (cb: any, type: any) => {
27
+ ons[type] = (...args: any[]) => {
28
+ _vm.$emit(type, ...args)
29
+ }
30
+ })
31
+ if (proxyConfig) {
32
+ if (proxyOpts.sort) {
33
+ ons['sort-change'] = _vm.sortChangeEvent
34
+ ons['clear-all-sort'] = _vm.clearAllSortEvent
35
+ }
36
+ if (proxyOpts.filter) {
37
+ ons['filter-change'] = _vm.filterChangeEvent
38
+ ons['clear-all-filter'] = _vm.clearAllFilterEvent
39
+ }
40
+ }
41
+ return ons
42
+ }
43
+
44
+ XEUtils.each(VxeTableComponent.methods, (fn, name) => {
45
+ tableMethods[name as keyof VxeTableMethods] = function (this: any, ...args: any[]) {
46
+ const $xeGrid = this
47
+ const $xeTable = $xeGrid.$refs.refTable
48
+
49
+ return $xeTable && $xeTable[name](...args)
50
+ }
51
+ })
52
+
53
+ function createReactData (): GridReactData {
54
+ return {
55
+ tableLoading: false,
56
+ proxyInited: false,
57
+ isZMax: false,
58
+ tableData: [],
59
+ filterData: [],
60
+ formData: {},
61
+ sortData: [],
62
+ footerData: [],
63
+ tZindex: 0,
64
+ tablePage: {
65
+ total: 0,
66
+ pageSize: getConfig().pager?.pageSize || 10,
67
+ currentPage: 1
68
+ }
69
+ }
70
+ }
71
+
72
+ function createInternalData (): GridInternalData {
73
+ return {
74
+ uFoot: false
75
+ }
76
+ }
77
+
78
+ export default /* define-vxe-component start */ defineVxeComponent({
79
+ name: 'VxeGrid',
80
+ mixins: [
81
+ globalMixins.sizeMixin
82
+ ],
83
+ props: {
84
+ ...(tableProps as unknown as {
85
+ border: PropType<VxeTablePropTypes.Border>
86
+ round: PropType<VxeTablePropTypes.Round>
87
+ loading: PropType<VxeTablePropTypes.Loading>
88
+ height: PropType<VxeTablePropTypes.Height>
89
+ minHeight: PropType<VxeTablePropTypes.MinHeight>
90
+ maxHeight: PropType<VxeTablePropTypes.MaxHeight>
91
+ seqConfig: PropType<VxeTablePropTypes.SeqConfig>
92
+ editConfig: PropType<VxeTablePropTypes.EditConfig>
93
+ sortConfig: PropType<VxeTablePropTypes.SortConfig>
94
+ filterConfig: PropType<VxeTablePropTypes.FilterConfig>
95
+ validConfig: PropType<VxeTablePropTypes.ValidConfig>
96
+ editRules: PropType<VxeTablePropTypes.EditRules>
97
+ animat: PropType<VxeTablePropTypes.Animat>
98
+ scrollbarConfig: PropType<VxeTablePropTypes.ScrollbarConfig>
99
+ showFooter: PropType<VxeTablePropTypes.ShowFooter>
100
+ params: PropType<VxeTablePropTypes.Params>
101
+ }),
102
+
103
+ layouts: Array as PropType<VxeGridPropTypes.Layouts>,
104
+ columns: Array as PropType<VxeGridPropTypes.Columns<any>>,
105
+ pagerConfig: Object as PropType<VxeGridPropTypes.PagerConfig>,
106
+ proxyConfig: Object as PropType<VxeGridPropTypes.ProxyConfig<any>>,
107
+ toolbarConfig: Object as PropType<VxeGridPropTypes.ToolbarConfig>,
108
+ formConfig: Object as PropType<VxeGridPropTypes.FormConfig>,
109
+ zoomConfig: Object as PropType<VxeGridPropTypes.ZoomConfig>,
110
+ size: {
111
+ type: String as PropType<VxeGridPropTypes.Size>,
112
+ default: () => getConfig().grid.size || getConfig().size
113
+ }
114
+ },
115
+ provide () {
116
+ const $xeGrid = this
117
+ const $xeGantt = null
118
+
119
+ return {
120
+ $xeGrid,
121
+ $xeGantt
122
+ }
123
+ },
124
+ data () {
125
+ const xID = XEUtils.uniqueId()
126
+
127
+ const reactData = createReactData()
128
+ const internalData = createInternalData()
129
+
130
+ return {
131
+ xID,
132
+ reactData,
133
+ internalData
134
+ }
135
+ },
136
+ computed: {
137
+ ...({} as {
138
+ computeSize(): VxeComponentSizeType
139
+ }),
140
+ isRespMsg () {
141
+ const $xeGrid = this
142
+
143
+ return $xeGrid.computeIsRespMsg
144
+ },
145
+ computeIsRespMsg () {
146
+ const $xeGrid = this
147
+
148
+ const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
149
+ return !!(XEUtils.isBoolean(proxyOpts.message) ? proxyOpts.message : proxyOpts.showResponseMsg)
150
+ },
151
+ isActiveMsg () {
152
+ const $xeGrid = this
153
+
154
+ return $xeGrid.computeIsActiveMsg
155
+ },
156
+ computeIsActiveMsg () {
157
+ const $xeGrid = this
158
+
159
+ const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
160
+ return XEUtils.isBoolean(proxyOpts.showActionMsg) ? proxyOpts.showActionMsg : !!proxyOpts.showActiveMsg
161
+ },
162
+ proxyOpts () {
163
+ const $xeGrid = this
164
+
165
+ return $xeGrid.computeProxyOpts
166
+ },
167
+ computeProxyOpts () {
168
+ const $xeGrid = this
169
+ const props = $xeGrid
170
+
171
+ return XEUtils.merge({}, XEUtils.clone(getConfig().grid.proxyConfig, true), props.proxyConfig) as VxeGridPropTypes.ProxyConfig
172
+ },
173
+ pagerOpts () {
174
+ const $xeGrid = this
175
+
176
+ return $xeGrid.computePagerOpts
177
+ },
178
+ computePagerOpts () {
179
+ const $xeGrid = this
180
+ const props = $xeGrid
181
+
182
+ return Object.assign({}, getConfig().grid.pagerConfig, props.pagerConfig)
183
+ },
184
+ formOpts () {
185
+ const $xeGrid = this
186
+
187
+ return $xeGrid.computeFormOpts
188
+ },
189
+ computeFormOpts () {
190
+ const $xeGrid = this
191
+ const props = $xeGrid
192
+
193
+ return Object.assign({}, getConfig().grid.formConfig, props.formConfig)
194
+ },
195
+ toolbarOpts () {
196
+ const $xeGrid = this
197
+
198
+ return $xeGrid.computeToolbarOpts
199
+ },
200
+ computeToolbarOpts () {
201
+ const $xeGrid = this
202
+ const props = $xeGrid
203
+
204
+ return Object.assign({}, getConfig().grid.toolbarConfig, props.toolbarConfig)
205
+ },
206
+ zoomOpts () {
207
+ const $xeGrid = this
208
+
209
+ return $xeGrid.computeZoomOpts
210
+ },
211
+ computeZoomOpts () {
212
+ const $xeGrid = this
213
+ const props = $xeGrid
214
+
215
+ return Object.assign({}, getConfig().grid.zoomConfig, props.zoomConfig)
216
+ },
217
+ computeStyles () {
218
+ const $xeGrid = this
219
+ const props = $xeGrid
220
+ const reactData = $xeGrid.reactData
221
+
222
+ const { height, maxHeight } = props
223
+ const { isZMax, tZindex } = reactData
224
+ const stys: VxeComponentStyleType = {}
225
+ if (isZMax) {
226
+ stys.zIndex = tZindex
227
+ } else {
228
+ if (height) {
229
+ stys.height = height === 'auto' || height === '100%' ? '100%' : toCssUnit(height)
230
+ }
231
+ if (maxHeight) {
232
+ stys.maxHeight = maxHeight === 'auto' || maxHeight === '100%' ? '100%' : toCssUnit(maxHeight)
233
+ }
234
+ }
235
+ return stys
236
+ },
237
+ computeTableExtendProps () {
238
+ const $xeGrid = this
239
+ const props = $xeGrid
240
+
241
+ const rest: any = {}
242
+ const gridProps: any = props
243
+ propKeys.forEach(key => {
244
+ if (gridProps[key] !== undefined) {
245
+ rest[key] = gridProps[key]
246
+ }
247
+ })
248
+ return rest
249
+ },
250
+ computeTableProps () {
251
+ const $xeGrid = this
252
+ const props = $xeGrid
253
+ const reactData = $xeGrid.reactData
254
+
255
+ const { showFooter, seqConfig, pagerConfig, editConfig, proxyConfig } = props
256
+ const { isZMax, tablePage, footerData } = reactData
257
+ const tableExtendProps = $xeGrid.computeTableExtendProps as any
258
+ const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
259
+ const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
260
+ const isLoading = $xeGrid.computeIsLoading as boolean
261
+ const tProps = Object.assign({}, tableExtendProps)
262
+ if (showFooter && !tProps.footerData) {
263
+ // 如果未设置自己的标位数据,则使用代理的
264
+ tProps.footerData = footerData
265
+ } else if (proxyOpts.footer && footerData.length) {
266
+ // 如果代理标为数据,且未请求到数据,则用自己的
267
+ tProps.footerData = footerData
268
+ }
269
+ if (isZMax) {
270
+ if (tProps.maxHeight) {
271
+ tProps.maxHeight = '100%'
272
+ } else {
273
+ tProps.height = '100%'
274
+ }
275
+ }
276
+ if (proxyConfig && isEnableConf(proxyOpts)) {
277
+ tProps.loading = isLoading
278
+ if (pagerConfig && proxyOpts.seq && isEnableConf(pagerOpts)) {
279
+ tProps.seqConfig = Object.assign({}, seqConfig, { startIndex: (tablePage.currentPage - 1) * tablePage.pageSize })
280
+ }
281
+ }
282
+ if (editConfig) {
283
+ tProps.editConfig = Object.assign({}, editConfig)
284
+ }
285
+ return tProps
286
+ },
287
+ tableProps () {
288
+ const $xeGrid = this
289
+
290
+ return $xeGrid.computeTableProps
291
+ },
292
+ computeCurrLayoutConf () {
293
+ const $xeGrid = this
294
+ const props = $xeGrid
295
+
296
+ const { layouts } = props
297
+ let confs: VxeGridPropTypes.Layouts = []
298
+ if (layouts && layouts.length) {
299
+ confs = layouts
300
+ } else {
301
+ confs = getConfig().grid.layouts || defaultLayouts
302
+ }
303
+ let headKeys: VxeGridDefines.LayoutKey[] = []
304
+ let bodyKeys: VxeGridDefines.LayoutKey[] = []
305
+ let footKeys: VxeGridDefines.LayoutKey[] = []
306
+ if (confs.length) {
307
+ if (XEUtils.isArray(confs[0])) {
308
+ headKeys = confs[0] as VxeGridDefines.LayoutKey[]
309
+ bodyKeys = (confs[1] || []) as VxeGridDefines.LayoutKey[]
310
+ footKeys = (confs[2] || []) as VxeGridDefines.LayoutKey[]
311
+ } else {
312
+ bodyKeys = confs as VxeGridDefines.LayoutKey[]
313
+ }
314
+ }
315
+ return {
316
+ headKeys,
317
+ bodyKeys,
318
+ footKeys
319
+ }
320
+ },
321
+ computeCustomCurrentPageFlag () {
322
+ const $xeGrid = this
323
+
324
+ const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
325
+ return pagerOpts.currentPage
326
+ },
327
+ computeCustomPageSizeFlag () {
328
+ const $xeGrid = this
329
+
330
+ const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
331
+ return pagerOpts.pageSize
332
+ },
333
+ computeCustomTotalFlag () {
334
+ const $xeGrid = this
335
+
336
+ const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
337
+ return pagerOpts.total
338
+ },
339
+ computePageCount () {
340
+ const $xeGrid = this
341
+ const reactData = ($xeGrid as any).reactData as GridReactData
342
+
343
+ const { tablePage } = reactData
344
+ return Math.max(Math.ceil(tablePage.total / tablePage.pageSize), 1)
345
+ },
346
+ computeIsLoading () {
347
+ const $xeGrid = this
348
+ const props = $xeGrid
349
+ const reactData = ($xeGrid as any).reactData as GridReactData
350
+
351
+ const { loading, proxyConfig } = props
352
+ const { tableLoading } = reactData
353
+ const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
354
+ const { showLoading } = proxyOpts
355
+ return loading || (tableLoading && showLoading && proxyConfig && isEnableConf(proxyOpts))
356
+ }
357
+ },
358
+ watch: {
359
+ columns (value: any) {
360
+ const $xeGrid = this
361
+
362
+ $xeGrid.$nextTick(() => $xeGrid.loadColumn(value))
363
+ },
364
+ toolbar (value: any) {
365
+ const $xeGrid = this
366
+
367
+ if (value) {
368
+ $xeGrid.initToolbar()
369
+ }
370
+ },
371
+ toolbarConfig (value: any) {
372
+ const $xeGrid = this
373
+
374
+ if (value) {
375
+ $xeGrid.initToolbar()
376
+ }
377
+ },
378
+ proxyConfig () {
379
+ const $xeGrid = this
380
+
381
+ $xeGrid.initProxy()
382
+ },
383
+ computeCustomCurrentPageFlag () {
384
+ const $xeGrid = this
385
+
386
+ $xeGrid.initPages('currentPage')
387
+ },
388
+ computeCustomPageSizeFlag () {
389
+ const $xeGrid = this
390
+
391
+ $xeGrid.initPages('pageSize')
392
+ },
393
+ computeCustomTotalFlag () {
394
+ const $xeGrid = this
395
+
396
+ $xeGrid.initPages('total')
397
+ }
398
+ },
399
+ methods: {
400
+ ...tableMethods,
401
+ dispatchEvent (type: ValueOf<VxeGridEmits>, params: Record<string, any>, evnt: Event | null) {
402
+ const $xeGrid = this
403
+ $xeGrid.$emit(type, createEvent(evnt, { $grid: $xeGrid, $gantt: null }, params))
404
+ },
405
+ initPages (propKey?: 'currentPage' | 'pageSize' | 'total') {
406
+ const $xeGrid = this
407
+ const props = $xeGrid
408
+ const reactData = $xeGrid.reactData
409
+
410
+ const { tablePage } = reactData
411
+ const { pagerConfig } = props
412
+ const pagerOpts = $xeGrid.computePagerOpts
413
+ if (pagerConfig && isEnableConf(pagerOpts)) {
414
+ if (propKey) {
415
+ if (pagerOpts[propKey]) {
416
+ tablePage[propKey] = XEUtils.toNumber(pagerOpts[propKey])
417
+ }
418
+ } else {
419
+ const { currentPage, pageSize, total } = pagerOpts
420
+ if (currentPage) {
421
+ tablePage.currentPage = currentPage
422
+ }
423
+ if (pageSize) {
424
+ tablePage.pageSize = pageSize
425
+ }
426
+ if (total) {
427
+ tablePage.total = total
428
+ }
429
+ }
430
+ }
431
+ },
432
+ callSlot (slotFunc: any, params: any, h: CreateElement) {
433
+ const $xeGrid = this
434
+ const slots = $xeGrid.$scopedSlots
435
+
436
+ if (slotFunc) {
437
+ if (XEUtils.isString(slotFunc)) {
438
+ slotFunc = slots[slotFunc] || null
439
+ }
440
+ if (XEUtils.isFunction(slotFunc)) {
441
+ return getSlotVNs(slotFunc.call(this, params, h))
442
+ }
443
+ }
444
+ return []
445
+ },
446
+ getEl () {
447
+ const $xeGrid = this
448
+
449
+ return $xeGrid.$refs.refElem as HTMLDivElement
450
+ },
451
+ /**
452
+ * 获取需要排除的高度
453
+ */
454
+ getExcludeHeight () {
455
+ const $xeGrid = this
456
+ const props = $xeGrid
457
+ const reactData = $xeGrid.reactData
458
+
459
+ const { height } = props
460
+ const { isZMax } = reactData
461
+ const el = $xeGrid.$refs.refElem as HTMLDivElement
462
+ if (el) {
463
+ const formWrapper = $xeGrid.$refs.refFormWrapper as HTMLDivElement
464
+ const toolbarWrapper = $xeGrid.$refs.refToolbarWrapper as HTMLDivElement
465
+ const topWrapper = $xeGrid.$refs.refTopWrapper as HTMLDivElement
466
+ const bottomWrapper = $xeGrid.$refs.refBottomWrapper as HTMLDivElement
467
+ const pagerWrapper = $xeGrid.$refs.refPagerWrapper as HTMLDivElement
468
+ const parentEl = el.parentElement as HTMLElement
469
+ let parentPaddingSize = 0
470
+ if (parentEl && (height === '100%' || height === 'auto')) {
471
+ parentPaddingSize = isZMax ? 0 : getPaddingTopBottomSize(parentEl)
472
+ }
473
+ return parentPaddingSize + getPaddingTopBottomSize(el) + getOffsetHeight(formWrapper) + getOffsetHeight(toolbarWrapper) + getOffsetHeight(topWrapper) + getOffsetHeight(bottomWrapper) + getOffsetHeight(pagerWrapper)
474
+ }
475
+ return 0
476
+ },
477
+ getParentHeight () {
478
+ const $xeGrid = this
479
+ const reactData = $xeGrid.reactData
480
+
481
+ const el = $xeGrid.$refs.refElem as HTMLDivElement
482
+ if (el) {
483
+ const parentEl = el.parentElement as HTMLElement
484
+ return (reactData.isZMax ? getDomNode().visibleHeight : (parentEl ? XEUtils.toNumber(getComputedStyle(parentEl).height) : 0)) - $xeGrid.getExcludeHeight()
485
+ }
486
+ return 0
487
+ },
488
+ initToolbar () {
489
+ const $xeGrid = this
490
+
491
+ $xeGrid.$nextTick(() => {
492
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
493
+ const $xeToolbar = $xeGrid.$refs.refToolbar as VxeToolbarInstance
494
+ if ($xeTable && $xeToolbar) {
495
+ $xeTable.connectToolbar($xeToolbar)
496
+ }
497
+ })
498
+ },
499
+ getDefaultFormData () {
500
+ const $xeGrid = this
501
+
502
+ const formOpts = $xeGrid.computeFormOpts
503
+ if (formOpts.items) {
504
+ const fData: any = {}
505
+ formOpts.items.forEach(item => {
506
+ const { field, itemRender } = item
507
+ if (field) {
508
+ let itemValue: any = null
509
+ if (itemRender) {
510
+ const { startField, endField, defaultValue } = itemRender
511
+ if (XEUtils.isFunction(defaultValue)) {
512
+ itemValue = defaultValue({ item })
513
+ } else if (!XEUtils.isUndefined(defaultValue)) {
514
+ itemValue = defaultValue
515
+ }
516
+ if (startField && endField) {
517
+ XEUtils.set(fData, startField, null)
518
+ XEUtils.set(fData, endField, null)
519
+ }
520
+ }
521
+ fData[field] = itemValue
522
+ }
523
+ })
524
+ return fData
525
+ }
526
+ return {}
527
+ },
528
+ initProxy () {
529
+ const $xeGrid = this
530
+ const props = $xeGrid
531
+ const reactData = $xeGrid.reactData
532
+ const internalData = $xeGrid.internalData
533
+
534
+ const { proxyConfig, formConfig } = props
535
+ const { proxyInited } = reactData
536
+ const proxyOpts = $xeGrid.computeProxyOpts
537
+ const formOpts = $xeGrid.computeFormOpts
538
+ if (proxyConfig) {
539
+ if (isEnableConf(formConfig) && proxyOpts.form && formOpts.items) {
540
+ reactData.formData = $xeGrid.getDefaultFormData()
541
+ }
542
+ if (!proxyInited) {
543
+ reactData.proxyInited = true
544
+ if (proxyOpts.autoLoad !== false) {
545
+ $xeGrid.$nextTick().then(() => {
546
+ internalData.uFoot = true
547
+ const rest = $xeGrid.commitProxy('initial')
548
+ internalData.uFoot = false
549
+ $xeGrid.updateQueryFooter()
550
+ return rest
551
+ }).then((rest) => {
552
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isInited: true }, new Event('initial'))
553
+ })
554
+ }
555
+ }
556
+ }
557
+ },
558
+ updateQueryFooter () {
559
+ const $xeGrid = this
560
+
561
+ const proxyOpts = $xeGrid.computeProxyOpts
562
+ const { ajax } = proxyOpts
563
+ if (ajax && ajax.queryFooter) {
564
+ return $xeGrid.commitProxy('queryFooter')
565
+ }
566
+ },
567
+ handleGlobalKeydownEvent (evnt: KeyboardEvent) {
568
+ const $xeGrid = this
569
+ const reactData = $xeGrid.reactData
570
+
571
+ const zoomOpts = $xeGrid.computeZoomOpts
572
+ const isEsc = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ESCAPE)
573
+ if (isEsc && reactData.isZMax && zoomOpts.escRestore !== false) {
574
+ $xeGrid.triggerZoomEvent(evnt)
575
+ }
576
+ },
577
+ getRespMsg (rest: any, defaultMsg: string) {
578
+ const $xeGrid = this
579
+
580
+ const proxyOpts = $xeGrid.computeProxyOpts
581
+ const resConfigs = proxyOpts.response || proxyOpts.props || {}
582
+ const messageProp = resConfigs.message
583
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
584
+ let msg
585
+ if (rest && messageProp) {
586
+ msg = XEUtils.isFunction(messageProp) ? messageProp({ data: rest, $table: $xeTable, $grid: $xeGrid as VxeGridConstructor, $gantt: null }) : XEUtils.get(rest, messageProp)
587
+ }
588
+ return msg || getI18n(defaultMsg)
589
+ },
590
+ handleDeleteRow (code: string, alertKey: string, callback: () => void): Promise<void> {
591
+ const $xeGrid = this
592
+
593
+ const isActiveMsg = $xeGrid.computeIsActiveMsg
594
+ const selectRecords = $xeGrid.getCheckboxRecords()
595
+ if (isActiveMsg) {
596
+ if (selectRecords.length) {
597
+ if (VxeUI.modal) {
598
+ return VxeUI.modal.confirm({ id: `cfm_${code}`, content: getI18n(alertKey), escClosable: true }).then((type) => {
599
+ if (type === 'confirm') {
600
+ return callback()
601
+ }
602
+ })
603
+ }
604
+ } else {
605
+ if (VxeUI.modal) {
606
+ VxeUI.modal.message({ id: `msg_${code}`, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
607
+ }
608
+ }
609
+ } else {
610
+ if (selectRecords.length) {
611
+ callback()
612
+ }
613
+ }
614
+ return Promise.resolve()
615
+ },
616
+ triggerPendingEvent (code: string) {
617
+ const $xeGrid = this
618
+
619
+ const isActiveMsg = $xeGrid.computeIsActiveMsg
620
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
621
+ const selectRecords = $xeTable.getCheckboxRecords()
622
+ if (selectRecords.length) {
623
+ $xeTable.togglePendingRow(selectRecords)
624
+ $xeGrid.clearCheckboxRow()
625
+ } else {
626
+ if (isActiveMsg) {
627
+ if (VxeUI.modal) {
628
+ VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
629
+ }
630
+ }
631
+ }
632
+ },
633
+ /**
634
+ * 提交指令,支持 code 或 button
635
+ * @param {String/Object} code 字符串或对象
636
+ */
637
+ commitProxy (proxyTarget: string | VxeToolbarPropTypes.ButtonConfig, ...args: any[]): Promise<any> {
638
+ const $xeGrid = this
639
+ const props = $xeGrid
640
+ const reactData = $xeGrid.reactData
641
+ const internalData = $xeGrid.internalData
642
+
643
+ /**
644
+ * 已废弃
645
+ * @deprecated
646
+ */
647
+ const toolbar = (props as any).toolbar
648
+
649
+ const { showFooter, proxyConfig, toolbarConfig, pagerConfig, editRules, validConfig } = props
650
+ const { tablePage } = reactData
651
+ const isActiveMsg = $xeGrid.computeIsActiveMsg
652
+ const isRespMsg = $xeGrid.computeIsRespMsg
653
+ const proxyOpts = $xeGrid.computeProxyOpts
654
+ const pagerOpts = $xeGrid.computePagerOpts
655
+ const toolbarOpts = $xeGrid.computeToolbarOpts
656
+ const { beforeQuery, afterQuery, beforeQueryFooter, afterQueryFooter, beforeDelete, afterDelete, beforeSave, afterSave, ajax = {} } = proxyOpts
657
+ const resConfigs = (proxyOpts.response || proxyOpts.props || {}) as VxeGridDefines.ProxyConfigResponseConfig
658
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
659
+ let formData = $xeGrid.getFormData()
660
+ let button: VxeToolbarPropTypes.ButtonConfig | null = null
661
+ let code: string | null = null
662
+ if (XEUtils.isString(proxyTarget)) {
663
+ const { buttons } = toolbarOpts
664
+ const matchObj = (toolbarConfig || toolbar) && isEnableConf(toolbarOpts) && buttons ? XEUtils.findTree(buttons, (item) => item.code === proxyTarget, { children: 'dropdowns' }) : null
665
+ button = matchObj ? matchObj.item as any : null
666
+ code = proxyTarget
667
+ } else {
668
+ button = proxyTarget
669
+ code = button.code as string
670
+ }
671
+ const btnParams = button ? button.params : null
672
+ switch (code) {
673
+ case 'insert':
674
+ return $xeTable.insert({})
675
+ case 'insert_edit':
676
+ return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
677
+
678
+ // 已废弃
679
+ case 'insert_actived':
680
+ return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
681
+ // 已废弃
682
+
683
+ case 'mark_cancel':
684
+ $xeGrid.triggerPendingEvent(code)
685
+ break
686
+ case 'remove':
687
+ return $xeGrid.handleDeleteRow(code, 'vxe.grid.removeSelectRecord', () => $xeTable.removeCheckboxRow())
688
+ case 'import':
689
+ $xeTable.importData(btnParams)
690
+ break
691
+ case 'open_import':
692
+ $xeTable.openImport(btnParams)
693
+ break
694
+ case 'export':
695
+ $xeTable.exportData(btnParams)
696
+ break
697
+ case 'open_export':
698
+ $xeTable.openExport(btnParams)
699
+ break
700
+ case 'reset_custom':
701
+ $xeTable.resetCustom(true)
702
+ break
703
+ case 'initial':
704
+ case 'reload':
705
+ case 'query': {
706
+ const qMethods = ajax.query
707
+ const qsMethods = ajax.querySuccess
708
+ const qeMethods = ajax.queryError
709
+ if (qMethods) {
710
+ const isInited = code === 'initial'
711
+ const isReload = code === 'reload'
712
+ if (!isInited && reactData.tableLoading) {
713
+ return $xeGrid.$nextTick()
714
+ }
715
+ let operPromise = null
716
+ let sortList: any[] = []
717
+ let filterList: VxeTableDefines.FilterCheckedParams[] = []
718
+ let pageParams: any = {}
719
+ if (pagerConfig) {
720
+ if (isInited || isReload) {
721
+ tablePage.currentPage = 1
722
+ }
723
+ if (isEnableConf(pagerConfig)) {
724
+ pageParams = { ...tablePage }
725
+ }
726
+ }
727
+ if (isInited) {
728
+ // 重置代理表单数据
729
+ if (proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form) {
730
+ formData = $xeGrid.getDefaultFormData()
731
+ reactData.formData = formData
732
+ }
733
+ if ($xeTable) {
734
+ const tableInternalData = $xeTable as unknown as TableInternalData
735
+ const { tableFullColumn, fullColumnFieldData } = tableInternalData
736
+ const sortOpts = $xeTable.computeSortOpts
737
+ let defaultSort = sortOpts.defaultSort
738
+ tableFullColumn.forEach((column) => {
739
+ column.order = null
740
+ })
741
+ // 如果使用默认排序
742
+ if (defaultSort) {
743
+ if (!XEUtils.isArray(defaultSort)) {
744
+ defaultSort = [defaultSort]
745
+ }
746
+ sortList = defaultSort.map((item) => {
747
+ const { field, order } = item
748
+ const colRest = fullColumnFieldData[field]
749
+ if (colRest) {
750
+ const column = colRest.column
751
+ if (column) {
752
+ column.order = order
753
+ }
754
+ }
755
+ return {
756
+ field,
757
+ property: field,
758
+ order
759
+ }
760
+ })
761
+ }
762
+ filterList = $xeTable.getCheckedFilters()
763
+ }
764
+ } else {
765
+ if ($xeTable) {
766
+ if (isReload) {
767
+ operPromise = $xeTable.clearAll()
768
+ } else {
769
+ sortList = $xeTable.getSortColumns()
770
+ filterList = $xeTable.getCheckedFilters()
771
+ }
772
+ }
773
+ }
774
+ const commitParams = {
775
+ $table: $xeTable,
776
+ $grid: $xeGrid as VxeGridConstructor,
777
+ $gantt: null,
778
+ code,
779
+ button,
780
+ isInited,
781
+ isReload,
782
+ page: pageParams,
783
+ sort: sortList.length ? sortList[0] : {},
784
+ sorts: sortList,
785
+ filters: filterList,
786
+ form: formData,
787
+ options: qMethods
788
+ }
789
+ reactData.sortData = sortList
790
+ reactData.filterData = filterList
791
+ reactData.tableLoading = true
792
+ return Promise.all([
793
+ Promise.resolve((beforeQuery || qMethods)(commitParams, ...args)),
794
+ operPromise
795
+ ]).then(([rest]) => {
796
+ let tableData: any[] = []
797
+ reactData.tableLoading = false
798
+ if (rest) {
799
+ const reParams = { data: rest, $table: $xeTable, $grid: $xeGrid as VxeGridConstructor, $gantt: null }
800
+ if (pagerConfig && isEnableConf(pagerOpts)) {
801
+ const totalProp = resConfigs.total
802
+ const total = (XEUtils.isFunction(totalProp) ? totalProp(reParams) : XEUtils.get(rest, totalProp || 'page.total')) || 0
803
+ tablePage.total = XEUtils.toNumber(total)
804
+ const resultProp = resConfigs.result
805
+ tableData = (XEUtils.isFunction(resultProp) ? resultProp(reParams) : XEUtils.get(rest, resultProp || 'result')) || []
806
+ // 检验当前页码,不能超出当前最大页数
807
+ const pageCount = Math.max(Math.ceil(total / tablePage.pageSize), 1)
808
+ if (tablePage.currentPage > pageCount) {
809
+ tablePage.currentPage = pageCount
810
+ }
811
+ } else {
812
+ const listProp = resConfigs.list
813
+ if (XEUtils.isArray(rest)) {
814
+ tableData = rest
815
+ } else if (listProp) {
816
+ tableData = (XEUtils.isFunction(listProp) ? listProp(reParams) : XEUtils.get(rest, listProp)) || []
817
+ }
818
+ }
819
+ if (showFooter) {
820
+ const fdProp = resConfigs.footerData
821
+ const footerList = fdProp ? (XEUtils.isFunction(fdProp) ? fdProp(reParams) : XEUtils.get(rest, fdProp)) : []
822
+ if (XEUtils.isArray(footerList)) {
823
+ reactData.footerData = footerList
824
+ }
825
+ }
826
+ }
827
+ if ($xeTable) {
828
+ $xeTable.loadData(tableData)
829
+ } else {
830
+ $xeGrid.$nextTick(() => {
831
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
832
+ if ($xeTable) {
833
+ $xeTable.loadData(tableData)
834
+ }
835
+ })
836
+ }
837
+ if (afterQuery) {
838
+ afterQuery(commitParams, ...args)
839
+ }
840
+ if (qsMethods) {
841
+ qsMethods({ ...commitParams, response: rest })
842
+ }
843
+ return { status: true }
844
+ }).catch((rest) => {
845
+ reactData.tableLoading = false
846
+ if (qeMethods) {
847
+ qeMethods({ ...commitParams, response: rest })
848
+ }
849
+ return { status: false }
850
+ })
851
+ } else {
852
+ errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.query'])
853
+ }
854
+ break
855
+ }
856
+ case 'queryFooter': {
857
+ const qfMethods = ajax.queryFooter
858
+ const qfSuccessMethods = ajax.queryFooterSuccess
859
+ const qfErrorMethods = ajax.queryFooterError
860
+ if (qfMethods) {
861
+ let filterList: VxeTableDefines.FilterCheckedParams[] = []
862
+ if ($xeTable) {
863
+ filterList = $xeTable.getCheckedFilters()
864
+ }
865
+ const commitParams = {
866
+ $table: $xeTable,
867
+ $grid: $xeGrid,
868
+ $gantt: null,
869
+ code,
870
+ button,
871
+ filters: filterList,
872
+ form: formData,
873
+ options: qfMethods
874
+ }
875
+ return Promise.resolve((beforeQueryFooter || qfMethods)(commitParams, ...args)).then(rest => {
876
+ reactData.footerData = XEUtils.isArray(rest) ? rest : []
877
+ if (afterQueryFooter) {
878
+ afterQueryFooter(commitParams, ...args)
879
+ }
880
+ if (qfSuccessMethods) {
881
+ qfSuccessMethods({ ...commitParams, response: rest })
882
+ }
883
+ return { status: true }
884
+ }).catch((rest) => {
885
+ if (qfErrorMethods) {
886
+ qfErrorMethods({ ...commitParams, response: rest })
887
+ }
888
+ return { status: false }
889
+ })
890
+ } else {
891
+ errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.queryFooter'])
892
+ }
893
+ break
894
+ }
895
+ case 'delete': {
896
+ const dMethods = ajax.delete
897
+ const deleteSuccessMethods = ajax.deleteSuccess
898
+ const deleteErrorMethods = ajax.deleteError
899
+ if (dMethods) {
900
+ const selectRecords = $xeTable.getCheckboxRecords()
901
+ const removeRecords = selectRecords.filter((row) => !$xeTable.isInsertByRow(row))
902
+ const body = { removeRecords }
903
+ const commitParams = {
904
+ $table: $xeTable,
905
+ $grid: $xeGrid as VxeGridConstructor,
906
+ $gantt: null,
907
+ code,
908
+ button,
909
+ body,
910
+ form: formData,
911
+ options: dMethods
912
+ }
913
+ const applyArgs = [commitParams].concat(args)
914
+ if (selectRecords.length) {
915
+ return $xeGrid.handleDeleteRow(code, 'vxe.grid.deleteSelectRecord', () => {
916
+ if (!removeRecords.length) {
917
+ return $xeTable.remove(selectRecords)
918
+ }
919
+ reactData.tableLoading = true
920
+ return Promise.resolve((beforeDelete || dMethods)(...applyArgs))
921
+ .then(rest => {
922
+ reactData.tableLoading = false
923
+ $xeTable.setPendingRow(removeRecords, false)
924
+ if (isRespMsg) {
925
+ if (VxeUI.modal) {
926
+ VxeUI.modal.message({ content: $xeGrid.getRespMsg(rest, 'vxe.grid.delSuccess'), status: 'success' })
927
+ }
928
+ }
929
+ if (afterDelete) {
930
+ afterDelete(...applyArgs)
931
+ } else {
932
+ internalData.uFoot = true
933
+ $xeGrid.commitProxy('query')
934
+ internalData.uFoot = false
935
+ $xeGrid.updateQueryFooter()
936
+ }
937
+ if (deleteSuccessMethods) {
938
+ deleteSuccessMethods({ ...commitParams, response: rest })
939
+ }
940
+ return { status: true }
941
+ })
942
+ .catch(rest => {
943
+ reactData.tableLoading = false
944
+ if (isRespMsg) {
945
+ if (VxeUI.modal) {
946
+ VxeUI.modal.message({ id: code, content: $xeGrid.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
947
+ }
948
+ }
949
+ if (deleteErrorMethods) {
950
+ deleteErrorMethods({ ...commitParams, response: rest })
951
+ }
952
+ return { status: false }
953
+ })
954
+ })
955
+ } else {
956
+ if (isActiveMsg) {
957
+ if (VxeUI.modal) {
958
+ VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
959
+ }
960
+ }
961
+ }
962
+ } else {
963
+ errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.delete'])
964
+ }
965
+ break
966
+ }
967
+ case 'save': {
968
+ const ajaxMethods = ajax.save
969
+ const saveSuccessMethods = ajax.saveSuccess
970
+ const saveErrorMethods = ajax.saveError
971
+ if (ajaxMethods) {
972
+ const body = $xeGrid.getRecordset()
973
+ const { insertRecords, removeRecords, updateRecords, pendingRecords } = body
974
+ const commitParams = {
975
+ $table: $xeTable,
976
+ $grid: $xeGrid as VxeGridConstructor,
977
+ $gantt: null,
978
+ code,
979
+ button,
980
+ body,
981
+ form: formData,
982
+ options: ajaxMethods
983
+ }
984
+ const applyArgs = [commitParams].concat(args)
985
+ // 排除掉新增且标记为删除的数据
986
+ if (insertRecords.length) {
987
+ body.pendingRecords = pendingRecords.filter((row) => insertRecords.indexOf(row) === -1)
988
+ }
989
+ // 排除已标记为删除的数据
990
+ if (pendingRecords.length) {
991
+ body.insertRecords = insertRecords.filter((row) => pendingRecords.indexOf(row) === -1)
992
+ }
993
+ let restPromise: Promise<any> = Promise.resolve()
994
+ if (editRules) {
995
+ // 只校验新增和修改的数据
996
+ restPromise = $xeGrid[validConfig && validConfig.msgMode === 'full' ? 'fullValidate' : 'validate'](body.insertRecords.concat(updateRecords))
997
+ }
998
+ return restPromise.then((errMap: any) => {
999
+ if (errMap) {
1000
+ // 如果校验不通过
1001
+ return
1002
+ }
1003
+ if (body.insertRecords.length || removeRecords.length || updateRecords.length || body.pendingRecords.length) {
1004
+ reactData.tableLoading = true
1005
+ return Promise.resolve((beforeSave || ajaxMethods)(...applyArgs))
1006
+ .then(rest => {
1007
+ reactData.tableLoading = false
1008
+ $xeTable.clearPendingRow()
1009
+ if (isRespMsg) {
1010
+ if (VxeUI.modal) {
1011
+ VxeUI.modal.message({ content: $xeGrid.getRespMsg(rest, 'vxe.grid.saveSuccess'), status: 'success' })
1012
+ }
1013
+ }
1014
+ if (afterSave) {
1015
+ afterSave(...applyArgs)
1016
+ } else {
1017
+ internalData.uFoot = true
1018
+ $xeGrid.commitProxy('query')
1019
+ internalData.uFoot = false
1020
+ $xeGrid.updateQueryFooter()
1021
+ }
1022
+ if (saveSuccessMethods) {
1023
+ saveSuccessMethods({ ...commitParams, response: rest })
1024
+ }
1025
+ return { status: true }
1026
+ })
1027
+ .catch(rest => {
1028
+ reactData.tableLoading = false
1029
+ if (isRespMsg) {
1030
+ if (VxeUI.modal) {
1031
+ VxeUI.modal.message({ id: code, content: $xeGrid.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1032
+ }
1033
+ }
1034
+ if (saveErrorMethods) {
1035
+ saveErrorMethods({ ...commitParams, response: rest })
1036
+ }
1037
+ return { status: false }
1038
+ })
1039
+ } else {
1040
+ if (isActiveMsg) {
1041
+ if (VxeUI.modal) {
1042
+ VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.dataUnchanged'), status: 'info' })
1043
+ }
1044
+ }
1045
+ }
1046
+ })
1047
+ } else {
1048
+ errLog('vxe.error.notFunc', ['[grid] proxy-config.ajax.save'])
1049
+ }
1050
+ break
1051
+ }
1052
+ default: {
1053
+ const gCommandOpts = commands.get(code)
1054
+ if (gCommandOpts) {
1055
+ const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
1056
+ if (tCommandMethod) {
1057
+ tCommandMethod({ code, button, $grid: $xeGrid as VxeGridConstructor, $table: $xeTable, $gantt: null }, ...args)
1058
+ } else {
1059
+ errLog('vxe.error.notCommands', [`[grid] ${code}`])
1060
+ }
1061
+ }
1062
+ }
1063
+ }
1064
+ return $xeGrid.$nextTick()
1065
+ },
1066
+ getFormData () {
1067
+ const $xeGrid = this
1068
+ const props = $xeGrid
1069
+ const reactData = $xeGrid.reactData
1070
+
1071
+ const { proxyConfig } = props
1072
+ const { formData } = reactData
1073
+ const proxyOpts = $xeGrid.computeProxyOpts
1074
+ const formOpts = $xeGrid.computeFormOpts
1075
+ return proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form ? formData : formOpts.data
1076
+ },
1077
+ getFormItems (itemIndex?: number): any {
1078
+ const $xeGrid = this
1079
+ const props = $xeGrid
1080
+
1081
+ const formOpts = $xeGrid.computeFormOpts
1082
+ const { formConfig } = props
1083
+ const { items } = formOpts
1084
+ const itemList: VxeFormItemProps[] = []
1085
+ XEUtils.eachTree(formConfig && isEnableConf(formOpts) && items ? items : [], item => {
1086
+ itemList.push(item)
1087
+ }, { children: 'children' })
1088
+ return XEUtils.isUndefined(itemIndex) ? itemList : itemList[itemIndex]
1089
+ },
1090
+ resetForm () {
1091
+ const $xeGrid = this
1092
+
1093
+ const $form = $xeGrid.$refs.refForm as VxeFormInstance
1094
+ if ($form) {
1095
+ return $form.reset()
1096
+ }
1097
+ return $xeGrid.$nextTick()
1098
+ },
1099
+ validateForm () {
1100
+ const $xeGrid = this
1101
+
1102
+ const $form = $xeGrid.$refs.refForm as VxeFormInstance
1103
+ if ($form) {
1104
+ return $form.validate()
1105
+ }
1106
+ return $xeGrid.$nextTick() as unknown as Promise<VxeFormDefines.ValidateErrorMapParams>
1107
+ },
1108
+ validateFormField (field: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null) {
1109
+ const $xeGrid = this
1110
+
1111
+ const $form = $xeGrid.$refs.refForm as VxeFormInstance
1112
+ if ($form) {
1113
+ return $form.validateField(field)
1114
+ }
1115
+ return $xeGrid.$nextTick() as unknown as Promise<VxeFormDefines.ValidateErrorMapParams>
1116
+ },
1117
+ clearFormValidate (field?: VxeFormItemPropTypes.Field | VxeFormItemPropTypes.Field[] | VxeFormDefines.ItemInfo | VxeFormDefines.ItemInfo[] | null) {
1118
+ const $xeGrid = this
1119
+
1120
+ const $form = $xeGrid.$refs.refForm as VxeFormInstance
1121
+ if ($form) {
1122
+ return $form.clearValidate(field)
1123
+ }
1124
+ return $xeGrid.$nextTick()
1125
+ },
1126
+ homePage () {
1127
+ const $xeGrid = this
1128
+ const reactData = $xeGrid.reactData
1129
+
1130
+ const { tablePage } = reactData
1131
+ tablePage.currentPage = 1
1132
+ return $xeGrid.$nextTick()
1133
+ },
1134
+ homePageByEvent (evnt: Event) {
1135
+ const $xeGrid = this
1136
+
1137
+ const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1138
+ if ($pager) {
1139
+ $pager.homePageByEvent(evnt)
1140
+ }
1141
+ },
1142
+ endPage () {
1143
+ const $xeGrid = this
1144
+ const reactData = $xeGrid.reactData
1145
+
1146
+ const { tablePage } = reactData
1147
+ const pageCount = $xeGrid.computePageCount
1148
+ tablePage.currentPage = pageCount
1149
+ return $xeGrid.$nextTick()
1150
+ },
1151
+ endPageByEvent (evnt: Event) {
1152
+ const $xeGrid = this
1153
+
1154
+ const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1155
+ if ($pager) {
1156
+ $pager.endPageByEvent(evnt)
1157
+ }
1158
+ },
1159
+ getCurrentPage () {
1160
+ const $xeGrid = this
1161
+ const reactData = $xeGrid.reactData
1162
+
1163
+ const { tablePage } = reactData
1164
+ return tablePage.currentPage
1165
+ },
1166
+ setCurrentPage (currentPage: number | string | null | undefined) {
1167
+ const $xeGrid = this
1168
+ const reactData = $xeGrid.reactData
1169
+
1170
+ const { tablePage } = reactData
1171
+ const pageCount = $xeGrid.computePageCount
1172
+ tablePage.currentPage = Math.min(pageCount, Math.max(1, XEUtils.toNumber(currentPage)))
1173
+ return $xeGrid.$nextTick()
1174
+ },
1175
+ setCurrentPageByEvent (evnt: Event, currentPage: number | string | null | undefined) {
1176
+ const $xeGrid = this
1177
+
1178
+ const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1179
+ if ($pager) {
1180
+ $pager.setCurrentPageByEvent(evnt, currentPage)
1181
+ }
1182
+ },
1183
+ getPageSize () {
1184
+ const $xeGrid = this
1185
+ const reactData = $xeGrid.reactData
1186
+
1187
+ const { tablePage } = reactData
1188
+ return tablePage.pageSize
1189
+ },
1190
+ setPageSize (pageSize: number | string | null | undefined) {
1191
+ const $xeGrid = this
1192
+ const reactData = $xeGrid.reactData
1193
+
1194
+ const { tablePage } = reactData
1195
+ tablePage.pageSize = Math.max(1, XEUtils.toNumber(pageSize))
1196
+ return $xeGrid.$nextTick()
1197
+ },
1198
+ setPageSizeByEvent (evnt: Event, pageSize: number | string | null | undefined) {
1199
+ const $xeGrid = this
1200
+
1201
+ const $pager = $xeGrid.$refs.refPager as VxePagerInstance
1202
+ if ($pager) {
1203
+ $pager.setPageSizeByEvent(evnt, pageSize)
1204
+ }
1205
+ },
1206
+ triggerToolbarCommitEvent (params: any, evnt: any) {
1207
+ const $xeGrid = this
1208
+ const internalData = $xeGrid.internalData
1209
+
1210
+ const { code } = params
1211
+ if (code) {
1212
+ const isUf = ['reload', 'delete', 'save'].includes(code)
1213
+ if (isUf) {
1214
+ internalData.uFoot = true
1215
+ }
1216
+ const rest = $xeGrid.commitProxy(params, evnt).then((rest) => {
1217
+ if (code && rest && rest.status && ['query', 'reload', 'delete', 'save'].includes(code)) {
1218
+ $xeGrid.dispatchEvent(code === 'delete' || code === 'save' ? `proxy-${code as 'delete' | 'save'}` : 'proxy-query', { ...rest, isReload: code === 'reload' }, evnt)
1219
+ }
1220
+ })
1221
+ if (isUf) {
1222
+ $xeGrid.updateQueryFooter()
1223
+ }
1224
+ internalData.uFoot = false
1225
+ return rest
1226
+ }
1227
+ return $xeGrid.$nextTick()
1228
+ },
1229
+ triggerToolbarBtnEvent (button: any, evnt: any) {
1230
+ const $xeGrid = this
1231
+
1232
+ $xeGrid.triggerToolbarCommitEvent(button, evnt)
1233
+ $xeGrid.dispatchEvent('toolbar-button-click', { code: button.code, button }, evnt)
1234
+ },
1235
+ triggerToolbarTolEvent (tool: any, evnt: any) {
1236
+ const $xeGrid = this
1237
+
1238
+ $xeGrid.triggerToolbarCommitEvent(tool, evnt)
1239
+ $xeGrid.dispatchEvent('toolbar-tool-click', { code: tool.code, tool }, evnt)
1240
+ },
1241
+ pageChangeEvent (params: VxePagerDefines.PageChangeEventParams) {
1242
+ const $xeGrid = this
1243
+ const props = $xeGrid
1244
+ const reactData = $xeGrid.reactData
1245
+
1246
+ const { proxyConfig } = props
1247
+ const { tablePage } = reactData
1248
+ const { $event, currentPage, pageSize } = params
1249
+ const proxyOpts = $xeGrid.computeProxyOpts
1250
+ tablePage.currentPage = currentPage
1251
+ tablePage.pageSize = pageSize
1252
+ $xeGrid.dispatchEvent('page-change', params, $event)
1253
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1254
+ $xeGrid.commitProxy('query').then((rest) => {
1255
+ $xeGrid.dispatchEvent('proxy-query', rest, $event)
1256
+ })
1257
+ }
1258
+ },
1259
+ handleSortEvent (params: VxeTableDefines.SortChangeEventParams) {
1260
+ const $xeGrid = this
1261
+ const props = $xeGrid
1262
+ const reactData = $xeGrid.reactData
1263
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1264
+
1265
+ const { proxyConfig } = props
1266
+ const proxyOpts = $xeGrid.computeProxyOpts
1267
+ const sortOpts = $xeTable.computeSortOpts
1268
+ // 如果是服务端排序
1269
+ if (sortOpts.remote) {
1270
+ reactData.sortData = params.sortList
1271
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1272
+ reactData.tablePage.currentPage = 1
1273
+ $xeGrid.commitProxy('query').then((rest) => {
1274
+ $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
1275
+ })
1276
+ }
1277
+ }
1278
+ },
1279
+ sortChangeEvent (params: VxeTableDefines.SortChangeEventParams) {
1280
+ const $xeGrid = this
1281
+
1282
+ $xeGrid.handleSortEvent(params)
1283
+ $xeGrid.dispatchEvent('sort-change', params, params.$event)
1284
+ },
1285
+ clearAllSortEvent (params: VxeTableDefines.SortChangeEventParams) {
1286
+ const $xeGrid = this
1287
+
1288
+ $xeGrid.handleSortEvent(params)
1289
+ $xeGrid.dispatchEvent('clear-all-sort', params, params.$event)
1290
+ },
1291
+ handleFilterEvent (params: VxeTableDefines.ClearAllFilterEventParams) {
1292
+ const $xeGrid = this
1293
+ const props = $xeGrid
1294
+ const reactData = $xeGrid.reactData
1295
+ const internalData = $xeGrid.internalData
1296
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1297
+
1298
+ const { proxyConfig } = props
1299
+ const proxyOpts = $xeGrid.computeProxyOpts
1300
+ const filterOpts = $xeTable.computeFilterOpts
1301
+ // 如果是服务端过滤
1302
+ if (filterOpts.remote) {
1303
+ reactData.filterData = params.filterList
1304
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1305
+ reactData.tablePage.currentPage = 1
1306
+ internalData.uFoot = true
1307
+ $xeGrid.commitProxy('query').then((rest) => {
1308
+ $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
1309
+ })
1310
+ internalData.uFoot = false
1311
+ $xeGrid.updateQueryFooter()
1312
+ }
1313
+ }
1314
+ },
1315
+ filterChangeEvent (params: VxeTableDefines.ClearAllFilterEventParams) {
1316
+ const $xeGrid = this
1317
+
1318
+ $xeGrid.handleFilterEvent(params)
1319
+ $xeGrid.dispatchEvent('filter-change', params, params.$event)
1320
+ },
1321
+ clearAllFilterEvent (params: VxeTableDefines.ClearAllFilterEventParams) {
1322
+ const $xeGrid = this
1323
+
1324
+ $xeGrid.handleFilterEvent(params)
1325
+ $xeGrid.dispatchEvent('clear-all-filter', params, params.$event)
1326
+ },
1327
+ submitFormEvent (params: VxeFormDefines.SubmitEventParams) {
1328
+ const $xeGrid = this
1329
+ const props = $xeGrid
1330
+ const reactData = $xeGrid.reactData
1331
+ const internalData = $xeGrid.internalData
1332
+
1333
+ const { proxyConfig } = props
1334
+ const proxyOpts = $xeGrid.computeProxyOpts
1335
+ if (reactData.tableLoading) {
1336
+ return
1337
+ }
1338
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1339
+ internalData.uFoot = true
1340
+ $xeGrid.commitProxy('reload').then((rest) => {
1341
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, params.$event)
1342
+ })
1343
+ internalData.uFoot = false
1344
+ $xeGrid.updateQueryFooter()
1345
+ }
1346
+ $xeGrid.dispatchEvent('form-submit', params, params.$event)
1347
+ },
1348
+ resetFormEvent (params: VxeFormDefines.ResetEventParams) {
1349
+ const $xeGrid = this
1350
+ const props = $xeGrid
1351
+ const internalData = $xeGrid.internalData
1352
+
1353
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1354
+ const { proxyConfig } = props
1355
+ const { $event } = params
1356
+ const proxyOpts = $xeGrid.computeProxyOpts
1357
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1358
+ $xeTable.clearScroll()
1359
+ internalData.uFoot = true
1360
+ $xeGrid.commitProxy('reload').then((rest) => {
1361
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, $event)
1362
+ })
1363
+ internalData.uFoot = false
1364
+ $xeGrid.updateQueryFooter()
1365
+ }
1366
+ $xeGrid.dispatchEvent('form-reset', params, $event)
1367
+ },
1368
+ submitInvalidEvent (params: VxeFormDefines.SubmitInvalidEventParams) {
1369
+ const $xeGrid = this
1370
+
1371
+ $xeGrid.dispatchEvent('form-submit-invalid', params, params.$event)
1372
+ },
1373
+ collapseEvent (params: VxeFormDefines.CollapseEventParams) {
1374
+ const $xeGrid = this
1375
+
1376
+ const { $event } = params
1377
+ $xeGrid.dispatchEvent('form-toggle-collapse', params, $event)
1378
+ $xeGrid.dispatchEvent('form-collapse', params, $event)
1379
+ },
1380
+ triggerZoomEvent (evnt: Event) {
1381
+ const $xeGrid = this
1382
+ const reactData = $xeGrid.reactData
1383
+
1384
+ $xeGrid.zoom()
1385
+ $xeGrid.dispatchEvent('zoom', { type: reactData.isZMax ? 'max' : 'revert' }, evnt)
1386
+ },
1387
+ getParams () {
1388
+ const $xeGrid = this
1389
+ const props = $xeGrid
1390
+
1391
+ return (props as any).params
1392
+ },
1393
+ zoom () {
1394
+ const $xeGrid = this
1395
+ const reactData = $xeGrid.reactData
1396
+
1397
+ if (reactData.isZMax) {
1398
+ return $xeGrid.revert()
1399
+ }
1400
+ return $xeGrid.maximize()
1401
+ },
1402
+ isMaximized () {
1403
+ const $xeGrid = this
1404
+ const reactData = $xeGrid.reactData
1405
+
1406
+ return reactData.isZMax
1407
+ },
1408
+ maximize () {
1409
+ const $xeGrid = this
1410
+
1411
+ return $xeGrid.handleZoom(true)
1412
+ },
1413
+ revert () {
1414
+ const $xeGrid = this
1415
+
1416
+ return $xeGrid.handleZoom()
1417
+ },
1418
+ handleZoom (isMax?: boolean) {
1419
+ const $xeGrid = this
1420
+ const reactData = $xeGrid.reactData
1421
+
1422
+ const { isZMax } = reactData
1423
+ if (isMax ? !isZMax : isZMax) {
1424
+ reactData.isZMax = !isZMax
1425
+ if (reactData.tZindex < getLastZIndex()) {
1426
+ reactData.tZindex = nextZIndex()
1427
+ }
1428
+ }
1429
+ return $xeGrid.$nextTick()
1430
+ .then(() => $xeGrid.recalculate(true))
1431
+ .then(() => {
1432
+ setTimeout(() => $xeGrid.recalculate(true), 15)
1433
+ return reactData.isZMax
1434
+ })
1435
+ },
1436
+ getProxyInfo () {
1437
+ const $xeGrid = this
1438
+ const props = $xeGrid
1439
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1440
+ const reactData = $xeGrid.reactData
1441
+
1442
+ if (props.proxyConfig) {
1443
+ const { sortData } = reactData
1444
+ return {
1445
+ data: $xeTable ? $xeTable.getFullData() : [],
1446
+ filter: reactData.filterData,
1447
+ form: $xeGrid.getFormData(),
1448
+ sort: sortData.length ? sortData[0] : {},
1449
+ sorts: sortData,
1450
+ pager: reactData.tablePage,
1451
+ pendingRecords: $xeTable ? $xeTable.getPendingRecords() : []
1452
+ }
1453
+ }
1454
+ return null
1455
+ },
1456
+ loadColumn (columns: any[]) {
1457
+ const $xeGrid = this
1458
+ const slots = $xeGrid.$scopedSlots
1459
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1460
+
1461
+ XEUtils.eachTree(columns, column => {
1462
+ if (column.slots) {
1463
+ XEUtils.each(column.slots, (func) => {
1464
+ if (!XEUtils.isFunction(func)) {
1465
+ if (!slots[func]) {
1466
+ errLog('vxe.error.notSlot', [`[grid] ${func}`])
1467
+ }
1468
+ }
1469
+ })
1470
+ }
1471
+ })
1472
+ return $xeTable.loadColumn(columns)
1473
+ },
1474
+ reloadColumn (columns: any[]) {
1475
+ const $xeGrid = this
1476
+
1477
+ $xeGrid.clearAll()
1478
+ return $xeGrid.loadColumn(columns)
1479
+ },
1480
+ getConfigSlot (slotConfigs?: Record<string, any>) {
1481
+ const $xeGrid = this
1482
+ const slots = $xeGrid.$scopedSlots
1483
+
1484
+ const slotConf: Record<string, any> = {}
1485
+ XEUtils.objectMap(slotConfigs, (slotFunc, slotKey) => {
1486
+ if (slotFunc) {
1487
+ if (XEUtils.isString(slotFunc)) {
1488
+ if (slots[slotFunc]) {
1489
+ slotConf[slotKey] = slots[slotFunc]
1490
+ } else {
1491
+ errLog('vxe.error.notSlot', [`[grid] ${slotFunc}`])
1492
+ }
1493
+ } else {
1494
+ slotConf[slotKey] = slotFunc
1495
+ }
1496
+ }
1497
+ })
1498
+ return slotConf
1499
+ },
1500
+ getToolbarSlots () {
1501
+ const $xeGrid = this
1502
+ const slots = $xeGrid.$scopedSlots
1503
+
1504
+ const toolbarOpts = $xeGrid.computeToolbarOpts
1505
+ const toolbarOptSlots = toolbarOpts.slots
1506
+ const toolbarSlots: {
1507
+ buttons?(params: any): any
1508
+ buttonPrefix?(params: any): any
1509
+ buttonSuffix?(params: any): any
1510
+ tools?(params: any): any
1511
+ toolPrefix?(params: any): any
1512
+ toolSuffix?(params: any): any
1513
+ } = {}
1514
+ if (slots.buttons && (!toolbarOptSlots || toolbarOptSlots.buttons !== 'buttons')) {
1515
+ warnLog('vxe.error.reqProp', ['[grid] toolbar-config.slots.buttons'])
1516
+ }
1517
+ if (slots.tools && (!toolbarOptSlots || toolbarOptSlots.tools !== 'tools')) {
1518
+ warnLog('vxe.error.reqProp', ['[grid] toolbar-config.slots.tools'])
1519
+ }
1520
+ if (toolbarOptSlots) {
1521
+ const buttonsSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttons')
1522
+ const buttonPrefixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttonPrefix')
1523
+ const buttonSuffixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttonSuffix')
1524
+ const toolsSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'tools')
1525
+ const toolPrefixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'toolPrefix')
1526
+ const toolSuffixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'toolSuffix')
1527
+ if (buttonsSlot) {
1528
+ toolbarSlots.buttons = buttonsSlot
1529
+ }
1530
+ if (buttonPrefixSlot) {
1531
+ toolbarSlots.buttonPrefix = buttonPrefixSlot
1532
+ }
1533
+ if (buttonSuffixSlot) {
1534
+ toolbarSlots.buttonSuffix = buttonSuffixSlot
1535
+ }
1536
+ if (toolsSlot) {
1537
+ toolbarSlots.tools = toolsSlot
1538
+ }
1539
+ if (toolPrefixSlot) {
1540
+ toolbarSlots.toolPrefix = toolPrefixSlot
1541
+ }
1542
+ if (toolSuffixSlot) {
1543
+ toolbarSlots.toolSuffix = toolSuffixSlot
1544
+ }
1545
+ }
1546
+ return toolbarSlots
1547
+ },
1548
+ getFuncSlot (optSlots: any, slotKey: any) {
1549
+ const $xeGrid = this
1550
+ const slots = $xeGrid.$scopedSlots
1551
+
1552
+ const funcSlot = optSlots[slotKey]
1553
+ if (funcSlot) {
1554
+ if (XEUtils.isString(funcSlot)) {
1555
+ if (slots[funcSlot]) {
1556
+ return slots[funcSlot]
1557
+ } else {
1558
+ errLog('vxe.error.notSlot', [`[grid] ${funcSlot}`])
1559
+ }
1560
+ } else {
1561
+ return funcSlot
1562
+ }
1563
+ }
1564
+ return null
1565
+ },
1566
+
1567
+ //
1568
+ // Render
1569
+ //
1570
+ renderDefaultForm (h: CreateElement) {
1571
+ const VxeUIFormComponent = VxeUI.getComponent('VxeForm')
1572
+
1573
+ const $xeGrid = this
1574
+ const props = $xeGrid
1575
+ const slots = $xeGrid.$scopedSlots
1576
+ const reactData = $xeGrid.reactData
1577
+
1578
+ const { proxyConfig, formConfig } = props
1579
+ const { formData } = reactData
1580
+ const proxyOpts = $xeGrid.computeProxyOpts
1581
+ const formOpts = $xeGrid.computeFormOpts
1582
+ if (isEnableConf(formConfig) && formOpts.items && formOpts.items.length) {
1583
+ const formSlots: any = {}
1584
+ if (!(formOpts as any).inited) {
1585
+ (formOpts as any).inited = true
1586
+ const beforeItem = proxyOpts.beforeItem
1587
+ if (proxyOpts && beforeItem) {
1588
+ formOpts.items.forEach((item) => {
1589
+ beforeItem.call($xeGrid, { $grid: $xeGrid, $gantt: null, item })
1590
+ })
1591
+ }
1592
+ }
1593
+ // 处理插槽
1594
+ formOpts.items.forEach((item) => {
1595
+ XEUtils.each(item.slots, (func) => {
1596
+ if (!XEUtils.isFunction(func)) {
1597
+ if (slots[func]) {
1598
+ formSlots[func] = slots[func]
1599
+ }
1600
+ }
1601
+ })
1602
+ })
1603
+ return [
1604
+ VxeUIFormComponent
1605
+ ? h(VxeUIFormComponent, {
1606
+ ref: 'refForm',
1607
+ props: Object.assign({}, formOpts, {
1608
+ data: proxyConfig && proxyOpts.form ? formData : formOpts.data
1609
+ }),
1610
+ on: {
1611
+ submit: $xeGrid.submitFormEvent,
1612
+ reset: $xeGrid.resetFormEvent,
1613
+ collapse: $xeGrid.collapseEvent,
1614
+ 'submit-invalid': $xeGrid.submitInvalidEvent
1615
+ },
1616
+ scopedSlots: formSlots
1617
+ })
1618
+ : renderEmptyElement($xeGrid)
1619
+ ]
1620
+ }
1621
+ return []
1622
+ },
1623
+ renderForm (h: CreateElement) {
1624
+ const $xeGrid = this
1625
+ const props = $xeGrid
1626
+ const slots = $xeGrid.$scopedSlots
1627
+
1628
+ const { formConfig } = props
1629
+ const formSlot = slots.form
1630
+ const hasForm = !!(formSlot || isEnableConf(formConfig))
1631
+
1632
+ if (hasForm) {
1633
+ return h('div', {
1634
+ key: 'form',
1635
+ ref: 'refFormWrapper',
1636
+ class: 'vxe-grid--form-wrapper'
1637
+ }, formSlot ? formSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null }) : $xeGrid.renderDefaultForm(h))
1638
+ }
1639
+ return renderEmptyElement($xeGrid)
1640
+ },
1641
+ renderToolbar (h: CreateElement) {
1642
+ const $xeGrid = this
1643
+ const props = $xeGrid
1644
+ const slots = $xeGrid.$scopedSlots
1645
+
1646
+ const { toolbarConfig } = props
1647
+ const toolbarSlot = slots.toolbar
1648
+ const toolbarOpts = $xeGrid.computeToolbarOpts
1649
+
1650
+ if ((toolbarConfig && isEnableConf(toolbarOpts)) || toolbarSlot) {
1651
+ return h('div', {
1652
+ key: 'toolbar',
1653
+ ref: 'refToolbarWrapper',
1654
+ class: 'vxe-grid--toolbar-wrapper'
1655
+ }, toolbarSlot
1656
+ ? toolbarSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null })
1657
+ : [
1658
+ h(VxeToolbarComponent, {
1659
+ props: Object.assign({}, toolbarOpts, { slots: undefined }),
1660
+ ref: 'refToolbar',
1661
+ scopedSlots: $xeGrid.getToolbarSlots()
1662
+ })
1663
+ ]
1664
+ )
1665
+ }
1666
+ return renderEmptyElement($xeGrid)
1667
+ },
1668
+ renderTop (h: CreateElement) {
1669
+ const $xeGrid = this
1670
+ const slots = $xeGrid.$scopedSlots
1671
+
1672
+ const topSlot = slots.top
1673
+ return topSlot
1674
+ ? h('div', {
1675
+ key: 'top',
1676
+ ref: 'refTopWrapper',
1677
+ class: 'vxe-grid--top-wrapper'
1678
+ }, topSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null }))
1679
+ : renderEmptyElement($xeGrid)
1680
+ },
1681
+ renderTableLeft (h: CreateElement) {
1682
+ const $xeGrid = this
1683
+ const slots = $xeGrid.$scopedSlots
1684
+
1685
+ const leftSlot = slots.left
1686
+ if (leftSlot) {
1687
+ return h('div', {
1688
+ class: 'vxe-grid--left-wrapper'
1689
+ }, leftSlot({ $grid: $xeGrid, $gantt: null }))
1690
+ }
1691
+ return renderEmptyElement($xeGrid)
1692
+ },
1693
+ renderTableRight (h: CreateElement) {
1694
+ const $xeGrid = this
1695
+ const slots = $xeGrid.$scopedSlots
1696
+
1697
+ const rightSlot = slots.right
1698
+ if (rightSlot) {
1699
+ return h('div', {
1700
+ class: 'vxe-grid--right-wrapper'
1701
+ }, rightSlot({ $grid: $xeGrid, $gantt: null }))
1702
+ }
1703
+ return renderEmptyElement($xeGrid)
1704
+ },
1705
+ renderTable (h: CreateElement) {
1706
+ const $xeGrid = this
1707
+ const slots = $xeGrid.$scopedSlots
1708
+
1709
+ const tableProps = $xeGrid.computeTableProps
1710
+ return h('div', {
1711
+ class: 'vxe-grid--table-wrapper'
1712
+ }, [
1713
+ h(VxeTableComponent, {
1714
+ key: 'table',
1715
+ props: tableProps,
1716
+ on: getTableOns($xeGrid),
1717
+ scopedSlots: slots,
1718
+ ref: 'refTable'
1719
+ })
1720
+ ])
1721
+ },
1722
+ renderBottom (h: CreateElement) {
1723
+ const $xeGrid = this
1724
+ const slots = $xeGrid.$scopedSlots
1725
+
1726
+ const bottomSlot = slots.bottom
1727
+ return bottomSlot
1728
+ ? h('div', {
1729
+ key: 'bottom',
1730
+ ref: 'refBottomWrapper',
1731
+ class: 'vxe-grid--bottom-wrapper'
1732
+ }, bottomSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null }))
1733
+ : renderEmptyElement($xeGrid)
1734
+ },
1735
+ renderPager (h: CreateElement) {
1736
+ const VxeUIPagerComponent = VxeUI.getComponent('VxePager')
1737
+
1738
+ const $xeGrid = this
1739
+ const props = $xeGrid
1740
+ const slots = $xeGrid.$scopedSlots
1741
+ const reactData = $xeGrid.reactData
1742
+
1743
+ const { proxyConfig, pagerConfig } = props
1744
+ const proxyOpts = $xeGrid.computeProxyOpts
1745
+ const pagerOpts = $xeGrid.computePagerOpts
1746
+ const pagerSlot = slots.pager
1747
+ if ((pagerConfig && isEnableConf(pagerOpts)) || slots.pager) {
1748
+ return h('div', {
1749
+ ref: 'refPagerWrapper',
1750
+ key: 'pager',
1751
+ class: 'vxe-grid--pager-wrapper'
1752
+ }, pagerSlot
1753
+ ? pagerSlot.call($xeGrid, { $grid: $xeGrid, $gantt: null })
1754
+ : [
1755
+ VxeUIPagerComponent
1756
+ ? h(VxeUIPagerComponent, {
1757
+ ref: 'refPager',
1758
+ props: {
1759
+ ...pagerOpts,
1760
+ ...(proxyConfig && isEnableConf(proxyOpts) ? reactData.tablePage : {})
1761
+ },
1762
+ on: {
1763
+ 'page-change': $xeGrid.pageChangeEvent
1764
+ },
1765
+ scopedSlots: $xeGrid.getConfigSlot(pagerOpts.slots)
1766
+ })
1767
+ : renderEmptyElement($xeGrid)
1768
+ ])
1769
+ }
1770
+ return renderEmptyElement($xeGrid)
1771
+ },
1772
+ renderChildLayout (h: CreateElement, layoutKeys: VxeGridDefines.LayoutKey[]) {
1773
+ const $xeGrid = this
1774
+
1775
+ const childVNs: VNode[] = []
1776
+ layoutKeys.forEach(key => {
1777
+ switch (key) {
1778
+ case 'Form':
1779
+ childVNs.push($xeGrid.renderForm(h))
1780
+ break
1781
+ case 'Toolbar':
1782
+ childVNs.push($xeGrid.renderToolbar(h))
1783
+ break
1784
+ case 'Top':
1785
+ childVNs.push($xeGrid.renderTop(h))
1786
+ break
1787
+ case 'Table':
1788
+ childVNs.push(
1789
+ h('div', {
1790
+ key: 'table',
1791
+ class: 'vxe-grid--table-container'
1792
+ }, [
1793
+ $xeGrid.renderTableLeft(h),
1794
+ $xeGrid.renderTable(h),
1795
+ $xeGrid.renderTableRight(h)
1796
+ ])
1797
+ )
1798
+ break
1799
+ case 'Bottom':
1800
+ childVNs.push($xeGrid.renderBottom(h))
1801
+ break
1802
+ case 'Pager':
1803
+ childVNs.push($xeGrid.renderPager(h))
1804
+ break
1805
+ default:
1806
+ errLog('vxe.error.notProp', [`[grid] layouts -> ${key}`])
1807
+ break
1808
+ }
1809
+ })
1810
+ return childVNs
1811
+ },
1812
+ renderLayout (h: CreateElement) {
1813
+ const $xeGrid = this
1814
+ const slots = $xeGrid.$scopedSlots
1815
+
1816
+ const currLayoutConf = $xeGrid.computeCurrLayoutConf
1817
+ const { headKeys, bodyKeys, footKeys } = currLayoutConf
1818
+ const asideLeftSlot = slots.asideLeft || slots['aside-left']
1819
+ const asideRightSlot = slots.asideRight || slots['aside-right']
1820
+ return [
1821
+ h('div', {
1822
+ class: 'vxe-grid--layout-header-wrapper'
1823
+ }, $xeGrid.renderChildLayout(h, headKeys)),
1824
+ h('div', {
1825
+ class: 'vxe-grid--layout-body-wrapper'
1826
+ }, [
1827
+ asideLeftSlot
1828
+ ? h('div', {
1829
+ class: 'vxe-grid--layout-aside-left-wrapper'
1830
+ }, asideLeftSlot({}))
1831
+ : renderEmptyElement($xeGrid),
1832
+ h('div', {
1833
+ class: 'vxe-grid--layout-body-content-wrapper'
1834
+ }, $xeGrid.renderChildLayout(h, bodyKeys)),
1835
+ asideRightSlot
1836
+ ? h('div', {
1837
+ class: 'vxe-grid--layout-aside-right-wrapper'
1838
+ }, asideRightSlot({}))
1839
+ : renderEmptyElement($xeGrid)
1840
+ ]),
1841
+ h('div', {
1842
+ class: 'vxe-grid--layout-footer-wrapper'
1843
+ }, $xeGrid.renderChildLayout(h, footKeys)),
1844
+ h('div', {
1845
+ ref: 'refPopupContainerElem'
1846
+ })
1847
+ ]
1848
+ },
1849
+ renderVN (h: CreateElement): VNode {
1850
+ const $xeGrid = this
1851
+ const props = $xeGrid
1852
+ const reactData = $xeGrid.reactData
1853
+
1854
+ const vSize = $xeGrid.computeSize
1855
+ const styles = $xeGrid.computeStyles
1856
+ const isLoading = $xeGrid.computeIsLoading
1857
+ return h('div', {
1858
+ ref: 'refElem',
1859
+ class: ['vxe-grid', {
1860
+ [`size--${vSize}`]: vSize,
1861
+ 'is--animat': !!props.animat,
1862
+ 'is--round': props.round,
1863
+ 'is--maximize': reactData.isZMax,
1864
+ 'is--loading': isLoading
1865
+ }],
1866
+ style: styles
1867
+ }, $xeGrid.renderLayout(h))
1868
+ }
1869
+ },
1870
+ created () {
1871
+ // 使用已安装的组件,如果未安装则不渲染
1872
+ const VxeUIFormComponent = VxeUI.getComponent('VxeForm')
1873
+ const VxeUIPagerComponent = VxeUI.getComponent('VxePager')
1874
+
1875
+ const $xeGrid = this
1876
+ const props = $xeGrid
1877
+
1878
+ const proxyOpts = $xeGrid.computeProxyOpts
1879
+
1880
+ // const { data, formOpts, proxyOpts, proxyConfig } = this
1881
+ // if (proxyConfig && (data || (proxyOpts.form && formOpts.data))) {
1882
+ // errLog('vxe.error.errConflicts', ['[grid] data', 'proxy-config'])
1883
+ // }
1884
+
1885
+ if ((props as any).toolbar) {
1886
+ errLog('vxe.error.delProp', ['[grid] toolbar', 'toolbar-config'])
1887
+ }
1888
+ if (props.toolbarConfig && !XEUtils.isObject(props.toolbarConfig)) {
1889
+ errLog('vxe.error.errProp', [`[grid] toolbar-config=${props.toolbarConfig}`, 'toolbar-config={}'])
1890
+ }
1891
+ if (proxyOpts.props) {
1892
+ warnLog('vxe.error.delProp', ['[grid] proxy-config.props', 'proxy-config.response'])
1893
+ }
1894
+
1895
+ $xeGrid.$nextTick(() => {
1896
+ if (props.formConfig) {
1897
+ if (!VxeUIFormComponent) {
1898
+ errLog('vxe.error.reqComp', ['vxe-form'])
1899
+ }
1900
+ }
1901
+ if (props.pagerConfig) {
1902
+ if (!VxeUIPagerComponent) {
1903
+ errLog('vxe.error.reqComp', ['vxe-pager'])
1904
+ }
1905
+ }
1906
+ })
1907
+
1908
+ $xeGrid.initPages()
1909
+ globalEvents.on($xeGrid, 'keydown', $xeGrid.handleGlobalKeydownEvent)
1910
+ },
1911
+ mounted () {
1912
+ const $xeGrid = this
1913
+ const props = $xeGrid
1914
+
1915
+ const { columns } = props
1916
+ if (columns && columns.length) {
1917
+ $xeGrid.loadColumn(columns)
1918
+ }
1919
+ $xeGrid.initToolbar()
1920
+ $xeGrid.initProxy()
1921
+ },
1922
+ beforeDestroy () {
1923
+ const $xeGrid = this
1924
+ const reactData = $xeGrid.reactData
1925
+ const internalData = $xeGrid.internalData
1926
+
1927
+ globalEvents.off($xeGrid, 'keydown')
1928
+
1929
+ XEUtils.assign(reactData, createReactData())
1930
+ XEUtils.assign(internalData, createInternalData())
1931
+ },
1932
+ render (this: any, h) {
1933
+ return this.renderVN(h)
1934
+ }
1935
+ }) /* define-vxe-component end */