vxe-table 3.7.0-beta.12 → 3.7.0-beta.13

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.
@@ -46,6 +46,156 @@ function insertTreeRow (_vm, newRecords, isAppend) {
46
46
  })
47
47
  }
48
48
 
49
+ function handleInsertRowAt (_vm, records, row, isInsertNextRow) {
50
+ const { tableFullTreeData, mergeList, afterFullData, editStore, tableFullData, treeConfig, fullDataRowIdData, fullAllDataRowIdData, treeOpts } = _vm
51
+ const { transform, rowField, mapChildrenField } = treeOpts
52
+ const childrenField = treeOpts.children || treeOpts.childrenField
53
+ if (!XEUtils.isArray(records)) {
54
+ records = [records]
55
+ }
56
+ const newRecords = _vm.defineField(records.map(record => Object.assign(treeConfig && transform ? { [mapChildrenField]: [], [childrenField]: [] } : {}, record)))
57
+ if (!row) {
58
+ // 如果为虚拟树
59
+ if (treeConfig && transform) {
60
+ insertTreeRow(_vm, newRecords, false)
61
+ } else {
62
+ afterFullData.unshift(...newRecords)
63
+ tableFullData.unshift(...newRecords)
64
+ // 刷新单元格合并
65
+ mergeList.forEach(mergeItem => {
66
+ const { row: mergeRowIndex } = mergeItem
67
+ if (mergeRowIndex > 0) {
68
+ mergeItem.row = mergeRowIndex + newRecords.length
69
+ }
70
+ })
71
+ }
72
+ } else {
73
+ if (row === -1) {
74
+ // 如果为虚拟树
75
+ if (treeConfig && transform) {
76
+ insertTreeRow(_vm, newRecords, true)
77
+ } else {
78
+ afterFullData.push(...newRecords)
79
+ tableFullData.push(...newRecords)
80
+ // 刷新单元格合并
81
+ mergeList.forEach(mergeItem => {
82
+ const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
83
+ if (mergeRowIndex + mergeRowspan > afterFullData.length) {
84
+ mergeItem.rowspan = mergeRowspan + newRecords.length
85
+ }
86
+ })
87
+ }
88
+ } else {
89
+ // 如果为虚拟树
90
+ if (treeConfig && transform) {
91
+ const matchMapObj = XEUtils.findTree(tableFullTreeData, item => row[rowField] === item[rowField], { children: mapChildrenField })
92
+ if (matchMapObj) {
93
+ const { parent: parentRow } = matchMapObj
94
+ const parentMapChilds = parentRow ? parentRow[mapChildrenField] : tableFullTreeData
95
+ const parentRest = fullAllDataRowIdData[getRowid(_vm, parentRow)]
96
+ const parentLevel = parentRest ? parentRest.level : 0
97
+ newRecords.forEach((item, i) => {
98
+ const rowid = getRowid(_vm, item)
99
+ if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
100
+ if (item[treeOpts.parentField]) {
101
+ if (parentRow && item[treeOpts.parentField] !== parentRow[rowField]) {
102
+ errLog('vxe.error.errProp', [`${treeOpts.parentField}=${item[treeOpts.parentField]}`, `${treeOpts.parentField}=${parentRow[rowField]}`])
103
+ }
104
+ }
105
+ }
106
+ if (parentRow) {
107
+ item[treeOpts.parentField] = parentRow[rowField]
108
+ }
109
+ let targetIndex = matchMapObj.index + i
110
+ if (isInsertNextRow) {
111
+ targetIndex = targetIndex + 1
112
+ }
113
+ parentMapChilds.splice(targetIndex, 0, item)
114
+ const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, items: parentMapChilds, parent: parentRow, level: parentLevel + 1 }
115
+ fullDataRowIdData[rowid] = rest
116
+ fullAllDataRowIdData[rowid] = rest
117
+ })
118
+
119
+ // 源
120
+ if (parentRow) {
121
+ const matchObj = XEUtils.findTree(tableFullTreeData, item => row[rowField] === item[rowField], { children: childrenField })
122
+ if (matchObj) {
123
+ const parentChilds = matchObj.items
124
+ let targetIndex = matchObj.index
125
+ if (isInsertNextRow) {
126
+ targetIndex = targetIndex + 1
127
+ }
128
+ parentChilds.splice(targetIndex, 0, ...newRecords)
129
+ }
130
+ }
131
+ } else {
132
+ if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
133
+ warnLog('vxe.error.unableInsert')
134
+ }
135
+ insertTreeRow(_vm, newRecords, true)
136
+ }
137
+ } else {
138
+ if (treeConfig) {
139
+ throw new Error(getLog('vxe.error.noTree', ['insert']))
140
+ }
141
+ let afIndex = -1
142
+ // 如果是可视索引
143
+ if (XEUtils.isNumber(row)) {
144
+ if (row < afterFullData.length) {
145
+ afIndex = row
146
+ }
147
+ } else {
148
+ afIndex = _vm.findRowIndexOf(afterFullData, row)
149
+ }
150
+ // 如果是插入指定行的下一行
151
+ if (isInsertNextRow) {
152
+ afIndex = Math.max(afterFullData.length, afIndex + 1)
153
+ }
154
+ if (afIndex === -1) {
155
+ throw new Error(errLog('vxe.error.unableInsert'))
156
+ }
157
+ afterFullData.splice(afIndex, 0, ...newRecords)
158
+ tableFullData.splice(_vm.findRowIndexOf(tableFullData, row), 0, ...newRecords)
159
+ // 刷新单元格合并
160
+ mergeList.forEach(mergeItem => {
161
+ const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
162
+ if (mergeRowIndex > afIndex) {
163
+ mergeItem.row = mergeRowIndex + newRecords.length
164
+ } else if (mergeRowIndex + mergeRowspan > afIndex) {
165
+ mergeItem.rowspan = mergeRowspan + newRecords.length
166
+ }
167
+ })
168
+ }
169
+ }
170
+ }
171
+ const { insertList, insertMaps } = editStore
172
+ newRecords.forEach(newRow => {
173
+ const rowid = getRowid(_vm, newRow)
174
+ insertMaps[rowid] = newRow
175
+ })
176
+ insertList.unshift(...newRecords)
177
+ _vm.cacheRowMap()
178
+ _vm.updateScrollYStatus()
179
+ _vm.handleTableData(treeConfig && transform)
180
+ if (!(treeConfig && transform)) {
181
+ _vm.updateAfterDataIndex()
182
+ }
183
+ _vm.updateFooter()
184
+ _vm.checkSelectionStatus()
185
+ if (_vm.scrollYLoad) {
186
+ _vm.updateScrollYSpace()
187
+ }
188
+ return _vm.$nextTick().then(() => {
189
+ _vm.updateCellAreas()
190
+ return _vm.recalculate()
191
+ }).then(() => {
192
+ return {
193
+ row: newRecords.length ? newRecords[newRecords.length - 1] : null,
194
+ rows: newRecords
195
+ }
196
+ })
197
+ }
198
+
49
199
  export default {
50
200
  methods: {
51
201
  /**
@@ -54,7 +204,7 @@ export default {
54
204
  * @param {*} records
55
205
  */
56
206
  _insert (records) {
57
- return this.insertAt(records)
207
+ return handleInsertRowAt(this, records, null)
58
208
  },
59
209
  /**
60
210
  * 往表格指定行中插入临时数据
@@ -63,133 +213,13 @@ export default {
63
213
  * 如果 row 为有效行则插入到该行的位置
64
214
  * @param {Object/Array} records 新的数据
65
215
  * @param {Row} row 指定行
216
+ * @returns
66
217
  */
67
218
  _insertAt (records, row) {
68
- const { tableFullTreeData, mergeList, afterFullData, editStore, tableFullData, treeConfig, fullDataRowIdData, fullAllDataRowIdData, treeOpts } = this
69
- const { transform, rowField, mapChildrenField } = treeOpts
70
- if (!XEUtils.isArray(records)) {
71
- records = [records]
72
- }
73
- const newRecords = this.defineField(records.map(record => Object.assign({}, record)))
74
- if (!row) {
75
- // 如果为虚拟树
76
- if (treeConfig && transform) {
77
- insertTreeRow(this, newRecords, false)
78
- } else {
79
- afterFullData.unshift(...newRecords)
80
- tableFullData.unshift(...newRecords)
81
- // 刷新单元格合并
82
- mergeList.forEach(mergeItem => {
83
- const { row: mergeRowIndex } = mergeItem
84
- if (mergeRowIndex > 0) {
85
- mergeItem.row = mergeRowIndex + newRecords.length
86
- }
87
- })
88
- }
89
- } else {
90
- if (row === -1) {
91
- // 如果为虚拟树
92
- if (treeConfig && transform) {
93
- insertTreeRow(this, newRecords, true)
94
- } else {
95
- afterFullData.push(...newRecords)
96
- tableFullData.push(...newRecords)
97
- // 刷新单元格合并
98
- mergeList.forEach(mergeItem => {
99
- const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
100
- if (mergeRowIndex + mergeRowspan > afterFullData.length) {
101
- mergeItem.rowspan = mergeRowspan + newRecords.length
102
- }
103
- })
104
- }
105
- } else {
106
- // 如果为虚拟树
107
- if (treeConfig && transform) {
108
- const matchObj = XEUtils.findTree(tableFullTreeData, item => row[rowField] === item[rowField], { children: mapChildrenField })
109
- if (matchObj) {
110
- const { parent: parentRow } = matchObj
111
- const parentChilds = matchObj.items
112
- const parentRest = fullAllDataRowIdData[getRowid(this, parentRow)]
113
- const parentLevel = parentRest ? parentRest.level : 0
114
- newRecords.forEach((item, i) => {
115
- const rowid = getRowid(this, item)
116
- if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
117
- if (item[treeOpts.parentField]) {
118
- if (parentRow && item[treeOpts.parentField] !== parentRow[rowField]) {
119
- errLog('vxe.error.errProp', [`${treeOpts.parentField}=${item[treeOpts.parentField]}`, `${treeOpts.parentField}=${parentRow[rowField]}`])
120
- }
121
- }
122
- }
123
- if (parentRow) {
124
- item[treeOpts.parentField] = parentRow[rowField]
125
- }
126
- parentChilds.splice(matchObj.index + i, 0, item)
127
- const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, items: parentChilds, parent: parentRow, level: parentLevel + 1 }
128
- fullDataRowIdData[rowid] = rest
129
- fullAllDataRowIdData[rowid] = rest
130
- })
131
- } else {
132
- if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
133
- warnLog('vxe.error.unableInsert')
134
- }
135
- insertTreeRow(this, newRecords, true)
136
- }
137
- } else {
138
- if (treeConfig) {
139
- throw new Error(getLog('vxe.error.noTree', ['insert']))
140
- }
141
- let afIndex = -1
142
- // 如果是可视索引
143
- if (XEUtils.isNumber(row)) {
144
- if (row < afterFullData.length) {
145
- afIndex = row
146
- }
147
- } else {
148
- afIndex = this.findRowIndexOf(afterFullData, row)
149
- }
150
- if (afIndex === -1) {
151
- throw new Error(errLog('vxe.error.unableInsert'))
152
- }
153
- afterFullData.splice(afIndex, 0, ...newRecords)
154
- tableFullData.splice(this.findRowIndexOf(tableFullData, row), 0, ...newRecords)
155
- // 刷新单元格合并
156
- mergeList.forEach(mergeItem => {
157
- const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
158
- if (mergeRowIndex > afIndex) {
159
- mergeItem.row = mergeRowIndex + newRecords.length
160
- } else if (mergeRowIndex + mergeRowspan > afIndex) {
161
- mergeItem.rowspan = mergeRowspan + newRecords.length
162
- }
163
- })
164
- }
165
- }
166
- }
167
- const { insertList, insertMaps } = editStore
168
- newRecords.forEach(newRow => {
169
- const rowid = getRowid(this, newRow)
170
- insertMaps[rowid] = newRow
171
- })
172
- insertList.unshift(...newRecords)
173
- this.cacheRowMap()
174
- this.updateScrollYStatus()
175
- this.handleTableData(treeConfig && transform)
176
- if (!(treeConfig && transform)) {
177
- this.updateAfterDataIndex()
178
- }
179
- this.updateFooter()
180
- this.checkSelectionStatus()
181
- if (this.scrollYLoad) {
182
- this.updateScrollYSpace()
183
- }
184
- return this.$nextTick().then(() => {
185
- this.updateCellAreas()
186
- return this.recalculate()
187
- }).then(() => {
188
- return {
189
- row: newRecords.length ? newRecords[newRecords.length - 1] : null,
190
- rows: newRecords
191
- }
192
- })
219
+ return handleInsertRowAt(this, records, row)
220
+ },
221
+ _insertNextAt (records, row) {
222
+ return handleInsertRowAt(this, records, row, true)
193
223
  },
