vxe-table 3.15.52 → 3.16.0-beta.1

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 (171) hide show
  1. package/es/grid/src/grid.js +853 -691
  2. package/es/index.esm.js +2 -1
  3. package/es/locale/lang/ar-EG.js +1 -3
  4. package/es/locale/lang/de-DE.js +1 -3
  5. package/es/locale/lang/en-US.js +1 -3
  6. package/es/locale/lang/es-ES.js +1 -3
  7. package/es/locale/lang/fr-FR.js +1 -3
  8. package/es/locale/lang/hu-HU.js +1 -3
  9. package/es/locale/lang/hy-AM.js +1 -3
  10. package/es/locale/lang/id-ID.js +1 -3
  11. package/es/locale/lang/it-IT.js +1 -3
  12. package/es/locale/lang/ja-JP.js +1 -3
  13. package/es/locale/lang/ko-KR.js +1 -3
  14. package/es/locale/lang/ms-MY.js +1 -3
  15. package/es/locale/lang/nb-NO.js +1 -3
  16. package/es/locale/lang/pt-BR.js +1 -3
  17. package/es/locale/lang/ru-RU.js +1 -3
  18. package/es/locale/lang/th-TH.js +1 -3
  19. package/es/locale/lang/ug-CN.js +1 -3
  20. package/es/locale/lang/uk-UA.js +1 -3
  21. package/es/locale/lang/uz-UZ.js +1 -3
  22. package/es/locale/lang/vi-VN.js +1 -3
  23. package/es/locale/lang/zh-CHT.js +1 -3
  24. package/es/locale/lang/zh-CN.js +1 -3
  25. package/es/style.css +1 -1
  26. package/es/table/module/edit/mixin.js +1 -31
  27. package/es/table/module/keyboard/mixin.js +2 -2
  28. package/es/table/src/columnInfo.js +1 -6
  29. package/es/table/src/methods.js +10 -28
  30. package/es/table/src/table.js +3 -22
  31. package/es/ui/index.js +2 -2
  32. package/es/ui/src/log.js +1 -1
  33. package/lib/grid/src/grid.js +952 -806
  34. package/lib/grid/src/grid.min.js +1 -1
  35. package/lib/index.common.js +2 -1
  36. package/lib/index.umd.js +1950 -3209
  37. package/lib/index.umd.min.js +1 -1
  38. package/lib/locale/lang/ar-EG.js +1 -3
  39. package/lib/locale/lang/ar-EG.min.js +1 -1
  40. package/lib/locale/lang/ar-EG.umd.js +1 -3
  41. package/lib/locale/lang/de-DE.js +1 -3
  42. package/lib/locale/lang/de-DE.min.js +1 -1
  43. package/lib/locale/lang/de-DE.umd.js +1 -3
  44. package/lib/locale/lang/en-US.js +1 -3
  45. package/lib/locale/lang/en-US.min.js +1 -1
  46. package/lib/locale/lang/en-US.umd.js +1 -3
  47. package/lib/locale/lang/es-ES.js +1 -3
  48. package/lib/locale/lang/es-ES.min.js +1 -1
  49. package/lib/locale/lang/es-ES.umd.js +1 -3
  50. package/lib/locale/lang/fr-FR.js +1 -3
  51. package/lib/locale/lang/fr-FR.min.js +1 -1
  52. package/lib/locale/lang/fr-FR.umd.js +1 -3
  53. package/lib/locale/lang/hu-HU.js +1 -3
  54. package/lib/locale/lang/hu-HU.min.js +1 -1
  55. package/lib/locale/lang/hu-HU.umd.js +1 -3
  56. package/lib/locale/lang/hy-AM.js +1 -3
  57. package/lib/locale/lang/hy-AM.min.js +1 -1
  58. package/lib/locale/lang/hy-AM.umd.js +1 -3
  59. package/lib/locale/lang/id-ID.js +1 -3
  60. package/lib/locale/lang/id-ID.min.js +1 -1
  61. package/lib/locale/lang/id-ID.umd.js +1 -3
  62. package/lib/locale/lang/it-IT.js +1 -3
  63. package/lib/locale/lang/it-IT.min.js +1 -1
  64. package/lib/locale/lang/it-IT.umd.js +1 -3
  65. package/lib/locale/lang/ja-JP.js +1 -3
  66. package/lib/locale/lang/ja-JP.min.js +1 -1
  67. package/lib/locale/lang/ja-JP.umd.js +1 -3
  68. package/lib/locale/lang/ko-KR.js +1 -3
  69. package/lib/locale/lang/ko-KR.min.js +1 -1
  70. package/lib/locale/lang/ko-KR.umd.js +1 -3
  71. package/lib/locale/lang/ms-MY.js +1 -3
  72. package/lib/locale/lang/ms-MY.min.js +1 -1
  73. package/lib/locale/lang/ms-MY.umd.js +1 -3
  74. package/lib/locale/lang/nb-NO.js +1 -3
  75. package/lib/locale/lang/nb-NO.min.js +1 -1
  76. package/lib/locale/lang/nb-NO.umd.js +1 -3
  77. package/lib/locale/lang/pt-BR.js +1 -3
  78. package/lib/locale/lang/pt-BR.min.js +1 -1
  79. package/lib/locale/lang/pt-BR.umd.js +1 -3
  80. package/lib/locale/lang/ru-RU.js +1 -3
  81. package/lib/locale/lang/ru-RU.min.js +1 -1
  82. package/lib/locale/lang/ru-RU.umd.js +1 -3
  83. package/lib/locale/lang/th-TH.js +1 -3
  84. package/lib/locale/lang/th-TH.min.js +1 -1
  85. package/lib/locale/lang/th-TH.umd.js +1 -3
  86. package/lib/locale/lang/ug-CN.js +1 -3
  87. package/lib/locale/lang/ug-CN.min.js +1 -1
  88. package/lib/locale/lang/ug-CN.umd.js +1 -3
  89. package/lib/locale/lang/uk-UA.js +1 -3
  90. package/lib/locale/lang/uk-UA.min.js +1 -1
  91. package/lib/locale/lang/uk-UA.umd.js +1 -3
  92. package/lib/locale/lang/uz-UZ.js +1 -3
  93. package/lib/locale/lang/uz-UZ.min.js +1 -1
  94. package/lib/locale/lang/uz-UZ.umd.js +1 -3
  95. package/lib/locale/lang/vi-VN.js +1 -3
  96. package/lib/locale/lang/vi-VN.min.js +1 -1
  97. package/lib/locale/lang/vi-VN.umd.js +1 -3
  98. package/lib/locale/lang/zh-CHT.js +1 -3
  99. package/lib/locale/lang/zh-CHT.min.js +1 -1
  100. package/lib/locale/lang/zh-CHT.umd.js +1 -3
  101. package/lib/locale/lang/zh-CN.js +1 -3
  102. package/lib/locale/lang/zh-CN.min.js +1 -1
  103. package/lib/locale/lang/zh-CN.umd.js +1 -3
  104. package/lib/style.css +1 -1
  105. package/lib/table/module/edit/mixin.js +1 -30
  106. package/lib/table/module/edit/mixin.min.js +1 -1
  107. package/lib/table/module/keyboard/mixin.js +2 -2
  108. package/lib/table/module/keyboard/mixin.min.js +1 -1
  109. package/lib/table/src/columnInfo.js +1 -6
  110. package/lib/table/src/columnInfo.min.js +1 -1
  111. package/lib/table/src/methods.js +13 -25
  112. package/lib/table/src/methods.min.js +1 -1
  113. package/lib/table/src/table.js +2 -22
  114. package/lib/table/src/table.min.js +1 -1
  115. package/lib/ui/index.js +2 -2
  116. package/lib/ui/index.min.js +1 -1
  117. package/lib/ui/src/log.js +1 -1
  118. package/lib/ui/src/log.min.js +1 -1
  119. package/lib/v-x-e-table/index.js +2 -1
  120. package/lib/v-x-e-table/index.min.js +1 -1
  121. package/lib/vxe-colgroup/index.js +2 -1
  122. package/lib/vxe-colgroup/index.min.js +1 -1
  123. package/lib/vxe-column/index.js +2 -1
  124. package/lib/vxe-column/index.min.js +1 -1
  125. package/lib/vxe-grid/index.js +2 -1
  126. package/lib/vxe-grid/index.min.js +1 -1
  127. package/lib/vxe-table/index.js +2 -1
  128. package/lib/vxe-table/index.min.js +1 -1
  129. package/lib/vxe-toolbar/index.js +2 -1
  130. package/lib/vxe-toolbar/index.min.js +1 -1
  131. package/lib/vxe-ui/index.js +2 -1
  132. package/lib/vxe-ui/index.min.js +1 -1
  133. package/lib/vxe-v-x-e-table/index.js +2 -1
  134. package/lib/vxe-v-x-e-table/index.min.js +1 -1
  135. package/package.json +1 -1
  136. package/packages/grid/src/grid.ts +993 -778
  137. package/packages/locale/lang/ar-EG.ts +1 -3
  138. package/packages/locale/lang/de-DE.ts +1 -3
  139. package/packages/locale/lang/en-US.ts +1 -3
  140. package/packages/locale/lang/es-ES.ts +1 -3
  141. package/packages/locale/lang/fr-FR.ts +1 -3
  142. package/packages/locale/lang/hu-HU.ts +1 -3
  143. package/packages/locale/lang/hy-AM.ts +1 -3
  144. package/packages/locale/lang/id-ID.ts +1 -3
  145. package/packages/locale/lang/it-IT.ts +1 -3
  146. package/packages/locale/lang/ja-JP.ts +1 -3
  147. package/packages/locale/lang/ko-KR.ts +1 -3
  148. package/packages/locale/lang/ms-MY.ts +1 -3
  149. package/packages/locale/lang/nb-NO.ts +1 -3
  150. package/packages/locale/lang/pt-BR.ts +1 -3
  151. package/packages/locale/lang/ru-RU.ts +1 -3
  152. package/packages/locale/lang/th-TH.ts +1 -3
  153. package/packages/locale/lang/ug-CN.ts +1 -3
  154. package/packages/locale/lang/uk-UA.ts +1 -3
  155. package/packages/locale/lang/uz-UZ.ts +1 -3
  156. package/packages/locale/lang/vi-VN.ts +1 -3
  157. package/packages/locale/lang/zh-CHT.ts +1 -3
  158. package/packages/locale/lang/zh-CN.ts +1 -3
  159. package/packages/table/module/edit/mixin.ts +2 -30
  160. package/packages/table/module/keyboard/mixin.ts +2 -2
  161. package/packages/table/src/columnInfo.ts +1 -6
  162. package/packages/table/src/methods.ts +10 -25
  163. package/packages/table/src/props.ts +4 -4
  164. package/packages/table/src/table.ts +3 -22
  165. package/packages/ui/index.ts +1 -1
  166. /package/es/{iconfont.1751505157215.ttf → iconfont.1750910486943.ttf} +0 -0
  167. /package/es/{iconfont.1751505157215.woff → iconfont.1750910486943.woff} +0 -0
  168. /package/es/{iconfont.1751505157215.woff2 → iconfont.1750910486943.woff2} +0 -0
  169. /package/lib/{iconfont.1751505157215.ttf → iconfont.1750910486943.ttf} +0 -0
  170. /package/lib/{iconfont.1751505157215.woff → iconfont.1750910486943.woff} +0 -0
  171. /package/lib/{iconfont.1751505157215.woff2 → iconfont.1750910486943.woff2} +0 -0
@@ -1,4 +1,5 @@
1
- import { CreateElement, VNode } from 'vue'
1
+ import { CreateElement, VNode, PropType } from 'vue'
2
+ import { defineVxeComponent } from '../../ui/src/comp'
2
3
  import XEUtils from 'xe-utils'
3
4
  import { getLastZIndex, nextZIndex, isEnableConf } from '../../ui/src/utils'
4
5
  import { getOffsetHeight, getPaddingTopBottomSize, getDomNode, toCssUnit } from '../../ui/src/dom'
@@ -9,180 +10,16 @@ import tableComponentProps from '../../table/src/props'
9
10
  import { getSlotVNs } from '../../ui/src/vn'
10
11
  import { warnLog, errLog } from '../../ui/src/log'
11
12
 
12
- import type { VxeFormComponent, VxePagerComponent, VxeComponentStyleType } from 'vxe-pc-ui'
13
- import type{ GridReactData, VxeGridConstructor, VxeGridPropTypes, VxeGridPrivateMethods, VxePagerDefines, VxeTableConstructor, VxeTableDefines, VxeTablePrivateMethods } from '../../../types'
13
+ import type { VxeFormComponent, VxePagerComponent, VxeFormItemProps, VxeFormDefines, VxeComponentStyleType, VxeComponentSizeType, ValueOf } from 'vxe-pc-ui'
14
+ import type { GridReactData, VxeTablePropTypes, VxeGridConstructor, VxeToolbarPropTypes, VxeToolbarInstance, VxeGridPropTypes, VxeTableMethods, VxeGridEmits, VxePagerDefines, VxeTableConstructor, VxeTableDefines, VxeTablePrivateMethods } from '../../../types'
14
15
 
15
- const { getConfig, getI18n, commands, globalEvents, globalMixins, renderEmptyElement } = VxeUI
16
+ const { getConfig, getI18n, commands, globalEvents, globalMixins, createEvent, GLOBAL_EVENT_KEYS, renderEmptyElement } = VxeUI
16
17
 
17
- const methods: any = {}
18
+ const tableMethods: VxeTableMethods = {} as VxeTableMethods
18
19
  const propKeys = Object.keys(tableComponentProps)
19
20
 
