vxe-table 4.23.19 → 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 (124) hide show
  1. package/dist/all.esm.js +283 -251
  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/style.css +4 -1
  12. package/es/table/style.mini.css +1 -1
  13. package/es/ui/abandon.d.ts +82 -0
  14. package/es/ui/abandon.js +90 -0
  15. package/es/ui/index.d.ts +1 -83
  16. package/es/ui/index.js +2 -89
  17. package/es/ui/src/log.js +1 -1
  18. package/es/vxe-table/style.css +4 -1
  19. package/es/vxe-table/style.mini.css +1 -1
  20. package/lib/components.d.ts +1 -3
  21. package/lib/components.js +1 -2
  22. package/lib/esm.index.d.ts +7 -0
  23. package/lib/esm.index.js +39 -0
  24. package/lib/index.umd.js +248 -247
  25. package/lib/index.umd.min.js +3 -3
  26. package/lib/style.css +4 -1
  27. package/lib/style.mini.css +1 -1
  28. package/lib/table/style/style.css +4 -1
  29. package/lib/table/style/style.mini.css +1 -1
  30. package/lib/ui/abandon.d.ts +82 -0
  31. package/lib/ui/abandon.js +110 -0
  32. package/lib/ui/index.d.ts +1 -83
  33. package/lib/ui/index.js +3 -89
  34. package/lib/ui/src/log.js +1 -1
  35. package/lib/vxe-table/style/style.css +4 -1
  36. package/lib/vxe-table/style/style.mini.css +1 -1
  37. package/package.json +1 -1
  38. package/packages/colgroup/index.ts +22 -22
  39. package/packages/column/index.ts +22 -22
  40. package/packages/components.ts +42 -45
  41. package/packages/esm.index.ts +10 -0
  42. package/packages/grid/index.ts +18 -18
  43. package/packages/grid/src/emits.ts +5 -5
  44. package/packages/grid/src/grid.ts +2220 -2220
  45. package/packages/grid/src/props.ts +22 -22
  46. package/packages/index.ts +13 -13
  47. package/packages/locale/lang/ar-EG.ts +914 -914
  48. package/packages/locale/lang/de-DE.ts +914 -914
  49. package/packages/locale/lang/en-US.ts +914 -914
  50. package/packages/locale/lang/es-ES.ts +914 -914
  51. package/packages/locale/lang/fr-FR.ts +914 -914
  52. package/packages/locale/lang/hu-HU.ts +914 -914
  53. package/packages/locale/lang/hy-AM.ts +914 -914
  54. package/packages/locale/lang/id-ID.ts +914 -914
  55. package/packages/locale/lang/it-IT.ts +914 -914
  56. package/packages/locale/lang/ja-JP.ts +914 -914
  57. package/packages/locale/lang/ko-KR.ts +914 -914
  58. package/packages/locale/lang/ms-MY.ts +914 -914
  59. package/packages/locale/lang/nb-NO.ts +914 -914
  60. package/packages/locale/lang/pt-BR.ts +914 -914
  61. package/packages/locale/lang/ru-RU.ts +914 -914
  62. package/packages/locale/lang/th-TH.ts +914 -914
  63. package/packages/locale/lang/ug-CN.ts +914 -914
  64. package/packages/locale/lang/uk-UA.ts +914 -914
  65. package/packages/locale/lang/uz-UZ.ts +914 -914
  66. package/packages/locale/lang/vi-VN.ts +914 -914
  67. package/packages/locale/lang/zh-CHT.ts +914 -914
  68. package/packages/locale/lang/zh-CN.ts +914 -914
  69. package/packages/locale/lang/zh-HK.ts +914 -914
  70. package/packages/locale/lang/zh-MO.ts +914 -914
  71. package/packages/locale/lang/zh-TC.ts +914 -914
  72. package/packages/locale/lang/zh-TW.ts +914 -914
  73. package/packages/table/index.ts +26 -26
  74. package/packages/table/module/custom/hook.ts +510 -510
  75. package/packages/table/module/custom/panel.ts +2002 -2002
  76. package/packages/table/module/edit/hook.ts +1232 -1232
  77. package/packages/table/module/export/export-panel.ts +697 -697
  78. package/packages/table/module/export/hook.ts +2158 -2158
  79. package/packages/table/module/export/import-panel.ts +319 -319
  80. package/packages/table/module/export/util.ts +25 -25
  81. package/packages/table/module/filter/hook.ts +505 -505
  82. package/packages/table/module/filter/panel.ts +368 -368
  83. package/packages/table/module/keyboard/hook.ts +498 -498
  84. package/packages/table/module/menu/hook.ts +330 -330
  85. package/packages/table/module/menu/panel.ts +272 -272
  86. package/packages/table/module/validator/hook.ts +653 -653
  87. package/packages/table/render/index.ts +1819 -1819
  88. package/packages/table/src/body.ts +1078 -1078
  89. package/packages/table/src/cell.ts +1524 -1524
  90. package/packages/table/src/column.ts +192 -192
  91. package/packages/table/src/columnInfo.ts +232 -232
  92. package/packages/table/src/emits.ts +134 -134
  93. package/packages/table/src/footer.ts +425 -425
  94. package/packages/table/src/group.ts +67 -67
  95. package/packages/table/src/header.ts +661 -661
  96. package/packages/table/src/props.ts +336 -336
  97. package/packages/table/src/store.ts +14 -14
  98. package/packages/table/src/use/cell-view.ts +41 -41
  99. package/packages/table/src/use/index.ts +1 -1
  100. package/packages/table/src/util.ts +1206 -1206
  101. package/packages/toolbar/index.ts +18 -18
  102. package/packages/toolbar/src/toolbar.ts +768 -768
  103. package/packages/ui/abandon.ts +136 -0
  104. package/packages/ui/index.ts +404 -524
  105. package/packages/ui/src/anime.ts +51 -51
  106. package/packages/ui/src/comp.ts +3 -3
  107. package/packages/ui/src/dom.ts +466 -466
  108. package/packages/ui/src/log.ts +19 -19
  109. package/packages/ui/src/utils.ts +66 -66
  110. package/packages/ui/src/vn.ts +55 -55
  111. package/packages/v-x-e-table/index.d.ts +3 -3
  112. package/packages/v-x-e-table/index.ts +3 -3
  113. package/styles/components/table.scss +2 -1
  114. package/types/all.d.ts +76 -76
  115. package/types/index.d.ts +4 -4
  116. /package/dist/{iconfont.1794474448348.ttf → iconfont.1794633824975.ttf} +0 -0
  117. /package/dist/{iconfont.1794474448348.woff → iconfont.1794633824975.woff} +0 -0
  118. /package/dist/{iconfont.1794474448348.woff2 → iconfont.1794633824975.woff2} +0 -0
  119. /package/es/{iconfont.1794474448348.ttf → iconfont.1794633824975.ttf} +0 -0
  120. /package/es/{iconfont.1794474448348.woff → iconfont.1794633824975.woff} +0 -0
  121. /package/es/{iconfont.1794474448348.woff2 → iconfont.1794633824975.woff2} +0 -0
  122. /package/lib/{iconfont.1794474448348.ttf → iconfont.1794633824975.ttf} +0 -0
  123. /package/lib/{iconfont.1794474448348.woff → iconfont.1794633824975.woff} +0 -0
  124. /package/lib/{iconfont.1794474448348.woff2 → iconfont.1794633824975.woff2} +0 -0
@@ -1,1232 +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
- 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
- })
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
+ })