194
224
  /**
195
225
  * 删除指定行数据
@@ -199,10 +229,11 @@ export default {
199
229
  */
200
230
  _remove (rows) {
201
231
  const { afterFullData, tableFullData, tableFullTreeData, treeConfig, mergeList, editStore, checkboxOpts, selectCheckboxRows, isInsertByRow, treeOpts } = this
202
- const { transform } = treeOpts
232
+ const { transform, mapChildrenField } = treeOpts
233
+ const childrenField = treeOpts.children || treeOpts.childrenField
203
234
  const { actived, removeList, insertList, insertMaps } = editStore
204
235
  const { checkField } = checkboxOpts
205
- let rest = []
236
+ let delList = []
206
237
  if (!rows) {
207
238
  rows = tableFullData
208
239
  } else if (!XEUtils.isArray(rows)) {
@@ -225,7 +256,7 @@ export default {
225
256
  }
226
257
  // 从数据源中移除
227
258
  if (tableFullData === rows) {
228
- rows = rest = tableFullData.slice(0)
259
+ rows = delList = tableFullData.slice(0)
229
260
  this.tableFullData = []
230
261
  this.afterFullData = []
231
262
  this.clearMergeCells()
@@ -234,10 +265,14 @@ export default {
234
265
  if (treeConfig && transform) {
235
266
  rows.forEach((row) => {
236
267
  const rowid = getRowid(this, row)
237
- const matchObj = XEUtils.findTree(tableFullTreeData, item => rowid === getRowid(this, item), treeOpts)
268
+ const matchMapObj = XEUtils.findTree(tableFullTreeData, item => rowid === getRowid(this, item), { children: mapChildrenField })
269
+ if (matchMapObj) {
270
+ const rItems = matchMapObj.items.splice(matchMapObj.index, 1)
271
+ delList.push(rItems[0])
272
+ }
273
+ const matchObj = XEUtils.findTree(tableFullTreeData, item => rowid === getRowid(this, item), { children: childrenField })
238
274
  if (matchObj) {
239
- const rItems = matchObj.items.splice(matchObj.index, 1)
240
- rest.push(rItems[0])
275
+ matchObj.items.splice(matchObj.index, 1)
241
276
  }
242
277
  const afIndex = this.findRowIndexOf(afterFullData, row)
243
278
  if (afIndex > -1) {
@@ -249,7 +284,7 @@ export default {
249
284
  const tfIndex = this.findRowIndexOf(tableFullData, row)
250
285
  if (tfIndex > -1) {
251
286
  const rItems = tableFullData.splice(tfIndex, 1)
252
- rest.push(rItems[0])
287
+ delList.push(rItems[0])
253
288
  }
254
289
  const afIndex = this.findRowIndexOf(afterFullData, row)
255
290
  if (afIndex > -1) {
@@ -294,7 +329,7 @@ export default {
294
329
  this.updateCellAreas()
295
330
  return this.recalculate()
296
331
  }).then(() => {
297
- return { row: rest.length ? rest[rest.length - 1] : null, rows: rest }
332
+ return { row: delList.length ? delList[delList.length - 1] : null, rows: delList }
298
333
  })
299
334
  },
300
335
  /**
@@ -4940,7 +4940,7 @@ const Methods = {
4940
4940
  }
4941
4941
 
4942
4942
  // Module methods
4943
- const funcs = 'setFilter,openFilter,clearFilter,getCheckedFilters,closeMenu,setActiveCellArea,getActiveCellArea,getCellAreas,clearCellAreas,copyCellArea,cutCellArea,pasteCellArea,getCopyCellArea,getCopyCellAreas,clearCopyCellArea,setCellAreas,openFind,openReplace,closeFNR,getSelectedCell,clearSelected,insert,insertAt,remove,removeCheckboxRow,removeRadioRow,removeCurrentRow,getRecordset,getInsertRecords,getRemoveRecords,getUpdateRecords,clearEdit,clearActived,getEditRecord,getActiveRecord,isEditByRow,isActiveByRow,setEditRow,setActiveRow,setEditCell,setActiveCell,setSelectCell,clearValidate,fullValidate,validate,openExport,openPrint,exportData,openImport,importData,saveFile,readFile,importByFile,print'.split(',')
4943
+ const funcs = 'setFilter,openFilter,clearFilter,getCheckedFilters,closeMenu,setActiveCellArea,getActiveCellArea,getCellAreas,clearCellAreas,copyCellArea,cutCellArea,pasteCellArea,getCopyCellArea,getCopyCellAreas,clearCopyCellArea,setCellAreas,openFind,openReplace,closeFNR,getSelectedCell,clearSelected,insert,insertAt,insertNextAt,remove,removeCheckboxRow,removeRadioRow,removeCurrentRow,getRecordset,getInsertRecords,getRemoveRecords,getUpdateRecords,clearEdit,clearActived,getEditRecord,getActiveRecord,isEditByRow,isActiveByRow,setEditRow,setActiveRow,setEditCell,setActiveCell,setSelectCell,clearValidate,fullValidate,validate,openExport,openPrint,exportData,openImport,importData,saveFile,readFile,importByFile,print'.split(',')
4944
4944
 
4945
4945
  funcs.forEach(name => {
4946
4946
  Methods[name] = function (...args) {
package/types/table.d.ts CHANGED
@@ -866,6 +866,15 @@ export declare class Table extends VXETableComponent {
866
866
  * @param {Row} row 指定行
867
867
  */
868
868
  insertAt(records: RecordInfo | RecordInfo[], row: RowInfo | -1 | null): Promise<{ row: RowInfo, rows: RowInfo[] }>;
869
+ /**
870
+ * 往表格在指定行中的下一行插入临时数据
871
+ * 如果 row 为空则从插入到顶部,如果为树结构,则插入到目标节点顶部
872
+ * 如果 row 为 -1 则从插入到底部,如果为树结构,则插入到目标节点底部
873
+ * 如果 row 为有效行则插入到该行的下一行位置,如果为树结构,则有插入到效的目标节点该行的下一行位置
874
+ * @param records records 新的数据
875
+ * @param row row 指定行
876
+ */
877
+ insertNextAtt(records: RecordInfo | RecordInfo[], row: RowInfo | -1 | null): Promise<{ row: RowInfo, rows: RowInfo[] }>;
869
878
  /**
870
879
  * 删除指定行数据,指定 row 或 [row, ...] 删除多条数据,如果为空则删除所有数据
871
880
  * @param rows 指定行