vxe-table 4.12.0-beta.7 → 4.12.0-beta.9

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.
@@ -9,7 +9,7 @@ import TableHeaderComponent from './header'
9
9
  import TableFooterComponent from './footer'
10
10
  import tableProps from './props'
11
11
  import tableEmits from './emits'
12
- import { getRowUniqueId, clearTableAllStatus, getRowkey, getRowid, rowToVisible, colToVisible, getCellValue, setCellValue, handleFieldOrColumn, toTreePathSeq, restoreScrollLocation, getRootColumn, getRefElem, getColReMinWidth, updateDeepRowKey, updateFastRowKey } from './util'
12
+ import { getRowUniqueId, clearTableAllStatus, getRowkey, getRowid, rowToVisible, colToVisible, getCellValue, setCellValue, handleRowidOrRow, handleFieldOrColumn, toTreePathSeq, restoreScrollLocation, getRootColumn, getRefElem, getColReMinWidth, updateDeepRowKey, updateFastRowKey } from './util'
13
13
  import { getSlotVNs } from '../../ui/src/vn'
14
14
  import { warnLog, errLog } from '../../ui/src/log'
15
15
  import TableCustomPanelComponent from '../module/custom/panel'
@@ -2367,6 +2367,7 @@ export default defineComponent({
2367
2367
  const childrenField = treeOpts.children || treeOpts.childrenField
2368
2368
  const checkboxOpts = computeCheckboxOpts.value
2369
2369
  const { checkField, reserve, checkMethod } = checkboxOpts
2370
+ // indeterminateField 仅支持读取
2370
2371
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
2371
2372
  const selectRowMaps: Record<string, any> = {}
2372
2373
  /**
@@ -3589,6 +3590,9 @@ export default defineComponent({
3589
3590
 
3590
3591
  tableMethods = {
3591
3592
  dispatchEvent,
3593
+ getEl () {
3594
+ return refElem.value
3595
+ },
3592
3596
  /**
3593
3597
  * 重置表格的一切数据状态
3594
3598
  */
@@ -3889,7 +3893,9 @@ export default defineComponent({
3889
3893
  */
3890
3894
  revertData (rows: any, field) {
3891
3895
  const { keepSource, treeConfig } = props
3896
+ const { editStore } = reactData
3892
3897
  const { fullAllDataRowIdData, fullDataRowIdData, tableSourceData, sourceDataRowIdData, tableFullData, afterFullData } = internalData
3898
+ const removeTempMaps = { ...editStore.removeMaps }
3893
3899
  const treeOpts = computeTreeOpts.value
3894
3900
  const { transform } = treeOpts
3895
3901
  if (!keepSource) {
@@ -3922,6 +3928,7 @@ export default defineComponent({
3922
3928
  XEUtils.destructuring(row, XEUtils.clone(oRow, true))
3923
3929
  }
3924
3930
  if (!fullDataRowIdData[rowid] && $xeTable.isRemoveByRow(row)) {
3931
+ delete removeTempMaps[rowid]
3925
3932
  tableFullData.unshift(row)
3926
3933
  afterFullData.unshift(row)
3927
3934
  reDelFlag = true
@@ -3933,6 +3940,7 @@ export default defineComponent({
3933
3940
  }
3934
3941
  if (rows) {
3935
3942
  if (reDelFlag) {
3943
+ editStore.removeMaps = removeTempMaps
3936
3944
  $xeTable.updateFooter()
3937
3945
  $xeTable.cacheRowMap(false)
3938
3946
  $xeTable.handleTableData(treeConfig && transform)
@@ -4080,18 +4088,20 @@ export default defineComponent({
4080
4088
  },
4081
4089
  /**
4082
4090
  * 检查行或列数据是否发生改变
4083
- * @param {Row} row 行对象
4091
+ * @param {Row} rowidOrRow 行对象、行主键
4084
4092
  * @param {String} field 字段名
4085
4093
  */
4086
- isUpdateByRow (row, field) {
4094
+ isUpdateByRow (rowidOrRow, field) {
4087
4095
  const { keepSource } = props
4088
4096
  const { tableFullColumn, fullDataRowIdData, sourceDataRowIdData } = internalData
4089
4097
  if (keepSource) {
4090
- const rowid = getRowid($xeTable, row)
4098
+ const rowid = XEUtils.isString(rowidOrRow) || XEUtils.isNumber(rowidOrRow) ? rowidOrRow : getRowid($xeTable, rowidOrRow)
4099
+ const rowRest = fullDataRowIdData[rowid]
4091
4100
  // 新增的数据不需要检测
4092
- if (!fullDataRowIdData[rowid]) {
4101
+ if (!rowRest) {
4093
4102
  return false
4094
4103
  }
4104
+ const row = rowRest.row
4095
4105
  const oRow = sourceDataRowIdData[rowid]
4096
4106
  if (oRow) {
4097
4107
  if (arguments.length > 1) {
@@ -4155,6 +4165,92 @@ export default defineComponent({
4155
4165
  tableColumn: reactData.tableColumn.slice(0)
4156
4166
  }
4157
4167
  },
4168
+ /**
4169
+ * 移动列到指定列的位置
4170
+ * @param fieldOrColumn
4171
+ * @param targetFieldOrColumn
4172
+ * @param options
4173
+ */
4174
+ moveColumnTo (fieldOrColumn, targetFieldOrColumn, options) {
4175
+ const { fullColumnIdData, visibleColumn } = internalData
4176
+ const { dragToChild, dragPos, isCrossDrag } = Object.assign({}, options)
4177
+ const dragCol = handleFieldOrColumn($xeTable, fieldOrColumn)
4178
+ let prevDragCol: VxeTableDefines.ColumnInfo | null = null
4179
+ const colRest = dragCol ? fullColumnIdData[dragCol.id] : null
4180
+ let defPos: 'left' | 'right' = 'left'
4181
+ if (XEUtils.isNumber(targetFieldOrColumn)) {
4182
+ if (colRest && targetFieldOrColumn) {
4183
+ let currList = colRest.items
4184
+ let offsetIndex = colRest._index + targetFieldOrColumn
4185
+ if (isCrossDrag) {
4186
+ currList = visibleColumn
4187
+ offsetIndex = colRest._index + targetFieldOrColumn
4188
+ }
4189
+ if (offsetIndex > 0 && offsetIndex < currList.length - 1) {
4190
+ prevDragCol = currList[offsetIndex]
4191
+ }
4192
+ if (targetFieldOrColumn > 0) {
4193
+ defPos = 'right'
4194
+ }
4195
+ }
4196
+ } else {
4197
+ prevDragCol = handleFieldOrColumn($xeTable, targetFieldOrColumn)
4198
+ const targetColRest = prevDragCol ? fullColumnIdData[prevDragCol.id] : null
4199
+ if (colRest && targetColRest) {
4200
+ if (targetColRest._index > colRest._index) {
4201
+ defPos = 'right'
4202
+ }
4203
+ }
4204
+ }
4205
+ return $xeTable.handleColDragSwapEvent(null, true, dragCol, prevDragCol, dragPos || defPos, dragToChild === true)
4206
+ },
4207
+ /**
4208
+ * 移动行到指定行的位置
4209
+ * @param rowidOrRow
4210
+ * @param targetRowidOrRow
4211
+ * @param options
4212
+ */
4213
+ moveRowTo (rowidOrRow, targetRowidOrRow, options) {
4214
+ const { treeConfig } = props
4215
+ const { fullAllDataRowIdData, afterFullData } = internalData
4216
+ const { dragToChild, dragPos, isCrossDrag } = Object.assign({}, options)
4217
+ const treeOpts = computeTreeOpts.value
4218
+ const dragRow = handleRowidOrRow($xeTable, rowidOrRow)
4219
+ let prevDragRow: any = null
4220
+ let defPos: 'top' | 'bottom' = 'top'
4221
+ const rowRest = dragRow ? fullAllDataRowIdData[getRowid($xeTable, dragRow)] : null
4222
+ if (XEUtils.isNumber(targetRowidOrRow)) {
4223
+ if (rowRest && targetRowidOrRow) {
4224
+ let currList = afterFullData
4225
+ let offsetIndex = rowRest._index + targetRowidOrRow
4226
+ if (treeConfig) {
4227
+ currList = rowRest.items
4228
+ if (treeOpts.transform) {
4229
+ offsetIndex = rowRest.treeIndex + targetRowidOrRow
4230
+ if (isCrossDrag) {
4231
+ currList = afterFullData
4232
+ offsetIndex = rowRest._index + targetRowidOrRow
4233
+ }
4234
+ }
4235
+ }
4236
+ if (offsetIndex >= 0 && offsetIndex <= currList.length - 1) {
4237
+ prevDragRow = currList[offsetIndex]
4238
+ }
4239
+ if (targetRowidOrRow > 0) {
4240
+ defPos = 'bottom'
4241
+ }
4242
+ }
4243
+ } else {
4244
+ prevDragRow = handleRowidOrRow($xeTable, targetRowidOrRow)
4245
+ const targetRowRest = prevDragRow ? fullAllDataRowIdData[getRowid($xeTable, prevDragRow)] : null
4246
+ if (rowRest && targetRowRest) {
4247
+ if (targetRowRest._index > rowRest._index) {
4248
+ defPos = 'bottom'
4249
+ }
4250
+ }
4251
+ }
4252
+ return $xeTable.handleRowDragSwapEvent(null, true, dragRow, prevDragRow, dragPos || defPos, dragToChild === true)
4253
+ },
4158
4254
  /**
4159
4255
  * 获取表格的全量列
4160
4256
  */
@@ -4174,6 +4270,7 @@ export default defineComponent({
4174
4270
  */
4175
4271
  getCheckboxRecords (isFull) {
4176
4272
  const { treeConfig } = props
4273
+ const { selectCheckboxMaps } = reactData
4177
4274
  const { tableFullData, afterFullData, afterTreeFullData, tableFullTreeData, fullDataRowIdData, afterFullRowMaps } = internalData
4178
4275
  const treeOpts = computeTreeOpts.value
4179
4276
  const checkboxOpts = computeCheckboxOpts.value
@@ -4181,15 +4278,15 @@ export default defineComponent({
4181
4278
  const { checkField } = checkboxOpts
4182
4279
  const childrenField = treeOpts.children || treeOpts.childrenField
4183
4280
  let rowList: any[] = []
4184
- const currTableData = isFull ? (transform ? tableFullTreeData : tableFullData) : (transform ? afterTreeFullData : afterFullData)
4185
4281
  if (checkField) {
4186
4282
  if (treeConfig) {
4283
+ const currTableData = isFull ? (transform ? tableFullTreeData : tableFullData) : (transform ? afterTreeFullData : afterFullData)
4187
4284
  rowList = XEUtils.filterTree(currTableData, row => XEUtils.get(row, checkField), { children: transform ? mapChildrenField : childrenField })
4188
4285
  } else {
4286
+ const currTableData = isFull ? tableFullData : afterFullData
4189
4287
  rowList = currTableData.filter((row) => XEUtils.get(row, checkField))
4190
4288
  }
4191
4289
  } else {
4192
- const { selectCheckboxMaps } = reactData
4193
4290
  XEUtils.each(selectCheckboxMaps, (row, rowid) => {
4194
4291
  if (isFull) {
4195
4292
  if (fullDataRowIdData[rowid]) {
@@ -4873,6 +4970,7 @@ export default defineComponent({
4873
4970
  const childrenField = treeOpts.children || treeOpts.childrenField
4874
4971
  const checkboxOpts = computeCheckboxOpts.value
4875
4972
  const { checkField, reserve } = checkboxOpts
4973
+ // indeterminateField 仅支持读取
4876
4974
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
4877
4975
  if (checkField) {
4878
4976
  const handleClearChecked = (item: any) => {
@@ -6889,6 +6987,9 @@ export default defineComponent({
6889
6987
  rowRest.level = level
6890
6988
  rowRest.index = currIndex
6891
6989
  rowRest.treeIndex = index
6990
+
6991
+ fullDataRowIdMaps[rowid] = rowRest
6992
+ fullAllDataRowIdMaps[rowid] = rowRest
6892
6993
  }
6893
6994
 
6894
6995
  if (treeConfig) {
@@ -7561,6 +7662,7 @@ export default defineComponent({
7561
7662
  const childrenField = treeOpts.children || treeOpts.childrenField
7562
7663
  const checkboxOpts = computeCheckboxOpts.value
7563
7664
  const { checkField, checkStrictly, checkMethod } = checkboxOpts
7665
+ // indeterminateField 仅支持读取
7564
7666
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
7565
7667
  if (checkField) {
7566
7668
  // 树结构
@@ -8198,6 +8300,9 @@ export default defineComponent({
8198
8300
  const { afterFullData, tableFullData } = internalData
8199
8301
  const dEndMethod = dragEndMethod || (dragConfig ? dragConfig.dragEndMethod : null)
8200
8302
  const dragOffsetIndex = prevDragPos === 'bottom' ? 1 : 0
8303
+ const errRest = {
8304
+ status: false
8305
+ }
8201
8306
  if (prevDragRow && dragRow) {
8202
8307
  // 判断是否有拖动
8203
8308
  if (prevDragRow !== dragRow) {
@@ -8212,7 +8317,7 @@ export default defineComponent({
8212
8317
  const isDragToChildFlag = isSelfToChildDrag && dragToChildMethod ? dragToChildMethod(dragParams) : prevDragToChild
8213
8318
  return Promise.resolve(dEndMethod ? dEndMethod(dragParams) : true).then((status) => {
8214
8319
  if (!status) {
8215
- return
8320
+ return errRest
8216
8321
  }
8217
8322
 
8218
8323
  let oafIndex = -1
@@ -8243,11 +8348,11 @@ export default defineComponent({
8243
8348
  if (isPeerDrag && !isCrossDrag) {
8244
8349
  if (oldRest.row[parentField] !== newRest.row[parentField]) {
8245
8350
  // 非同级
8246
- return
8351
+ return errRest
8247
8352
  }
8248
8353
  } else {
8249
8354
  if (!isCrossDrag) {
8250
- return
8355
+ return errRest
8251
8356
  }
8252
8357
  if (oldAllMaps[newRowid]) {
8253
8358
  isSelfToChildStatus = true
@@ -8258,7 +8363,7 @@ export default defineComponent({
8258
8363
  content: getI18n('vxe.error.treeDragChild')
8259
8364
  })
8260
8365
  }
8261
- return
8366
+ return errRest
8262
8367
  }
8263
8368
  }
8264
8369
  }
@@ -8266,13 +8371,13 @@ export default defineComponent({
8266
8371
  // 子到根
8267
8372
 
8268
8373
  if (!isCrossDrag) {
8269
- return
8374
+ return errRest
8270
8375
  }
8271
8376
  } else if (newLevel) {
8272
8377
  // 根到子
8273
8378
 
8274
8379
  if (!isCrossDrag) {
8275
- return
8380
+ return errRest
8276
8381
  }
8277
8382
  if (oldAllMaps[newRowid]) {
8278
8383
  isSelfToChildStatus = true
@@ -8283,7 +8388,7 @@ export default defineComponent({
8283
8388
  content: getI18n('vxe.error.treeDragChild')
8284
8389
  })
8285
8390
  }
8286
- return
8391
+ return errRest
8287
8392
  }
8288
8393
  }
8289
8394
  } else {
@@ -8347,28 +8452,36 @@ export default defineComponent({
8347
8452
  if (reactData.scrollYLoad) {
8348
8453
  $xeTable.updateScrollYSpace()
8349
8454
  }
8350
- nextTick().then(() => {
8455
+
8456
+ if (evnt) {
8457
+ dispatchEvent('row-dragend', {
8458
+ oldRow: dragRow,
8459
+ newRow: prevDragRow,
8460
+ dragRow,
8461
+ dragPos: prevDragPos as any,
8462
+ dragToChild: isDragToChildFlag,
8463
+ offsetIndex: dragOffsetIndex,
8464
+ _index: {
8465
+ newIndex: nafIndex,
8466
+ oldIndex: oafIndex
8467
+ }
8468
+ }, evnt)
8469
+ }
8470
+
8471
+ return nextTick().then(() => {
8351
8472
  $xeTable.updateCellAreas()
8352
8473
  $xeTable.recalculate()
8353
- })
8354
-
8355
- dispatchEvent('row-dragend', {
8356
- oldRow: dragRow,
8357
- newRow: prevDragRow,
8358
- dragRow,
8359
- dragPos: prevDragPos as any,
8360
- dragToChild: isDragToChildFlag,
8361
- offsetIndex: dragOffsetIndex,
8362
- _index: {
8363
- newIndex: nafIndex,
8364
- oldIndex: oafIndex
8474
+ }).then(() => {
8475
+ return {
8476
+ status: true
8365
8477
  }
8366
- }, evnt)
8478
+ })
8367
8479
  }).catch(() => {
8480
+ return errRest
8368
8481
  })
8369
8482
  }
8370
8483
  }
8371
- return Promise.resolve()
8484
+ return Promise.resolve(errRest)
8372
8485
  },
8373
8486
  handleRowDragDragendEvent (evnt) {
8374
8487
  const { treeConfig } = props
@@ -8493,6 +8606,9 @@ export default defineComponent({
8493
8606
  const { isPeerDrag, isCrossDrag, isSelfToChildDrag, isToChildDrag, dragEndMethod, dragToChildMethod } = columnDragOpts
8494
8607
  const { collectColumn } = internalData
8495
8608
  const dragOffsetIndex = prevDragPos === 'right' ? 1 : 0
8609
+ const errRest = {
8610
+ status: false
8611
+ }
8496
8612
  if (prevDragCol && dragCol) {
8497
8613
  // 判断是否有拖动
8498
8614
  if (prevDragCol !== dragCol) {
@@ -8509,7 +8625,7 @@ export default defineComponent({
8509
8625
  const isDragToChildFlag = isSelfToChildDrag && dragToChildMethod ? dragToChildMethod(dragParams) : prevDragToChild
8510
8626
  return Promise.resolve(dragEndMethod ? dragEndMethod(dragParams) : true).then((status) => {
8511
8627
  if (!status) {
8512
- return
8628
+ return errRest
8513
8629
  }
8514
8630
 
8515
8631
  let oafIndex = -1
@@ -8528,11 +8644,11 @@ export default defineComponent({
8528
8644
  if (isPeerDrag && !isCrossDrag) {
8529
8645
  if (dragColumn.parentId !== newColumn.parentId) {
8530
8646
  // 非同级
8531
- return
8647
+ return errRest
8532
8648
  }
8533
8649
  } else {
8534
8650
  if (!isCrossDrag) {
8535
- return
8651
+ return errRest
8536
8652
  }
8537
8653
 
8538
8654
  if (oldAllMaps[newColumn.id]) {
@@ -8544,7 +8660,7 @@ export default defineComponent({
8544
8660
  content: getI18n('vxe.error.treeDragChild')
8545
8661
  })
8546
8662
  }
8547
- return
8663
+ return errRest
8548
8664
  }
8549
8665
  }
8550
8666
  }
@@ -8552,13 +8668,13 @@ export default defineComponent({
8552
8668
  // 子到根
8553
8669
 
8554
8670
  if (!isCrossDrag) {
8555
- return
8671
+ return errRest
8556
8672
  }
8557
8673
  } else if (newColumn.parentId) {
8558
8674
  // 根到子
8559
8675
 
8560
8676
  if (!isCrossDrag) {
8561
- return
8677
+ return errRest
8562
8678
  }
8563
8679
  if (oldAllMaps[newColumn.id]) {
8564
8680
  isSelfToChildStatus = true
@@ -8569,7 +8685,7 @@ export default defineComponent({
8569
8685
  content: getI18n('vxe.error.treeDragChild')
8570
8686
  })
8571
8687
  }
8572
- return
8688
+ return errRest
8573
8689
  }
8574
8690
  }
8575
8691
  } else {
@@ -8633,27 +8749,34 @@ export default defineComponent({
8633
8749
  }
8634
8750
  }
8635
8751
 
8636
- dispatchEvent('column-dragend', {
8637
- oldColumn: dragColumn,
8638
- newColumn,
8639
- dragColumn,
8640
- dragPos: prevDragPos,
8641
- dragToChild: isDragToChildFlag,
8642
- offsetIndex: dragOffsetIndex,
8643
- _index: {
8644
- newIndex: nafIndex,
8645
- oldIndex: oafIndex
8646
- }
8647
- }, evnt)
8752
+ if (evnt) {
8753
+ dispatchEvent('column-dragend', {
8754
+ oldColumn: dragColumn,
8755
+ newColumn,
8756
+ dragColumn,
8757
+ dragPos: prevDragPos,
8758
+ dragToChild: isDragToChildFlag,
8759
+ offsetIndex: dragOffsetIndex,
8760
+ _index: {
8761
+ newIndex: nafIndex,
8762
+ oldIndex: oafIndex
8763
+ }
8764
+ }, evnt)
8765
+ }
8648
8766
 
8649
8767
  if (isSyncColumn) {
8650
8768
  $xeTable.handleColDragSwapColumn()
8651
8769
  }
8770
+
8771
+ return {
8772
+ status: true
8773
+ }
8652
8774
  }).catch(() => {
8775
+ return errRest
8653
8776
  })
8654
8777
  }
8655
8778
  }
8656
- return Promise.resolve()
8779
+ return Promise.resolve(errRest)
8657
8780
  },
8658
8781
  handleHeaderCellDragDragendEvent (evnt) {
8659
8782
  const { dragCol } = reactData
@@ -146,6 +146,14 @@ export const handleFieldOrColumn = ($xeTable: VxeTableConstructor, fieldOrColumn
146
146
  return null
147
147
  }
148
148
 
149
+ export const handleRowidOrRow = ($xeTable: VxeTableConstructor, rowidOrRow: any) => {
150
+ if (rowidOrRow) {
151
+ const rowid = XEUtils.isString(rowidOrRow) || XEUtils.isNumber(rowidOrRow) ? rowidOrRow : getRowid($xeTable, rowidOrRow)
152
+ return $xeTable.getRowById(rowid)
153
+ }
154
+ return null
155
+ }
156
+
149
157
  function getPaddingLeftRightSize (elem: HTMLElement | null) {
150
158
  if (elem) {
151
159
  const computedStyle = getComputedStyle(elem)