vxe-table 4.23.18 → 4.23.20

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 (135) hide show
  1. package/dist/all.esm.js +301 -274
  2. package/dist/all.esm.min.js +3 -3
  3. package/dist/style.css +4 -1
  4. package/dist/style.mini.css +1 -1
  5. package/es/components.d.ts +1 -3
  6. package/es/components.js +1 -2
  7. package/es/esm.index.d.ts +7 -0
  8. package/es/esm.index.js +8 -0
  9. package/es/style.css +4 -1
  10. package/es/style.mini.css +1 -1
  11. package/es/table/module/edit/hook.js +2 -4
  12. package/es/table/module/export/export-panel.js +5 -5
  13. package/es/table/module/export/hook.js +8 -10
  14. package/es/table/module/export/import-panel.js +5 -5
  15. package/es/table/src/table.js +0 -1
  16. package/es/table/style.css +4 -1
  17. package/es/table/style.mini.css +1 -1
  18. package/es/ui/abandon.d.ts +82 -0
  19. package/es/ui/abandon.js +90 -0
  20. package/es/ui/index.d.ts +1 -82
  21. package/es/ui/index.js +2 -88
  22. package/es/ui/src/log.js +1 -1
  23. package/es/vxe-table/style.css +4 -1
  24. package/es/vxe-table/style.mini.css +1 -1
  25. package/lib/components.d.ts +1 -3
  26. package/lib/components.js +1 -2
  27. package/lib/esm.index.d.ts +7 -0
  28. package/lib/esm.index.js +39 -0
  29. package/lib/index.umd.js +266 -270
  30. package/lib/index.umd.min.js +3 -3
  31. package/lib/style.css +4 -1
  32. package/lib/style.mini.css +1 -1
  33. package/lib/table/module/edit/hook.js +2 -4
  34. package/lib/table/module/export/export-panel.js +5 -5
  35. package/lib/table/module/export/hook.js +8 -10
  36. package/lib/table/module/export/import-panel.js +5 -5
  37. package/lib/table/src/table.js +0 -1
  38. package/lib/table/style/style.css +4 -1
  39. package/lib/table/style/style.mini.css +1 -1
  40. package/lib/ui/abandon.d.ts +82 -0
  41. package/lib/ui/abandon.js +110 -0
  42. package/lib/ui/index.d.ts +1 -82
  43. package/lib/ui/index.js +3 -88
  44. package/lib/ui/src/log.js +1 -1
  45. package/lib/vxe-table/style/style.css +4 -1
  46. package/lib/vxe-table/style/style.mini.css +1 -1
  47. package/package.json +2 -2
  48. package/packages/colgroup/index.ts +22 -22
  49. package/packages/column/index.ts +22 -22
  50. package/packages/components.ts +42 -45
  51. package/packages/esm.index.ts +10 -0
  52. package/packages/grid/index.ts +18 -18
  53. package/packages/grid/src/emits.ts +5 -5
  54. package/packages/grid/src/grid.ts +2220 -2220
  55. package/packages/grid/src/props.ts +22 -22
  56. package/packages/index.ts +13 -13
  57. package/packages/locale/lang/ar-EG.ts +914 -914
  58. package/packages/locale/lang/de-DE.ts +914 -914
  59. package/packages/locale/lang/en-US.ts +914 -914
  60. package/packages/locale/lang/es-ES.ts +914 -914
  61. package/packages/locale/lang/fr-FR.ts +914 -914
  62. package/packages/locale/lang/hu-HU.ts +914 -914
  63. package/packages/locale/lang/hy-AM.ts +914 -914
  64. package/packages/locale/lang/id-ID.ts +914 -914
  65. package/packages/locale/lang/it-IT.ts +914 -914
  66. package/packages/locale/lang/ja-JP.ts +914 -914
  67. package/packages/locale/lang/ko-KR.ts +914 -914
  68. package/packages/locale/lang/ms-MY.ts +914 -914
  69. package/packages/locale/lang/nb-NO.ts +914 -914
  70. package/packages/locale/lang/pt-BR.ts +914 -914
  71. package/packages/locale/lang/ru-RU.ts +914 -914
  72. package/packages/locale/lang/th-TH.ts +914 -914
  73. package/packages/locale/lang/ug-CN.ts +914 -914
  74. package/packages/locale/lang/uk-UA.ts +914 -914
  75. package/packages/locale/lang/uz-UZ.ts +914 -914
  76. package/packages/locale/lang/vi-VN.ts +914 -914
  77. package/packages/locale/lang/zh-CHT.ts +914 -914
  78. package/packages/locale/lang/zh-CN.ts +914 -914
  79. package/packages/locale/lang/zh-HK.ts +914 -914
  80. package/packages/locale/lang/zh-MO.ts +914 -914
  81. package/packages/locale/lang/zh-TC.ts +914 -914
  82. package/packages/locale/lang/zh-TW.ts +914 -914
  83. package/packages/table/index.ts +26 -26
  84. package/packages/table/module/custom/hook.ts +510 -510
  85. package/packages/table/module/custom/panel.ts +2002 -2002
  86. package/packages/table/module/edit/hook.ts +1232 -1235
  87. package/packages/table/module/export/export-panel.ts +697 -697
  88. package/packages/table/module/export/hook.ts +2158 -2160
  89. package/packages/table/module/export/import-panel.ts +319 -319
  90. package/packages/table/module/export/util.ts +25 -25
  91. package/packages/table/module/filter/hook.ts +505 -505
  92. package/packages/table/module/filter/panel.ts +368 -368
  93. package/packages/table/module/keyboard/hook.ts +498 -498
  94. package/packages/table/module/menu/hook.ts +330 -330
  95. package/packages/table/module/menu/panel.ts +272 -272
  96. package/packages/table/module/validator/hook.ts +653 -653
  97. package/packages/table/render/index.ts +1819 -1819
  98. package/packages/table/src/body.ts +1078 -1078
  99. package/packages/table/src/cell.ts +1524 -1524
  100. package/packages/table/src/column.ts +192 -192
  101. package/packages/table/src/columnInfo.ts +232 -232
  102. package/packages/table/src/emits.ts +134 -134
  103. package/packages/table/src/footer.ts +425 -425
  104. package/packages/table/src/group.ts +67 -67
  105. package/packages/table/src/header.ts +661 -661
  106. package/packages/table/src/props.ts +336 -336
  107. package/packages/table/src/store.ts +14 -14
  108. package/packages/table/src/table.ts +0 -1
  109. package/packages/table/src/use/cell-view.ts +41 -41
  110. package/packages/table/src/use/index.ts +1 -1
  111. package/packages/table/src/util.ts +1206 -1206
  112. package/packages/toolbar/index.ts +18 -18
  113. package/packages/toolbar/src/toolbar.ts +768 -768
  114. package/packages/ui/abandon.ts +136 -0
  115. package/packages/ui/index.ts +404 -520
  116. package/packages/ui/src/anime.ts +51 -51
  117. package/packages/ui/src/comp.ts +3 -3
  118. package/packages/ui/src/dom.ts +466 -466
  119. package/packages/ui/src/log.ts +19 -19
  120. package/packages/ui/src/utils.ts +66 -66
  121. package/packages/ui/src/vn.ts +55 -55
  122. package/packages/v-x-e-table/index.d.ts +3 -3
  123. package/packages/v-x-e-table/index.ts +3 -3
  124. package/styles/components/table.scss +2 -1
  125. package/types/all.d.ts +76 -76
  126. package/types/index.d.ts +4 -4
  127. /package/dist/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  128. /package/dist/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  129. /package/dist/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
  130. /package/es/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  131. /package/es/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  132. /package/es/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
  133. /package/lib/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  134. /package/lib/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  135. /package/lib/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