20
21
  const defaultLayouts: VxeGridPropTypes.Layouts = [['Form'], ['Toolbar', 'Top', 'Table', 'Bottom', 'Pager']]
21
22
 
22
- function initPages ($xeGrid: VxeGridConstructor & VxeGridPrivateMethods, propKey?: 'currentPage' | 'pageSize' | 'total') {
23
- const props = $xeGrid
24
- const reactData = $xeGrid as unknown as GridReactData
25
-
26
- const { tablePage } = reactData
27
- const { pagerConfig } = props
28
- const pagerOpts = $xeGrid.computePagerOpts
29
- if (pagerConfig && isEnableConf(pagerOpts)) {
30
- if (propKey) {
31
- if (pagerOpts[propKey]) {
32
- tablePage[propKey] = XEUtils.toNumber(pagerOpts[propKey])
33
- }
34
- } else {
35
- const { currentPage, pageSize, total } = pagerOpts
36
- if (currentPage) {
37
- tablePage.currentPage = currentPage
38
- }
39
- if (pageSize) {
40
- tablePage.pageSize = pageSize
41
- }
42
- if (total) {
43
- tablePage.pageSize = total
44
- }
45
- }
46
- }
47
- }
48
-
49
- function renderDefaultForm (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
50
- const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
51
- const props = $xeGrid
52
- const slots = $xeGrid.$scopedSlots
53
- const reactData = $xeGrid as unknown as GridReactData
54
-
55
- const { proxyConfig, formConfig } = props
56
- const { formData } = reactData
57
- const proxyOpts = $xeGrid.computeProxyOpts
58
- const formOpts = $xeGrid.computeFormOpts
59
- if (isEnableConf(formConfig) && formOpts.items && formOpts.items.length) {
60
- const formSlots: any = {}
61
- if (!formOpts.inited) {
62
- formOpts.inited = true
63
- const beforeItem = proxyOpts.beforeItem
64
- if (proxyOpts && beforeItem) {
65
- formOpts.items.forEach((item: any) => {
66
- beforeItem.call($xeGrid, { $grid: $xeGrid, item })
67
- })
68
- }
69
- }
70
- // 处理插槽
71
- formOpts.items.forEach((item: any) => {
72
- XEUtils.each(item.slots, (func) => {
73
- if (!XEUtils.isFunction(func)) {
74
- if (slots[func]) {
75
- formSlots[func] = slots[func]
76
- }
77
- }
78
- })
79
- })
80
- return [
81
- VxeUIFormComponent
82
- ? h(VxeUIFormComponent, {
83
- props: Object.assign({}, formOpts, {
84
- data: proxyConfig && proxyOpts.form ? formData : formOpts.data
85
- }),
86
- on: {
87
- submit: ($xeGrid as any).submitEvent,
88
- reset: ($xeGrid as any).resetEvent,
89
- collapse: ($xeGrid as any).collapseEvent,
90
- 'submit-invalid': ($xeGrid as any).submitInvalidEvent
91
- },
92
- scopedSlots: formSlots
93
- })
94
- : renderEmptyElement($xeGrid)
95
- ]
96
- }
97
- return []
98
- }
99
-
100
- function getFuncSlot ($xeGrid: VxeGridConstructor & VxeGridPrivateMethods, optSlots: any, slotKey: any) {
101
- const slots = $xeGrid.$scopedSlots
102
-
103
- const funcSlot = optSlots[slotKey]
104
- if (funcSlot) {
105
- if (XEUtils.isString(funcSlot)) {
106
- if (slots[funcSlot]) {
107
- return slots[funcSlot]
108
- } else {
109
- errLog('vxe.error.notSlot', [funcSlot])
110
- }
111
- } else {
112
- return funcSlot
113
- }
114
- }
115
- return null
116
- }
117
-
118
- const getConfigSlot = ($xeGrid: VxeGridConstructor & VxeGridPrivateMethods, slotConfigs?: Record<string, any>) => {
119
- const slots = $xeGrid.$scopedSlots
120
-
121
- const slotConf: Record<string, any> = {}
122
- XEUtils.objectMap(slotConfigs, (slotFunc, slotKey) => {
123
- if (slotFunc) {
124
- if (XEUtils.isString(slotFunc)) {
125
- if (slots[slotFunc]) {
126
- slotConf[slotKey] = slots[slotFunc]
127
- } else {
128
- errLog('vxe.error.notSlot', [slotFunc])
129
- }
130
- } else {
131
- slotConf[slotKey] = slotFunc
132
- }
133
- }
134
- })
135
- return slotConf
136
- }
137
-
138
- function getToolbarSlots ($xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
139
- const slots = $xeGrid.$scopedSlots
140
-
141
- const toolbarOpts = $xeGrid.computeToolbarOpts
142
- const toolbarOptSlots = toolbarOpts.slots
143
- const toolbarSlots: {
144
- buttons?(params: any): any
145
- buttonPrefix?(params: any): any
146
- buttonSuffix?(params: any): any
147
- tools?(params: any): any
148
- toolPrefix?(params: any): any
149
- toolSuffix?(params: any): any
150
- } = {}
151
- if (slots.buttons && (!toolbarOptSlots || toolbarOptSlots.buttons !== 'buttons')) {
152
- warnLog('vxe.error.reqProp', ['toolbar-config.slots.buttons'])
153
- }
154
- if (slots.tools && (!toolbarOptSlots || toolbarOptSlots.tools !== 'tools')) {
155
- warnLog('vxe.error.reqProp', ['toolbar-config.slots.tools'])
156
- }
157
- if (toolbarOptSlots) {
158
- const buttonsSlot = getFuncSlot($xeGrid, toolbarOptSlots, 'buttons')
159
- const buttonPrefixSlot = getFuncSlot($xeGrid, toolbarOptSlots, 'buttonPrefix')
160
- const buttonSuffixSlot = getFuncSlot($xeGrid, toolbarOptSlots, 'buttonSuffix')
161
- const toolsSlot = getFuncSlot($xeGrid, toolbarOptSlots, 'tools')
162
- const toolPrefixSlot = getFuncSlot($xeGrid, toolbarOptSlots, 'toolPrefix')
163
- const toolSuffixSlot = getFuncSlot($xeGrid, toolbarOptSlots, 'toolSuffix')
164
- if (buttonsSlot) {
165
- toolbarSlots.buttons = buttonsSlot
166
- }
167
- if (buttonPrefixSlot) {
168
- toolbarSlots.buttonPrefix = buttonPrefixSlot
169
- }
170
- if (buttonSuffixSlot) {
171
- toolbarSlots.buttonSuffix = buttonSuffixSlot
172
- }
173
- if (toolsSlot) {
174
- toolbarSlots.tools = toolsSlot
175
- }
176
- if (toolPrefixSlot) {
177
- toolbarSlots.toolPrefix = toolPrefixSlot
178
- }
179
- if (toolSuffixSlot) {
180
- toolbarSlots.toolSuffix = toolSuffixSlot
181
- }
182
- }
183
- return toolbarSlots
184
- }
185
-
186
23
  function getTableOns (_vm: any) {
187
24
  const { $listeners, proxyConfig, proxyOpts } = _vm
188
25
  const ons: any = {}
@@ -202,304 +39,64 @@ function getTableOns (_vm: any) {
202
39
  return ons
203
40
  }
204
41
 
205
- function pageChangeEvent ($xeGrid: VxeGridConstructor & VxeGridPrivateMethods, params: VxePagerDefines.PageChangeEventParams) {
206
- const props = $xeGrid
207
- const reactData = $xeGrid as unknown as GridReactData
208
-
209
- const { proxyConfig } = props
210
- const { tablePage } = reactData
211
- const { $event, currentPage, pageSize } = params
212
- const proxyOpts = $xeGrid.computeProxyOpts
213
- tablePage.currentPage = currentPage
214
- tablePage.pageSize = pageSize
215
- $xeGrid.dispatchEvent('page-change', params, $event)
216
- if (proxyConfig && isEnableConf(proxyOpts)) {
217
- $xeGrid.commitProxy('query').then((rest) => {
218
- $xeGrid.dispatchEvent('proxy-query', rest, $event)
219
- })
220
- }
221
- }
222
-
223
- /**
224
- * 渲染表单
225
- */
226
- function renderForm (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
227
- const slots = $xeGrid.$scopedSlots
228
- const props = $xeGrid
229
-
230
- const { formConfig } = props
231
- const formSlot = slots.form
232
- const hasForm = !!(formSlot || isEnableConf(formConfig))
233
-
234
- if (hasForm) {
235
- return h('div', {
236
- key: 'form',
237
- ref: 'refFormWrapper',
238
- class: 'vxe-grid--form-wrapper'
239
- }, formSlot ? formSlot.call($xeGrid, { $grid: $xeGrid }) : renderDefaultForm(h, $xeGrid))
240
- }
241
- return renderEmptyElement($xeGrid)
242
- }
243
-
244
- /**
245
- * 渲染工具栏
246
- */
247
- function renderToolbar (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
248
- const slots = $xeGrid.$scopedSlots
249
- const props = $xeGrid
250
-
251
- const { toolbarConfig } = props
252
- const toolbarSlot = slots.toolbar
253
- const hasToolbar = !!(toolbarSlot || isEnableConf(toolbarConfig) || toolbar)
254
- const toolbarOpts = $xeGrid.computeToolbarOpts
255
-
256
- if (hasToolbar) {
257
- return h('div', {
258
- key: 'toolbar',
259
- ref: 'refToolbarWrapper',
260
- class: 'vxe-grid--toolbar-wrapper'
261
- }, toolbarSlot
262
- ? toolbarSlot.call($xeGrid, { $grid: $xeGrid })
263
- : [
264
- h(VxeToolbarComponent, {
265
- props: Object.assign({}, toolbarOpts, { slots: undefined }),
266
- ref: 'xToolbar',
267
- scopedSlots: getToolbarSlots($xeGrid)
268
- })
269
- ]
270
- )
271
- }
272
- return renderEmptyElement($xeGrid)
273
- }
274
-
275
- /**
276
- * 渲染表格顶部区域
277
- */
278
- function renderTop (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
279
- const slots = $xeGrid.$scopedSlots
280
-
281
- const topSlot = slots.top
282
-
283
- return topSlot
284
- ? h('div', {
285
- key: 'top',
286
- ref: 'refTopWrapper',
287
- class: 'vxe-grid--top-wrapper'
288
- }, topSlot.call($xeGrid, { $grid: $xeGrid }))
289
- : renderEmptyElement($xeGrid)
290
- }
291
-
292
- function renderTableLeft (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
293
- const slots = $xeGrid.$scopedSlots
294
-
295
- const leftSlot = slots.left
296
- if (leftSlot) {
297
- return h('div', {
298
- class: 'vxe-grid--left-wrapper'
299
- }, leftSlot({ $grid: $xeGrid }))
300
- }
301
- return renderEmptyElement($xeGrid)
302
- }
303
-
304
- function renderTableRight (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
305
- const slots = $xeGrid.$scopedSlots
306
-
307
- const rightSlot = slots.right
308
- if (rightSlot) {
309
- return h('div', {
310
- class: 'vxe-grid--right-wrapper'
311
- }, rightSlot({ $grid: $xeGrid }))
312
- }
313
- return renderEmptyElement($xeGrid)
314
- }
315
-
316
- /**
317
- * 渲染表格
318
- */
319
- function renderTable (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
320
- const slots = $xeGrid.$scopedSlots
321
-
322
- const tableProps = $xeGrid.computeTableProps
323
-
324
- return h('div', {
325
- class: 'vxe-grid--table-wrapper'
326
- }, [
327
- h('vxe-table', {
328
- key: 'table',
329
- props: tableProps,
330
- on: getTableOns($xeGrid),
331
- scopedSlots: slots,
332
- ref: 'xTable'
333
- })
334
- ])
335
- }
336
-
337
- /**
338
- * 渲染表格底部区域
339
- */
340
- function renderBottom (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
341
- const slots = $xeGrid.$scopedSlots
342
-
343
- const bottomSlot = slots.bottom
344
-
345
- return bottomSlot
346
- ? h('div', {
347
- key: 'bottom',
348
- ref: 'refBottomWrapper',
349
- class: 'vxe-grid--bottom-wrapper'
350
- }, bottomSlot.call($xeGrid, { $grid: $xeGrid }))
351
- : renderEmptyElement($xeGrid)
352
- }
353
-
354
- /**
355
- * 渲染分页
356
- */
357
- function renderPager (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
358
- const VxeUIPagerComponent = VxeUI.getComponent<VxePagerComponent>('VxePager')
359
- const props = $xeGrid
360
- const slots = $xeGrid.$scopedSlots
361
- const reactData = $xeGrid as unknown as GridReactData
362
-
363
- const { proxyConfig, pagerConfig } = props
364
- const proxyOpts = $xeGrid.computeProxyOpts
365
- const pagerOpts = $xeGrid.computePagerOpts
366
- const pagerSlot = slots.pager
367
- if ((pagerConfig && isEnableConf(pagerOpts)) || slots.pager) {
368
- return h('div', {
369
- ref: 'refPagerWrapper',
370
- key: 'pager',
371
- class: 'vxe-grid--pager-wrapper'
372
- }, pagerSlot
373
- ? pagerSlot.call($xeGrid, { $grid: $xeGrid })
374
- : [
375
- VxeUIPagerComponent
376
- ? h(VxeUIPagerComponent, {
377
- ref: 'refPager',
378
- props: {
379
- ...pagerOpts,
380
- ...(proxyConfig && isEnableConf(proxyOpts) ? reactData.tablePage : {})
381
- },
382
- on: {
383
- 'page-change' (params: any) {
384
- pageChangeEvent($xeGrid, params)
385
- }
386
- },
387
- scopedSlots: getConfigSlot($xeGrid, pagerOpts.slots)
388
- })
389
- : renderEmptyElement($xeGrid)
390
- ])
391
- }
392
- return renderEmptyElement($xeGrid)
393
- }
394
-
395
- function renderChildLayout (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods, layoutKeys: VxeGridPropTypes.LayoutKey[]) {
396
- const childVNs: VNode[] = []
397
- layoutKeys.forEach(key => {
398
- switch (key) {
399
- case 'Form':
400
- childVNs.push(renderForm(h, $xeGrid))
401
- break
402
- case 'Toolbar':
403
- childVNs.push(renderToolbar(h, $xeGrid))
404
- break
405
- case 'Top':
406
- childVNs.push(renderTop(h, $xeGrid))
407
- break
408
- case 'Table':
409
- childVNs.push(
410
- h('div', {
411
- key: 'table',
412
- class: 'vxe-grid--table-container'
413
- }, [
414
- renderTableLeft(h, $xeGrid),
415
- renderTable(h, $xeGrid),
416
- renderTableRight(h, $xeGrid)
417
- ])
418
- )
419
- break
420
- case 'Bottom':
421
- childVNs.push(renderBottom(h, $xeGrid))
422
- break
423
- case 'Pager':
424
- childVNs.push(renderPager(h, $xeGrid))
425
- break
426
- default:
427
- errLog('vxe.error.notProp', [`layouts -> ${key}`])
428
- break
429
- }
430
- })
431
- return childVNs
432
- }
433
-
434
- function renderLayout (h: CreateElement, $xeGrid: VxeGridConstructor & VxeGridPrivateMethods) {
435
- const slots = $xeGrid.$scopedSlots
436
-
437
- const currLayoutConf = ($xeGrid as any).computeCurrLayoutConf as {
438
- headKeys: VxeGridPropTypes.LayoutKey[]
439
- bodyKeys: VxeGridPropTypes.LayoutKey[]
440
- footKeys: VxeGridPropTypes.LayoutKey[]
441
- }
442
- const { headKeys, bodyKeys, footKeys } = currLayoutConf
443
- const asideLeftSlot = slots.asideLeft || slots['aside-left']
444
- const asideRightSlot = slots.asideRight || slots['aside-right']
445
- return [
446
- h('div', {
447
- class: 'vxe-grid--layout-header-wrapper'
448
- }, renderChildLayout(h, $xeGrid, headKeys)),
449
- h('div', {
450
- class: 'vxe-grid--layout-body-wrapper'
451
- }, [
452
- asideLeftSlot
453
- ? h('div', {
454
- class: 'vxe-grid--layout-aside-left-wrapper'
455
- }, asideLeftSlot({}))
456
- : renderEmptyElement($xeGrid),
457
- h('div', {
458
- class: 'vxe-grid--layout-body-content-wrapper'
459
- }, renderChildLayout(h, $xeGrid, bodyKeys)),
460
- asideRightSlot
461
- ? h('div', {
462
- class: 'vxe-grid--layout-aside-right-wrapper'
463
- }, asideRightSlot({}))
464
- : renderEmptyElement($xeGrid)
465
- ]),
466
- h('div', {
467
- class: 'vxe-grid--layout-footer-wrapper'
468
- }, renderChildLayout(h, $xeGrid, footKeys))
469
- ]
470
- }
42
+ XEUtils.each(VxeTableComponent.methods, (fn, name) => {
43
+ (tableMethods as any)[name] = function (...args: any[]) {
44
+ const $xeGrid = this
45
+ const $xeTable = $xeGrid.$refs.refTable
471
46
 
472
- Object.keys(VxeTableComponent.methods).forEach((name: any) => {
473
- methods[name] = function (this: any, ...args: any[]) {
474
- return this.$refs.xTable && this.$refs.xTable[name](...args)
47
+ return $xeTable && $xeTable[name](...args)
475
48
  }
476
49
  })
477
50
 
478
- export default {
51
+ export default /* define-vxe-component start */ defineVxeComponent({
479
52
  name: 'VxeGrid',
480
53
  mixins: [
481
54
  globalMixins.sizeMixin
482
55
  ],
483
56
  props: {
484
- ...tableComponentProps,
485
- layouts: Array,
486
- columns: Array,
487
- pagerConfig: [Boolean, Object],
488
- proxyConfig: Object,
489
- toolbar: [Boolean, Object],
490
- toolbarConfig: [Boolean, Object],
491
- formConfig: [Boolean, Object],
492
- zoomConfig: Object,
493
- size: { type: String, default: () => getConfig().grid.size || getConfig().size }
57
+ // 以下仅用于类型
58
+ round: { type: Boolean, default: () => getConfig().table.round },
59
+ height: [Number, String] as PropType<VxeTablePropTypes.Height>,
60
+ minHeight: { type: [Number, String] as PropType<VxeTablePropTypes.MinHeight>, default: () => getConfig().table.minHeight },
61
+ maxHeight: [Number, String] as PropType<VxeTablePropTypes.MaxHeight>,
62
+ seqConfig: Object as PropType<VxeTablePropTypes.SeqConfig>,
63
+ sortConfig: Object as PropType<VxeTablePropTypes.SortConfig>,
64
+ filterConfig: Object as PropType<VxeTablePropTypes.FilterConfig>,
65
+ editConfig: [Boolean, Object] as PropType<VxeTablePropTypes.EditConfig>,
66
+ loading: Boolean as PropType<VxeTablePropTypes.Loading>,
67
+ validConfig: Object as PropType<VxeTablePropTypes.ValidConfig>,
68
+ editRules: Object as PropType<VxeTablePropTypes.EditRules>,
69
+ animat: { type: Boolean, default: () => getConfig().table.animat },
70
+
71
+ // eslint-disable-next-line @typescript-eslint/ban-types
72
+ ...(tableComponentProps as {}),
73
+ // 以上仅用于类型
74
+
75
+ layouts: Array as PropType<VxeGridPropTypes.Layouts>,
76
+ columns: Array as PropType<VxeGridPropTypes.Columns<any>>,
77
+ pagerConfig: Object as PropType<VxeGridPropTypes.PagerConfig>,
78
+ proxyConfig: Object as PropType<VxeGridPropTypes.ProxyConfig<any>>,
79
+ toolbarConfig: Object as PropType<VxeGridPropTypes.ToolbarConfig>,
80
+ formConfig: Object as PropType<VxeGridPropTypes.FormConfig>,
81
+ zoomConfig: Object as PropType<VxeGridPropTypes.ZoomConfig>,
82
+ size: {
83
+ type: String as PropType<VxeGridPropTypes.Size>,
84
+ default: () => getConfig().grid.size || getConfig().size
85
+ }
494
86
  },
495
87
  provide () {
88
+ const $xeGrid = this
89
+
496
90
  return {
497
- $xeGrid: this
91
+ $xeGrid
498
92
  }
499
93
  },
500
94
  data () {
501
- return {
95
+ const xID = XEUtils.uniqueId()
96
+
97
+ const reactData: GridReactData = {
502
98
  tableLoading: false,
99
+ proxyInited: false,
503
100
  isZMax: false,
504
101
  tableData: [],
505
102
  filterData: [],
@@ -512,49 +109,97 @@ export default {
512
109
  currentPage: 1
513
110
  }
514
111
  }
112
+
113
+ return {
114
+ xID,
115
+ reactData
116
+ }
515
117
  },
516
118
  computed: {
119
+ ...({} as {
120
+ computeSize(): VxeComponentSizeType
121
+ }),
517
122
  isRespMsg () {
518
- const { proxyOpts } = this
519
- return XEUtils.isBoolean(proxyOpts.message) ? proxyOpts.message : proxyOpts.showResponseMsg
123
+ const $xeGrid = this
124
+
125
+ return $xeGrid.computeIsRespMsg
126
+ },
127
+ computeIsRespMsg () {
128
+ const $xeGrid = this
129
+
130
+ const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
131
+ return !!(XEUtils.isBoolean(proxyOpts.message) ? proxyOpts.message : proxyOpts.showResponseMsg)
520
132
  },
521
133
  isActiveMsg () {
522
- return this.proxyOpts.showActiveMsg
134
+ const $xeGrid = this
135
+
136
+ return $xeGrid.computeIsActiveMsg
137
+ },
138
+ computeIsActiveMsg () {
139
+ const $xeGrid = this
140
+
141
+ const proxyOpts = $xeGrid.computeProxyOpts as VxeGridPropTypes.ProxyConfig
142
+ return !!proxyOpts.showActiveMsg
523
143
  },
524
144
  proxyOpts () {
525
- return this.computeProxyOpts
145
+ const $xeGrid = this
146
+
147
+ return $xeGrid.computeProxyOpts
526
148
  },
527
149
  computeProxyOpts () {
528
- return XEUtils.merge({}, XEUtils.clone(getConfig().grid.proxyConfig, true), this.proxyConfig)
150
+ const $xeGrid = this
151
+ const props = $xeGrid
152
+
153
+ return XEUtils.merge({}, XEUtils.clone(getConfig().grid.proxyConfig, true), props.proxyConfig) as VxeGridPropTypes.ProxyConfig
529
154
  },
530
155
  pagerOpts () {
531
- return this.computePagerOpts
156
+ const $xeGrid = this
157
+
158
+ return $xeGrid.computePagerOpts
532
159
  },
533
160
  computePagerOpts () {
534
- return Object.assign({}, getConfig().grid.pagerConfig, this.pagerConfig)
161
+ const $xeGrid = this
162
+ const props = $xeGrid
163
+
164
+ return Object.assign({}, getConfig().grid.pagerConfig, props.pagerConfig)
535
165
  },
536
166
  formOpts () {
537
- return this.computeFormOpts
167
+ const $xeGrid = this
168
+
169
+ return $xeGrid.computeFormOpts
538
170
  },
539
171
  computeFormOpts () {
540
- return Object.assign({}, getConfig().grid.formConfig, this.formConfig)
172
+ const $xeGrid = this
173
+ const props = $xeGrid
174
+
175
+ return Object.assign({}, getConfig().grid.formConfig, props.formConfig)
541
176
  },
542
177
  toolbarOpts () {
543
- return this.computeToolbarOpts
178
+ const $xeGrid = this
179
+
180
+ return $xeGrid.computeToolbarOpts
544
181
  },
545
182
  computeToolbarOpts () {
546
- return Object.assign({}, getConfig().grid.toolbarConfig, this.toolbarConfig || this.toolbar)
183
+ const $xeGrid = this
184
+ const props = $xeGrid
185
+
186
+ return Object.assign({}, getConfig().grid.toolbarConfig, props.toolbarConfig)
547
187
  },
548
188
  zoomOpts () {
549
- return this.computeZoomOpts
189
+ const $xeGrid = this
190
+
191
+ return $xeGrid.computeZoomOpts
550
192
  },
551
193
  computeZoomOpts () {
552
- return Object.assign({}, getConfig().grid.zoomConfig, this.zoomConfig)
194
+ const $xeGrid = this
195
+ const props = $xeGrid
196
+
197
+ return Object.assign({}, getConfig().grid.zoomConfig, props.zoomConfig)
553
198
  },
554
199
  computeStyles () {
555
200
  const $xeGrid = this
556
201
  const props = $xeGrid
557
- const reactData = $xeGrid as GridReactData
202
+ const reactData = $xeGrid.reactData
558
203
 
559
204
  const { height, maxHeight } = props
560
205
  const { isZMax, tZindex } = reactData
@@ -571,15 +216,27 @@ export default {
571
216
  }
572
217
  return stys
573
218
  },
574
- tableExtendProps () {
219
+ computeTableExtendProps () {
220
+ const $xeGrid = this
221
+ const props = $xeGrid
222
+
575
223
  const rest: any = {}
224
+ const gridProps: any = props
576
225
  propKeys.forEach(key => {
577
- rest[key] = this[key]
226
+ rest[key] = gridProps[key]
578
227
  })
579
228
  return rest
580
229
  },
581
230
  computeTableProps () {
582
- const { isZMax, seqConfig, pagerConfig, loading, editConfig, proxyConfig, proxyOpts, tableExtendProps, tableLoading, tablePage } = this
231
+ const $xeGrid = this
232
+ const props = $xeGrid
233
+ const reactData = $xeGrid.reactData
234
+
235
+ const { seqConfig, pagerConfig, loading, editConfig, proxyConfig } = props
236
+ const { isZMax, tableLoading, tablePage } = reactData
237
+ const tableExtendProps = $xeGrid.computeTableExtendProps as any
238
+ const proxyOpts = $xeGrid.computeProxyOpts
239
+ const pagerOpts = $xeGrid.computePagerOpts
583
240
  const tProps = Object.assign({}, tableExtendProps)
584
241
  if (isZMax) {
585
242
  if (tableExtendProps.maxHeight) {
@@ -588,9 +245,9 @@ export default {
588
245
  tProps.height = '100%'
589
246
  }
590
247
  }
591
- if (proxyConfig) {
248
+ if (proxyConfig && isEnableConf(proxyOpts)) {
592
249
  tProps.loading = loading || tableLoading
593
- if (proxyOpts.seq && isEnableConf(pagerConfig)) {
250
+ if (pagerConfig && proxyOpts.seq && isEnableConf(pagerOpts)) {
594
251
  tProps.seqConfig = Object.assign({}, seqConfig, { startIndex: (tablePage.currentPage - 1) * tablePage.pageSize })
595
252
  }
596
253
  }
@@ -600,7 +257,9 @@ export default {
600
257
  return tProps
601
258
  },
602
259
  tableProps () {
603
- return this.computeTableProps
260
+ const $xeGrid = this
261
+
262
+ return $xeGrid.computeTableProps
604
263
  },
605
264
  computeCurrLayoutConf () {
606
265
  const $xeGrid = this
@@ -634,126 +293,98 @@ export default {
634
293
  computeCustomCurrentPageFlag () {
635
294
  const $xeGrid = this
636
295
 
637
- const pagerOpts = $xeGrid.computePagerOpts
296
+ const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
638
297
  return pagerOpts.currentPage
639
298
  },
640
299
  computeCustomPageSizeFlag () {
641
300
  const $xeGrid = this
642
301
 
643
- const pagerOpts = $xeGrid.computePagerOpts
302
+ const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
644
303
  return pagerOpts.pageSize
645
304
  },
646
305
  computeCustomTotalFlag () {
647
306
  const $xeGrid = this
648
307
 
649
- const pagerOpts = $xeGrid.computePagerOpts
308
+ const pagerOpts = $xeGrid.computePagerOpts as VxeGridPropTypes.PagerConfig
650
309
  return pagerOpts.total
651
310
  }
652
- } as any,
311
+ },
653
312
  watch: {
654
313
  columns (value: any) {
655
- this.$nextTick(() => this.loadColumn(value))
314
+ const $xeGrid = this
315
+
316
+ $xeGrid.$nextTick(() => $xeGrid.loadColumn(value))
656
317
  },
657
318
  toolbar (value: any) {
319
+ const $xeGrid = this
320
+
658
321
  if (value) {
659
- this.initToolbar()
322
+ $xeGrid.initToolbar()
660
323
  }
661
324
  },
662
325
  toolbarConfig (value: any) {
326
+ const $xeGrid = this
327
+
663
328
  if (value) {
664
- this.initToolbar()
329
+ $xeGrid.initToolbar()
665
330
  }
666
331
  },
667
332
  proxyConfig () {
668
- this.initProxy()
333
+ const $xeGrid = this
334
+
335
+ $xeGrid.initProxy()
669
336
  },
670
337
  computeCustomCurrentPageFlag () {
671
- const $xeGrid = this as VxeGridConstructor & VxeGridPrivateMethods
338
+ const $xeGrid = this
672
339
 
673
- initPages($xeGrid, 'currentPage')
340
+ $xeGrid.initPages('currentPage')
674
341
  },
675
342
  computeCustomPageSizeFlag () {
676
- const $xeGrid = this as VxeGridConstructor & VxeGridPrivateMethods
343
+ const $xeGrid = this
677
344
 
678
- initPages($xeGrid, 'pageSize')
345
+ $xeGrid.initPages('pageSize')
679
346
  },
680
347
  computeCustomTotalFlag () {
681
- const $xeGrid = this as VxeGridConstructor & VxeGridPrivateMethods
682
-
683
- initPages($xeGrid, 'total')
684
- }
685
- } as any,
686
- created (this: any) {
687
- const $xeGrid = this
688
- const props = $xeGrid
689
-
690
- // const { data, formOpts, proxyOpts, proxyConfig } = this
691
- // if (proxyConfig && (data || (proxyOpts.form && formOpts.data))) {
692
- // errLog('vxe.error.errConflicts', ['grid.data', 'grid.proxy-config'])
693
- // }
348
+ const $xeGrid = this
694
349
 
695
- if (this.toolbar) {
696
- warnLog('vxe.error.delProp', ['grid.toolbar', 'grid.toolbar-config'])
697
- }
698
- if (this.toolbarConfig && !XEUtils.isObject(this.toolbarConfig)) {
699
- warnLog('vxe.error.errProp', [`grid.toolbar-config=${this.toolbarConfig}`, 'grid.toolbar-config={}'])
350
+ $xeGrid.initPages('total')
700
351
  }
701
- // if (proxyOpts.props) {
702
- // warnLog('vxe.error.delProp', ['proxy-config.props', 'proxy-config.response'])
703
- // }
352
+ },
704
353
 
705
- // 使用已安装的组件,如果未安装则不渲染
706
- const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
707
- const VxeUIPagerComponent = VxeUI.getComponent<VxePagerComponent>('VxePager')
354
+ methods: {
355
+ ...tableMethods,
356
+ dispatchEvent (type: ValueOf<VxeGridEmits>, params: Record<string, any>, evnt: Event | null) {
357
+ const $xeGrid = this
358
+ $xeGrid.$emit(type, createEvent(evnt, { $grid: $xeGrid }, params))
359
+ },
360
+ initPages (propKey?: 'currentPage' | 'pageSize' | 'total') {
361
+ const $xeGrid = this
362
+ const props = $xeGrid
363
+ const reactData = $xeGrid.reactData
708
364
 
709
- $xeGrid.$nextTick(() => {
710
- if (props.formConfig) {
711
- if (!VxeUIFormComponent) {
712
- errLog('vxe.error.reqComp', ['vxe-form'])
713
- }
714
- }
715
- if (props.pagerConfig) {
716
- if (!VxeUIPagerComponent) {
717
- errLog('vxe.error.reqComp', ['vxe-pager'])
365
+ const { tablePage } = reactData
366
+ const { pagerConfig } = props
367
+ const pagerOpts = $xeGrid.computePagerOpts
368
+ if (pagerConfig && isEnableConf(pagerOpts)) {
369
+ if (propKey) {
370
+ if (pagerOpts[propKey]) {
371
+ tablePage[propKey] = XEUtils.toNumber(pagerOpts[propKey])
372
+ }
373
+ } else {
374
+ const { currentPage, pageSize, total } = pagerOpts
375
+ if (currentPage) {
376
+ tablePage.currentPage = currentPage
377
+ }
378
+ if (pageSize) {
379
+ tablePage.pageSize = pageSize
380
+ }
381
+ if (total) {
382
+ tablePage.pageSize = total
383
+ }
718
384
  }
719
385
  }
720
- })
721
-
722
- initPages($xeGrid)
723
- globalEvents.on(this, 'keydown', this.handleGlobalKeydownEvent)
724
- },
725
- mounted (this: any) {
726
- if (this.columns && this.columns.length) {
727
- this.loadColumn(this.columns)
728
- }
729
- this.initToolbar()
730
- this.initProxy()
731
- },
732
- destroyed (this: any) {
733
- globalEvents.off(this, 'keydown')
734
- },
735
- render (this: any, h: CreateElement) {
736
- const $xeGrid = this
737
- const props = $xeGrid
738
- const reactData = $xeGrid as GridReactData
739
-
740
- const vSize = $xeGrid.computeSize
741
- const styles = $xeGrid.computeStyles
742
- return h('div', {
743
- ref: 'refElem',
744
- class: ['vxe-grid', {
745
- [`size--${vSize}`]: vSize,
746
- 'is--animat': !!this.animat,
747
- 'is--round': this.round,
748
- 'is--maximize': reactData.isZMax,
749
- 'is--loading': props.loading || reactData.tableLoading
750
- }],
751
- style: styles
752
- }, renderLayout(h, $xeGrid))
753
- },
754
- methods: {
755
- ...methods,
756
- callSlot (slotFunc: any, params: any, h: any, vNodes: any) {
386
+ },
387
+ callSlot (slotFunc: any, params: any, h: CreateElement, vNodes: any) {
757
388
  const $xeGrid = this
758
389
  const slots = $xeGrid.$scopedSlots
759
390
 
@@ -777,7 +408,7 @@ export default {
777
408
  */
778
409
  getExcludeHeight () {
779
410
  const $xeGrid = this
780
- const reactData = $xeGrid as GridReactData
411
+ const reactData = $xeGrid.reactData
781
412
 
782
413
  const { isZMax } = reactData
783
414
  const el = $xeGrid.$refs.refElem as HTMLDivElement
@@ -794,8 +425,8 @@ export default {
794
425
  return 0
795
426
  },
796
427
  getParentHeight () {
797
- const $xeGrid = this as VxeGridConstructor & VxeGridPrivateMethods
798
- const reactData = $xeGrid as unknown as GridReactData
428
+ const $xeGrid = this
429
+ const reactData = $xeGrid.reactData
799
430
 
800
431
  const el = $xeGrid.$refs.refElem as HTMLDivElement
801
432
  if (el) {
@@ -805,89 +436,181 @@ export default {
805
436
  return 0
806
437
  },
807
438
  initToolbar () {
808
- this.$nextTick(() => {
809
- const { xTable, xToolbar } = this.$refs
810
- if (xTable && xToolbar) {
811
- xTable.connect(xToolbar)
439
+ const $xeGrid = this
440
+
441
+ $xeGrid.$nextTick(() => {
442
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
443
+ const $xeToolbar = $xeGrid.$refs.refToolbar as VxeToolbarInstance
444
+ if ($xeTable && $xeToolbar) {
445
+ $xeTable.connect($xeToolbar)
812
446
  }
813
447
  })
814
448
  },
449
+ getDefaultFormData () {
450
+ const $xeGrid = this
451
+
452
+ const formOpts = $xeGrid.computeFormOpts
453
+ if (formOpts.items) {
454
+ const fData: any = {}
455
+ formOpts.items.forEach(item => {
456
+ const { field, itemRender } = item
457
+ if (field) {
458
+ let itemValue: any = null
459
+ if (itemRender) {
460
+ const { defaultValue } = itemRender
461
+ if (XEUtils.isFunction(defaultValue)) {
462
+ itemValue = defaultValue({ item })
463
+ } else if (!XEUtils.isUndefined(defaultValue)) {
464
+ itemValue = defaultValue
465
+ }
466
+ }
467
+ fData[field] = itemValue
468
+ }
469
+ })
470
+ return fData
471
+ }
472
+ return {}
473
+ },
815
474
  initProxy () {
816
- const { proxyInited, proxyConfig, proxyOpts, formConfig, formOpts } = this
475
+ const $xeGrid = this
476
+ const props = $xeGrid
477
+ const reactData = $xeGrid.reactData
478
+
479
+ const { proxyConfig, formConfig } = props
480
+ const { proxyInited } = reactData
481
+ const proxyOpts = $xeGrid.computeProxyOpts
482
+ const formOpts = $xeGrid.computeFormOpts
817
483
  if (proxyConfig) {
818
484
  if (isEnableConf(formConfig) && proxyOpts.form && formOpts.items) {
819
- const fData: any = {}
820
- formOpts.items.forEach((item: any) => {
821
- const { field, itemRender } = item
822
- if (field) {
823
- let itemValue = null
824
- if (itemRender) {
825
- const { defaultValue } = itemRender
826
- if (XEUtils.isFunction(defaultValue)) {
827
- itemValue = defaultValue({ item })
828
- } else if (!XEUtils.isUndefined(defaultValue)) {
829
- itemValue = defaultValue
830
- }
831
- }
832
- fData[field] = itemValue
833
- }
834
- })
835
- this.formData = fData
485
+ reactData.formData = $xeGrid.getDefaultFormData()
836
486
  }
837
487
  if (!proxyInited && proxyOpts.autoLoad !== false) {
838
- this.proxyInited = true
839
- this.$nextTick().then(() => this.commitProxy('_init')).then((rest: any) => {
840
- this.$emit('proxy-query', { ...rest, isInited: true, $grid: this, $event: new Event('init') })
488
+ reactData.proxyInited = true
489
+ $xeGrid.$nextTick().then(() => $xeGrid.commitProxy('initial')).then((rest) => {
490
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isInited: true }, new Event('initial'))
841
491
  })
842
492
  }
843
493
  }
844
494
  },
845
- handleGlobalKeydownEvent (evnt: any) {
846
- const isEsc = evnt.keyCode === 27
847
- if (isEsc && this.isZMax && this.zoomOpts.escRestore !== false) {
848
- this.triggerZoomEvent(evnt)
849
- }
850
- },
495
+ handleGlobalKeydownEvent (evnt: KeyboardEvent) {
496
+ const $xeGrid = this
497
+ const reactData = $xeGrid.reactData
498
+
499
+ const zoomOpts = $xeGrid.computeZoomOpts
500
+ const isEsc = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ESCAPE)
501
+ if (isEsc && reactData.isZMax && zoomOpts.escRestore !== false) {
502
+ $xeGrid.triggerZoomEvent(evnt)
503
+ }
504
+ },
505
+ getRespMsg (rest: any, defaultMsg: string) {
506
+ const $xeGrid = this
507
+
508
+ const proxyOpts = $xeGrid.computeProxyOpts
509
+ const resConfigs = proxyOpts.response || proxyOpts.props || {}
510
+ const messageProp = resConfigs.message
511
+ let msg
512
+ if (rest && messageProp) {
513
+ msg = XEUtils.isFunction(messageProp) ? messageProp({ data: rest, $grid: $xeGrid as unknown as VxeGridConstructor }) : XEUtils.get(rest, messageProp)
514
+ }
515
+ return msg || getI18n(defaultMsg)
516
+ },
517
+ handleDeleteRow (code: string, alertKey: string, callback: () => void): Promise<void> {
518
+ const $xeGrid = this
519
+
520
+ const isActiveMsg = $xeGrid.computeIsActiveMsg
521
+ const selectRecords = $xeGrid.getCheckboxRecords()
522
+ if (isActiveMsg) {
523
+ if (selectRecords.length) {
524
+ if (VxeUI.modal) {
525
+ return VxeUI.modal.confirm({ id: `cfm_${code}`, content: getI18n(alertKey), escClosable: true }).then((type) => {
526
+ if (type === 'confirm') {
527
+ return callback()
528
+ }
529
+ })
530
+ }
531
+ } else {
532
+ if (VxeUI.modal) {
533
+ VxeUI.modal.message({ id: `msg_${code}`, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
534
+ }
535
+ }
536
+ } else {
537
+ if (selectRecords.length) {
538
+ callback()
539
+ }
540
+ }
541
+ return Promise.resolve()
542
+ },
543
+ triggerPendingEvent (code: string) {
544
+ const $xeGrid = this
545
+
546
+ const isActiveMsg = $xeGrid.computeIsActiveMsg
547
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
548
+ const selectRecords = $xeTable.getCheckboxRecords()
549
+ if (selectRecords.length) {
550
+ $xeTable.togglePendingRow(selectRecords)
551
+ $xeGrid.clearCheckboxRow()
552
+ } else {
553
+ if (isActiveMsg) {
554
+ if (VxeUI.modal) {
555
+ VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
556
+ }
557
+ }
558
+ }
559
+ },
851
560
  /**
852
561
  * 提交指令,支持 code 或 button
853
562
  * @param {String/Object} code 字符串或对象
854
563
  */
855
- commitProxy (proxyTarget: any, ...args: any[]) {
856
- const $xeGrid = this as VxeGridConstructor & VxeGridPrivateMethods
857
- const reactData = $xeGrid as unknown as GridReactData
858
-
859
- const { $refs, toolbar, toolbarConfig, toolbarOpts, proxyOpts, tablePage, pagerConfig, editRules, isRespMsg, isActiveMsg, validConfig, pagerOpts } = this
564
+ commitProxy (proxyTarget: string | VxeToolbarPropTypes.ButtonConfig, ...args: any[]): Promise<any> {
565
+ const $xeGrid = this
566
+ const props = $xeGrid
567
+ const reactData = $xeGrid.reactData
568
+
569
+ /**
570
+ * 已废弃
571
+ * @deprecated
572
+ */
573
+ const toolbar = (props as any).toolbar
574
+
575
+ const { proxyConfig, toolbarConfig, pagerConfig, editRules, validConfig } = props
576
+ const { tablePage } = reactData
577
+ const isActiveMsg = $xeGrid.computeIsActiveMsg
578
+ const isRespMsg = $xeGrid.computeIsRespMsg
579
+ const proxyOpts = $xeGrid.computeProxyOpts
580
+ const pagerOpts = $xeGrid.computePagerOpts
581
+ const toolbarOpts = $xeGrid.computeToolbarOpts
860
582
  const { beforeQuery, afterQuery, beforeDelete, afterDelete, beforeSave, afterSave, ajax = {} } = proxyOpts
861
583
  const resConfigs = proxyOpts.response || proxyOpts.props || {}
862
- const $xeTable = $refs.xTable as VxeTableConstructor & VxeTablePrivateMethods
863
- const formData = this.getFormData()
864
- let button: any
865
- let code: string
584
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
585
+ let formData = $xeGrid.getFormData()
586
+ let button: VxeToolbarPropTypes.ButtonConfig | null = null
587
+ let code: string | null = null
866
588
  if (XEUtils.isString(proxyTarget)) {
867
- const matchObj = toolbarConfig || toolbar ? XEUtils.findTree(toolbarOpts.buttons, (item: any) => item.code === proxyTarget, { children: 'dropdowns' }) : null
589
+ const { buttons } = toolbarOpts
590
+ const matchObj = (toolbarConfig || toolbar) && isEnableConf(toolbarOpts) && buttons ? XEUtils.findTree(buttons, (item) => item.code === proxyTarget, { children: 'dropdowns' }) : null
591
+ button = matchObj ? matchObj.item as any : null
868
592
  code = proxyTarget
869
- button = matchObj ? matchObj.item : null
870
593
  } else {
871
594
  button = proxyTarget
872
- code = button.code
595
+ code = button.code as string
873
596
  }
874
597
  const btnParams = button ? button.params : null
875
598
  switch (code) {
876
599
  case 'insert':
877
600
  return $xeTable.insert({})
878
601
  case 'insert_edit':
879
- return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
602
+ return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row))
880
603
 
881
604
  // 已废弃
882
605
  case 'insert_actived':
883
- return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row, true))
606
+ return $xeTable.insert({}).then(({ row }) => $xeTable.setEditRow(row))
884
607
  // 已废弃
885
608
 
886
609
  case 'mark_cancel':
887
- this.triggerPendingEvent(code)
610
+ $xeGrid.triggerPendingEvent(code)
888
611
  break
889
612
  case 'remove':
890
- return this.handleDeleteRow(code, 'vxe.grid.removeSelectRecord', () => this.removeCheckboxRow())
613
+ return $xeGrid.handleDeleteRow(code, 'vxe.grid.removeSelectRecord', () => $xeTable.removeCheckboxRow())
891
614
  case 'import':
892
615
  $xeTable.importData(btnParams)
893
616
  break
@@ -903,14 +626,14 @@ export default {
903
626
  case 'reset_custom':
904
627
  $xeTable.resetCustom(true)
905
628
  break
906
- case '_init':
629
+ case 'initial':
907
630
  case 'reload':
908
631
  case 'query': {
909
632
  const ajaxMethods = ajax.query
910
633
  const querySuccessMethods = ajax.querySuccess
911
634
  const queryErrorMethods = ajax.queryError
912
635
  if (ajaxMethods) {
913
- const isInited = code === '_init'
636
+ const isInited = code === 'initial'
914
637
  const isReload = code === 'reload'
915
638
  if (!isInited && reactData.tableLoading) {
916
639
  return $xeGrid.$nextTick()
@@ -927,25 +650,40 @@ export default {
927
650
  }
928
651
  }
929
652
  if (isInited) {
930
- let defaultSort = null
931
- if ($xeTable) {
932
- const { sortOpts } = $xeTable
933
- defaultSort = sortOpts.defaultSort
934
- }
935
- // 如果使用默认排序
936
- if (defaultSort) {
937
- if (!XEUtils.isArray(defaultSort)) {
938
- defaultSort = [defaultSort]
939
- }
940
- sortList = defaultSort.map((item) => {
941
- return {
942
- field: item.field,
943
- property: item.field,
944
- order: item.order
945
- }
946
- })
653
+ // 重置代理表单数据
654
+ if (proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form) {
655
+ formData = $xeGrid.getDefaultFormData()
656
+ reactData.formData = formData
947
657
  }
948
658
  if ($xeTable) {
659
+ const { internalData: tableInternalData } = $xeTable
660
+ const { tableFullColumn, fullColumnFieldData } = tableInternalData
661
+ const sortOpts = $xeTable.computeSortOpts
662
+ let defaultSort = sortOpts.defaultSort
663
+ tableFullColumn.forEach((column) => {
664
+ column.order = null
665
+ })
666
+ // 如果使用默认排序
667
+ if (defaultSort) {
668
+ if (!XEUtils.isArray(defaultSort)) {
669
+ defaultSort = [defaultSort]
670
+ }
671
+ sortList = defaultSort.map((item) => {
672
+ const { field, order } = item
673
+ const colRest = fullColumnFieldData[field]
674
+ if (colRest) {
675
+ const column = colRest.column
676
+ if (column) {
677
+ column.order = order
678
+ }
679
+ }
680
+ return {
681
+ field,
682
+ property: field,
683
+ order
684
+ }
685
+ })
686
+ }
949
687
  filterList = $xeTable.getCheckedFilters()
950
688
  }
951
689
  } else {
@@ -963,7 +701,7 @@ export default {
963
701
  button,
964
702
  isInited,
965
703
  isReload,
966
- $grid: this,
704
+ $grid: $xeGrid as unknown as VxeGridConstructor,
967
705
  page: pageParams,
968
706
  sort: sortList.length ? sortList[0] : {},
969
707
  sorts: sortList,
@@ -971,21 +709,21 @@ export default {
971
709
  form: formData,
972
710
  options: ajaxMethods
973
711
  }
974
- this.sortData = sortList
975
- this.filterData = filterList
976
- this.tableLoading = true
712
+ reactData.sortData = sortList
713
+ reactData.filterData = filterList
714
+ reactData.tableLoading = true
977
715
  const applyArgs = [commitParams].concat(args)
978
716
  return Promise.resolve((beforeQuery || ajaxMethods)(...applyArgs))
979
717
  .then(rest => {
980
718
  let tableData: any[] = []
981
- this.tableLoading = false
719
+ reactData.tableLoading = false
982
720
  if (rest) {
983
721
  if (pagerConfig && isEnableConf(pagerOpts)) {
984
722
  const totalProp = resConfigs.total
985
- const total = (XEUtils.isFunction(totalProp) ? totalProp({ data: rest, $grid: this }) : XEUtils.get(rest, totalProp || 'page.total')) || 0
723
+ const total = (XEUtils.isFunction(totalProp) ? totalProp({ data: rest, $grid: $xeGrid as unknown as VxeGridConstructor }) : XEUtils.get(rest, totalProp || 'page.total')) || 0
986
724
  tablePage.total = XEUtils.toNumber(total)
987
725
  const resultProp = resConfigs.result
988
- tableData = (XEUtils.isFunction(resultProp) ? resultProp({ data: rest, $grid: this }) : XEUtils.get(rest, resultProp || 'result')) || []
726
+ tableData = (XEUtils.isFunction(resultProp) ? resultProp({ data: rest, $grid: $xeGrid as unknown as VxeGridConstructor }) : XEUtils.get(rest, resultProp || 'result')) || []
989
727
  // 检验当前页码,不能超出当前最大页数
990
728
  const pageCount = Math.max(Math.ceil(total / tablePage.pageSize), 1)
991
729
  if (tablePage.currentPage > pageCount) {
@@ -993,7 +731,7 @@ export default {
993
731
  }
994
732
  } else {
995
733
  const listProp = resConfigs.list
996
- tableData = (listProp ? (XEUtils.isFunction(listProp) ? listProp({ data: rest, $grid: this }) : XEUtils.get(rest, listProp)) : rest) || []
734
+ tableData = (listProp ? (XEUtils.isFunction(listProp) ? listProp({ data: rest, $grid: $xeGrid as unknown as VxeGridConstructor }) : XEUtils.get(rest, listProp)) : rest) || []
997
735
  }
998
736
  }
999
737
  if ($xeTable as any) {
@@ -1013,7 +751,7 @@ export default {
1013
751
  }
1014
752
  return { status: true }
1015
753
  }).catch((rest) => {
1016
- this.tableLoading = false
754
+ reactData.tableLoading = false
1017
755
  if (queryErrorMethods) {
1018
756
  queryErrorMethods({ ...commitParams, response: rest })
1019
757
  }
@@ -1032,29 +770,29 @@ export default {
1032
770
  const selectRecords = $xeTable.getCheckboxRecords()
1033
771
  const removeRecords = selectRecords.filter((row) => !$xeTable.isInsertByRow(row))
1034
772
  const body = { removeRecords }
1035
- const commitParams = { $grid: this, code, button, body, form: formData, options: ajaxMethods }
773
+ const commitParams = { $grid: $xeGrid, code, button, body, form: formData, options: ajaxMethods }
1036
774
  const applyArgs = [commitParams].concat(args)
1037
775
  if (selectRecords.length) {
1038
- return this.handleDeleteRow(code, 'vxe.grid.deleteSelectRecord', () => {
776
+ return $xeGrid.handleDeleteRow(code, 'vxe.grid.deleteSelectRecord', () => {
1039
777
  if (!removeRecords.length) {
1040
778
  return $xeTable.remove(selectRecords)
1041
779
  }
1042
- this.tableLoading = true
780
+ reactData.tableLoading = true
1043
781
  return Promise.resolve((beforeDelete || ajaxMethods)(...applyArgs))
1044
782
  .then(rest => {
1045
- this.tableLoading = false
783
+ reactData.tableLoading = false
1046
784
  $xeTable.setPendingRow(removeRecords, false)
1047
785
  if (isRespMsg) {
1048
786
  // 检测弹窗模块
1049
787
  if (!VxeUI.modal) {
1050
788
  errLog('vxe.error.reqModule', ['Modal'])
1051
789
  }
1052
- VxeUI.modal.message({ content: this.getRespMsg(rest, 'vxe.grid.delSuccess'), status: 'success' })
790
+ VxeUI.modal.message({ content: $xeGrid.getRespMsg(rest, 'vxe.grid.delSuccess'), status: 'success' })
1053
791
  }
1054
792
  if (afterDelete) {
1055
793
  afterDelete(...applyArgs)
1056
794
  } else {
1057
- this.commitProxy('query')
795
+ $xeGrid.commitProxy('query')
1058
796
  }
1059
797
  if (deleteSuccessMethods) {
1060
798
  deleteSuccessMethods({ ...commitParams, response: rest })
@@ -1062,13 +800,13 @@ export default {
1062
800
  return { status: true }
1063
801
  })
1064
802
  .catch(rest => {
1065
- this.tableLoading = false
803
+ reactData.tableLoading = false
1066
804
  if (isRespMsg) {
1067
805
  // 检测弹窗模块
1068
806
  if (!VxeUI.modal) {
1069
807
  errLog('vxe.error.reqModule', ['Modal'])
1070
808
  }
1071
- VxeUI.modal.message({ id: code, content: this.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
809
+ VxeUI.modal.message({ id: code, content: $xeGrid.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1072
810
  }
1073
811
  if (deleteErrorMethods) {
1074
812
  deleteErrorMethods({ ...commitParams, response: rest })
@@ -1095,22 +833,22 @@ export default {
1095
833
  const saveSuccessMethods = ajax.saveSuccess
1096
834
  const saveErrorMethods = ajax.saveError
1097
835
  if (ajaxMethods) {
1098
- const body = this.getRecordset()
836
+ const body = $xeGrid.getRecordset()
1099
837
  const { insertRecords, removeRecords, updateRecords, pendingRecords } = body
1100
- const commitParams = { $grid: this, code, button, body, form: formData, options: ajaxMethods }
838
+ const commitParams = { $grid: $xeGrid, code, button, body, form: formData, options: ajaxMethods }
1101
839
  const applyArgs = [commitParams].concat(args)
1102
840
  // 排除掉新增且标记为删除的数据
1103
841
  if (insertRecords.length) {
1104
- body.pendingRecords = pendingRecords.filter((row: any) => insertRecords.indexOf(row) === -1)
842
+ body.pendingRecords = pendingRecords.filter((row) => insertRecords.indexOf(row) === -1)
1105
843
  }
1106
844
  // 排除已标记为删除的数据
1107
845
  if (pendingRecords.length) {
1108
- body.insertRecords = insertRecords.filter((row: any) => pendingRecords.indexOf(row) === -1)
846
+ body.insertRecords = insertRecords.filter((row) => pendingRecords.indexOf(row) === -1)
1109
847
  }
1110
- let restPromise = Promise.resolve()
848
+ let restPromise: Promise<any> = Promise.resolve()
1111
849
  if (editRules) {
1112
850
  // 只校验新增和修改的数据
1113
- restPromise = this[validConfig && validConfig.msgMode === 'full' ? 'fullValidate' : 'validate'](body.insertRecords.concat(updateRecords))
851
+ restPromise = $xeGrid[validConfig && validConfig.msgMode === 'full' ? 'fullValidate' : 'validate'](body.insertRecords.concat(updateRecords))
1114
852
  }
1115
853
  return restPromise.then((errMap: any) => {
1116
854
  if (errMap) {
@@ -1118,22 +856,22 @@ export default {
1118
856
  return
1119
857
  }
1120
858
  if (body.insertRecords.length || removeRecords.length || updateRecords.length || body.pendingRecords.length) {
1121
- this.tableLoading = true
859
+ reactData.tableLoading = true
1122
860
  return Promise.resolve((beforeSave || ajaxMethods)(...applyArgs))
1123
861
  .then(rest => {
1124
- this.tableLoading = false
862
+ reactData.tableLoading = false
1125
863
  $xeTable.clearPendingRow()
1126
864
  if (isRespMsg) {
1127
865
  // 检测弹窗模块
1128
866
  if (!VxeUI.modal) {
1129
867
  errLog('vxe.error.reqModule', ['Modal'])
1130
868
  }
1131
- VxeUI.modal.message({ content: this.getRespMsg(rest, 'vxe.grid.saveSuccess'), status: 'success' })
869
+ VxeUI.modal.message({ content: $xeGrid.getRespMsg(rest, 'vxe.grid.saveSuccess'), status: 'success' })
1132
870
  }
1133
871
  if (afterSave) {
1134
872
  afterSave(...applyArgs)
1135
873
  } else {
1136
- this.commitProxy('query')
874
+ $xeGrid.commitProxy('query')
1137
875
  }
1138
876
  if (saveSuccessMethods) {
1139
877
  saveSuccessMethods({ ...commitParams, response: rest })
@@ -1141,13 +879,13 @@ export default {
1141
879
  return { status: true }
1142
880
  })
1143
881
  .catch(rest => {
1144
- this.tableLoading = false
882
+ reactData.tableLoading = false
1145
883
  if (isRespMsg) {
1146
884
  // 检测弹窗模块
1147
885
  if (!VxeUI.modal) {
1148
886
  errLog('vxe.error.reqModule', ['Modal'])
1149
887
  }
1150
- VxeUI.modal.message({ id: code, content: this.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
888
+ VxeUI.modal.message({ id: code, content: $xeGrid.getRespMsg(rest, 'vxe.grid.operError'), status: 'error' })
1151
889
  }
1152
890
  if (saveErrorMethods) {
1153
891
  saveErrorMethods({ ...commitParams, response: rest })
@@ -1173,198 +911,228 @@ export default {
1173
911
  const gCommandOpts = commands.get(code)
1174
912
  if (gCommandOpts) {
1175
913
  if (gCommandOpts.commandMethod) {
1176
- gCommandOpts.commandMethod({ code, button, $grid: this, $table: $xeTable }, ...args)
914
+ gCommandOpts.commandMethod({ code, button, $grid: $xeGrid as unknown as VxeGridConstructor, $table: $xeTable }, ...args)
1177
915
  } else {
1178
916
  errLog('vxe.error.notCommands', [code])
1179
917
  }
1180
918
  }
1181
919
  }
1182
920
  }
1183
- return this.$nextTick()
1184
- },
1185
- getRespMsg (rest: any, defaultMsg: any) {
1186
- const { proxyOpts } = this
1187
- const resConfigs = proxyOpts.response || proxyOpts.props || {}
1188
- let msg: any
1189
- if (rest && resConfigs.message) {
1190
- msg = XEUtils.get(rest, resConfigs.message)
1191
- }
1192
- return msg || getI18n(defaultMsg)
1193
- },
1194
- handleDeleteRow (code: any, alertKey: any, callback: any) {
1195
- const selectRecords = this.getCheckboxRecords()
1196
- if (this.isActiveMsg) {
1197
- if (selectRecords.length) {
1198
- return VxeUI.modal.confirm({ id: `cfm_${code}`, content: getI18n(alertKey), escClosable: true }).then(type => {
1199
- if (type === 'confirm') {
1200
- return callback()
1201
- }
1202
- })
1203
- } else {
1204
- // 检测弹窗模块
1205
- if (!VxeUI.modal) {
1206
- errLog('vxe.error.reqModule', ['Modal'])
1207
- }
1208
- VxeUI.modal.message({ id: `msg_${code}`, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
1209
- }
1210
- } else {
1211
- if (selectRecords.length) {
1212
- callback()
1213
- }
1214
- }
1215
- return Promise.resolve()
921
+ return $xeGrid.$nextTick()
1216
922
  },
1217
923
  getFormData () {
1218
- const { proxyConfig, proxyOpts, formOpts, formData } = this
924
+ const $xeGrid = this
925
+ const props = $xeGrid
926
+ const reactData = $xeGrid.reactData
927
+
928
+ const { proxyConfig } = props
929
+ const { formData } = reactData
930
+ const proxyOpts = $xeGrid.computeProxyOpts
931
+ const formOpts = $xeGrid.computeFormOpts
1219
932
  return proxyConfig && isEnableConf(proxyOpts) && proxyOpts.form ? formData : formOpts.data
1220
933
  },
1221
- getFormItems (itemIndex: any) {
1222
- const { formConfig, formOpts } = this
1223
- const itemList: any[] = []
1224
- XEUtils.eachTree(isEnableConf(formConfig) && formOpts.items ? formOpts.items : [], item => {
934
+ getFormItems (itemIndex?: number): any {
935
+ const $xeGrid = this
936
+ const props = $xeGrid
937
+
938
+ const formOpts = $xeGrid.computeFormOpts
939
+ const { formConfig } = props
940
+ const { items } = formOpts
941
+ const itemList: VxeFormItemProps[] = []
942
+ XEUtils.eachTree(formConfig && isEnableConf(formOpts) && items ? items : [], item => {
1225
943
  itemList.push(item)
1226
944
  }, { children: 'children' })
1227
945
  return XEUtils.isUndefined(itemIndex) ? itemList : itemList[itemIndex]
1228
946
  },
1229
947
  triggerToolbarCommitEvent (params: any, evnt: any) {
948
+ const $xeGrid = this
949
+
1230
950
  const { code } = params
1231
- return this.commitProxy(params, evnt).then((rest: any) => {
951
+ return $xeGrid.commitProxy(params, evnt).then((rest) => {
1232
952
  if (code && rest && rest.status && ['query', 'reload', 'delete', 'save'].includes(code)) {
1233
- this.$emit(code === 'delete' || code === 'save' ? `proxy-${code}` : 'proxy-query', { ...rest, isReload: code === 'reload', $grid: this, $event: evnt })
953
+ $xeGrid.dispatchEvent(code === 'delete' || code === 'save' ? `proxy-${code as 'delete' | 'save'}` : 'proxy-query', { ...rest, isReload: code === 'reload' }, evnt)
1234
954
  }
1235
955
  })
1236
956
  },
1237
957
  triggerToolbarBtnEvent (button: any, evnt: any) {
1238
- this.triggerToolbarCommitEvent(button, evnt)
1239
- this.$emit('toolbar-button-click', { code: button.code, button, $grid: this, $event: evnt })
958
+ const $xeGrid = this
959
+
960
+ $xeGrid.triggerToolbarCommitEvent(button, evnt)
961
+ $xeGrid.dispatchEvent('toolbar-button-click', { code: button.code, button }, evnt)
1240
962
  },
1241
963
  triggerToolbarTolEvent (tool: any, evnt: any) {
1242
- this.triggerToolbarCommitEvent(tool, evnt)
1243
- this.$emit('toolbar-tool-click', { code: tool.code, tool, $grid: this, $event: evnt })
1244
- },
1245
- triggerPendingEvent (code: any) {
1246
- const { isActiveMsg } = this
1247
- const selectRecords = this.getCheckboxRecords()
1248
- if (selectRecords.length) {
1249
- this.togglePendingRow(selectRecords)
1250
- this.clearCheckboxRow()
1251
- } else {
1252
- if (isActiveMsg) {
1253
- // 检测弹窗模块
1254
- if (!VxeUI.modal) {
1255
- errLog('vxe.error.reqModule', ['Modal'])
1256
- }
1257
- VxeUI.modal.message({ id: code, content: getI18n('vxe.grid.selectOneRecord'), status: 'warning' })
1258
- }
1259
- }
964
+ const $xeGrid = this
965
+
966
+ $xeGrid.triggerToolbarCommitEvent(tool, evnt)
967
+ $xeGrid.dispatchEvent('toolbar-tool-click', { code: tool.code, tool }, evnt)
1260
968
  },
1261
- sortChangeEvent (params: any) {
1262
- const { $table, column, sortList } = params
1263
- const isRemote = XEUtils.isBoolean(column.remoteSort) ? column.remoteSort : $table.sortOpts.remote
969
+ sortChangeEvent (params: VxeTableDefines.SortChangeEventParams) {
970
+ const $xeGrid = this
971
+ const props = $xeGrid
972
+ const reactData = $xeGrid.reactData
973
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
974
+
975
+ const { proxyConfig } = props
976
+ const proxyOpts = $xeGrid.computeProxyOpts
977
+ const sortOpts = $xeTable.computeSortOpts
1264
978
  // 如果是服务端排序
1265
- if (isRemote) {
1266
- this.sortData = sortList
1267
- if (this.proxyConfig) {
1268
- this.tablePage.currentPage = 1
1269
- this.commitProxy('query').then((rest: any) => {
1270
- this.$emit('proxy-query', { ...rest, $grid: this, $event: params.$event })
979
+ if (sortOpts.remote) {
980
+ reactData.sortData = params.sortList
981
+ if (proxyConfig && isEnableConf(proxyOpts)) {
982
+ reactData.tablePage.currentPage = 1
983
+ $xeGrid.commitProxy('query').then((rest) => {
984
+ $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
1271
985
  })
1272
986
  }
1273
987
  }
1274
- this.$emit('sort-change', Object.assign({ $grid: this }, params))
988
+ $xeGrid.dispatchEvent('sort-change', params, params.$event)
989
+ },
990
+ pageChangeEvent (params: VxePagerDefines.PageChangeEventParams) {
991
+ const $xeGrid = this
992
+ const props = $xeGrid
993
+ const reactData = $xeGrid.reactData
994
+
995
+ const { proxyConfig } = props
996
+ const { tablePage } = reactData
997
+ const { $event, currentPage, pageSize } = params
998
+ const proxyOpts = $xeGrid.computeProxyOpts
999
+ tablePage.currentPage = currentPage
1000
+ tablePage.pageSize = pageSize
1001
+ $xeGrid.dispatchEvent('page-change', params, $event)
1002
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1003
+ $xeGrid.commitProxy('query').then((rest) => {
1004
+ $xeGrid.dispatchEvent('proxy-query', rest, $event)
1005
+ })
1006
+ }
1275
1007
  },
1276
- filterChangeEvent (params: any) {
1277
- const { $table, filterList } = params
1008
+ filterChangeEvent (params: VxeTableDefines.FilterChangeEventParams) {
1009
+ const $xeGrid = this
1010
+ const props = $xeGrid
1011
+ const reactData = $xeGrid.reactData
1012
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1013
+
1014
+ const { proxyConfig } = props
1015
+ const proxyOpts = $xeGrid.computeProxyOpts
1016
+ const filterOpts = $xeTable.computeFilterOpts
1278
1017
  // 如果是服务端过滤
1279
- if ($table.filterOpts.remote) {
1280
- this.filterData = filterList
1281
- if (this.proxyConfig) {
1282
- this.tablePage.currentPage = 1
1283
- this.commitProxy('query').then((rest: any) => {
1284
- this.$emit('proxy-query', { ...rest, $grid: this, $event: params.$event })
1018
+ if (filterOpts.remote) {
1019
+ reactData.filterData = params.filterList
1020
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1021
+ reactData.tablePage.currentPage = 1
1022
+ $xeGrid.commitProxy('query').then((rest) => {
1023
+ $xeGrid.dispatchEvent('proxy-query', rest, params.$event)
1285
1024
  })
1286
1025
  }
1287
1026
  }
1288
- this.$emit('filter-change', Object.assign({ $grid: this }, params))
1027
+ $xeGrid.dispatchEvent('filter-change', params, params.$event)
1289
1028
  },
1290
- submitEvent (params: any) {
1029
+ submitFormEvent (params: VxeFormDefines.SubmitEventParams) {
1291
1030
  const $xeGrid = this
1292
- const reactData = $xeGrid
1031
+ const props = $xeGrid
1032
+ const reactData = $xeGrid.reactData
1293
1033
 
1294
- const { proxyConfig } = this
1034
+ const { proxyConfig } = props
1035
+ const proxyOpts = $xeGrid.computeProxyOpts
1295
1036
  if (reactData.tableLoading) {
1296
1037
  return
1297
1038
  }
1298
- if (proxyConfig) {
1299
- this.commitProxy('reload').then((rest: any) => {
1300
- this.$emit('proxy-query', { ...rest, isReload: true, $grid: this, $event: params.$event })
1039
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1040
+ $xeGrid.commitProxy('reload').then((rest) => {
1041
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, params.$event)
1301
1042
  })
1302
1043
  }
1303
- this.$emit('form-submit', Object.assign({ $grid: this }, params))
1044
+ $xeGrid.dispatchEvent('form-submit', params, params.$event)
1304
1045
  },
1305
- resetEvent (params: any) {
1306
- const { proxyConfig } = this
1307
- const $xeTable = this.$refs.xTable
1308
- if (proxyConfig) {
1046
+ resetFormEvent (params: any) {
1047
+ const $xeGrid = this
1048
+ const props = $xeGrid
1049
+
1050
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1051
+ const { proxyConfig } = props
1052
+ const { $event } = params
1053
+ const proxyOpts = $xeGrid.computeProxyOpts
1054
+ if (proxyConfig && isEnableConf(proxyOpts)) {
1309
1055
  $xeTable.clearScroll()
1310
- this.commitProxy('reload').then((rest: any) => {
1311
- this.$emit('proxy-query', { ...rest, isReload: true, $grid: this, $event: params.$event })
1056
+ $xeGrid.commitProxy('reload').then((rest) => {
1057
+ $xeGrid.dispatchEvent('proxy-query', { ...rest, isReload: true }, $event)
1312
1058
  })
1313
1059
  }
1314
- this.$emit('form-reset', Object.assign({ $grid: this }, params))
1060
+ $xeGrid.dispatchEvent('form-reset', params, $event)
1315
1061
  },
1316
- submitInvalidEvent (params: any) {
1317
- this.$emit('form-submit-invalid', Object.assign({ $grid: this }, params))
1062
+ submitInvalidEvent (params: VxeFormDefines.SubmitInvalidEventParams) {
1063
+ const $xeGrid = this
1064
+
1065
+ $xeGrid.dispatchEvent('form-submit-invalid', params, params.$event)
1318
1066
  },
1319
- collapseEvent (params: any) {
1320
- this.$nextTick(() => this.recalculate(true))
1321
- this.$emit('form-toggle-collapse', Object.assign({ $grid: this }, params))
1322
- this.$emit('form-collapse', Object.assign({ $grid: this }, params))
1067
+ collapseEvent (params: VxeFormDefines.CollapseEventParams) {
1068
+ const $xeGrid = this
1069
+
1070
+ const { $event } = params
1071
+ $xeGrid.dispatchEvent('form-toggle-collapse', params, $event)
1072
+ $xeGrid.dispatchEvent('form-collapse', params, $event)
1323
1073
  },
1324
- triggerZoomEvent (evnt: any) {
1325
- this.zoom()
1326
- this.$emit('zoom', { $grid: this, type: this.isZMax ? 'max' : 'revert', $event: evnt })
1074
+ triggerZoomEvent (evnt: Event) {
1075
+ const $xeGrid = this
1076
+ const reactData = $xeGrid.reactData
1077
+
1078
+ $xeGrid.zoom()
1079
+ $xeGrid.dispatchEvent('zoom', { type: reactData.isZMax ? 'max' : 'revert' }, evnt)
1327
1080
  },
1328
1081
  zoom () {
1329
- return this[this.isZMax ? 'revert' : 'maximize']()
1082
+ const $xeGrid = this
1083
+ const reactData = $xeGrid.reactData
1084
+
1085
+ return $xeGrid[reactData.isZMax ? 'revert' : 'maximize']()
1330
1086
  },
1331
1087
  isMaximized () {
1332
- return this.isZMax
1088
+ const $xeGrid = this
1089
+ const reactData = $xeGrid.reactData
1090
+
1091
+ return reactData.isZMax
1333
1092
  },
1334
1093
  maximize () {
1335
- return this.handleZoom(true)
1094
+ const $xeGrid = this
1095
+
1096
+ return $xeGrid.handleZoom(true)
1336
1097
  },
1337
1098
  revert () {
1338
- return this.handleZoom()
1099
+ const $xeGrid = this
1100
+
1101
+ return $xeGrid.handleZoom()
1339
1102
  },
1340
- handleZoom (isMax: any) {
1341
- const { isZMax } = this
1103
+ handleZoom (isMax?: boolean) {
1104
+ const $xeGrid = this
1105
+ const reactData = $xeGrid.reactData
1106
+
1107
+ const { isZMax } = reactData
1342
1108
  if (isMax ? !isZMax : isZMax) {
1343
- this.isZMax = !isZMax
1344
- if (this.tZindex < getLastZIndex()) {
1345
- this.tZindex = nextZIndex()
1109
+ reactData.isZMax = !isZMax
1110
+ if (reactData.tZindex < getLastZIndex()) {
1111
+ reactData.tZindex = nextZIndex()
1346
1112
  }
1347
1113
  }
1348
- return this.$nextTick()
1349
- .then(() => this.recalculate(true))
1114
+ return $xeGrid.$nextTick()
1115
+ .then(() => $xeGrid.recalculate(true))
1350
1116
  .then(() => {
1351
- setTimeout(() => this.recalculate(true), 15)
1352
- return this.isZMax
1117
+ setTimeout(() => $xeGrid.recalculate(true), 15)
1118
+ return reactData.isZMax
1353
1119
  })
1354
1120
  },
1355
1121
  getProxyInfo () {
1356
1122
  const $xeGrid = this
1357
- const $xeTable = $xeGrid.$refs.xTable as VxeTableConstructor & VxeTablePrivateMethods
1123
+ const props = $xeGrid
1124
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1125
+ const reactData = $xeGrid.reactData
1358
1126
 
1359
- const { sortData, proxyConfig } = this
1360
- if (proxyConfig) {
1127
+ if (props.proxyConfig) {
1128
+ const { sortData } = reactData
1361
1129
  return {
1362
1130
  data: $xeTable ? $xeTable.getFullData() : [],
1363
- filter: this.filterData,
1364
- form: this.getFormData(),
1131
+ filter: reactData.filterData,
1132
+ form: $xeGrid.getFormData(),
1365
1133
  sort: sortData.length ? sortData[0] : {},
1366
1134
  sorts: sortData,
1367
- pager: this.tablePage,
1135
+ pager: reactData.tablePage,
1368
1136
  pendingRecords: $xeTable ? $xeTable.getPendingRecords() : []
1369
1137
  }
1370
1138
  }
@@ -1372,14 +1140,14 @@ export default {
1372
1140
  },
1373
1141
  loadColumn (columns: any[]) {
1374
1142
  const $xeGrid = this
1375
- const $xeTable = $xeGrid.$refs.xTable as VxeTableConstructor & VxeTablePrivateMethods
1143
+ const slots = $xeGrid.$scopedSlots
1144
+ const $xeTable = $xeGrid.$refs.refTable as VxeTableConstructor & VxeTablePrivateMethods
1376
1145
 
1377
- const { $scopedSlots } = this
1378
1146
  XEUtils.eachTree(columns, column => {
1379
1147
  if (column.slots) {
1380
1148
  XEUtils.each(column.slots, (func) => {
1381
1149
  if (!XEUtils.isFunction(func)) {
1382
- if (!$scopedSlots[func]) {
1150
+ if (!slots[func]) {
1383
1151
  errLog('vxe.error.notSlot', [func])
1384
1152
  }
1385
1153
  }
@@ -1393,6 +1161,453 @@ export default {
1393
1161
 
1394
1162
  $xeGrid.clearAll()
1395
1163
  return $xeGrid.loadColumn(columns)
1164
+ },
1165
+ getConfigSlot (slotConfigs?: Record<string, any>) {
1166
+ const $xeGrid = this
1167
+ const slots = $xeGrid.$scopedSlots
1168
+
1169
+ const slotConf: Record<string, any> = {}
1170
+ XEUtils.objectMap(slotConfigs, (slotFunc, slotKey) => {
1171
+ if (slotFunc) {
1172
+ if (XEUtils.isString(slotFunc)) {
1173
+ if (slots[slotFunc]) {
1174
+ slotConf[slotKey] = slots[slotFunc]
1175
+ } else {
1176
+ errLog('vxe.error.notSlot', [slotFunc])
1177
+ }
1178
+ } else {
1179
+ slotConf[slotKey] = slotFunc
1180
+ }
1181
+ }
1182
+ })
1183
+ return slotConf
1184
+ },
1185
+ getToolbarSlots () {
1186
+ const $xeGrid = this
1187
+ const slots = $xeGrid.$scopedSlots
1188
+
1189
+ const toolbarOpts = $xeGrid.computeToolbarOpts
1190
+ const toolbarOptSlots = toolbarOpts.slots
1191
+ const toolbarSlots: {
1192
+ buttons?(params: any): any
1193
+ buttonPrefix?(params: any): any
1194
+ buttonSuffix?(params: any): any
1195
+ tools?(params: any): any
1196
+ toolPrefix?(params: any): any
1197
+ toolSuffix?(params: any): any
1198
+ } = {}
1199
+ if (slots.buttons && (!toolbarOptSlots || toolbarOptSlots.buttons !== 'buttons')) {
1200
+ warnLog('vxe.error.reqProp', ['toolbar-config.slots.buttons'])
1201
+ }
1202
+ if (slots.tools && (!toolbarOptSlots || toolbarOptSlots.tools !== 'tools')) {
1203
+ warnLog('vxe.error.reqProp', ['toolbar-config.slots.tools'])
1204
+ }
1205
+ if (toolbarOptSlots) {
1206
+ const buttonsSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttons')
1207
+ const buttonPrefixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttonPrefix')
1208
+ const buttonSuffixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'buttonSuffix')
1209
+ const toolsSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'tools')
1210
+ const toolPrefixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'toolPrefix')
1211
+ const toolSuffixSlot = $xeGrid.getFuncSlot(toolbarOptSlots, 'toolSuffix')
1212
+ if (buttonsSlot) {
1213
+ toolbarSlots.buttons = buttonsSlot
1214
+ }
1215
+ if (buttonPrefixSlot) {
1216
+ toolbarSlots.buttonPrefix = buttonPrefixSlot
1217
+ }
1218
+ if (buttonSuffixSlot) {
1219
+ toolbarSlots.buttonSuffix = buttonSuffixSlot
1220
+ }
1221
+ if (toolsSlot) {
1222
+ toolbarSlots.tools = toolsSlot
1223
+ }
1224
+ if (toolPrefixSlot) {
1225
+ toolbarSlots.toolPrefix = toolPrefixSlot
1226
+ }
1227
+ if (toolSuffixSlot) {
1228
+ toolbarSlots.toolSuffix = toolSuffixSlot
1229
+ }
1230
+ }
1231
+ return toolbarSlots
1232
+ },
1233
+ getFuncSlot (optSlots: any, slotKey: any) {
1234
+ const $xeGrid = this
1235
+ const slots = $xeGrid.$scopedSlots
1236
+
1237
+ const funcSlot = optSlots[slotKey]
1238
+ if (funcSlot) {
1239
+ if (XEUtils.isString(funcSlot)) {
1240
+ if (slots[funcSlot]) {
1241
+ return slots[funcSlot]
1242
+ } else {
1243
+ errLog('vxe.error.notSlot', [funcSlot])
1244
+ }
1245
+ } else {
1246
+ return funcSlot
1247
+ }
1248
+ }
1249
+ return null
1250
+ },
1251
+
1252
+ //
1253
+ // Render
1254
+ //
1255
+ renderDefaultForm (h: CreateElement) {
1256
+ const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
1257
+
1258
+ const $xeGrid = this
1259
+ const props = $xeGrid
1260
+ const slots = $xeGrid.$scopedSlots
1261
+ const reactData = $xeGrid.reactData
1262
+
1263
+ const { proxyConfig, formConfig } = props
1264
+ const { formData } = reactData
1265
+ const proxyOpts = $xeGrid.computeProxyOpts
1266
+ const formOpts = $xeGrid.computeFormOpts
1267
+ if (isEnableConf(formConfig) && formOpts.items && formOpts.items.length) {
1268
+ const formSlots: any = {}
1269
+ if (!(formOpts as any).inited) {
1270
+ (formOpts as any).inited = true
1271
+ const beforeItem = proxyOpts.beforeItem
1272
+ if (proxyOpts && beforeItem) {
1273
+ formOpts.items.forEach((item: any) => {
1274
+ beforeItem.call($xeGrid, { $grid: $xeGrid, item })
1275
+ })
1276
+ }
1277
+ }
1278
+ // 处理插槽
1279
+ formOpts.items.forEach((item: any) => {
1280
+ XEUtils.each(item.slots, (func) => {
1281
+ if (!XEUtils.isFunction(func)) {
1282
+ if (slots[func]) {
1283
+ formSlots[func] = slots[func]
1284
+ }
1285
+ }
1286
+ })
1287
+ })
1288
+ return [
1289
+ VxeUIFormComponent
1290
+ ? h(VxeUIFormComponent, {
1291
+ props: Object.assign({}, formOpts, {
1292
+ data: proxyConfig && proxyOpts.form ? formData : formOpts.data
1293
+ }),
1294
+ on: {
1295
+ submit: $xeGrid.submitFormEvent,
1296
+ reset: $xeGrid.resetFormEvent,
1297
+ collapse: $xeGrid.collapseEvent,
1298
+ 'submit-invalid': $xeGrid.submitInvalidEvent
1299
+ },
1300
+ scopedSlots: formSlots
1301
+ })
1302
+ : renderEmptyElement($xeGrid)
1303
+ ]
1304
+ }
1305
+ return []
1306
+ },
1307
+ renderForm (h: CreateElement) {
1308
+ const $xeGrid = this
1309
+ const props = $xeGrid
1310
+ const slots = $xeGrid.$scopedSlots
1311
+
1312
+ const { formConfig } = props
1313
+ const formSlot = slots.form
1314
+ const hasForm = !!(formSlot || isEnableConf(formConfig))
1315
+
1316
+ if (hasForm) {
1317
+ return h('div', {
1318
+ key: 'form',
1319
+ ref: 'refFormWrapper',
1320
+ class: 'vxe-grid--form-wrapper'
1321
+ }, formSlot ? formSlot.call($xeGrid, { $grid: $xeGrid }) : $xeGrid.renderDefaultForm(h))
1322
+ }
1323
+ return renderEmptyElement($xeGrid)
1324
+ },
1325
+ renderToolbar (h: CreateElement) {
1326
+ const $xeGrid = this
1327
+ const props = $xeGrid
1328
+ const slots = $xeGrid.$scopedSlots
1329
+
1330
+ const { toolbarConfig } = props
1331
+ const toolbarSlot = slots.toolbar
1332
+ const hasToolbar = !!(toolbarSlot || isEnableConf(toolbarConfig) || toolbar)
1333
+ const toolbarOpts = $xeGrid.computeToolbarOpts
1334
+
1335
+ if (hasToolbar) {
1336
+ return h('div', {
1337
+ key: 'toolbar',
1338
+ ref: 'refToolbarWrapper',
1339
+ class: 'vxe-grid--toolbar-wrapper'
1340
+ }, toolbarSlot
1341
+ ? toolbarSlot.call($xeGrid, { $grid: $xeGrid })
1342
+ : [
1343
+ h(VxeToolbarComponent, {
1344
+ props: Object.assign({}, toolbarOpts, { slots: undefined }),
1345
+ ref: 'xToolbar',
1346
+ scopedSlots: $xeGrid.getToolbarSlots()
1347
+ })
1348
+ ]
1349
+ )
1350
+ }
1351
+ return renderEmptyElement($xeGrid)
1352
+ },
1353
+ renderTop (h: CreateElement) {
1354
+ const $xeGrid = this
1355
+ const slots = $xeGrid.$scopedSlots
1356
+
1357
+ const topSlot = slots.top
1358
+ return topSlot
1359
+ ? h('div', {
1360
+ key: 'top',
1361
+ ref: 'refTopWrapper',
1362
+ class: 'vxe-grid--top-wrapper'
1363
+ }, topSlot.call($xeGrid, { $grid: $xeGrid }))
1364
+ : renderEmptyElement($xeGrid)
1365
+ },
1366
+ renderTableLeft (h: CreateElement) {
1367
+ const $xeGrid = this
1368
+ const slots = $xeGrid.$scopedSlots
1369
+
1370
+ const leftSlot = slots.left
1371
+ if (leftSlot) {
1372
+ return h('div', {
1373
+ class: 'vxe-grid--left-wrapper'
1374
+ }, leftSlot({ $grid: $xeGrid }))
1375
+ }
1376
+ return renderEmptyElement($xeGrid)
1377
+ },
1378
+ renderTableRight (h: CreateElement) {
1379
+ const $xeGrid = this
1380
+ const slots = $xeGrid.$scopedSlots
1381
+
1382
+ const rightSlot = slots.right
1383
+ if (rightSlot) {
1384
+ return h('div', {
1385
+ class: 'vxe-grid--right-wrapper'
1386
+ }, rightSlot({ $grid: $xeGrid }))
1387
+ }
1388
+ return renderEmptyElement($xeGrid)
1389
+ },
1390
+ renderTable (h: CreateElement) {
1391
+ const $xeGrid = this
1392
+ const slots = $xeGrid.$scopedSlots
1393
+
1394
+ const tableProps = $xeGrid.computeTableProps
1395
+
1396
+ return h('div', {
1397
+ class: 'vxe-grid--table-wrapper'
1398
+ }, [
1399
+ h(VxeTableComponent, {
1400
+ key: 'table',
1401
+ props: tableProps,
1402
+ on: getTableOns($xeGrid),
1403
+ scopedSlots: slots,
1404
+ ref: 'refTable'
1405
+ })
1406
+ ])
1407
+ },
1408
+ renderBottom (h: CreateElement) {
1409
+ const $xeGrid = this
1410
+ const slots = $xeGrid.$scopedSlots
1411
+
1412
+ const bottomSlot = slots.bottom
1413
+
1414
+ return bottomSlot
1415
+ ? h('div', {
1416
+ key: 'bottom',
1417
+ ref: 'refBottomWrapper',
1418
+ class: 'vxe-grid--bottom-wrapper'
1419
+ }, bottomSlot.call($xeGrid, { $grid: $xeGrid }))
1420
+ : renderEmptyElement($xeGrid)
1421
+ },
1422
+ renderPager (h: CreateElement) {
1423
+ const VxeUIPagerComponent = VxeUI.getComponent<VxePagerComponent>('VxePager')
1424
+
1425
+ const $xeGrid = this
1426
+ const props = $xeGrid
1427
+ const slots = $xeGrid.$scopedSlots
1428
+ const reactData = $xeGrid.reactData
1429
+
1430
+ const { proxyConfig, pagerConfig } = props
1431
+ const proxyOpts = $xeGrid.computeProxyOpts
1432
+ const pagerOpts = $xeGrid.computePagerOpts
1433
+ const pagerSlot = slots.pager
1434
+ if ((pagerConfig && isEnableConf(pagerOpts)) || slots.pager) {
1435
+ return h('div', {
1436
+ ref: 'refPagerWrapper',
1437
+ key: 'pager',
1438
+ class: 'vxe-grid--pager-wrapper'
1439
+ }, pagerSlot
1440
+ ? pagerSlot.call($xeGrid, { $grid: $xeGrid })
1441
+ : [
1442
+ VxeUIPagerComponent
1443
+ ? h(VxeUIPagerComponent, {
1444
+ ref: 'refPager',
1445
+ props: {
1446
+ ...pagerOpts,
1447
+ ...(proxyConfig && isEnableConf(proxyOpts) ? reactData.tablePage : {})
1448
+ },
1449
+ on: {
1450
+ 'page-change': $xeGrid.pageChangeEvent
1451
+ },
1452
+ scopedSlots: $xeGrid.getConfigSlot(pagerOpts.slots)
1453
+ })
1454
+ : renderEmptyElement($xeGrid)
1455
+ ])
1456
+ }
1457
+ return renderEmptyElement($xeGrid)
1458
+ },
1459
+ renderChildLayout (h: CreateElement, layoutKeys: VxeGridPropTypes.LayoutKey[]) {
1460
+ const $xeGrid = this
1461
+
1462
+ const childVNs: VNode[] = []
1463
+ layoutKeys.forEach(key => {
1464
+ switch (key) {
1465
+ case 'Form':
1466
+ childVNs.push($xeGrid.renderForm(h))
1467
+ break
1468
+ case 'Toolbar':
1469
+ childVNs.push($xeGrid.renderToolbar(h))
1470
+ break
1471
+ case 'Top':
1472
+ childVNs.push($xeGrid.renderTop(h))
1473
+ break
1474
+ case 'Table':
1475
+ childVNs.push(
1476
+ h('div', {
1477
+ key: 'table',
1478
+ class: 'vxe-grid--table-container'
1479
+ }, [
1480
+ $xeGrid.renderTableLeft(h),
1481
+ $xeGrid.renderTable(h),
1482
+ $xeGrid.renderTableRight(h)
1483
+ ])
1484
+ )
1485
+ break
1486
+ case 'Bottom':
1487
+ childVNs.push($xeGrid.renderBottom(h))
1488
+ break
1489
+ case 'Pager':
1490
+ childVNs.push($xeGrid.renderPager(h))
1491
+ break
1492
+ default:
1493
+ errLog('vxe.error.notProp', [`layouts -> ${key}`])
1494
+ break
1495
+ }
1496
+ })
1497
+ return childVNs
1498
+ },
1499
+ renderLayout (h: CreateElement) {
1500
+ const $xeGrid = this
1501
+ const slots = $xeGrid.$scopedSlots
1502
+
1503
+ const currLayoutConf = $xeGrid.computeCurrLayoutConf
1504
+ const { headKeys, bodyKeys, footKeys } = currLayoutConf
1505
+ const asideLeftSlot = slots.asideLeft || slots['aside-left']
1506
+ const asideRightSlot = slots.asideRight || slots['aside-right']
1507
+ return [
1508
+ h('div', {
1509
+ class: 'vxe-grid--layout-header-wrapper'
1510
+ }, $xeGrid.renderChildLayout(h, headKeys)),
1511
+ h('div', {
1512
+ class: 'vxe-grid--layout-body-wrapper'
1513
+ }, [
1514
+ asideLeftSlot
1515
+ ? h('div', {
1516
+ class: 'vxe-grid--layout-aside-left-wrapper'
1517
+ }, asideLeftSlot({}))
1518
+ : renderEmptyElement($xeGrid),
1519
+ h('div', {
1520
+ class: 'vxe-grid--layout-body-content-wrapper'
1521
+ }, $xeGrid.renderChildLayout(h, bodyKeys)),
1522
+ asideRightSlot
1523
+ ? h('div', {
1524
+ class: 'vxe-grid--layout-aside-right-wrapper'
1525
+ }, asideRightSlot({}))
1526
+ : renderEmptyElement($xeGrid)
1527
+ ]),
1528
+ h('div', {
1529
+ class: 'vxe-grid--layout-footer-wrapper'
1530
+ }, $xeGrid.renderChildLayout(h, footKeys))
1531
+ ]
1532
+ },
1533
+ renderVN (h: CreateElement): VNode {
1534
+ const $xeGrid = this
1535
+ const props = $xeGrid
1536
+ const reactData = $xeGrid.reactData
1537
+
1538
+ const vSize = $xeGrid.computeSize
1539
+ const styles = $xeGrid.computeStyles
1540
+ return h('div', {
1541
+ ref: 'refElem',
1542
+ class: ['vxe-grid', {
1543
+ [`size--${vSize}`]: vSize,
1544
+ 'is--animat': !!props.animat,
1545
+ 'is--round': props.round,
1546
+ 'is--maximize': reactData.isZMax,
1547
+ 'is--loading': props.loading || reactData.tableLoading
1548
+ }],
1549
+ style: styles
1550
+ }, $xeGrid.renderLayout(h))
1396
1551
  }
1397
- } as any
1398
- }
1552
+ },
1553
+ created () {
1554
+ // 使用已安装的组件,如果未安装则不渲染
1555
+ const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
1556
+ const VxeUIPagerComponent = VxeUI.getComponent<VxePagerComponent>('VxePager')
1557
+
1558
+ const $xeGrid = this
1559
+ const props = $xeGrid
1560
+
1561
+ const proxyOpts = $xeGrid.computeProxyOpts
1562
+
1563
+ // const { data, formOpts, proxyOpts, proxyConfig } = this
1564
+ // if (proxyConfig && (data || (proxyOpts.form && formOpts.data))) {
1565
+ // errLog('vxe.error.errConflicts', ['grid.data', 'grid.proxy-config'])
1566
+ // }
1567
+
1568
+ if ((props as any).toolbar) {
1569
+ errLog('vxe.error.delProp', ['grid.toolbar', 'grid.toolbar-config'])
1570
+ }
1571
+ if (props.toolbarConfig && !XEUtils.isObject(props.toolbarConfig)) {
1572
+ errLog('vxe.error.errProp', [`grid.toolbar-config=${props.toolbarConfig}`, 'grid.toolbar-config={}'])
1573
+ }
1574
+ if (proxyOpts.props) {
1575
+ warnLog('vxe.error.delProp', ['proxy-config.props', 'proxy-config.response'])
1576
+ }
1577
+
1578
+ $xeGrid.$nextTick(() => {
1579
+ if (props.formConfig) {
1580
+ if (!VxeUIFormComponent) {
1581
+ errLog('vxe.error.reqComp', ['vxe-form'])
1582
+ }
1583
+ }
1584
+ if (props.pagerConfig) {
1585
+ if (!VxeUIPagerComponent) {
1586
+ errLog('vxe.error.reqComp', ['vxe-pager'])
1587
+ }
1588
+ }
1589
+ })
1590
+
1591
+ $xeGrid.initPages()
1592
+ globalEvents.on($xeGrid, 'keydown', $xeGrid.handleGlobalKeydownEvent)
1593
+ },
1594
+ mounted () {
1595
+ const $xeGrid = this
1596
+ const props = $xeGrid
1597
+
1598
+ const { columns } = props
1599
+ if (columns && columns.length) {
1600
+ $xeGrid.loadColumn(columns)
1601
+ }
1602
+ $xeGrid.initToolbar()
1603
+ $xeGrid.initProxy()
1604
+ },
1605
+ destroyed () {
1606
+ const $xeGrid = this
1607
+
1608
+ globalEvents.off($xeGrid, 'keydown')
1609
+ },
1610
+ render (this: any, h) {
1611
+ return this.renderVN(h)
1612
+ }
1613
+ }) /* define-vxe-component end */