vxe-table 4.18.5 → 4.18.7

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