@@ -1,1235 +1,1232 @@
1
- import { reactive, nextTick } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import { VxeUI } from '@vxe-ui/core'
4
- import { hasEnableConf, isEnableConf } from '../../../ui/src/utils'
5
- import { getCellValue, setCellValue, getRowid } from '../../src/util'
6
- import { removeClass, addClass } from '../../../ui/src/dom'
7
- import { createComponentLog } from '../../../ui/src/log'
8
-
9
- import type { VxeTableConstructor, TableEditMethods, TableEditPrivateMethods, VxeTableDefines, VxeGlobalRendererHandles } from '../../../../types'
10
-
11
- const { warnLog, errLog } = createComponentLog('table')
12
-
13
- const { getConfig, renderer, hooks, getI18n } = VxeUI
14
-
15
- const tableEditMethodKeys: (keyof TableEditMethods)[] = [
16
- 'insert',
17
- 'insertAt',
18
- 'insertNextAt',
19
- 'insertChild',
20
- 'insertChildAt',
21
- 'insertChildNextAt',
22
- 'remove',
23
- 'removeCheckboxRow',
24
- 'removeRadioRow',
25
- 'removeCurrentRow',
26
- 'getRecordset',
27
- 'getInsertRecords',
28
- 'getRemoveRecords',
29
- 'getUpdateRecords',
30
- 'getEditRecord',
31
- 'getActiveRecord',
32
- 'getEditCell',
33
- 'getSelectedCell',
34
- 'clearEdit',
35
- 'clearActived',
36
- 'clearSelected',
37
- 'isEditByRow',
38
- 'isActiveByRow',
39
- 'setEditRow',
40
- 'setActiveRow',
41
- 'setEditCell',
42
- 'setActiveCell',
43
- 'setSelectCell'
44
- ]
45
-
46
- hooks.add('tableEditModule', {
47
- setupTable($xeTable) {
48
- const { props, reactData, internalData } = $xeTable
49
- const { refElem } = $xeTable.getRefMaps()
50
- const { computeMouseOpts, computeEditOpts, computeCheckboxOpts, computeTreeOpts, computeValidOpts, computeRendererOpts } = $xeTable.getComputeMaps()
51
-
52
- const browseObj = XEUtils.browse()
53
-
54
- let editMethods = {} as TableEditMethods
55
- let editPrivateMethods = {} as TableEditPrivateMethods
56
-
57
- const getEditColumnModel = (row: any, column: VxeTableDefines.ColumnInfo) => {
58
- const { model, editRender } = column
59
- if (editRender) {
60
- model.value = getCellValue(row, column)
61
- model.update = false
62
- }
63
- }
64
-
65
- const setEditColumnModel = (row: any, column: VxeTableDefines.ColumnInfo) => {
66
- const { model, editRender } = column
67
- if (editRender && model.update) {
68
- setCellValue(row, column, model.value)
69
- model.update = false
70
- model.value = null
71
- }
72
- }
73
-
74
- const removeCellSelectedClass = () => {
75
- const el = refElem.value
76
- if (el) {
77
- const cell = el.querySelector('.col--selected')
78
- if (cell) {
79
- removeClass(cell, 'col--selected')
80
- }
81
- }
82
- }
83
-
84
- const syncActivedCell = () => {
85
- const { editStore, tableColumn } = reactData
86
- const editOpts = computeEditOpts.value
87
- const { actived } = editStore
88
- const { row, column } = actived
89
- if (row && column) {
90
- if (editOpts.mode === 'row') {
91
- tableColumn.forEach((column) => setEditColumnModel(row, column))
92
- } else {
93
- setEditColumnModel(row, column)
94
- }
95
- }
96
- }
97
-
98
- const insertTreeRow = (newRecords: any[], isAppend: boolean) => {
99
- const { tableFullTreeData, afterFullData, fullDataRowIdData, fullAllDataRowIdData } = internalData
100
- const treeOpts = computeTreeOpts.value
101
- const { rowField, parentField, mapChildrenField } = treeOpts
102
- const childrenField = treeOpts.children || treeOpts.childrenField
103
- const funcName = isAppend ? 'push' : 'unshift'
104
- newRecords.forEach((item) => {
105
- const parentRowId = item[parentField]
106
- const rowid = getRowid($xeTable, item)
107
- const matchObj = parentRowId ? XEUtils.findTree(tableFullTreeData, (item) => parentRowId === item[rowField], { children: mapChildrenField }) : null
108
- if (matchObj) {
109
- const { item: parentRow } = matchObj
110
- const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
111
- const parentLevel = parentRest ? parentRest.level : 0
112
- let pChilds = parentRow[childrenField]
113
- let pMapChilds = parentRow[mapChildrenField]
114
- if (!XEUtils.isArray(pChilds)) {
115
- pChilds = parentRow[childrenField] = []
116
- }
117
- if (!XEUtils.isArray(pMapChilds)) {
118
- pMapChilds = parentRow[mapChildrenField] = []
119
- }
120
- pChilds[funcName](item)
121
- pMapChilds[funcName](item)
122
- const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: pChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
123
- fullDataRowIdData[rowid] = rest
124
- fullAllDataRowIdData[rowid] = rest
125
- } else {
126
- if (parentRowId) {
127
- warnLog('vxe.error.unableInsert')
128
- }
129
- afterFullData[funcName](item)
130
- tableFullTreeData[funcName](item)
131
- const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: tableFullTreeData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
132
- fullDataRowIdData[rowid] = rest
133
- fullAllDataRowIdData[rowid] = rest
134
- }
135
- })
136
- }
137
-
138
- // const insertGroupRow = (newRecords: any[], isAppend: boolean) => {
139
-
140
- // }
141
-
142
- const handleInsertRowAt = (records: any, targetRowOrRowid: any, isInsertNextRow?: boolean) => {
143
- const { treeConfig } = props
144
- const { isRowGroupStatus } = reactData
145
- const { tableFullTreeData, afterFullData, mergeBodyList, tableFullData, fullDataRowIdData, fullAllDataRowIdData, insertRowMaps, removeRowMaps } = internalData
146
- const treeOpts = computeTreeOpts.value
147
- const { transform, parentField, rowField, mapChildrenField } = treeOpts
148
- const childrenField = treeOpts.children || treeOpts.childrenField
149
- if (!XEUtils.isArray(records)) {
150
- records = [records]
151
- }
152
- let targetRow = targetRowOrRowid
153
- if (XEUtils.isString(targetRowOrRowid) || XEUtils.isNumber(targetRowOrRowid)) {
154
- const rowRest = fullAllDataRowIdData[targetRowOrRowid]
155
- if (rowRest) {
156
- targetRow = rowRest.row
157
- }
158
- }
159
- if (!records.length) {
160
- return Promise.resolve({ row: null, rows: [] })
161
- }
162
- $xeTable.handlePushStack()
163
- const newRecords: any[] = reactive($xeTable.defineField(records.map((record: any) => Object.assign(treeConfig && transform ? { [mapChildrenField]: [], [childrenField]: [] } : {}, record))))
164
- let treeRecords: any[] = []
165
- if (treeConfig && transform) {
166
- treeRecords = XEUtils.toArrayTree(newRecords, { key: rowField, parentKey: parentField, children: childrenField })
167
- }
168
- if (XEUtils.eqNull(targetRow)) {
169
- // 如果为虚拟树
170
- if (treeConfig && transform) {
171
- insertTreeRow(newRecords, false)
172
- } else if (isRowGroupStatus) {
173
- // 如果分组
174
- if (treeConfig) {
175
- throw new Error(getI18n('vxe.error.noTree', ['insert']))
176
- }
177
- errLog(getI18n('vxe.error.noGroup', ['insert']))
178
- // insertGroupRow(newRecords, false)
179
- } else {
180
- newRecords.forEach((item) => {
181
- const rowid = getRowid($xeTable, item)
182
- const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
183
- fullDataRowIdData[rowid] = rest
184
- fullAllDataRowIdData[rowid] = rest
185
- afterFullData.unshift(item)
186
- tableFullData.unshift(item)
187
- })
188
- // 刷新单元格合并
189
- mergeBodyList.forEach((mergeItem: any) => {
190
- const { row: mergeRowIndex } = mergeItem
191
- if (mergeRowIndex >= 0) {
192
- mergeItem.row = mergeRowIndex + newRecords.length
193
- }
194
- })
195
- }
196
- } else {
197
- if (targetRow === -1) {
198
- // 如果为虚拟树
199
- if (treeConfig && transform) {
200
- insertTreeRow(newRecords, true)
201
- } else if (isRowGroupStatus) {
202
- // 如果分组
203
- if (treeConfig) {
204
- throw new Error(getI18n('vxe.error.noTree', ['insert']))
205
- }
206
- errLog(getI18n('vxe.error.noGroup', ['insert']))
207
- // insertGroupRow(newRecords, true)
208
- } else {
209
- newRecords.forEach((item) => {
210
- const rowid = getRowid($xeTable, item)
211
- const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, treeIndex: -1, _tIndex: -1, $index: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
212
- fullDataRowIdData[rowid] = rest
213
- fullAllDataRowIdData[rowid] = rest
214
- afterFullData.push(item)
215
- tableFullData.push(item)
216
- })
217
- }
218
- } else {
219
- // 如果为虚拟树
220
- if (treeConfig && transform) {
221
- const matchMapObj = XEUtils.findTree(tableFullTreeData, (item) => targetRow[rowField] === item[rowField], { children: mapChildrenField })
222
- if (matchMapObj) {
223
- const { parent: parentRow } = matchMapObj
224
- const parentMapChilds = parentRow ? parentRow[mapChildrenField] : tableFullTreeData
225
- const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
226
- const parentLevel = parentRest ? parentRest.level : 0
227
- treeRecords.forEach((row, i) => {
228
- if (parentRow) {
229
- if (row[parentField] !== parentRow[rowField]) {
230
- errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, `${parentField}=${parentRow[rowField]}`])
231
- row[parentField] = parentRow[rowField]
232
- }
233
- } else {
234
- if (row[parentField] !== null) {
235
- if (!XEUtils.eqNull(row[parentField])) {
236
- errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, 'null'])
237
- }
238
- row[parentField] = null
239
- }
240
- }
241
- let targetIndex = matchMapObj.index + i
242
- if (isInsertNextRow) {
243
- targetIndex = targetIndex + 1
244
- }
245
- parentMapChilds.splice(targetIndex, 0, row)
246
- })
247
- XEUtils.eachTree(
248
- treeRecords,
249
- (item) => {
250
- const rowid = getRowid($xeTable, item)
251
- const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: parentMapChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
252
- if (item[childrenField]) {
253
- item[mapChildrenField] = item[childrenField]
254
- }
255
- fullDataRowIdData[rowid] = rest
256
- fullAllDataRowIdData[rowid] = rest
257
- },
258
- { children: childrenField }
259
- )
260
- // 源
261
- if (parentRow) {
262
- const matchObj = XEUtils.findTree(tableFullTreeData, (item) => targetRow[rowField] === item[rowField], { children: childrenField })
263
- if (matchObj) {
264
- const parentChilds = matchObj.items
265
- let targetIndex = matchObj.index
266
- if (isInsertNextRow) {
267
- targetIndex = targetIndex + 1
268
- }
269
- parentChilds.splice(targetIndex, 0, ...treeRecords)
270
- }
271
- }
272
- } else {
273
- warnLog('vxe.error.unableInsert')
274
- insertTreeRow(newRecords, true)
275
- }
276
- } else if (isRowGroupStatus) {
277
- // 如果分组
278
- if (treeConfig) {
279
- throw new Error(getI18n('vxe.error.noTree', ['insert']))
280
- }
281
- errLog(getI18n('vxe.error.noGroup', ['insert']))
282
- } else {
283
- if (treeConfig) {
284
- throw new Error(getI18n('vxe.error.noTree', ['insert']))
285
- }
286
- let afIndex = -1
287
- // 如果是可视索引
288
- if (XEUtils.isNumber(targetRow)) {
289
- if (targetRow < afterFullData.length) {
290
- afIndex = targetRow
291
- }
292
- } else {
293
- afIndex = $xeTable.findRowIndexOf(afterFullData, targetRow)
294
- }
295
- // 如果是插入指定行的下一行
296
- if (isInsertNextRow) {
297
- afIndex = Math.min(afterFullData.length, afIndex + 1)
298
- }
299
- if (afIndex === -1) {
300
- throw new Error(getI18n('vxe.error.unableInsert'))
301
- }
302
- afterFullData.splice(afIndex, 0, ...newRecords)
303
- const tfIndex = $xeTable.findRowIndexOf(tableFullData, targetRow)
304
- if (tfIndex > -1) {
305
- tableFullData.splice(tfIndex + (isInsertNextRow ? 1 : 0), 0, ...newRecords)
306
- } else {
307
- tableFullData.push(...newRecords)
308
- }
309
- // 刷新单元格合并
310
- mergeBodyList.forEach((mergeItem: any) => {
311
- const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
312
- if (mergeRowIndex >= afIndex) {
313
- mergeItem.row = mergeRowIndex + newRecords.length
314
- } else if (isInsertNextRow ? mergeRowIndex + mergeRowspan >= afIndex : mergeRowIndex + mergeRowspan > afIndex) {
315
- mergeItem.rowspan = mergeRowspan + newRecords.length
316
- }
317
- })
318
- }
319
- }
320
- }
321
-
322
- const handleStatus = (newRow: any) => {
323
- const rowid = getRowid($xeTable, newRow)
324
- // 如果是被删除的数据,则还原状态
325
- if (removeRowMaps[rowid]) {
326
- delete removeRowMaps[rowid]
327
- if (insertRowMaps[rowid]) {
328
- delete insertRowMaps[rowid]
329
- }
330
- } else {
331
- insertRowMaps[rowid] = newRow
332
- }
333
- }
334
- // 如果为虚拟树
335
- if (treeConfig && transform) {
336
- XEUtils.eachTree(treeRecords, handleStatus, { children: mapChildrenField })
337
- } else {
338
- newRecords.forEach(handleStatus)
339
- }
340
-
341
- reactData.removeRowFlag++
342
- reactData.insertRowFlag++
343
- $xeTable.cacheRowMap(false, false)
344
- $xeTable.updateScrollYStatus()
345
- $xeTable.handleTableData(treeConfig && transform)
346
- if (!(treeConfig && transform)) {
347
- $xeTable.updateAfterDataIndex()
348
- }
349
- $xeTable.updateFooter()
350
- $xeTable.handleUpdateBodyMerge()
351
- $xeTable.checkSelectionStatus()
352
- if (reactData.scrollYLoad) {
353
- $xeTable.updateScrollYSpace()
354
- }
355
- return nextTick()
356
- .then(() => {
357
- $xeTable.updateCellAreas()
358
- return $xeTable.recalculate(true)
359
- })
360
- .then(() => {
361
- return {
362
- row: newRecords.length ? newRecords[newRecords.length - 1] : null,
363
- rows: newRecords
364
- }
365
- })
366
- }
367
-
368
- const handleInsertChildRowAt = (records: any, parentRowOrParentId: any, targetRow: any, isInsertNextRow?: boolean) => {
369
- const { treeConfig } = props
370
- const { fullAllDataRowIdData } = internalData
371
- const treeOpts = computeTreeOpts.value
372
- const { transform, rowField, parentField } = treeOpts
373
- if (treeConfig && transform) {
374
- if (!XEUtils.isArray(records)) {
375
- records = [records]
376
- }
377
- let parentRow = parentRowOrParentId
378
- if (XEUtils.isString(parentRowOrParentId) || XEUtils.isNumber(parentRowOrParentId)) {
379
- const rowRest = fullAllDataRowIdData[parentRowOrParentId]
380
- if (rowRest) {
381
- parentRow = rowRest.row
382
- }
383
- }
384
- return handleInsertRowAt(
385
- records.map((item: any) => Object.assign({}, item, { [parentField]: parentRow[rowField] })),
386
- targetRow,
387
- isInsertNextRow
388
- )
389
- } else {
390
- errLog('vxe.error.errProp', ['tree-config.transform=false', 'tree-config.transform=true'])
391
- }
392
- return Promise.resolve({ row: null, rows: [] })
393
- }
394
-
395
- const handleClearEdit = (evnt: Event | null, targetRow?: any) => {
396
- const { editStore } = reactData
397
- const { actived, focused } = editStore
398
- const { row, column } = actived
399
- const validOpts = computeValidOpts.value
400
- if (row || column) {
401
- if (targetRow && getRowid($xeTable, targetRow) !== getRowid($xeTable, row)) {
402
- return nextTick()
403
- }
404
- syncActivedCell()
405
- $xeTable.updateFooter()
406
- actived.args = null
407
- actived.row = null
408
- actived.column = null
409
- $xeTable.dispatchEvent(
410
- 'edit-closed',
411
- {
412
- row,
413
- rowIndex: $xeTable.getRowIndex(row),
414
- $rowIndex: $xeTable.getVMRowIndex(row),
415
- column,
416
- columnIndex: $xeTable.getColumnIndex(column),
417
- $columnIndex: $xeTable.getVMColumnIndex(column)
418
- },
419
- evnt || null
420
- )
421
- }
422
- focused.row = null
423
- focused.column = null
424
- if (validOpts.autoClear) {
425
- if (validOpts.msgMode !== 'full' || getConfig().cellVaildMode === 'obsolete') {
426
- if ($xeTable.clearValidate) {
427
- return $xeTable.clearValidate()
428
- }
429
- }
430
- }
431
- return nextTick().then(() => $xeTable.updateCellAreas())
432
- }
433
-
434
- const handleEditActive = (
435
- params: {
436
- $table: VxeTableConstructor
437
- column: VxeTableDefines.ColumnInfo
438
- columnIndex: number
439
- _columnIndex: number
440
- $columnIndex: number
441
- rowIndex: number
442
- $rowIndex: number
443
- _rowIndex: number
444
- row: any
445
- cell?: HTMLElement
446
- },
447
- evnt: Event | null,
448
- options: {
449
- isClear?: boolean
450
- isFocus?: boolean
451
- isPos?: boolean
452
- }
453
- ) => {
454
- const $xeGrid = $xeTable.xeGrid
455
- const $xeGantt = $xeTable.xeGantt
456
-
457
- const { editConfig, mouseConfig } = props
458
- const { editStore, tableColumn } = reactData
459
- const editOpts = computeEditOpts.value
460
- const mouseOpts = computeMouseOpts.value
461
- const { mode } = editOpts
462
- const { actived, focused } = editStore
463
- const { row, column } = params
464
- const { editRender } = column
465
- const { isFocus, isPos, isClear } = options
466
- const cell = (params.cell || $xeTable.getCellElement(row, column)) as HTMLElement
467
- const beforeEditFn = editOpts.beforeEditMethod || editOpts.activeMethod
468
- const beforeEditAsyncFn = editOpts.beforeEditAsyncMethod
469
- const editParams = { ...params, cell }
470
-
471
- if (!cell || !isEnableConf(editConfig) || !isEnableConf(editRender)) {
472
- return nextTick()
473
- }
474
- if ($xeTable.isPendingByRow(row) || $xeTable.isAggregateRecord(row)) {
475
- return nextTick()
476
- }
477
-
478
- // 激活编辑
479
- if (actived.row !== row || (mode === 'cell' ? actived.column !== column : false)) {
480
- const evntParams = {
481
- row,
482
- rowIndex: $xeTable.getRowIndex(row),
483
- $rowIndex: $xeTable.getVMRowIndex(row),
484
- column,
485
- columnIndex: $xeTable.getColumnIndex(column),
486
- $columnIndex: $xeTable.getVMColumnIndex(column)
487
- }
488
-
489
- const handleCellEdit = (status: boolean) => {
490
- if (status) {
491
- if (hasEnableConf(mouseConfig, mouseOpts)) {
492
- $xeTable.clearSelected()
493
- if ($xeTable.clearCellAreas) {
494
- $xeTable.clearCellAreas()
495
- $xeTable.clearCopyCellArea()
496
- }
497
- }
498
- $xeTable.closeTooltip()
499
- if (actived.column) {
500
- handleClearEdit(evnt)
501
- }
502
- column.renderHeight = cell.offsetHeight
503
- actived.args = editParams
504
- actived.row = row
505
- actived.column = column
506
- $xeTable.handlePushStack()
507
- if (isClear) {
508
- setCellValue(row, column, null)
509
- }
510
- if (mode === 'row') {
511
- tableColumn.forEach((column) => getEditColumnModel(row, column))
512
- } else {
513
- getEditColumnModel(row, column)
514
- }
515
- const afterEditMethod = editOpts.afterEditMethod
516
- nextTick(() => {
517
- if (isFocus) {
518
- $xeTable.handleFocus(editParams, evnt)
519
- }
520
- if (afterEditMethod) {
521
- afterEditMethod({ ...editParams, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
522
- }
523
- })
524
-
525
- $xeTable.dispatchEvent('edit-activated', evntParams, evnt)
526
- // v4已废弃
527
- $xeTable.dispatchEvent('edit-actived', evntParams, evnt)
528
- } else {
529
- $xeTable.dispatchEvent('edit-disabled', evntParams, evnt)
530
- }
531
- focused.column = null
532
- focused.row = null
533
- $xeTable.focus()
534
- }
535
-
536
- const eFnParams = { ...editParams, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt }
537
-
538
- // 是否被禁用
539
- if (beforeEditFn) {
540
- handleCellEdit(!!beforeEditFn(eFnParams))
541
- } else if (beforeEditAsyncFn) {
542
- return Promise.resolve()
543
- .then(() => beforeEditAsyncFn(eFnParams))
544
- .catch(() => false)
545
- .then((status) => {
546
- handleCellEdit(!!status)
547
- })
548
- } else {
549
- handleCellEdit(true)
550
- }
551
- return nextTick()
552
- }
553
-
554
- const { column: oldColumn } = actived
555
- if (hasEnableConf(mouseConfig, mouseOpts)) {
556
- $xeTable.clearSelected()
557
- if ($xeTable.clearCellAreas) {
558
- $xeTable.clearCellAreas()
559
- $xeTable.clearCopyCellArea()
560
- }
561
- }
562
- if (oldColumn && oldColumn !== column) {
563
- const { model: oldModel } = oldColumn
564
- if (oldModel.update) {
565
- setCellValue(row, oldColumn, oldModel.value)
566
- }
567
- if ($xeTable.clearValidate) {
568
- $xeTable.clearValidate(row, column)
569
- }
570
- }
571
- column.renderHeight = cell.offsetHeight
572
- actived.args = editParams
573
- actived.column = column
574
- if (isPos) {
575
- setTimeout(() => {
576
- $xeTable.handleFocus(editParams, evnt)
577
- })
578
- }
579
- focused.column = null
580
- focused.row = null
581
- $xeTable.focus()
582
- return nextTick()
583
- }
584
-
585
- const handleEditCell = (
586
- row: any,
587
- fieldOrColumn: string | VxeTableDefines.ColumnInfo | null,
588
- options: {
589
- isClear?: boolean | undefined
590
- isFocus?: boolean | undefined
591
- isPos?: boolean | undefined
592
- }
593
- ) => {
594
- const { editConfig } = props
595
- const { isPos } = options
596
- const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
597
- if (row && column && isEnableConf(editConfig) && isEnableConf(column.editRender) && !$xeTable.isAggregateRecord(row)) {
598
- return Promise.resolve(isPos ? $xeTable.scrollToRow(row, column) : null).then(() => {
599
- const cell = $xeTable.getCellElement(row, column)
600
- if (cell) {
601
- handleEditActive(
602
- {
603
- row,
604
- rowIndex: $xeTable.getRowIndex(row),
605
- $rowIndex: $xeTable.getVMRowIndex(row),
606
- _rowIndex: $xeTable.getVTRowIndex(row),
607
- column,
608
- columnIndex: $xeTable.getColumnIndex(column),
609
- $columnIndex: $xeTable.getVMColumnIndex(column),
610
- _columnIndex: $xeTable.getVTColumnIndex(column),
611
- cell,
612
- $table: $xeTable
613
- },
614
- null,
615
- {
616
- isFocus: isPos,
617
- isPos
618
- }
619
- )
620
- internalData._lastCallTime = Date.now()
621
- }
622
- return nextTick()
623
- })
624
- }
625
- return nextTick()
626
- }
627
-
628
- editMethods = {
629
- /**
630
- * 往表格中插入临时数据
631
- *
632
- * @param {*} records
633
- */
634
- insert(records) {
635
- return handleInsertRowAt(records, null)
636
- },
637
- /**
638
- * 往表格指定行中插入临时数据
639
- * 如果 row 为空则从插入到顶部,如果为树结构,则插入到目标节点顶部
640
- * 如果 row 为 -1 则从插入到底部,如果为树结构,则插入到目标节点底部
641
- * 如果 row 为有效行则插入到该行的位置,如果为树结构,则有插入到效的目标节点该行的位置
642
- */
643
- insertAt(records, targetRowOrRowid) {
644
- return handleInsertRowAt(records, targetRowOrRowid)
645
- },
646
- insertNextAt(records, targetRowOrRowid) {
647
- return handleInsertRowAt(records, targetRowOrRowid, true)
648
- },
649
- insertChild(records, parentRowOrParentId) {
650
- return handleInsertChildRowAt(records, parentRowOrParentId, null)
651
- },
652
- insertChildAt(records, parentRowOrParentId, targetRow) {
653
- return handleInsertChildRowAt(records, parentRowOrParentId, targetRow)
654
- },
655
- insertChildNextAt(records, parentRowOrParentId, targetRow) {
656
- return handleInsertChildRowAt(records, parentRowOrParentId, targetRow, true)
657
- },
658
- /**
659
- * 删除指定行数据
660
- * 如果传 row 则删除一行
661
- * 如果传 rows 则删除多行
662
- * 如果为空则删除所有
663
- */
664
- remove(rows: any) {
665
- const { treeConfig } = props
666
- const { editStore, isRowGroupStatus } = reactData
667
- const { tableFullTreeData, selectCheckboxMaps, afterFullData, mergeBodyList, tableFullData, pendingRowMaps, insertRowMaps, removeRowMaps } = internalData
668
- const checkboxOpts = computeCheckboxOpts.value
669
- const treeOpts = computeTreeOpts.value
670
- const { transform, mapChildrenField } = treeOpts
671
- const childrenField = treeOpts.children || treeOpts.childrenField
672
- const { actived } = editStore
673
- const { checkField } = checkboxOpts
674
- let delList: any[] = []
675
- if (!rows) {
676
- rows = tableFullData
677
- } else if (!XEUtils.isArray(rows)) {
678
- rows = [rows]
679
- }
680
- if (!rows.length) {
681
- return Promise.resolve({ row: null, rows: [] })
682
- }
683
- $xeTable.handlePushStack()
684
- // 如果是新增,则保存记录
685
- rows.forEach((row: any) => {
686
- if (!$xeTable.isInsertByRow(row)) {
687
- const rowid = getRowid($xeTable, row)
688
- removeRowMaps[rowid] = row
689
- }
690
- })
691
- // 如果绑定了多选属性,则更新状态
692
- if (!checkField) {
693
- rows.forEach((row: any) => {
694
- const rowid = getRowid($xeTable, row)
695
- if (selectCheckboxMaps[rowid]) {
696
- delete selectCheckboxMaps[rowid]
697
- }
698
- })
699
- reactData.updateCheckboxFlag++
700
- }
701
- // 从数据源中移除
702
- if (tableFullData === rows) {
703
- rows = delList = tableFullData.slice(0)
704
- internalData.tableFullData = []
705
- internalData.afterFullData = []
706
- $xeTable.clearMergeCells()
707
- } else {
708
- // 如果为虚拟树
709
- if (treeConfig && transform) {
710
- rows.forEach((row: any) => {
711
- const rowid = getRowid($xeTable, row)
712
- const matchMapObj = XEUtils.findTree(tableFullTreeData, (item) => rowid === getRowid($xeTable, item), { children: mapChildrenField })
713
- if (matchMapObj) {
714
- const rItems = matchMapObj.items.splice(matchMapObj.index, 1)
715
- delList.push(rItems[0])
716
- }
717
- const matchObj = XEUtils.findTree(tableFullTreeData, (item) => rowid === getRowid($xeTable, item), { children: childrenField })
718
- if (matchObj) {
719
- matchObj.items.splice(matchObj.index, 1)
720
- }
721
- const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
722
- if (afIndex > -1) {
723
- afterFullData.splice(afIndex, 1)
724
- }
725
- })
726
- } else if (isRowGroupStatus) {
727
- // 如果分组
728
- warnLog(getI18n('vxe.error.noGroup', ['remove']))
729
- } else {
730
- rows.forEach((row: any) => {
731
- const tfIndex = $xeTable.findRowIndexOf(tableFullData, row)
732
- if (tfIndex > -1) {
733
- const rItems = tableFullData.splice(tfIndex, 1)
734
- delList.push(rItems[0])
735
- }
736
- const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
737
- if (afIndex > -1) {
738
- // 刷新单元格合并
739
- mergeBodyList.forEach((mergeItem) => {
740
- const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
741
- if (mergeRowIndex > afIndex) {
742
- mergeItem.row = mergeRowIndex - 1
743
- } else if (mergeRowIndex + mergeRowspan > afIndex) {
744
- mergeItem.rowspan = mergeRowspan - 1
745
- }
746
- })
747
- afterFullData.splice(afIndex, 1)
748
- }
749
- })
750
- }
751
- }
752
- // 如果当前行被激活编辑,则清除激活状态
753
- if (actived.row && $xeTable.findRowIndexOf(rows, actived.row) > -1) {
754
- editMethods.clearEdit()
755
- }
756
- // 从新增中移除已删除的数据
757
- rows.forEach((row: any) => {
758
- const rowid = getRowid($xeTable, row)
759
- if (insertRowMaps[rowid]) {
760
- delete insertRowMaps[rowid]
761
- }
762
- if (pendingRowMaps[rowid]) {
763
- delete pendingRowMaps[rowid]
764
- }
765
- })
766
- reactData.removeRowFlag++
767
- reactData.insertRowFlag++
768
- reactData.pendingRowFlag++
769
- $xeTable.cacheRowMap(false, false)
770
- $xeTable.handleTableData(treeConfig && transform)
771
- $xeTable.updateFooter()
772
- $xeTable.handleUpdateBodyMerge()
773
- if (!(treeConfig && transform)) {
774
- $xeTable.updateAfterDataIndex()
775
- }
776
- $xeTable.checkSelectionStatus()
777
- if (reactData.scrollYLoad) {
778
- $xeTable.updateScrollYSpace()
779
- }
780
- return nextTick()
781
- .then(() => {
782
- $xeTable.updateCellAreas()
783
- return $xeTable.recalculate(true)
784
- })
785
- .then(() => {
786
- return { row: delList.length ? delList[delList.length - 1] : null, rows: delList }
787
- })
788
- },
789
- /**
790
- * 删除复选框选中的数据
791
- */
792
- removeCheckboxRow() {
793
- return editMethods.remove($xeTable.getCheckboxRecords()).then((params: any) => {
794
- $xeTable.clearCheckboxRow()
795
- return params
796
- })
797
- },
798
- /**
799
- * 删除单选框选中的数据
800
- */
801
- removeRadioRow() {
802
- const radioRecord = $xeTable.getRadioRecord()
803
- return editMethods.remove(radioRecord || []).then((params: any) => {
804
- $xeTable.clearRadioRow()
805
- return params
806
- })
807
- },
808
- /**
809
- * 删除当前行选中的数据
810
- */
811
- removeCurrentRow() {
812
- const currentRecord = $xeTable.getCurrentRecord()
813
- return editMethods.remove(currentRecord || []).then((params: any) => {
814
- $xeTable.clearCurrentRow()
815
- return params
816
- })
817
- },
818
- /**
819
- * 获取表格数据集,包含新增、删除、修改、标记
820
- */
821
- getRecordset() {
822
- const removeRecords = editMethods.getRemoveRecords()
823
- const pendingRecords = $xeTable.getPendingRecords()
824
- const delRecords = removeRecords.concat(pendingRecords)
825
- // 如果已经被删除,则无需放到更新数组
826
- const updateRecords = editMethods.getUpdateRecords().filter((row) => {
827
- return !delRecords.some((item) => $xeTable.eqRow(item, row))
828
- })
829
- return {
830
- insertRecords: editMethods.getInsertRecords(),
831
- removeRecords,
832
- updateRecords,
833
- pendingRecords
834
- }
835
- },
836
- /**
837
- * 获取新增的临时数据
838
- */
839
- getInsertRecords() {
840
- const { fullAllDataRowIdData, insertRowMaps } = internalData
841
- const insertRecords: any[] = []
842
- XEUtils.each(insertRowMaps, (row, rowid) => {
843
- if (fullAllDataRowIdData[rowid]) {
844
- insertRecords.push(row)
845
- }
846
- })
847
- return insertRecords
848
- },
849
- /**
850
- * 获取已删除的数据
851
- */
852
- getRemoveRecords() {
853
- const { removeRowMaps } = internalData
854
- const removeRecords: any[] = []
855
- XEUtils.each(removeRowMaps, (row) => {
856
- removeRecords.push(row)
857
- })
858
- return removeRecords
859
- },
860
- /**
861
- * 获取更新数据
862
- * 只精准匹配 row 的更改
863
- * 如果是树表格,子节点更改状态不会影响父节点的更新状态
864
- */
865
- getUpdateRecords() {
866
- const { keepSource, treeConfig } = props
867
- const { tableFullData, tableFullTreeData } = internalData
868
- const treeOpts = computeTreeOpts.value
869
- const updateRecords: any[] = []
870
- if (keepSource) {
871
- syncActivedCell()
872
- if (treeConfig) {
873
- const childrenField = treeOpts.children || treeOpts.childrenField
874
- XEUtils.eachTree(
875
- tableFullTreeData,
876
- (row) => {
877
- if ($xeTable.isUpdateByRow(row)) {
878
- updateRecords.push(row)
879
- }
880
- },
881
- { children: childrenField }
882
- )
883
- } else {
884
- tableFullData.forEach((row) => {
885
- if ($xeTable.isUpdateByRow(row)) {
886
- updateRecords.push(row)
887
- }
888
- })
889
- }
890
- }
891
- return updateRecords
892
- },
893
- getActiveRecord() {
894
- warnLog('vxe.error.delFunc', ['getActiveRecord', 'getEditCell'])
895
- const { editStore } = reactData
896
- const { fullAllDataRowIdData } = internalData
897
- const { args, row } = editStore.actived
898
- if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
899
- return Object.assign({}, args, { row })
900
- }
901
- return null
902
- },
903
- getEditRecord() {
904
- warnLog('vxe.error.delFunc', ['getEditRecord', 'getEditCell'])
905
- const { editStore } = reactData
906
- const { fullAllDataRowIdData } = internalData
907
- const { args, row } = editStore.actived
908
- if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
909
- return Object.assign({}, args, { row })
910
- }
911
- return null
912
- },
913
- getEditCell() {
914
- const { editStore } = reactData
915
- const { row, column } = editStore.actived
916
- if (column && row) {
917
- return {
918
- row,
919
- rowIndex: $xeTable.getRowIndex(row),
920
- column,
921
- columnIndex: $xeTable.getColumnIndex(column)
922
- }
923
- }
924
- return null
925
- },
926
- /**
927
- * 获取选中的单元格
928
- */
929
- getSelectedCell() {
930
- const { editStore } = reactData
931
- const { row, column } = editStore.selected
932
- if (row && column) {
933
- return {
934
- row,
935
- column
936
- }
937
- }
938
- return null
939
- },
940
- clearActived(row) {
941
- // 即将废弃
942
- warnLog('vxe.error.delFunc', ['clearActived', 'clearEdit'])
943
- return $xeTable.clearEdit(row)
944
- },
945
- /**
946
- * 清除激活的编辑
947
- */
948
- clearEdit(row) {
949
- return handleClearEdit(null, row)
950
- },
951
- /**
952
- * 清除所选中源状态
953
- */
954
- clearSelected() {
955
- const { editStore } = reactData
956
- const { selected } = editStore
957
- selected.row = null
958
- selected.column = null
959
- removeCellSelectedClass()
960
- return nextTick()
961
- },
962
- isActiveByRow(row) {
963
- warnLog('vxe.error.delFunc', ['isActiveByRow', 'isEditByRow'])
964
- // 即将废弃
965
- return $xeTable.isEditByRow(row)
966
- },
967
- /**
968
- * 判断行是否为激活编辑状态
969
- * @param {Row} row 行对象
970
- */
971
- isEditByRow(row) {
972
- const { editStore } = reactData
973
- return editStore.actived.row === row
974
- },
975
- setActiveRow(row) {
976
- warnLog('vxe.error.delFunc', ['setActiveRow', 'setEditRow'])
977
- // 即将废弃
978
- return editMethods.setEditRow(row)
979
- },
980
- /**
981
- * 激活行编辑
982
- */
983
- setEditRow(row, fieldOrColumn, options) {
984
- const { visibleColumn } = internalData
985
- let column: any = XEUtils.find(visibleColumn, (column) => isEnableConf(column.editRender))
986
- let isPos = false
987
- if (fieldOrColumn) {
988
- isPos = true
989
- if (fieldOrColumn !== true) {
990
- column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
991
- }
992
- }
993
- return handleEditCell(
994
- row,
995
- column,
996
- Object.assign(
997
- {
998
- isPos,
999
- isFocus: isPos
1000
- },
1001
- options
1002
- )
1003
- )
1004
- },
1005
- setActiveCell(row, fieldOrColumn) {
1006
- warnLog('vxe.error.delFunc', ['setActiveCell', 'setEditCell'])
1007
- // 即将废弃
1008
- return editMethods.setEditCell(row, fieldOrColumn)
1009
- },
1010
- /**
1011
- * 激活单元格编辑
1012
- */
1013
- setEditCell(row, fieldOrColumn, options) {
1014
- return handleEditCell(
1015
- row,
1016
- fieldOrColumn,
1017
- Object.assign(
1018
- {
1019
- isFocus: true,
1020
- isPos: true
1021
- },
1022
- options
1023
- )
1024
- )
1025
- },
1026
- /**
1027
- * 只对 trigger=dblclick 有效,选中单元格
1028
- */
1029
- setSelectCell(row, fieldOrColumn) {
1030
- const { tableData } = reactData
1031
- const editOpts = computeEditOpts.value
1032
- const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
1033
- if (row && column && editOpts.trigger !== 'manual') {
1034
- const rowIndex = $xeTable.findRowIndexOf(tableData, row)
1035
- if (rowIndex > -1 && column) {
1036
- const cell = $xeTable.getCellElement(row, column)
1037
- const params = {
1038
- $table: $xeTable,
1039
- row,
1040
- rowIndex,
1041
- $rowIndex: $xeTable.getVMRowIndex(row),
1042
- _rowIndex: $xeTable.getVTRowIndex(row),
1043
- column,
1044
- columnIndex: $xeTable.getColumnIndex(column),
1045
- $columnIndex: $xeTable.getVMColumnIndex(column),
1046
- _columnIndex: $xeTable.getVTColumnIndex(column),
1047
- cell
1048
- }
1049
- $xeTable.handleSelected(params, null)
1050
- }
1051
- }
1052
- return nextTick()
1053
- }
1054
- }
1055
-
1056
- const handleCellFocus = (
1057
- cell: HTMLElement,
1058
- params: {
1059
- $table: VxeTableConstructor
1060
- column: VxeTableDefines.ColumnInfo
1061
- row: any
1062
- }
1063
- ) => {
1064
- const { editConfig } = props
1065
- const { column } = params
1066
- const { editRender } = column
1067
- const editOpts = computeEditOpts.value
1068
- if (editConfig && isEnableConf(editRender)) {
1069
- const rendererOpts = computeRendererOpts.value
1070
- const renderName = editRender.name
1071
- const compRender = renderName ? rendererOpts[renderName] || renderer.get(renderName) : null
1072
- let autoFocus: boolean | string | ((params: VxeGlobalRendererHandles.TableAutoFocusParams) => HTMLElement | null) | null | undefined = editRender.autofocus || editRender.autoFocus
1073
- let autoSelect = editRender.autoSelect || editRender.autoselect
1074
- let inputElem: HTMLElement | null = null
1075
- // 是否启用聚焦
1076
- if (editOpts.autoFocus) {
1077
- if (!autoFocus && compRender) {
1078
- autoFocus = compRender.tableAutoFocus || compRender.tableAutofocus || compRender.autofocus
1079
- }
1080
- if (!autoSelect && compRender) {
1081
- autoSelect = compRender.tableAutoSelect || compRender.autoselect
1082
- }
1083
- // 如果指定了聚焦 class
1084
- if (XEUtils.isFunction(autoFocus)) {
1085
- inputElem = autoFocus(params)
1086
- } else if (autoFocus) {
1087
- if (autoFocus === true) {
1088
- // 自动匹配模式,会自动匹配第一个可输入元素
1089
- inputElem = cell.querySelector('input,textarea')
1090
- } else {
1091
- inputElem = cell.querySelector(autoFocus)
1092
- }
1093
- if (inputElem) {
1094
- inputElem.focus()
1095
- }
1096
- }
1097
- }
1098
- return inputElem as HTMLInputElement
1099
- }
1100
- return null
1101
- }
1102
-
1103
- editPrivateMethods = {
1104
- /**
1105
- * 处理激活编辑
1106
- */
1107
- handleEdit(params, evnt, options) {
1108
- return handleEditActive(
1109
- params,
1110
- evnt,
1111
- Object.assign(
1112
- {
1113
- isFocus: true,
1114
- isPos: true
1115
- },
1116
- options
1117
- )
1118
- )
1119
- },
1120
- /**
1121
- * @deprecated
1122
- */
1123
- handleActived(params, evnt) {
1124
- return editPrivateMethods.handleEdit(params, evnt)
1125
- },
1126
- /**
1127
- * 处理取消编辑
1128
- * @param evnt
1129
- * @returns
1130
- */
1131
- handleClearEdit,
1132
- handleCellFocus,
1133
- /**
1134
- * 处理聚焦
1135
- */
1136
- handleFocus(params) {
1137
- const { row, column, cell } = params
1138
- const { editRender } = column
1139
- const editOpts = computeEditOpts.value
1140
- if (isEnableConf(editRender)) {
1141
- const autoSelect = editRender.autoSelect || editRender.autoselect
1142
- const inputElem = handleCellFocus(cell, params)
1143
- if (inputElem) {
1144
- if (autoSelect) {
1145
- inputElem.select()
1146
- } else {
1147
- // 保持一致行为,光标移到末端
1148
- if (browseObj.msie) {
1149
- const textRange = (inputElem as any).createTextRange()
1150
- textRange.collapse(false)
1151
- textRange.select()
1152
- }
1153
- }
1154
- } else {
1155
- // 是否自动定位
1156
- if (editOpts.autoPos) {
1157
- if (!column.fixed) {
1158
- // 显示到可视区中
1159
- $xeTable.scrollToRow(row, column)
1160
- }
1161
- }
1162
- }
1163
- }
1164
- },
1165
- /**
1166
- * 处理选中源
1167
- */
1168
- handleSelected(params, evnt) {
1169
- const { mouseConfig, editConfig } = props
1170
- const { editStore } = reactData
1171
- const mouseOpts = computeMouseOpts.value
1172
- const editOpts = computeEditOpts.value
1173
- const { actived, selected } = editStore
1174
- const { row, column } = params
1175
- const isMouseSelected = hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.selected
1176
- const selectMethod = () => {
1177
- if (isMouseSelected && (selected.row !== row || selected.column !== column)) {
1178
- if (actived.row !== row || (editOpts.mode === 'cell' ? actived.column !== column : false)) {
1179
- handleClearEdit(evnt)
1180
- $xeTable.clearSelected()
1181
- if ($xeTable.clearCellAreas) {
1182
- $xeTable.clearCellAreas()
1183
- $xeTable.clearCopyCellArea()
1184
- }
1185
- selected.args = params
1186
- selected.row = row
1187
- selected.column = column
1188
- if (isMouseSelected) {
1189
- editPrivateMethods.addCellSelectedClass()
1190
- }
1191
- $xeTable.focus()
1192
- // 如果是支持可复用控件
1193
- if (editConfig && editOpts.isReuseKeep && isEnableConf(editOpts) && isEnableConf(column.editRender)) {
1194
- setTimeout(() => {
1195
- const cell = $xeTable.getCellElement(row, column)
1196
- if (cell) {
1197
- const hasReusekeep = cell.querySelector('.vxe-reusekeep-control')
1198
- if (hasReusekeep) {
1199
- handleCellFocus(cell, params)
1200
- }
1201
- }
1202
- }, 0)
1203
- }
1204
- if (evnt) {
1205
- $xeTable.dispatchEvent('cell-selected', params, evnt)
1206
- }
1207
- }
1208
- }
1209
- return nextTick()
1210
- }
1211
- return selectMethod()
1212
- },
1213
- addCellSelectedClass() {
1214
- const { editStore } = reactData
1215
- const { selected } = editStore
1216
- const { row, column } = selected
1217
- removeCellSelectedClass()
1218
- if (row && column) {
1219
- const cell = $xeTable.getCellElement(row, column)
1220
- if (cell) {
1221
- addClass(cell, 'col--selected')
1222
- }
1223
- }
1224
- }
1225
- }
1226
-
1227
- return { ...editMethods, ...editPrivateMethods }
1228
- },
1229
- setupGrid($xeGrid) {
1230
- return $xeGrid.extendTableMethods(tableEditMethodKeys)
1231
- },
1232
- setupGantt($xeGantt) {
1233
- return $xeGantt.extendTableMethods(tableEditMethodKeys)
1234
- }
1235
- })
1
+ import { reactive, nextTick } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import { VxeUI } from '@vxe-ui/core'
4
+ import { hasEnableConf, isEnableConf } from '../../../ui/src/utils'
5
+ import { getCellValue, setCellValue, getRowid } from '../../src/util'
6
+ import { removeClass, addClass } from '../../../ui/src/dom'
7
+ import { createComponentLog } from '../../../ui/src/log'
8
+
9
+ import type { VxeTableConstructor, TableEditMethods, TableEditPrivateMethods, VxeTableDefines, VxeGlobalRendererHandles } from '../../../../types'
10
+
11
+ const { warnLog, errLog } = createComponentLog('table')
12
+
13
+ const { getConfig, renderer, hooks, getI18n } = VxeUI
14
+
15
+ const tableEditMethodKeys: (keyof TableEditMethods)[] = [
16
+ 'insert',
17
+ 'insertAt',
18
+ 'insertNextAt',
19
+ 'insertChild',
20
+ 'insertChildAt',
21
+ 'insertChildNextAt',
22
+ 'remove',
23
+ 'removeCheckboxRow',
24
+ 'removeRadioRow',
25
+ 'removeCurrentRow',
26
+ 'getRecordset',
27
+ 'getInsertRecords',
28
+ 'getRemoveRecords',
29
+ 'getUpdateRecords',
30
+ 'getEditRecord',
31
+ 'getActiveRecord',
32
+ 'getEditCell',
33
+ 'getSelectedCell',
34
+ 'clearEdit',
35
+ 'clearActived',
36
+ 'clearSelected',
37
+ 'isEditByRow',
38
+ 'isActiveByRow',
39
+ 'setEditRow',
40
+ 'setActiveRow',
41
+ 'setEditCell',
42
+ 'setActiveCell',
43
+ 'setSelectCell'
44
+ ]
45
+
46
+ hooks.add('tableEditModule', {
47
+ setupTable($xeTable) {
48
+ const { props, reactData, internalData } = $xeTable
49
+ const { refElem } = $xeTable.getRefMaps()
50
+ const { computeMouseOpts, computeEditOpts, computeCheckboxOpts, computeTreeOpts, computeValidOpts, computeRendererOpts } = $xeTable.getComputeMaps()
51
+
52
+ const browseObj = XEUtils.browse()
53
+
54
+ const getEditColumnModel = (row: any, column: VxeTableDefines.ColumnInfo) => {
55
+ const { model, editRender } = column
56
+ if (editRender) {
57
+ model.value = getCellValue(row, column)
58
+ model.update = false
59
+ }
60
+ }
61
+
62
+ const setEditColumnModel = (row: any, column: VxeTableDefines.ColumnInfo) => {
63
+ const { model, editRender } = column
64
+ if (editRender && model.update) {
65
+ setCellValue(row, column, model.value)
66
+ model.update = false
67
+ model.value = null
68
+ }
69
+ }
70
+
71
+ const removeCellSelectedClass = () => {
72
+ const el = refElem.value
73
+ if (el) {
74
+ const cell = el.querySelector('.col--selected')
75
+ if (cell) {
76
+ removeClass(cell, 'col--selected')
77
+ }
78
+ }
79
+ }
80
+
81
+ const syncActivedCell = () => {
82
+ const { editStore, tableColumn } = reactData
83
+ const editOpts = computeEditOpts.value
84
+ const { actived } = editStore
85
+ const { row, column } = actived
86
+ if (row && column) {
87
+ if (editOpts.mode === 'row') {
88
+ tableColumn.forEach((column) => setEditColumnModel(row, column))
89
+ } else {
90
+ setEditColumnModel(row, column)
91
+ }
92
+ }
93
+ }
94
+
95
+ const insertTreeRow = (newRecords: any[], isAppend: boolean) => {
96
+ const { tableFullTreeData, afterFullData, fullDataRowIdData, fullAllDataRowIdData } = internalData
97
+ const treeOpts = computeTreeOpts.value
98
+ const { rowField, parentField, mapChildrenField } = treeOpts
99
+ const childrenField = treeOpts.children || treeOpts.childrenField
100
+ const funcName = isAppend ? 'push' : 'unshift'
101
+ newRecords.forEach((item) => {
102
+ const parentRowId = item[parentField]
103
+ const rowid = getRowid($xeTable, item)
104
+ const matchObj = parentRowId ? XEUtils.findTree(tableFullTreeData, (item) => parentRowId === item[rowField], { children: mapChildrenField }) : null
105
+ if (matchObj) {
106
+ const { item: parentRow } = matchObj
107
+ const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
108
+ const parentLevel = parentRest ? parentRest.level : 0
109
+ let pChilds = parentRow[childrenField]
110
+ let pMapChilds = parentRow[mapChildrenField]
111
+ if (!XEUtils.isArray(pChilds)) {
112
+ pChilds = parentRow[childrenField] = []
113
+ }
114
+ if (!XEUtils.isArray(pMapChilds)) {
115
+ pMapChilds = parentRow[mapChildrenField] = []
116
+ }
117
+ pChilds[funcName](item)
118
+ pMapChilds[funcName](item)
119
+ const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: pChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
120
+ fullDataRowIdData[rowid] = rest
121
+ fullAllDataRowIdData[rowid] = rest
122
+ } else {
123
+ if (parentRowId) {
124
+ warnLog('vxe.error.unableInsert')
125
+ }
126
+ afterFullData[funcName](item)
127
+ tableFullTreeData[funcName](item)
128
+ const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: tableFullTreeData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
129
+ fullDataRowIdData[rowid] = rest
130
+ fullAllDataRowIdData[rowid] = rest
131
+ }
132
+ })
133
+ }
134
+
135
+ // const insertGroupRow = (newRecords: any[], isAppend: boolean) => {
136
+
137
+ // }
138
+
139
+ const handleInsertRowAt = (records: any, targetRowOrRowid: any, isInsertNextRow?: boolean) => {
140
+ const { treeConfig } = props
141
+ const { isRowGroupStatus } = reactData
142
+ const { tableFullTreeData, afterFullData, mergeBodyList, tableFullData, fullDataRowIdData, fullAllDataRowIdData, insertRowMaps, removeRowMaps } = internalData
143
+ const treeOpts = computeTreeOpts.value
144
+ const { transform, parentField, rowField, mapChildrenField } = treeOpts
145
+ const childrenField = treeOpts.children || treeOpts.childrenField
146
+ if (!XEUtils.isArray(records)) {
147
+ records = [records]
148
+ }
149
+ let targetRow = targetRowOrRowid
150
+ if (XEUtils.isString(targetRowOrRowid) || XEUtils.isNumber(targetRowOrRowid)) {
151
+ const rowRest = fullAllDataRowIdData[targetRowOrRowid]
152
+ if (rowRest) {
153
+ targetRow = rowRest.row
154
+ }
155
+ }
156
+ if (!records.length) {
157
+ return Promise.resolve({ row: null, rows: [] })
158
+ }
159
+ $xeTable.handlePushStack()
160
+ const newRecords: any[] = reactive($xeTable.defineField(records.map((record: any) => Object.assign(treeConfig && transform ? { [mapChildrenField]: [], [childrenField]: [] } : {}, record))))
161
+ let treeRecords: any[] = []
162
+ if (treeConfig && transform) {
163
+ treeRecords = XEUtils.toArrayTree(newRecords, { key: rowField, parentKey: parentField, children: childrenField })
164
+ }
165
+ if (XEUtils.eqNull(targetRow)) {
166
+ // 如果为虚拟树
167
+ if (treeConfig && transform) {
168
+ insertTreeRow(newRecords, false)
169
+ } else if (isRowGroupStatus) {
170
+ // 如果分组
171
+ if (treeConfig) {
172
+ throw new Error(getI18n('vxe.error.noTree', ['insert']))
173
+ }
174
+ errLog(getI18n('vxe.error.noGroup', ['insert']))
175
+ // insertGroupRow(newRecords, false)
176
+ } else {
177
+ newRecords.forEach((item) => {
178
+ const rowid = getRowid($xeTable, item)
179
+ const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
180
+ fullDataRowIdData[rowid] = rest
181
+ fullAllDataRowIdData[rowid] = rest
182
+ afterFullData.unshift(item)
183
+ tableFullData.unshift(item)
184
+ })
185
+ // 刷新单元格合并
186
+ mergeBodyList.forEach((mergeItem: any) => {
187
+ const { row: mergeRowIndex } = mergeItem
188
+ if (mergeRowIndex >= 0) {
189
+ mergeItem.row = mergeRowIndex + newRecords.length
190
+ }
191
+ })
192
+ }
193
+ } else {
194
+ if (targetRow === -1) {
195
+ // 如果为虚拟树
196
+ if (treeConfig && transform) {
197
+ insertTreeRow(newRecords, true)
198
+ } else if (isRowGroupStatus) {
199
+ // 如果分组
200
+ if (treeConfig) {
201
+ throw new Error(getI18n('vxe.error.noTree', ['insert']))
202
+ }
203
+ errLog(getI18n('vxe.error.noGroup', ['insert']))
204
+ // insertGroupRow(newRecords, true)
205
+ } else {
206
+ newRecords.forEach((item) => {
207
+ const rowid = getRowid($xeTable, item)
208
+ const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, treeIndex: -1, _tIndex: -1, $index: -1, items: afterFullData, parent: null, level: 0, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
209
+ fullDataRowIdData[rowid] = rest
210
+ fullAllDataRowIdData[rowid] = rest
211
+ afterFullData.push(item)
212
+ tableFullData.push(item)
213
+ })
214
+ }
215
+ } else {
216
+ // 如果为虚拟树
217
+ if (treeConfig && transform) {
218
+ const matchMapObj = XEUtils.findTree(tableFullTreeData, (item) => targetRow[rowField] === item[rowField], { children: mapChildrenField })
219
+ if (matchMapObj) {
220
+ const { parent: parentRow } = matchMapObj
221
+ const parentMapChilds = parentRow ? parentRow[mapChildrenField] : tableFullTreeData
222
+ const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)]
223
+ const parentLevel = parentRest ? parentRest.level : 0
224
+ treeRecords.forEach((row, i) => {
225
+ if (parentRow) {
226
+ if (row[parentField] !== parentRow[rowField]) {
227
+ errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, `${parentField}=${parentRow[rowField]}`])
228
+ row[parentField] = parentRow[rowField]
229
+ }
230
+ } else {
231
+ if (row[parentField] !== null) {
232
+ if (!XEUtils.eqNull(row[parentField])) {
233
+ errLog('vxe.error.errProp', [`${parentField}=${row[parentField]}`, 'null'])
234
+ }
235
+ row[parentField] = null
236
+ }
237
+ }
238
+ let targetIndex = matchMapObj.index + i
239
+ if (isInsertNextRow) {
240
+ targetIndex = targetIndex + 1
241
+ }
242
+ parentMapChilds.splice(targetIndex, 0, row)
243
+ })
244
+ XEUtils.eachTree(
245
+ treeRecords,
246
+ (item) => {
247
+ const rowid = getRowid($xeTable, item)
248
+ const rest = { row: item, rowid, _seq: -1, seq: -1, index: -1, _index: -1, $index: -1, treeIndex: -1, _tIndex: -1, items: parentMapChilds, parent: parentRow, level: parentLevel + 1, height: 0, resizeHeight: 0, oTop: 0, expandHeight: 0 }
249
+ if (item[childrenField]) {
250
+ item[mapChildrenField] = item[childrenField]
251
+ }
252
+ fullDataRowIdData[rowid] = rest
253
+ fullAllDataRowIdData[rowid] = rest
254
+ },
255
+ { children: childrenField }
256
+ )
257
+ // 源
258
+ if (parentRow) {
259
+ const matchObj = XEUtils.findTree(tableFullTreeData, (item) => targetRow[rowField] === item[rowField], { children: childrenField })
260
+ if (matchObj) {
261
+ const parentChilds = matchObj.items
262
+ let targetIndex = matchObj.index
263
+ if (isInsertNextRow) {
264
+ targetIndex = targetIndex + 1
265
+ }
266
+ parentChilds.splice(targetIndex, 0, ...treeRecords)
267
+ }
268
+ }
269
+ } else {
270
+ warnLog('vxe.error.unableInsert')
271
+ insertTreeRow(newRecords, true)
272
+ }
273
+ } else if (isRowGroupStatus) {
274
+ // 如果分组
275
+ if (treeConfig) {
276
+ throw new Error(getI18n('vxe.error.noTree', ['insert']))
277
+ }
278
+ errLog(getI18n('vxe.error.noGroup', ['insert']))
279
+ } else {
280
+ if (treeConfig) {
281
+ throw new Error(getI18n('vxe.error.noTree', ['insert']))
282
+ }
283
+ let afIndex = -1
284
+ // 如果是可视索引
285
+ if (XEUtils.isNumber(targetRow)) {
286
+ if (targetRow < afterFullData.length) {
287
+ afIndex = targetRow
288
+ }
289
+ } else {
290
+ afIndex = $xeTable.findRowIndexOf(afterFullData, targetRow)
291
+ }
292
+ // 如果是插入指定行的下一行
293
+ if (isInsertNextRow) {
294
+ afIndex = Math.min(afterFullData.length, afIndex + 1)
295
+ }
296
+ if (afIndex === -1) {
297
+ throw new Error(getI18n('vxe.error.unableInsert'))
298
+ }
299
+ afterFullData.splice(afIndex, 0, ...newRecords)
300
+ const tfIndex = $xeTable.findRowIndexOf(tableFullData, targetRow)
301
+ if (tfIndex > -1) {
302
+ tableFullData.splice(tfIndex + (isInsertNextRow ? 1 : 0), 0, ...newRecords)
303
+ } else {
304
+ tableFullData.push(...newRecords)
305
+ }
306
+ // 刷新单元格合并
307
+ mergeBodyList.forEach((mergeItem: any) => {
308
+ const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
309
+ if (mergeRowIndex >= afIndex) {
310
+ mergeItem.row = mergeRowIndex + newRecords.length
311
+ } else if (isInsertNextRow ? mergeRowIndex + mergeRowspan >= afIndex : mergeRowIndex + mergeRowspan > afIndex) {
312
+ mergeItem.rowspan = mergeRowspan + newRecords.length
313
+ }
314
+ })
315
+ }
316
+ }
317
+ }
318
+
319
+ const handleStatus = (newRow: any) => {
320
+ const rowid = getRowid($xeTable, newRow)
321
+ // 如果是被删除的数据,则还原状态
322
+ if (removeRowMaps[rowid]) {
323
+ delete removeRowMaps[rowid]
324
+ if (insertRowMaps[rowid]) {
325
+ delete insertRowMaps[rowid]
326
+ }
327
+ } else {
328
+ insertRowMaps[rowid] = newRow
329
+ }
330
+ }
331
+ // 如果为虚拟树
332
+ if (treeConfig && transform) {
333
+ XEUtils.eachTree(treeRecords, handleStatus, { children: mapChildrenField })
334
+ } else {
335
+ newRecords.forEach(handleStatus)
336
+ }
337
+
338
+ reactData.removeRowFlag++
339
+ reactData.insertRowFlag++
340
+ $xeTable.cacheRowMap(false, false)
341
+ $xeTable.updateScrollYStatus()
342
+ $xeTable.handleTableData(treeConfig && transform)
343
+ if (!(treeConfig && transform)) {
344
+ $xeTable.updateAfterDataIndex()
345
+ }
346
+ $xeTable.updateFooter()
347
+ $xeTable.handleUpdateBodyMerge()
348
+ $xeTable.checkSelectionStatus()
349
+ if (reactData.scrollYLoad) {
350
+ $xeTable.updateScrollYSpace()
351
+ }
352
+ return nextTick()
353
+ .then(() => {
354
+ $xeTable.updateCellAreas()
355
+ return $xeTable.recalculate(true)
356
+ })
357
+ .then(() => {
358
+ return {
359
+ row: newRecords.length ? newRecords[newRecords.length - 1] : null,
360
+ rows: newRecords
361
+ }
362
+ })
363
+ }
364
+
365
+ const handleInsertChildRowAt = (records: any, parentRowOrParentId: any, targetRow: any, isInsertNextRow?: boolean) => {
366
+ const { treeConfig } = props
367
+ const { fullAllDataRowIdData } = internalData
368
+ const treeOpts = computeTreeOpts.value
369
+ const { transform, rowField, parentField } = treeOpts
370
+ if (treeConfig && transform) {
371
+ if (!XEUtils.isArray(records)) {
372
+ records = [records]
373
+ }
374
+ let parentRow = parentRowOrParentId
375
+ if (XEUtils.isString(parentRowOrParentId) || XEUtils.isNumber(parentRowOrParentId)) {
376
+ const rowRest = fullAllDataRowIdData[parentRowOrParentId]
377
+ if (rowRest) {
378
+ parentRow = rowRest.row
379
+ }
380
+ }
381
+ return handleInsertRowAt(
382
+ records.map((item: any) => Object.assign({}, item, { [parentField]: parentRow[rowField] })),
383
+ targetRow,
384
+ isInsertNextRow
385
+ )
386
+ } else {
387
+ errLog('vxe.error.errProp', ['tree-config.transform=false', 'tree-config.transform=true'])
388
+ }
389
+ return Promise.resolve({ row: null, rows: [] })
390
+ }
391
+
392
+ const handleClearEdit = (evnt: Event | null, targetRow?: any) => {
393
+ const { editStore } = reactData
394
+ const { actived, focused } = editStore
395
+ const { row, column } = actived
396
+ const validOpts = computeValidOpts.value
397
+ if (row || column) {
398
+ if (targetRow && getRowid($xeTable, targetRow) !== getRowid($xeTable, row)) {
399
+ return nextTick()
400
+ }
401
+ syncActivedCell()
402
+ $xeTable.updateFooter()
403
+ actived.args = null
404
+ actived.row = null
405
+ actived.column = null
406
+ $xeTable.dispatchEvent(
407
+ 'edit-closed',
408
+ {
409
+ row,
410
+ rowIndex: $xeTable.getRowIndex(row),
411
+ $rowIndex: $xeTable.getVMRowIndex(row),
412
+ column,
413
+ columnIndex: $xeTable.getColumnIndex(column),
414
+ $columnIndex: $xeTable.getVMColumnIndex(column)
415
+ },
416
+ evnt || null
417
+ )
418
+ }
419
+ focused.row = null
420
+ focused.column = null
421
+ if (validOpts.autoClear) {
422
+ if (validOpts.msgMode !== 'full' || getConfig().cellVaildMode === 'obsolete') {
423
+ if ($xeTable.clearValidate) {
424
+ return $xeTable.clearValidate()
425
+ }
426
+ }
427
+ }
428
+ return nextTick().then(() => $xeTable.updateCellAreas())
429
+ }
430
+
431
+ const handleEditActive = (
432
+ params: {
433
+ $table: VxeTableConstructor
434
+ column: VxeTableDefines.ColumnInfo
435
+ columnIndex: number
436
+ _columnIndex: number
437
+ $columnIndex: number
438
+ rowIndex: number
439
+ $rowIndex: number
440
+ _rowIndex: number
441
+ row: any
442
+ cell?: HTMLElement
443
+ },
444
+ evnt: Event | null,
445
+ options: {
446
+ isClear?: boolean
447
+ isFocus?: boolean
448
+ isPos?: boolean
449
+ }
450
+ ) => {
451
+ const $xeGrid = $xeTable.xeGrid
452
+ const $xeGantt = $xeTable.xeGantt
453
+
454
+ const { editConfig, mouseConfig } = props
455
+ const { editStore, tableColumn } = reactData
456
+ const editOpts = computeEditOpts.value
457
+ const mouseOpts = computeMouseOpts.value
458
+ const { mode } = editOpts
459
+ const { actived, focused } = editStore
460
+ const { row, column } = params
461
+ const { editRender } = column
462
+ const { isFocus, isPos, isClear } = options
463
+ const cell = (params.cell || $xeTable.getCellElement(row, column)) as HTMLElement
464
+ const beforeEditFn = editOpts.beforeEditMethod || editOpts.activeMethod
465
+ const beforeEditAsyncFn = editOpts.beforeEditAsyncMethod
466
+ const editParams = { ...params, cell }
467
+
468
+ if (!cell || !isEnableConf(editConfig) || !isEnableConf(editRender)) {
469
+ return nextTick()
470
+ }
471
+ if ($xeTable.isPendingByRow(row) || $xeTable.isAggregateRecord(row)) {
472
+ return nextTick()
473
+ }
474
+
475
+ // 激活编辑
476
+ if (actived.row !== row || (mode === 'cell' ? actived.column !== column : false)) {
477
+ const evntParams = {
478
+ row,
479
+ rowIndex: $xeTable.getRowIndex(row),
480
+ $rowIndex: $xeTable.getVMRowIndex(row),
481
+ column,
482
+ columnIndex: $xeTable.getColumnIndex(column),
483
+ $columnIndex: $xeTable.getVMColumnIndex(column)
484
+ }
485
+
486
+ const handleCellEdit = (status: boolean) => {
487
+ if (status) {
488
+ if (hasEnableConf(mouseConfig, mouseOpts)) {
489
+ $xeTable.clearSelected()
490
+ if ($xeTable.clearCellAreas) {
491
+ $xeTable.clearCellAreas()
492
+ $xeTable.clearCopyCellArea()
493
+ }
494
+ }
495
+ $xeTable.closeTooltip()
496
+ if (actived.column) {
497
+ handleClearEdit(evnt)
498
+ }
499
+ column.renderHeight = cell.offsetHeight
500
+ actived.args = editParams
501
+ actived.row = row
502
+ actived.column = column
503
+ $xeTable.handlePushStack()
504
+ if (isClear) {
505
+ setCellValue(row, column, null)
506
+ }
507
+ if (mode === 'row') {
508
+ tableColumn.forEach((column) => getEditColumnModel(row, column))
509
+ } else {
510
+ getEditColumnModel(row, column)
511
+ }
512
+ const afterEditMethod = editOpts.afterEditMethod
513
+ nextTick(() => {
514
+ if (isFocus) {
515
+ $xeTable.handleFocus(editParams, evnt)
516
+ }
517
+ if (afterEditMethod) {
518
+ afterEditMethod({ ...editParams, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt })
519
+ }
520
+ })
521
+
522
+ $xeTable.dispatchEvent('edit-activated', evntParams, evnt)
523
+ // v4已废弃
524
+ $xeTable.dispatchEvent('edit-actived', evntParams, evnt)
525
+ } else {
526
+ $xeTable.dispatchEvent('edit-disabled', evntParams, evnt)
527
+ }
528
+ focused.column = null
529
+ focused.row = null
530
+ $xeTable.focus()
531
+ }
532
+
533
+ const eFnParams = { ...editParams, $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt }
534
+
535
+ // 是否被禁用
536
+ if (beforeEditFn) {
537
+ handleCellEdit(!!beforeEditFn(eFnParams))
538
+ } else if (beforeEditAsyncFn) {
539
+ return Promise.resolve()
540
+ .then(() => beforeEditAsyncFn(eFnParams))
541
+ .catch(() => false)
542
+ .then((status) => {
543
+ handleCellEdit(!!status)
544
+ })
545
+ } else {
546
+ handleCellEdit(true)
547
+ }
548
+ return nextTick()
549
+ }
550
+
551
+ const { column: oldColumn } = actived
552
+ if (hasEnableConf(mouseConfig, mouseOpts)) {
553
+ $xeTable.clearSelected()
554
+ if ($xeTable.clearCellAreas) {
555
+ $xeTable.clearCellAreas()
556
+ $xeTable.clearCopyCellArea()
557
+ }
558
+ }
559
+ if (oldColumn && oldColumn !== column) {
560
+ const { model: oldModel } = oldColumn
561
+ if (oldModel.update) {
562
+ setCellValue(row, oldColumn, oldModel.value)
563
+ }
564
+ if ($xeTable.clearValidate) {
565
+ $xeTable.clearValidate(row, column)
566
+ }
567
+ }
568
+ column.renderHeight = cell.offsetHeight
569
+ actived.args = editParams
570
+ actived.column = column
571
+ if (isPos) {
572
+ setTimeout(() => {
573
+ $xeTable.handleFocus(editParams, evnt)
574
+ })
575
+ }
576
+ focused.column = null
577
+ focused.row = null
578
+ $xeTable.focus()
579
+ return nextTick()
580
+ }
581
+
582
+ const handleEditCell = (
583
+ row: any,
584
+ fieldOrColumn: string | VxeTableDefines.ColumnInfo | null,
585
+ options: {
586
+ isClear?: boolean | undefined
587
+ isFocus?: boolean | undefined
588
+ isPos?: boolean | undefined
589
+ }
590
+ ) => {
591
+ const { editConfig } = props
592
+ const { isPos } = options
593
+ const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
594
+ if (row && column && isEnableConf(editConfig) && isEnableConf(column.editRender) && !$xeTable.isAggregateRecord(row)) {
595
+ return Promise.resolve(isPos ? $xeTable.scrollToRow(row, column) : null).then(() => {
596
+ const cell = $xeTable.getCellElement(row, column)
597
+ if (cell) {
598
+ handleEditActive(
599
+ {
600
+ row,
601
+ rowIndex: $xeTable.getRowIndex(row),
602
+ $rowIndex: $xeTable.getVMRowIndex(row),
603
+ _rowIndex: $xeTable.getVTRowIndex(row),
604
+ column,
605
+ columnIndex: $xeTable.getColumnIndex(column),
606
+ $columnIndex: $xeTable.getVMColumnIndex(column),
607
+ _columnIndex: $xeTable.getVTColumnIndex(column),
608
+ cell,
609
+ $table: $xeTable
610
+ },
611
+ null,
612
+ {
613
+ isFocus: isPos,
614
+ isPos
615
+ }
616
+ )
617
+ internalData._lastCallTime = Date.now()
618
+ }
619
+ return nextTick()
620
+ })
621
+ }
622
+ return nextTick()
623
+ }
624
+
625
+ const editMethods: TableEditMethods = {
626
+ /**
627
+ * 往表格中插入临时数据
628
+ *
629
+ * @param {*} records
630
+ */
631
+ insert(records) {
632
+ return handleInsertRowAt(records, null)
633
+ },
634
+ /**
635
+ * 往表格指定行中插入临时数据
636
+ * 如果 row 为空则从插入到顶部,如果为树结构,则插入到目标节点顶部
637
+ * 如果 row 为 -1 则从插入到底部,如果为树结构,则插入到目标节点底部
638
+ * 如果 row 为有效行则插入到该行的位置,如果为树结构,则有插入到效的目标节点该行的位置
639
+ */
640
+ insertAt(records, targetRowOrRowid) {
641
+ return handleInsertRowAt(records, targetRowOrRowid)
642
+ },
643
+ insertNextAt(records, targetRowOrRowid) {
644
+ return handleInsertRowAt(records, targetRowOrRowid, true)
645
+ },
646
+ insertChild(records, parentRowOrParentId) {
647
+ return handleInsertChildRowAt(records, parentRowOrParentId, null)
648
+ },
649
+ insertChildAt(records, parentRowOrParentId, targetRow) {
650
+ return handleInsertChildRowAt(records, parentRowOrParentId, targetRow)
651
+ },
652
+ insertChildNextAt(records, parentRowOrParentId, targetRow) {
653
+ return handleInsertChildRowAt(records, parentRowOrParentId, targetRow, true)
654
+ },
655
+ /**
656
+ * 删除指定行数据
657
+ * 如果传 row 则删除一行
658
+ * 如果传 rows 则删除多行
659
+ * 如果为空则删除所有
660
+ */
661
+ remove(rows: any) {
662
+ const { treeConfig } = props
663
+ const { editStore, isRowGroupStatus } = reactData
664
+ const { tableFullTreeData, selectCheckboxMaps, afterFullData, mergeBodyList, tableFullData, pendingRowMaps, insertRowMaps, removeRowMaps } = internalData
665
+ const checkboxOpts = computeCheckboxOpts.value
666
+ const treeOpts = computeTreeOpts.value
667
+ const { transform, mapChildrenField } = treeOpts
668
+ const childrenField = treeOpts.children || treeOpts.childrenField
669
+ const { actived } = editStore
670
+ const { checkField } = checkboxOpts
671
+ let delList: any[] = []
672
+ if (!rows) {
673
+ rows = tableFullData
674
+ } else if (!XEUtils.isArray(rows)) {
675
+ rows = [rows]
676
+ }
677
+ if (!rows.length) {
678
+ return Promise.resolve({ row: null, rows: [] })
679
+ }
680
+ $xeTable.handlePushStack()
681
+ // 如果是新增,则保存记录
682
+ rows.forEach((row: any) => {
683
+ if (!$xeTable.isInsertByRow(row)) {
684
+ const rowid = getRowid($xeTable, row)
685
+ removeRowMaps[rowid] = row
686
+ }
687
+ })
688
+ // 如果绑定了多选属性,则更新状态
689
+ if (!checkField) {
690
+ rows.forEach((row: any) => {
691
+ const rowid = getRowid($xeTable, row)
692
+ if (selectCheckboxMaps[rowid]) {
693
+ delete selectCheckboxMaps[rowid]
694
+ }
695
+ })
696
+ reactData.updateCheckboxFlag++
697
+ }
698
+ // 从数据源中移除
699
+ if (tableFullData === rows) {
700
+ rows = delList = tableFullData.slice(0)
701
+ internalData.tableFullData = []
702
+ internalData.afterFullData = []
703
+ $xeTable.clearMergeCells()
704
+ } else {
705
+ // 如果为虚拟树
706
+ if (treeConfig && transform) {
707
+ rows.forEach((row: any) => {
708
+ const rowid = getRowid($xeTable, row)
709
+ const matchMapObj = XEUtils.findTree(tableFullTreeData, (item) => rowid === getRowid($xeTable, item), { children: mapChildrenField })
710
+ if (matchMapObj) {
711
+ const rItems = matchMapObj.items.splice(matchMapObj.index, 1)
712
+ delList.push(rItems[0])
713
+ }
714
+ const matchObj = XEUtils.findTree(tableFullTreeData, (item) => rowid === getRowid($xeTable, item), { children: childrenField })
715
+ if (matchObj) {
716
+ matchObj.items.splice(matchObj.index, 1)
717
+ }
718
+ const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
719
+ if (afIndex > -1) {
720
+ afterFullData.splice(afIndex, 1)
721
+ }
722
+ })
723
+ } else if (isRowGroupStatus) {
724
+ // 如果分组
725
+ warnLog(getI18n('vxe.error.noGroup', ['remove']))
726
+ } else {
727
+ rows.forEach((row: any) => {
728
+ const tfIndex = $xeTable.findRowIndexOf(tableFullData, row)
729
+ if (tfIndex > -1) {
730
+ const rItems = tableFullData.splice(tfIndex, 1)
731
+ delList.push(rItems[0])
732
+ }
733
+ const afIndex = $xeTable.findRowIndexOf(afterFullData, row)
734
+ if (afIndex > -1) {
735
+ // 刷新单元格合并
736
+ mergeBodyList.forEach((mergeItem) => {
737
+ const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
738
+ if (mergeRowIndex > afIndex) {
739
+ mergeItem.row = mergeRowIndex - 1
740
+ } else if (mergeRowIndex + mergeRowspan > afIndex) {
741
+ mergeItem.rowspan = mergeRowspan - 1
742
+ }
743
+ })
744
+ afterFullData.splice(afIndex, 1)
745
+ }
746
+ })
747
+ }
748
+ }
749
+ // 如果当前行被激活编辑,则清除激活状态
750
+ if (actived.row && $xeTable.findRowIndexOf(rows, actived.row) > -1) {
751
+ editMethods.clearEdit()
752
+ }
753
+ // 从新增中移除已删除的数据
754
+ rows.forEach((row: any) => {
755
+ const rowid = getRowid($xeTable, row)
756
+ if (insertRowMaps[rowid]) {
757
+ delete insertRowMaps[rowid]
758
+ }
759
+ if (pendingRowMaps[rowid]) {
760
+ delete pendingRowMaps[rowid]
761
+ }
762
+ })
763
+ reactData.removeRowFlag++
764
+ reactData.insertRowFlag++
765
+ reactData.pendingRowFlag++
766
+ $xeTable.cacheRowMap(false, false)
767
+ $xeTable.handleTableData(treeConfig && transform)
768
+ $xeTable.updateFooter()
769
+ $xeTable.handleUpdateBodyMerge()
770
+ if (!(treeConfig && transform)) {
771
+ $xeTable.updateAfterDataIndex()
772
+ }
773
+ $xeTable.checkSelectionStatus()
774
+ if (reactData.scrollYLoad) {
775
+ $xeTable.updateScrollYSpace()
776
+ }
777
+ return nextTick()
778
+ .then(() => {
779
+ $xeTable.updateCellAreas()
780
+ return $xeTable.recalculate(true)
781
+ })
782
+ .then(() => {
783
+ return { row: delList.length ? delList[delList.length - 1] : null, rows: delList }
784
+ })
785
+ },
786
+ /**
787
+ * 删除复选框选中的数据
788
+ */
789
+ removeCheckboxRow() {
790
+ return editMethods.remove($xeTable.getCheckboxRecords()).then((params: any) => {
791
+ $xeTable.clearCheckboxRow()
792
+ return params
793
+ })
794
+ },
795
+ /**
796
+ * 删除单选框选中的数据
797
+ */
798
+ removeRadioRow() {
799
+ const radioRecord = $xeTable.getRadioRecord()
800
+ return editMethods.remove(radioRecord || []).then((params: any) => {
801
+ $xeTable.clearRadioRow()
802
+ return params
803
+ })
804
+ },
805
+ /**
806
+ * 删除当前行选中的数据
807
+ */
808
+ removeCurrentRow() {
809
+ const currentRecord = $xeTable.getCurrentRecord()
810
+ return editMethods.remove(currentRecord || []).then((params: any) => {
811
+ $xeTable.clearCurrentRow()
812
+ return params
813
+ })
814
+ },
815
+ /**
816
+ * 获取表格数据集,包含新增、删除、修改、标记
817
+ */
818
+ getRecordset() {
819
+ const removeRecords = editMethods.getRemoveRecords()
820
+ const pendingRecords = $xeTable.getPendingRecords()
821
+ const delRecords = removeRecords.concat(pendingRecords)
822
+ // 如果已经被删除,则无需放到更新数组
823
+ const updateRecords = editMethods.getUpdateRecords().filter((row) => {
824
+ return !delRecords.some((item) => $xeTable.eqRow(item, row))
825
+ })
826
+ return {
827
+ insertRecords: editMethods.getInsertRecords(),
828
+ removeRecords,
829
+ updateRecords,
830
+ pendingRecords
831
+ }
832
+ },
833
+ /**
834
+ * 获取新增的临时数据
835
+ */
836
+ getInsertRecords() {
837
+ const { fullAllDataRowIdData, insertRowMaps } = internalData
838
+ const insertRecords: any[] = []
839
+ XEUtils.each(insertRowMaps, (row, rowid) => {
840
+ if (fullAllDataRowIdData[rowid]) {
841
+ insertRecords.push(row)
842
+ }
843
+ })
844
+ return insertRecords
845
+ },
846
+ /**
847
+ * 获取已删除的数据
848
+ */
849
+ getRemoveRecords() {
850
+ const { removeRowMaps } = internalData
851
+ const removeRecords: any[] = []
852
+ XEUtils.each(removeRowMaps, (row) => {
853
+ removeRecords.push(row)
854
+ })
855
+ return removeRecords
856
+ },
857
+ /**
858
+ * 获取更新数据
859
+ * 只精准匹配 row 的更改
860
+ * 如果是树表格,子节点更改状态不会影响父节点的更新状态
861
+ */
862
+ getUpdateRecords() {
863
+ const { keepSource, treeConfig } = props
864
+ const { tableFullData, tableFullTreeData } = internalData
865
+ const treeOpts = computeTreeOpts.value
866
+ const updateRecords: any[] = []
867
+ if (keepSource) {
868
+ syncActivedCell()
869
+ if (treeConfig) {
870
+ const childrenField = treeOpts.children || treeOpts.childrenField
871
+ XEUtils.eachTree(
872
+ tableFullTreeData,
873
+ (row) => {
874
+ if ($xeTable.isUpdateByRow(row)) {
875
+ updateRecords.push(row)
876
+ }
877
+ },
878
+ { children: childrenField }
879
+ )
880
+ } else {
881
+ tableFullData.forEach((row) => {
882
+ if ($xeTable.isUpdateByRow(row)) {
883
+ updateRecords.push(row)
884
+ }
885
+ })
886
+ }
887
+ }
888
+ return updateRecords
889
+ },
890
+ getActiveRecord() {
891
+ warnLog('vxe.error.delFunc', ['getActiveRecord', 'getEditCell'])
892
+ const { editStore } = reactData
893
+ const { fullAllDataRowIdData } = internalData
894
+ const { args, row } = editStore.actived
895
+ if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
896
+ return Object.assign({}, args, { row })
897
+ }
898
+ return null
899
+ },
900
+ getEditRecord() {
901
+ warnLog('vxe.error.delFunc', ['getEditRecord', 'getEditCell'])
902
+ const { editStore } = reactData
903
+ const { fullAllDataRowIdData } = internalData
904
+ const { args, row } = editStore.actived
905
+ if (args && row && fullAllDataRowIdData[getRowid($xeTable, row)]) {
906
+ return Object.assign({}, args, { row })
907
+ }
908
+ return null
909
+ },
910
+ getEditCell() {
911
+ const { editStore } = reactData
912
+ const { row, column } = editStore.actived
913
+ if (column && row) {
914
+ return {
915
+ row,
916
+ rowIndex: $xeTable.getRowIndex(row),
917
+ column,
918
+ columnIndex: $xeTable.getColumnIndex(column)
919
+ }
920
+ }
921
+ return null
922
+ },
923
+ /**
924
+ * 获取选中的单元格
925
+ */
926
+ getSelectedCell() {
927
+ const { editStore } = reactData
928
+ const { row, column } = editStore.selected
929
+ if (row && column) {
930
+ return {
931
+ row,
932
+ column
933
+ }
934
+ }
935
+ return null
936
+ },
937
+ clearActived(row) {
938
+ // 即将废弃
939
+ warnLog('vxe.error.delFunc', ['clearActived', 'clearEdit'])
940
+ return $xeTable.clearEdit(row)
941
+ },
942
+ /**
943
+ * 清除激活的编辑
944
+ */
945
+ clearEdit(row) {
946
+ return handleClearEdit(null, row)
947
+ },
948
+ /**
949
+ * 清除所选中源状态
950
+ */
951
+ clearSelected() {
952
+ const { editStore } = reactData
953
+ const { selected } = editStore
954
+ selected.row = null
955
+ selected.column = null
956
+ removeCellSelectedClass()
957
+ return nextTick()
958
+ },
959
+ isActiveByRow(row) {
960
+ warnLog('vxe.error.delFunc', ['isActiveByRow', 'isEditByRow'])
961
+ // 即将废弃
962
+ return $xeTable.isEditByRow(row)
963
+ },
964
+ /**
965
+ * 判断行是否为激活编辑状态
966
+ * @param {Row} row 行对象
967
+ */
968
+ isEditByRow(row) {
969
+ const { editStore } = reactData
970
+ return editStore.actived.row === row
971
+ },
972
+ setActiveRow(row) {
973
+ warnLog('vxe.error.delFunc', ['setActiveRow', 'setEditRow'])
974
+ // 即将废弃
975
+ return editMethods.setEditRow(row)
976
+ },
977
+ /**
978
+ * 激活行编辑
979
+ */
980
+ setEditRow(row, fieldOrColumn, options) {
981
+ const { visibleColumn } = internalData
982
+ let column: any = XEUtils.find(visibleColumn, (column) => isEnableConf(column.editRender))
983
+ let isPos = false
984
+ if (fieldOrColumn) {
985
+ isPos = true
986
+ if (fieldOrColumn !== true) {
987
+ column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
988
+ }
989
+ }
990
+ return handleEditCell(
991
+ row,
992
+ column,
993
+ Object.assign(
994
+ {
995
+ isPos,
996
+ isFocus: isPos
997
+ },
998
+ options
999
+ )
1000
+ )
1001
+ },
1002
+ setActiveCell(row, fieldOrColumn) {
1003
+ warnLog('vxe.error.delFunc', ['setActiveCell', 'setEditCell'])
1004
+ // 即将废弃
1005
+ return editMethods.setEditCell(row, fieldOrColumn)
1006
+ },
1007
+ /**
1008
+ * 激活单元格编辑
1009
+ */
1010
+ setEditCell(row, fieldOrColumn, options) {
1011
+ return handleEditCell(
1012
+ row,
1013
+ fieldOrColumn,
1014
+ Object.assign(
1015
+ {
1016
+ isFocus: true,
1017
+ isPos: true
1018
+ },
1019
+ options
1020
+ )
1021
+ )
1022
+ },
1023
+ /**
1024
+ * 只对 trigger=dblclick 有效,选中单元格
1025
+ */
1026
+ setSelectCell(row, fieldOrColumn) {
1027
+ const { tableData } = reactData
1028
+ const editOpts = computeEditOpts.value
1029
+ const column = XEUtils.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn
1030
+ if (row && column && editOpts.trigger !== 'manual') {
1031
+ const rowIndex = $xeTable.findRowIndexOf(tableData, row)
1032
+ if (rowIndex > -1 && column) {
1033
+ const cell = $xeTable.getCellElement(row, column)
1034
+ const params = {
1035
+ $table: $xeTable,
1036
+ row,
1037
+ rowIndex,
1038
+ $rowIndex: $xeTable.getVMRowIndex(row),
1039
+ _rowIndex: $xeTable.getVTRowIndex(row),
1040
+ column,
1041
+ columnIndex: $xeTable.getColumnIndex(column),
1042
+ $columnIndex: $xeTable.getVMColumnIndex(column),
1043
+ _columnIndex: $xeTable.getVTColumnIndex(column),
1044
+ cell
1045
+ }
1046
+ $xeTable.handleSelected(params, null)
1047
+ }
1048
+ }
1049
+ return nextTick()
1050
+ }
1051
+ }
1052
+
1053
+ const handleCellFocus = (
1054
+ cell: HTMLElement,
1055
+ params: {
1056
+ $table: VxeTableConstructor
1057
+ column: VxeTableDefines.ColumnInfo
1058
+ row: any
1059
+ }
1060
+ ) => {
1061
+ const { editConfig } = props
1062
+ const { column } = params
1063
+ const { editRender } = column
1064
+ const editOpts = computeEditOpts.value
1065
+ if (editConfig && isEnableConf(editRender)) {
1066
+ const rendererOpts = computeRendererOpts.value
1067
+ const renderName = editRender.name
1068
+ const compRender = renderName ? rendererOpts[renderName] || renderer.get(renderName) : null
1069
+ let autoFocus: boolean | string | ((params: VxeGlobalRendererHandles.TableAutoFocusParams) => HTMLElement | null) | null | undefined = editRender.autofocus || editRender.autoFocus
1070
+ let autoSelect = editRender.autoSelect || editRender.autoselect
1071
+ let inputElem: HTMLElement | null = null
1072
+ // 是否启用聚焦
1073
+ if (editOpts.autoFocus) {
1074
+ if (!autoFocus && compRender) {
1075
+ autoFocus = compRender.tableAutoFocus || compRender.tableAutofocus || compRender.autofocus
1076
+ }
1077
+ if (!autoSelect && compRender) {
1078
+ autoSelect = compRender.tableAutoSelect || compRender.autoselect
1079
+ }
1080
+ // 如果指定了聚焦 class
1081
+ if (XEUtils.isFunction(autoFocus)) {
1082
+ inputElem = autoFocus(params)
1083
+ } else if (autoFocus) {
1084
+ if (autoFocus === true) {
1085
+ // 自动匹配模式,会自动匹配第一个可输入元素
1086
+ inputElem = cell.querySelector('input,textarea')
1087
+ } else {
1088
+ inputElem = cell.querySelector(autoFocus)
1089
+ }
1090
+ if (inputElem) {
1091
+ inputElem.focus()
1092
+ }
1093
+ }
1094
+ }
1095
+ return inputElem as HTMLInputElement
1096
+ }
1097
+ return null
1098
+ }
1099
+
1100
+ const editPrivateMethods: TableEditPrivateMethods = {
1101
+ /**
1102
+ * 处理激活编辑
1103
+ */
1104
+ handleEdit(params, evnt, options) {
1105
+ return handleEditActive(
1106
+ params,
1107
+ evnt,
1108
+ Object.assign(
1109
+ {
1110
+ isFocus: true,
1111
+ isPos: true
1112
+ },
1113
+ options
1114
+ )
1115
+ )
1116
+ },
1117
+ /**
1118
+ * @deprecated
1119
+ */
1120
+ handleActived(params, evnt) {
1121
+ return editPrivateMethods.handleEdit(params, evnt)
1122
+ },
1123
+ /**
1124
+ * 处理取消编辑
1125
+ * @param evnt
1126
+ * @returns
1127
+ */
1128
+ handleClearEdit,
1129
+ handleCellFocus,
1130
+ /**
1131
+ * 处理聚焦
1132
+ */
1133
+ handleFocus(params) {
1134
+ const { row, column, cell } = params
1135
+ const { editRender } = column
1136
+ const editOpts = computeEditOpts.value
1137
+ if (isEnableConf(editRender)) {
1138
+ const autoSelect = editRender.autoSelect || editRender.autoselect
1139
+ const inputElem = handleCellFocus(cell, params)
1140
+ if (inputElem) {
1141
+ if (autoSelect) {
1142
+ inputElem.select()
1143
+ } else {
1144
+ // 保持一致行为,光标移到末端
1145
+ if (browseObj.msie) {
1146
+ const textRange = (inputElem as any).createTextRange()
1147
+ textRange.collapse(false)
1148
+ textRange.select()
1149
+ }
1150
+ }
1151
+ } else {
1152
+ // 是否自动定位
1153
+ if (editOpts.autoPos) {
1154
+ if (!column.fixed) {
1155
+ // 显示到可视区中
1156
+ $xeTable.scrollToRow(row, column)
1157
+ }
1158
+ }
1159
+ }
1160
+ }
1161
+ },
1162
+ /**
1163
+ * 处理选中源
1164
+ */
1165
+ handleSelected(params, evnt) {
1166
+ const { mouseConfig, editConfig } = props
1167
+ const { editStore } = reactData
1168
+ const mouseOpts = computeMouseOpts.value
1169
+ const editOpts = computeEditOpts.value
1170
+ const { actived, selected } = editStore
1171
+ const { row, column } = params
1172
+ const isMouseSelected = hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.selected
1173
+ const selectMethod = () => {
1174
+ if (isMouseSelected && (selected.row !== row || selected.column !== column)) {
1175
+ if (actived.row !== row || (editOpts.mode === 'cell' ? actived.column !== column : false)) {
1176
+ handleClearEdit(evnt)
1177
+ $xeTable.clearSelected()
1178
+ if ($xeTable.clearCellAreas) {
1179
+ $xeTable.clearCellAreas()
1180
+ $xeTable.clearCopyCellArea()
1181
+ }
1182
+ selected.args = params
1183
+ selected.row = row
1184
+ selected.column = column
1185
+ if (isMouseSelected) {
1186
+ editPrivateMethods.addCellSelectedClass()
1187
+ }
1188
+ $xeTable.focus()
1189
+ // 如果是支持可复用控件
1190
+ if (editConfig && editOpts.isReuseKeep && isEnableConf(editOpts) && isEnableConf(column.editRender)) {
1191
+ setTimeout(() => {
1192
+ const cell = $xeTable.getCellElement(row, column)
1193
+ if (cell) {
1194
+ const hasReusekeep = cell.querySelector('.vxe-reusekeep-control')
1195
+ if (hasReusekeep) {
1196
+ handleCellFocus(cell, params)
1197
+ }
1198
+ }
1199
+ }, 0)
1200
+ }
1201
+ if (evnt) {
1202
+ $xeTable.dispatchEvent('cell-selected', params, evnt)
1203
+ }
1204
+ }
1205
+ }
1206
+ return nextTick()
1207
+ }
1208
+ return selectMethod()
1209
+ },
1210
+ addCellSelectedClass() {
1211
+ const { editStore } = reactData
1212
+ const { selected } = editStore
1213
+ const { row, column } = selected
1214
+ removeCellSelectedClass()
1215
+ if (row && column) {
1216
+ const cell = $xeTable.getCellElement(row, column)
1217
+ if (cell) {
1218
+ addClass(cell, 'col--selected')
1219
+ }
1220
+ }
1221
+ }
1222
+ }
1223
+
1224
+ return { ...editMethods, ...editPrivateMethods }
1225
+ },
1226
+ setupGrid($xeGrid) {
1227
+ return $xeGrid.extendTableMethods(tableEditMethodKeys)
1228
+ },
1229
+ setupGantt($xeGantt) {
1230
+ return $xeGantt.extendTableMethods(tableEditMethodKeys)
1231
+ }
1232
+ })