vxe-table 3.7.0-beta.15 → 3.7.0-beta.17

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 (56) hide show
  1. package/README.md +1 -1
  2. package/lib/edit/src/mixin.js +6 -4
  3. package/lib/edit/src/mixin.min.js +1 -1
  4. package/lib/export/src/mixin.js +4 -1
  5. package/lib/export/src/mixin.min.js +1 -1
  6. package/lib/icon/style/style.css +1 -1
  7. package/lib/icon/style/style.min.css +1 -1
  8. package/lib/index.css +1 -1
  9. package/lib/index.umd.js +663 -428
  10. package/lib/index.umd.min.js +1 -1
  11. package/lib/input/src/input.js +24 -1
  12. package/lib/input/src/input.min.js +1 -1
  13. package/lib/input/style/style.css +21 -0
  14. package/lib/input/style/style.min.css +1 -1
  15. package/lib/keyboard/src/mixin.js +4 -1
  16. package/lib/keyboard/src/mixin.min.js +1 -1
  17. package/lib/style.css +1 -1
  18. package/lib/style.min.css +1 -1
  19. package/lib/table/src/body.js +10 -8
  20. package/lib/table/src/body.min.js +1 -1
  21. package/lib/table/src/cell.js +20 -16
  22. package/lib/table/src/cell.min.js +1 -1
  23. package/lib/table/src/methods.js +573 -379
  24. package/lib/table/src/methods.min.js +1 -1
  25. package/lib/table/src/table.js +15 -13
  26. package/lib/table/src/table.min.js +1 -1
  27. package/lib/table/style/style.css +2 -2
  28. package/lib/table/style/style.min.css +1 -1
  29. package/lib/tools/log.js +1 -1
  30. package/lib/tools/log.min.js +1 -1
  31. package/lib/v-x-e-table/index.js +1 -1
  32. package/lib/v-x-e-table/index.min.js +1 -1
  33. package/lib/validator/src/mixin.js +4 -1
  34. package/lib/validator/src/mixin.min.js +1 -1
  35. package/package.json +4 -9
  36. package/packages/edit/src/mixin.js +7 -5
  37. package/packages/export/src/mixin.js +2 -1
  38. package/packages/input/src/input.js +24 -1
  39. package/packages/keyboard/src/mixin.js +2 -1
  40. package/packages/table/src/body.js +10 -8
  41. package/packages/table/src/cell.js +18 -14
  42. package/packages/table/src/methods.js +408 -202
  43. package/packages/table/src/table.js +15 -13
  44. package/packages/validator/src/mixin.js +2 -1
  45. package/styles/css-variable.scss +3 -3
  46. package/styles/input.scss +25 -0
  47. package/styles/table.scss +6 -2
  48. package/styles/textarea.scss +3 -3
  49. package/styles/variable.scss +3 -3
  50. package/types/v-x-e-table/index.d.ts +1 -1
  51. /package/lib/icon/style/{iconfont.1692577739980.ttf → iconfont.1693628087676.ttf} +0 -0
  52. /package/lib/icon/style/{iconfont.1692577739980.woff → iconfont.1693628087676.woff} +0 -0
  53. /package/lib/icon/style/{iconfont.1692577739980.woff2 → iconfont.1693628087676.woff2} +0 -0
  54. /package/lib/{iconfont.1692577739980.ttf → iconfont.1693628087676.ttf} +0 -0
  55. /package/lib/{iconfont.1692577739980.woff → iconfont.1693628087676.woff} +0 -0
  56. /package/lib/{iconfont.1692577739980.woff2 → iconfont.1693628087676.woff2} +0 -0
@@ -52,9 +52,15 @@ function getCustomStorageMap (key) {
52
52
  return rest && rest._v === version ? rest : { _v: version }
53
53
  }
54
54
 
55
- function getRecoverRow (_vm, list) {
56
- const { fullAllDataRowMap } = _vm
57
- return list.filter(row => fullAllDataRowMap.has(row))
55
+ const getRecoverRowMaps = (_vm, keyMaps) => {
56
+ const { fullAllDataRowIdData } = _vm
57
+ const restKeys = {}
58
+ XEUtils.each(keyMaps, (row, rowid) => {
59
+ if (fullAllDataRowIdData[rowid]) {
60
+ restKeys[rowid] = row
61
+ }
62
+ })
63
+ return restKeys
58
64
  }
59
65
 
60
66
  function handleReserveRow (_vm, reserveRowMap) {
@@ -623,7 +629,7 @@ const Methods = {
623
629
  fullAllDataRowIdData = this.fullAllDataRowIdData = {}
624
630
  fullAllDataRowMap.clear()
625
631
  if (treeConfig) {
626
- XEUtils.eachTree(tableFullTreeData, handleCache, treeOpts)
632
+ XEUtils.eachTree(tableFullTreeData, handleCache, { children: childrenField })
627
633
  } else {
628
634
  tableFullData.forEach(handleCache)
629
635
  }
@@ -646,14 +652,15 @@ const Methods = {
646
652
  }
647
653
  // 源数据缓存
648
654
  if (treeConfig && !treeOpts.transform) {
649
- XEUtils.eachTree(sourceData, handleSourceRow, treeOpts)
655
+ const childrenField = treeOpts.children || treeOpts.childrenField
656
+ XEUtils.eachTree(sourceData, handleSourceRow, { children: treeOpts.transform ? treeOpts.mapChildrenField : childrenField })
650
657
  } else {
651
658
  sourceData.forEach(handleSourceRow)
652
659
  }
653
660
  this.tableSourceData = sourceData
654
661
  },
655
662
  loadTreeChildren (row, childRecords) {
656
- const { keepSource, tableSourceData, treeOpts, fullDataRowIdData, fullDataRowMap, fullAllDataRowMap, fullAllDataRowIdData } = this
663
+ const { keepSource, tableSourceData, treeOpts, fullDataRowIdData, fullDataRowMap, fullAllDataRowMap, fullAllDataRowIdData, sourceDataRowIdData } = this
657
664
  const { transform, mapChildrenField } = treeOpts
658
665
  const childrenField = treeOpts.children || treeOpts.childrenField
659
666
  const rest = fullAllDataRowIdData[getRowid(this, row)]
@@ -661,10 +668,14 @@ const Methods = {
661
668
  return this.createData(childRecords).then((rows) => {
662
669
  if (keepSource) {
663
670
  const rowid = getRowid(this, row)
664
- const matchObj = XEUtils.findTree(tableSourceData, (item) => rowid === getRowid(this, item), treeOpts)
671
+ const matchObj = XEUtils.findTree(tableSourceData, (item) => rowid === getRowid(this, item), { children: childrenField })
665
672
  if (matchObj) {
666
673
  matchObj.item[childrenField] = XEUtils.clone(rows, true)
667
674
  }
675
+ rows.forEach(childRow => {
676
+ const rowid = getRowid(this, childRow)
677
+ sourceDataRowIdData[rowid] = XEUtils.clone(childRow, true)
678
+ })
668
679
  }
669
680
  XEUtils.eachTree(rows, (childRow, index, items, path, parent, nodes) => {
670
681
  const rowid = getRowid(this, childRow)
@@ -673,7 +684,7 @@ const Methods = {
673
684
  fullDataRowMap.set(childRow, rest)
674
685
  fullAllDataRowIdData[rowid] = rest
675
686
  fullAllDataRowMap.set(childRow, rest)
676
- }, treeOpts)
687
+ }, { children: childrenField })
677
688
  row[childrenField] = rows
678
689
  if (transform) {
679
690
  row[mapChildrenField] = rows
@@ -1160,7 +1171,7 @@ const Methods = {
1160
1171
  * 用于多选行,获取已选中的数据
1161
1172
  */
1162
1173
  getCheckboxRecords (isFull) {
1163
- const { tableFullData, afterFullData, treeConfig, treeOpts, checkboxOpts, tableFullTreeData, afterTreeFullData } = this
1174
+ const { tableFullData, afterFullData, treeConfig, treeOpts, checkboxOpts, tableFullTreeData, afterTreeFullData, afterFullRowMaps } = this
1164
1175
  const { transform, mapChildrenField } = treeOpts
1165
1176
  const { checkField } = checkboxOpts
1166
1177
  const childrenField = treeOpts.children || treeOpts.childrenField
@@ -1173,12 +1184,12 @@ const Methods = {
1173
1184
  rowList = currTableData.filter(row => XEUtils.get(row, checkField))
1174
1185
  }
1175
1186
  } else {
1176
- const { selectCheckboxRows } = this
1177
- if (treeConfig) {
1178
- rowList = XEUtils.filterTree(currTableData, row => this.findRowIndexOf(selectCheckboxRows, row) > -1, { children: transform ? mapChildrenField : childrenField })
1179
- } else {
1180
- rowList = currTableData.filter(row => this.findRowIndexOf(selectCheckboxRows, row) > -1)
1181
- }
1187
+ const { selectCheckboxMaps, fullDataRowIdData } = this
1188
+ XEUtils.each(selectCheckboxMaps, (row, rowid) => {
1189
+ if (isFull ? fullDataRowIdData[rowid] : afterFullRowMaps[rowid]) {
1190
+ rowList.push(row)
1191
+ }
1192
+ })
1182
1193
  }
1183
1194
  return rowList
1184
1195
  },
@@ -1187,13 +1198,15 @@ const Methods = {
1187
1198
  * @returns
1188
1199
  */
1189
1200
  handleVirtualTreeToList () {
1190
- const { treeOpts, treeConfig, treeExpandeds, afterTreeFullData, afterFullData } = this
1201
+ const { treeOpts, treeConfig, treeExpandedMaps, afterTreeFullData, afterFullData } = this
1191
1202
  if (treeConfig && treeOpts.transform) {
1192
1203
  const fullData = []
1193
- const expandMaps = new Map()
1204
+ const expandMaps = {}
1194
1205
  XEUtils.eachTree(afterTreeFullData, (row, index, items, path, parent) => {
1195
- if (!parent || (expandMaps.has(parent) && treeExpandeds.indexOf(parent) > -1)) {
1196
- expandMaps.set(row, 1)
1206
+ const rowid = getRowid(this, row)
1207
+ const parentRowid = getRowid(this, parent)
1208
+ if (!parent || (expandMaps[parentRowid] && treeExpandedMaps[parentRowid])) {
1209
+ expandMaps[rowid] = 1
1197
1210
  fullData.push(row)
1198
1211
  }
1199
1212
  }, { children: treeOpts.mapChildrenField })
@@ -1321,6 +1334,7 @@ const Methods = {
1321
1334
  updateAfterDataIndex () {
1322
1335
  const { treeConfig, afterFullData, fullDataRowIdData, fullAllDataRowIdData, afterTreeFullData, treeOpts } = this
1323
1336
  const childrenField = treeOpts.children || treeOpts.childrenField
1337
+ const fullMaps = {}
1324
1338
  if (treeConfig) {
1325
1339
  XEUtils.eachTree(afterTreeFullData, (row, index, items, path) => {
1326
1340
  const rowid = getRowid(this, row)
@@ -1334,6 +1348,7 @@ const Methods = {
1334
1348
  fullAllDataRowIdData[rowid] = rest
1335
1349
  fullDataRowIdData[rowid] = rest
1336
1350
  }
1351
+ fullMaps[rowid] = row
1337
1352
  }, { children: treeOpts.transform ? treeOpts.mapChildrenField : childrenField })
1338
1353
  } else {
1339
1354
  afterFullData.forEach((row, index) => {
@@ -1348,8 +1363,10 @@ const Methods = {
1348
1363
  fullAllDataRowIdData[rowid] = rest
1349
1364
  fullDataRowIdData[rowid] = rest
1350
1365
  }
1366
+ fullMaps[rowid] = row
1351
1367
  })
1352
1368
  }
1369
+ this.afterFullRowMaps = fullMaps
1353
1370
  },
1354
1371
  /**
1355
1372
  * 只对 tree-config 有效,获取行的父级
@@ -2520,6 +2537,7 @@ const Methods = {
2520
2537
  const operArrow = isLeftArrow || isUpArrow || isRightArrow || isDwArrow
2521
2538
  const operCtxMenu = isCtxMenu && ctxMenuStore.visible && (isEnter || isSpacebar || operArrow)
2522
2539
  const isEditStatus = isEnableConf(editConfig) && actived.column && actived.row
2540
+ const childrenField = treeOpts.children || treeOpts.childrenField
2523
2541
  let params
2524
2542
  if (filterStore.visible) {
2525
2543
  if (isEsc) {
@@ -2592,7 +2610,7 @@ const Methods = {
2592
2610
  }
2593
2611
  } else if (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2594
2612
  // 如果是树形表格当前行回车移动到子节点
2595
- const childrens = currentRow[treeOpts.children]
2613
+ const childrens = currentRow[childrenField]
2596
2614
  if (childrens && childrens.length) {
2597
2615
  evnt.preventDefault()
2598
2616
  const targetRow = childrens[0]
@@ -2654,7 +2672,7 @@ const Methods = {
2654
2672
  }
2655
2673
  } else if (isBack && keyboardOpts.isArrow && treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2656
2674
  // 如果树形表格回退键关闭当前行返回父节点
2657
- const { parent: parentRow } = XEUtils.findTree(this.afterFullData, item => item === currentRow, treeOpts)
2675
+ const { parent: parentRow } = XEUtils.findTree(this.afterFullData, item => item === currentRow, { children: childrenField })
2658
2676
  if (parentRow) {
2659
2677
  evnt.preventDefault()
2660
2678
  params = { $table: this, row: parentRow }
@@ -2920,12 +2938,22 @@ const Methods = {
2920
2938
  * 获取复选框半选状态的行数据
2921
2939
  */
2922
2940
  getCheckboxIndeterminateRecords (isFull) {
2923
- const { treeConfig, treeIndeterminates, fullDataRowIdData } = this
2941
+ const { treeConfig, treeIndeterminateMaps, fullDataRowIdData } = this
2924
2942
  if (treeConfig) {
2925
- return isFull ? treeIndeterminates.slice(0) : treeIndeterminates.filter(row => {
2926
- const rowid = getRowid(this, row)
2927
- return fullDataRowIdData[rowid]
2943
+ const fullRest = []
2944
+ const defRest = []
2945
+ XEUtils.each(treeIndeterminateMaps, (item, rowid) => {
2946
+ if (item) {
2947
+ fullRest.push(item)
2948
+ if (fullDataRowIdData[rowid]) {
2949
+ defRest.push(item)
2950
+ }
2951
+ }
2928
2952
  })
2953
+ if (isFull) {
2954
+ return fullRest
2955
+ }
2956
+ return defRest
2929
2957
  }
2930
2958
  return []
2931
2959
  },
@@ -2963,29 +2991,36 @@ const Methods = {
2963
2991
  return this.handleCheckedCheckboxRow(rows, value, true)
2964
2992
  },
2965
2993
  isCheckedByCheckboxRow (row) {
2966
- const { selectCheckboxRows } = this
2994
+ const { selectCheckboxMaps } = this
2967
2995
  const { checkField } = this.checkboxOpts
2968
2996
  if (checkField) {
2969
2997
  return XEUtils.get(row, checkField)
2970
2998
  }
2971
- return this.findRowIndexOf(selectCheckboxRows, row) > -1
2999
+ return !!selectCheckboxMaps[getRowid(this, row)]
2972
3000
  },
2973
3001
  isIndeterminateByCheckboxRow (row) {
2974
- const { treeIndeterminates } = this
2975
- return this.findRowIndexOf(treeIndeterminates, row) > -1 && !this.isCheckedByCheckboxRow(row)
3002
+ const { treeIndeterminateMaps } = this
3003
+ return !!treeIndeterminateMaps[getRowid(this, row)] && !this.isCheckedByCheckboxRow(row)
2976
3004
  },
2977
3005
  /**
2978
3006
  * 多选,行选中事件
2979
3007
  * value 选中true 不选false 半选-1
2980
3008
  */
2981
3009
  handleSelectRow ({ row }, value, isForce) {
2982
- const { selectCheckboxRows, afterFullData, treeConfig, treeOpts, treeIndeterminates, checkboxOpts } = this
3010
+ const { selectCheckboxMaps, afterFullData, treeConfig, treeOpts, treeIndeterminateMaps, checkboxOpts } = this
2983
3011
  const { checkField, checkStrictly, checkMethod } = checkboxOpts
3012
+ const selectRowMaps = { ...selectCheckboxMaps }
3013
+ const childrenField = treeOpts.children || treeOpts.childrenField
3014
+ const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
3015
+ const rowid = getRowid(this, row)
2984
3016
  if (checkField) {
2985
3017
  if (treeConfig && !checkStrictly) {
2986
3018
  if (value === -1) {
2987
- if (this.findRowIndexOf(treeIndeterminates, row) === -1) {
2988
- treeIndeterminates.push(row)
3019
+ if (!treeIndeterminateMaps[rowid]) {
3020
+ if (indeterminateField) {
3021
+ XEUtils.set(row, indeterminateField, true)
3022
+ }
3023
+ treeIndeterminateMaps[rowid] = row
2989
3024
  }
2990
3025
  XEUtils.set(row, checkField, false)
2991
3026
  } else {
@@ -2993,23 +3028,48 @@ const Methods = {
2993
3028
  XEUtils.eachTree([row], (item) => {
2994
3029
  if (this.eqRow(item, row) || (isForce || (!checkMethod || checkMethod({ row: item })))) {
2995
3030
  XEUtils.set(item, checkField, value)
2996
- XEUtils.remove(treeIndeterminates, half => this.eqRow(half, item))
3031
+ if (indeterminateField) {
3032
+ XEUtils.set(row, indeterminateField, false)
3033
+ }
3034
+ delete treeIndeterminateMaps[getRowid(this, item)]
2997
3035
  this.handleCheckboxReserveRow(row, value)
2998
3036
  }
2999
- }, treeOpts)
3037
+ }, { children: childrenField })
3000
3038
  }
3001
3039
  // 如果存在父节点,更新父节点状态
3002
- const matchObj = XEUtils.findTree(afterFullData, item => this.eqRow(item, row), treeOpts)
3040
+ const matchObj = XEUtils.findTree(afterFullData, item => this.eqRow(item, row), { children: childrenField })
3003
3041
  if (matchObj && matchObj.parent) {
3004
3042
  let parentStatus
3005
- const vItems = !isForce && checkMethod ? matchObj.items.filter((item) => checkMethod({ row: item })) : matchObj.items
3006
- const indeterminatesItem = XEUtils.find(matchObj.items, item => this.findRowIndexOf(treeIndeterminates, item) > -1)
3043
+ const vItems = []
3044
+ const vItemMaps = {}
3045
+ if (!isForce && checkMethod) {
3046
+ matchObj.items.forEach((item) => {
3047
+ if (checkMethod({ row: item })) {
3048
+ const itemRid = getRowid(this, item)
3049
+ vItemMaps[itemRid] = item
3050
+ vItems.push(item)
3051
+ }
3052
+ })
3053
+ } else {
3054
+ matchObj.items.forEach(item => {
3055
+ const itemRid = getRowid(this, item)
3056
+ vItemMaps[itemRid] = item
3057
+ vItems.push(item)
3058
+ })
3059
+ }
3060
+ const indeterminatesItem = XEUtils.find(matchObj.items, item => !!treeIndeterminateMaps[getRowid(this, item)])
3007
3061
  if (indeterminatesItem) {
3008
3062
  parentStatus = -1
3009
3063
  } else {
3010
- const selectItems = matchObj.items.filter(item => XEUtils.get(item, checkField))
3011
- parentStatus = selectItems.filter(item => this.findRowIndexOf(vItems, item) > -1).length === vItems.length ? true : (selectItems.length || value === -1 ? -1 : false)
3064
+ const selectItems = []
3065
+ matchObj.items.forEach(item => {
3066
+ if (XEUtils.get(item, checkField)) {
3067
+ selectItems.push(item)
3068
+ }
3069
+ })
3070
+ parentStatus = selectItems.filter(item => vItemMaps[getRowid(this, item)]).length === vItems.length ? true : (selectItems.length || value === -1 ? -1 : false)
3012
3071
  }
3072
+ this.selectCheckboxMaps = selectRowMaps
3013
3073
  return this.handleSelectRow({ row: matchObj.parent }, parentStatus, isForce)
3014
3074
  }
3015
3075
  } else {
@@ -3021,58 +3081,100 @@ const Methods = {
3021
3081
  } else {
3022
3082
  if (treeConfig && !checkStrictly) {
3023
3083
  if (value === -1) {
3024
- if (this.findRowIndexOf(treeIndeterminates, row) === -1) {
3025
- treeIndeterminates.push(row)
3084
+ if (!treeIndeterminateMaps[rowid]) {
3085
+ if (indeterminateField) {
3086
+ XEUtils.set(row, indeterminateField, true)
3087
+ }
3088
+ treeIndeterminateMaps[rowid] = row
3089
+ }
3090
+ if (selectRowMaps[rowid]) {
3091
+ delete selectRowMaps[rowid]
3026
3092
  }
3027
- XEUtils.remove(selectCheckboxRows, item => this.eqRow(item, row))
3028
3093
  } else {
3029
3094
  // 更新子节点状态
3030
3095
  XEUtils.eachTree([row], (item) => {
3096
+ const itemRid = getRowid(this, item)
3031
3097
  if (this.eqRow(item, row) || (isForce || (!checkMethod || checkMethod({ row: item })))) {
3032
3098
  if (value) {
3033
- selectCheckboxRows.push(item)
3099
+ selectRowMaps[itemRid] = item
3034
3100
  } else {
3035
- XEUtils.remove(selectCheckboxRows, select => this.eqRow(select, item))
3101
+ if (selectRowMaps[itemRid]) {
3102
+ delete selectRowMaps[itemRid]
3103
+ }
3036
3104
  }
3037
- XEUtils.remove(treeIndeterminates, half => this.eqRow(half, item))
3105
+ if (indeterminateField) {
3106
+ XEUtils.set(row, indeterminateField, false)
3107
+ }
3108
+ delete treeIndeterminateMaps[getRowid(this, item)]
3038
3109
  this.handleCheckboxReserveRow(row, value)
3039
3110
  }
3040
- }, treeOpts)
3111
+ }, { children: childrenField })
3041
3112
  }
3042
3113
  // 如果存在父节点,更新父节点状态
3043
- const matchObj = XEUtils.findTree(afterFullData, item => this.eqRow(item, row), treeOpts)
3114
+ const matchObj = XEUtils.findTree(afterFullData, item => this.eqRow(item, row), { children: childrenField })
3044
3115
  if (matchObj && matchObj.parent) {
3045
3116
  let parentStatus
3046
- const vItems = !isForce && checkMethod ? matchObj.items.filter((item) => checkMethod({ row: item })) : matchObj.items
3047
- const indeterminatesItem = XEUtils.find(matchObj.items, item => this.findRowIndexOf(treeIndeterminates, item) > -1)
3117
+ const vItems = []
3118
+ const vItemMaps = {}
3119
+ if (!isForce && checkMethod) {
3120
+ matchObj.items.forEach((item) => {
3121
+ if (checkMethod({ row: item })) {
3122
+ const itemRid = getRowid(this, item)
3123
+ vItemMaps[itemRid] = item
3124
+ vItems.push(item)
3125
+ }
3126
+ })
3127
+ } else {
3128
+ matchObj.items.forEach(item => {
3129
+ const itemRid = getRowid(this, item)
3130
+ vItemMaps[itemRid] = item
3131
+ vItems.push(item)
3132
+ })
3133
+ }
3134
+ const indeterminatesItem = XEUtils.find(matchObj.items, item => !!treeIndeterminateMaps[getRowid(this, item)])
3048
3135
  if (indeterminatesItem) {
3049
3136
  parentStatus = -1
3050
3137
  } else {
3051
- const selectItems = matchObj.items.filter(item => this.findRowIndexOf(selectCheckboxRows, item) > -1)
3052
- parentStatus = selectItems.filter(item => this.findRowIndexOf(vItems, item) > -1).length === vItems.length ? true : (selectItems.length || value === -1 ? -1 : false)
3138
+ const selectItems = []
3139
+ matchObj.items.forEach(item => {
3140
+ const itemRid = getRowid(this, item)
3141
+ if (selectRowMaps[itemRid]) {
3142
+ selectItems.push(item)
3143
+ }
3144
+ })
3145
+ parentStatus = selectItems.filter(item => vItemMaps[getRowid(this, item)]).length === vItems.length ? true : (selectItems.length || value === -1 ? -1 : false)
3053
3146
  }
3147
+ this.selectCheckboxMaps = selectRowMaps
3054
3148
  return this.handleSelectRow({ row: matchObj.parent }, parentStatus, isForce)
3055
3149
  }
3056
3150
  } else {
3057
3151
  if (isForce || (!checkMethod || checkMethod({ row }))) {
3058
3152
  if (value) {
3059
- if (this.findRowIndexOf(selectCheckboxRows, row) === -1) {
3060
- selectCheckboxRows.push(row)
3153
+ if (!selectRowMaps[rowid]) {
3154
+ selectRowMaps[rowid] = row
3061
3155
  }
3062
3156
  } else {
3063
- XEUtils.remove(selectCheckboxRows, item => this.eqRow(item, row))
3157
+ if (selectRowMaps[rowid]) {
3158
+ delete selectRowMaps[rowid]
3159
+ }
3064
3160
  }
3065
3161
  this.handleCheckboxReserveRow(row, value)
3066
3162
  }
3067
3163
  }
3068
3164
  }
3165
+ this.selectCheckboxMaps = selectRowMaps
3069
3166
  this.checkSelectionStatus()
3070
3167
  },
3071
3168
  handleToggleCheckRowEvent (evnt, params) {
3072
- const { selectCheckboxRows, checkboxOpts } = this
3169
+ const { selectCheckboxMaps, checkboxOpts } = this
3073
3170
  const { checkField } = checkboxOpts
3074
3171
  const { row } = params
3075
- const value = checkField ? !XEUtils.get(row, checkField) : this.findRowIndexOf(selectCheckboxRows, row) === -1
3172
+ let value = false
3173
+ if (checkField) {
3174
+ value = !XEUtils.get(row, checkField)
3175
+ } else {
3176
+ value = !selectCheckboxMaps[getRowid(this, row)]
3177
+ }
3076
3178
  if (evnt) {
3077
3179
  this.triggerCheckRowEvent(evnt, params, value)
3078
3180
  } else {
@@ -3112,18 +3214,29 @@ const Methods = {
3112
3214
  * 多选,切换某一行的选中状态
3113
3215
  */
3114
3216
  toggleCheckboxRow (row) {
3115
- const { selectCheckboxRows, checkboxOpts } = this
3217
+ const { selectCheckboxMaps, checkboxOpts } = this
3116
3218
  const { checkField } = checkboxOpts
3117
- const value = checkField ? !XEUtils.get(row, checkField) : this.findRowIndexOf(selectCheckboxRows, row) === -1
3219
+ const value = checkField ? !XEUtils.get(row, checkField) : !selectCheckboxMaps[getRowid(this, row)]
3118
3220
  this.handleSelectRow({ row }, value, true)
3119
3221
  return this.$nextTick()
3120
3222
  },
3121
3223
  handleCheckedAllCheckboxRow (value, isForce) {
3122
- const { afterFullData, treeConfig, treeOpts, selectCheckboxRows, checkboxReserveRowMap, checkboxOpts } = this
3224
+ const { afterFullData, treeConfig, treeOpts, selectCheckboxMaps, checkboxReserveRowMap, checkboxOpts, afterFullRowMaps } = this
3123
3225
  const { checkField, reserve, checkStrictly, checkMethod } = checkboxOpts
3124
3226
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
3125
- let selectRows = []
3126
- const beforeSelection = treeConfig ? [] : selectCheckboxRows.filter(row => this.findRowIndexOf(afterFullData, row) === -1)
3227
+ const childrenField = treeOpts.children || treeOpts.childrenField
3228
+ const selectRowMaps = {}
3229
+
3230
+ // 疑惑!
3231
+ if (!treeConfig) {
3232
+ XEUtils.each(selectCheckboxMaps, (row, rowid) => {
3233
+ if (!afterFullRowMaps[rowid]) {
3234
+ selectRowMaps[rowid] = row
3235
+ }
3236
+ })
3237
+ }
3238
+ // 疑惑!
3239
+
3127
3240
  if (checkStrictly) {
3128
3241
  this.isAllSelected = value
3129
3242
  } else {
@@ -3135,7 +3248,7 @@ const Methods = {
3135
3248
  const checkValFn = (row) => {
3136
3249
  if (isForce || (!checkMethod || checkMethod({ row }))) {
3137
3250
  if (value) {
3138
- selectRows.push(row)
3251
+ selectRowMaps[getRowid(this, row)] = row
3139
3252
  }
3140
3253
  XEUtils.set(row, checkField, value)
3141
3254
  }
@@ -3146,7 +3259,7 @@ const Methods = {
3146
3259
  // 如果存在选中方法
3147
3260
  // 如果方法成立,则更新值,否则忽略该数据
3148
3261
  if (treeConfig) {
3149
- XEUtils.eachTree(afterFullData, checkValFn, treeOpts)
3262
+ XEUtils.eachTree(afterFullData, checkValFn, { children: childrenField })
3150
3263
  } else {
3151
3264
  afterFullData.forEach(checkValFn)
3152
3265
  }
@@ -3163,9 +3276,9 @@ const Methods = {
3163
3276
  */
3164
3277
  XEUtils.eachTree(afterFullData, (row) => {
3165
3278
  if (isForce || (!checkMethod || checkMethod({ row }))) {
3166
- selectRows.push(row)
3279
+ selectRowMaps[getRowid(this, row)] = row
3167
3280
  }
3168
- }, treeOpts)
3281
+ }, { children: childrenField })
3169
3282
  } else {
3170
3283
  /**
3171
3284
  * 如果是树取消
@@ -3173,10 +3286,11 @@ const Methods = {
3173
3286
  */
3174
3287
  if (!isForce && checkMethod) {
3175
3288
  XEUtils.eachTree(afterFullData, (row) => {
3176
- if (checkMethod({ row }) ? 0 : this.findRowIndexOf(selectCheckboxRows, row) > -1) {
3177
- selectRows.push(row)
3289
+ const rowid = getRowid(this, row)
3290
+ if (checkMethod({ row }) ? 0 : selectCheckboxMaps[rowid]) {
3291
+ selectRowMaps[rowid] = row
3178
3292
  }
3179
- }, treeOpts)
3293
+ }, { children: childrenField })
3180
3294
  }
3181
3295
  }
3182
3296
  } else {
@@ -3187,9 +3301,16 @@ const Methods = {
3187
3301
  * 如果不存在选中方法,则添加所有数据到临时集合中
3188
3302
  */
3189
3303
  if (!isForce && checkMethod) {
3190
- selectRows = afterFullData.filter((row) => this.findRowIndexOf(selectCheckboxRows, row) > -1 || checkMethod({ row }))
3304
+ afterFullData.forEach((row) => {
3305
+ const rowid = getRowid(this, row)
3306
+ if (selectCheckboxMaps[rowid] || checkMethod({ row })) {
3307
+ selectRowMaps[rowid] = row
3308
+ }
3309
+ })
3191
3310
  } else {
3192
- selectRows = afterFullData.slice(0)
3311
+ afterFullData.forEach(row => {
3312
+ selectRowMaps[getRowid(this, row)] = row
3313
+ })
3193
3314
  }
3194
3315
  } else {
3195
3316
  /**
@@ -3198,23 +3319,29 @@ const Methods = {
3198
3319
  * 如果不存在选中方法,无需处理,临时集合默认为空
3199
3320
  */
3200
3321
  if (!isForce && checkMethod) {
3201
- selectRows = afterFullData.filter((row) => checkMethod({ row }) ? 0 : this.findRowIndexOf(selectCheckboxRows, row) > -1)
3322
+ afterFullData.forEach((row) => {
3323
+ const rowid = getRowid(this, row)
3324
+ if (checkMethod({ row }) ? 0 : selectCheckboxMaps[rowid]) {
3325
+ selectRowMaps[rowid] = row
3326
+ }
3327
+ })
3202
3328
  }
3203
3329
  }
3204
3330
  }
3205
3331
  }
3206
3332
  if (reserve) {
3207
3333
  if (value) {
3208
- selectRows.forEach(row => {
3209
- checkboxReserveRowMap[getRowid(this, row)] = row
3334
+ XEUtils.each(selectRowMaps, (row, rowid) => {
3335
+ checkboxReserveRowMap[rowid] = row
3210
3336
  })
3211
3337
  } else {
3212
- afterFullData.forEach(row => this.handleCheckboxReserveRow(row, false))
3338
+ afterFullData.forEach((row) => this.handleCheckboxReserveRow(row, false))
3213
3339
  }
3214
3340
  }
3215
- this.selectCheckboxRows = checkField ? [] : beforeSelection.concat(selectRows)
3341
+ this.selectCheckboxMaps = checkField ? {} : selectRowMaps
3216
3342
  }
3217
- this.treeIndeterminates = []
3343
+ this.treeIndeterminateMaps = {}
3344
+ this.treeIndeterminateRowMaps = {}
3218
3345
  this.checkSelectionStatus()
3219
3346
  return this.$nextTick()
3220
3347
  },
@@ -3226,7 +3353,7 @@ const Methods = {
3226
3353
  return this.handleCheckedAllCheckboxRow(value, true)
3227
3354
  },
3228
3355
  checkSelectionStatus () {
3229
- const { afterFullData, selectCheckboxRows, treeIndeterminates, checkboxOpts, treeConfig } = this
3356
+ const { afterFullData, selectCheckboxMaps, treeIndeterminateMaps, checkboxOpts, treeConfig } = this
3230
3357
  const { checkField, checkStrictly, checkMethod } = checkboxOpts
3231
3358
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
3232
3359
  if (!checkStrictly) {
@@ -3254,15 +3381,15 @@ const Methods = {
3254
3381
  isAllSelected = isAllResolve && afterFullData.length !== disableRows.length
3255
3382
  if (treeConfig) {
3256
3383
  if (indeterminateField) {
3257
- isIndeterminate = !isAllSelected && afterFullData.some(row => XEUtils.get(row, checkField) || XEUtils.get(row, indeterminateField) || this.findRowIndexOf(treeIndeterminates, row) > -1)
3384
+ isIndeterminate = !isAllSelected && afterFullData.some((row) => XEUtils.get(row, checkField) || XEUtils.get(row, indeterminateField) || !!treeIndeterminateMaps[getRowid(this, row)])
3258
3385
  } else {
3259
- isIndeterminate = !isAllSelected && afterFullData.some(row => XEUtils.get(row, checkField) || this.findRowIndexOf(treeIndeterminates, row) > -1)
3386
+ isIndeterminate = !isAllSelected && afterFullData.some((row) => XEUtils.get(row, checkField) || !!treeIndeterminateMaps[getRowid(this, row)])
3260
3387
  }
3261
3388
  } else {
3262
3389
  if (indeterminateField) {
3263
- isIndeterminate = !isAllSelected && afterFullData.some(row => XEUtils.get(row, checkField) || XEUtils.get(row, indeterminateField))
3390
+ isIndeterminate = !isAllSelected && afterFullData.some((row) => XEUtils.get(row, checkField) || XEUtils.get(row, indeterminateField))
3264
3391
  } else {
3265
- isIndeterminate = !isAllSelected && afterFullData.some(row => XEUtils.get(row, checkField))
3392
+ isIndeterminate = !isAllSelected && afterFullData.some((row) => XEUtils.get(row, checkField))
3266
3393
  }
3267
3394
  }
3268
3395
  } else {
@@ -3273,19 +3400,22 @@ const Methods = {
3273
3400
  disableRows.push(row)
3274
3401
  return true
3275
3402
  }
3276
- if (this.findRowIndexOf(selectCheckboxRows, row) > -1) {
3403
+ if (selectCheckboxMaps[getRowid(this, row)]) {
3277
3404
  checkRows.push(row)
3278
3405
  return true
3279
3406
  }
3280
3407
  return false
3281
3408
  }
3282
- : row => this.findRowIndexOf(selectCheckboxRows, row) > -1
3409
+ : row => selectCheckboxMaps[getRowid(this, row)]
3283
3410
  )
3284
3411
  isAllSelected = isAllResolve && afterFullData.length !== disableRows.length
3285
3412
  if (treeConfig) {
3286
- isIndeterminate = !isAllSelected && afterFullData.some(row => this.findRowIndexOf(treeIndeterminates, row) > -1 || this.findRowIndexOf(selectCheckboxRows, row) > -1)
3413
+ isIndeterminate = !isAllSelected && afterFullData.some((row) => {
3414
+ const itemRid = getRowid(this, row)
3415
+ return treeIndeterminateMaps[itemRid] || selectCheckboxMaps[itemRid]
3416
+ })
3287
3417
  } else {
3288
- isIndeterminate = !isAllSelected && afterFullData.some(row => this.findRowIndexOf(selectCheckboxRows, row) > -1)
3418
+ isIndeterminate = !isAllSelected && afterFullData.some((row) => selectCheckboxMaps[getRowid(this, row)])
3289
3419
  }
3290
3420
  }
3291
3421
  this.isAllSelected = isAllSelected
@@ -3294,10 +3424,10 @@ const Methods = {
3294
3424
  },
3295
3425
  // 还原展开、选中等相关状态
3296
3426
  handleReserveStatus () {
3297
- const { expandColumn, treeOpts, treeConfig, fullDataRowIdData, fullAllDataRowMap, currentRow, selectRow, radioReserveRow, radioOpts, checkboxOpts, selectCheckboxRows, rowExpandeds, treeExpandeds, expandOpts } = this
3427
+ const { expandColumn, treeOpts, treeConfig, fullDataRowIdData, fullAllDataRowMap, currentRow, selectRadioRow, radioReserveRow, radioOpts, checkboxOpts, selectCheckboxMaps, rowExpandedMaps, treeExpandedMaps, expandOpts } = this
3298
3428
  // 单选框
3299
- if (selectRow && !fullAllDataRowMap.has(selectRow)) {
3300
- this.selectRow = null // 刷新单选行状态
3429
+ if (selectRadioRow && !fullAllDataRowMap.has(selectRadioRow)) {
3430
+ this.selectRadioRow = null // 刷新单选行状态
3301
3431
  }
3302
3432
  // 还原保留选中状态
3303
3433
  if (radioOpts.reserve && radioReserveRow) {
@@ -3307,7 +3437,7 @@ const Methods = {
3307
3437
  }
3308
3438
  }
3309
3439
  // 复选框
3310
- this.selectCheckboxRows = getRecoverRow(this, selectCheckboxRows) // 刷新多选行状态
3440
+ this.selectCheckboxMaps = getRecoverRowMaps(this, selectCheckboxMaps) // 刷新多选行状态
3311
3441
  // 还原保留选中状态
3312
3442
  if (checkboxOpts.reserve) {
3313
3443
  this.handleCheckedCheckboxRow(handleReserveRow(this, this.checkboxReserveRowMap), true, true)
@@ -3316,13 +3446,13 @@ const Methods = {
3316
3446
  this.currentRow = null // 刷新当前行状态
3317
3447
  }
3318
3448
  // 行展开
3319
- this.rowExpandeds = expandColumn ? getRecoverRow(this, rowExpandeds) : [] // 刷新行展开状态
3449
+ this.rowExpandedMaps = expandColumn ? getRecoverRowMaps(this, rowExpandedMaps) : [] // 刷新行展开状态
3320
3450
  // 还原保留状态
3321
3451
  if (expandColumn && expandOpts.reserve) {
3322
3452
  this.setRowExpand(handleReserveRow(this, this.rowExpandedReserveRowMap), true)
3323
3453
  }
3324
3454
  // 树展开
3325
- this.treeExpandeds = treeConfig ? getRecoverRow(this, treeExpandeds) : [] // 刷新树展开状态
3455
+ this.treeExpandedMaps = treeConfig ? getRecoverRowMaps(this, treeExpandedMaps) : [] // 刷新树展开状态
3326
3456
  if (treeConfig && treeOpts.reserve) {
3327
3457
  this.setTreeExpand(handleReserveRow(this, this.treeExpandedReserveRowMap), true)
3328
3458
  }
@@ -3332,6 +3462,7 @@ const Methods = {
3332
3462
  */
3333
3463
  getRadioReserveRecord (isFull) {
3334
3464
  const { fullDataRowIdData, radioReserveRow, radioOpts, afterFullData, treeConfig, treeOpts } = this
3465
+ const childrenField = treeOpts.children || treeOpts.childrenField
3335
3466
  if (radioOpts.reserve && radioReserveRow) {
3336
3467
  const rowid = getRowid(this, radioReserveRow)
3337
3468
  if (isFull) {
@@ -3341,7 +3472,7 @@ const Methods = {
3341
3472
  } else {
3342
3473
  const rowkey = getRowkey(this)
3343
3474
  if (treeConfig) {
3344
- const matchObj = XEUtils.findTree(afterFullData, row => rowid === XEUtils.get(row, rowkey), treeOpts)
3475
+ const matchObj = XEUtils.findTree(afterFullData, row => rowid === XEUtils.get(row, rowkey), { children: childrenField })
3345
3476
  if (matchObj) {
3346
3477
  return radioReserveRow
3347
3478
  }
@@ -3369,13 +3500,14 @@ const Methods = {
3369
3500
  */
3370
3501
  getCheckboxReserveRecords (isFull) {
3371
3502
  const { fullDataRowIdData, afterFullData, checkboxReserveRowMap, checkboxOpts, treeConfig, treeOpts } = this
3503
+ const childrenField = treeOpts.children || treeOpts.childrenField
3372
3504
  const reserveSelection = []
3373
3505
  if (checkboxOpts.reserve) {
3374
3506
  const afterFullIdMaps = {}
3375
3507
  if (treeConfig) {
3376
3508
  XEUtils.eachTree(afterFullData, row => {
3377
3509
  afterFullIdMaps[getRowid(this, row)] = 1
3378
- }, treeOpts)
3510
+ }, { children: childrenField })
3379
3511
  } else {
3380
3512
  afterFullData.forEach(row => {
3381
3513
  afterFullIdMaps[getRowid(this, row)] = 1
@@ -3433,6 +3565,7 @@ const Methods = {
3433
3565
  clearCheckboxRow () {
3434
3566
  const { tableFullData, treeConfig, treeOpts, checkboxOpts } = this
3435
3567
  const { checkField, reserve } = checkboxOpts
3568
+ const childrenField = treeOpts.children || treeOpts.childrenField
3436
3569
  const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
3437
3570
  if (checkField) {
3438
3571
  const handleClearChecked = (item) => {
@@ -3442,7 +3575,7 @@ const Methods = {
3442
3575
  XEUtils.set(item, checkField, false)
3443
3576
  }
3444
3577
  if (treeConfig) {
3445
- XEUtils.eachTree(tableFullData, handleClearChecked, treeOpts)
3578
+ XEUtils.eachTree(tableFullData, handleClearChecked, { children: childrenField })
3446
3579
  } else {
3447
3580
  tableFullData.forEach(handleClearChecked)
3448
3581
  }
@@ -3452,8 +3585,8 @@ const Methods = {
3452
3585
  }
3453
3586
  this.isAllSelected = false
3454
3587
  this.isIndeterminate = false
3455
- this.selectCheckboxRows = []
3456
- this.treeIndeterminates = []
3588
+ this.selectCheckboxMaps = {}
3589
+ this.treeIndeterminateMaps = {}
3457
3590
  return this.$nextTick()
3458
3591
  },
3459
3592
  /**
@@ -3476,7 +3609,7 @@ const Methods = {
3476
3609
  * 单选,行选中事件
3477
3610
  */
3478
3611
  triggerRadioRowEvent (evnt, params) {
3479
- const { selectRow: oldValue, radioOpts } = this
3612
+ const { selectRadioRow: oldValue, radioOpts } = this
3480
3613
  const { row } = params
3481
3614
  let newValue = row
3482
3615
  let isChange = oldValue !== newValue
@@ -3519,13 +3652,13 @@ const Methods = {
3519
3652
  return this.$nextTick()
3520
3653
  },
3521
3654
  isCheckedByRadioRow (row) {
3522
- return this.selectRow === row
3655
+ return this.selectRadioRow === row
3523
3656
  },
3524
3657
  handleCheckedRadioRow (row, isForce) {
3525
3658
  const { radioOpts } = this
3526
3659
  const { checkMethod } = radioOpts
3527
3660
  if (row && (isForce || (!checkMethod || checkMethod({ row })))) {
3528
- this.selectRow = row
3661
+ this.selectRadioRow = row
3529
3662
  this.handleRadioReserveRow(row)
3530
3663
  }
3531
3664
  return this.$nextTick()
@@ -3553,7 +3686,7 @@ const Methods = {
3553
3686
  * 用于单选行,手动清空用户的选择
3554
3687
  */
3555
3688
  clearRadioRow () {
3556
- this.selectRow = null
3689
+ this.selectRadioRow = null
3557
3690
  return this.$nextTick()
3558
3691
  },
3559
3692
  /**
@@ -3566,24 +3699,16 @@ const Methods = {
3566
3699
  * 用于单选行,获取当已选中的数据
3567
3700
  */
3568
3701
  getRadioRecord (isFull) {
3569
- const { treeConfig, treeOpts, selectRow, fullDataRowIdData, afterFullData } = this
3570
- if (selectRow) {
3571
- const rowid = getRowid(this, selectRow)
3702
+ const { selectRadioRow, fullDataRowIdData, afterFullRowMaps } = this
3703
+ if (selectRadioRow) {
3704
+ const rowid = getRowid(this, selectRadioRow)
3572
3705
  if (isFull) {
3573
3706
  if (!fullDataRowIdData[rowid]) {
3574
- return selectRow
3707
+ return selectRadioRow
3575
3708
  }
3576
3709
  } else {
3577
- if (treeConfig) {
3578
- const rowkey = getRowkey(this)
3579
- const matchObj = XEUtils.findTree(afterFullData, row => rowid === XEUtils.get(row, rowkey), treeOpts)
3580
- if (matchObj) {
3581
- return selectRow
3582
- }
3583
- } else {
3584
- if (afterFullData.indexOf(selectRow) > -1) {
3585
- return selectRow
3586
- }
3710
+ if (afterFullRowMaps[rowid]) {
3711
+ return selectRadioRow
3587
3712
  }
3588
3713
  }
3589
3714
  }
@@ -3947,12 +4072,17 @@ const Methods = {
3947
4072
  return rest && rest.expandLoaded
3948
4073
  },
3949
4074
  clearRowExpandLoaded (row) {
3950
- const { expandOpts, expandLazyLoadeds, fullAllDataRowMap } = this
4075
+ const { expandOpts, rowExpandLazyLoadedMaps, fullAllDataRowMap } = this
3951
4076
  const { lazy } = expandOpts
4077
+ const rowid = getRowid(this, row)
3952
4078
  const rest = fullAllDataRowMap.get(row)
3953
4079
  if (lazy && rest) {
3954
4080
  rest.expandLoaded = false
3955
- XEUtils.remove(expandLazyLoadeds, item => this.eqRow(item, row))
4081
+ const rowTempExpandLazyLoadedMaps = { ...rowExpandLazyLoadedMaps }
4082
+ if (rowTempExpandLazyLoadedMaps[rowid]) {
4083
+ delete rowTempExpandLazyLoadedMaps[rowid]
4084
+ }
4085
+ this.rowExpandLazyLoadedMaps = rowTempExpandLazyLoadedMaps
3956
4086
  }
3957
4087
  return this.$nextTick()
3958
4088
  },
@@ -3961,9 +4091,10 @@ const Methods = {
3961
4091
  * @param {Row} row 行对象
3962
4092
  */
3963
4093
  reloadRowExpand (row) {
3964
- const { expandOpts, expandLazyLoadeds } = this
4094
+ const { expandOpts, rowExpandLazyLoadedMaps } = this
3965
4095
  const { lazy } = expandOpts
3966
- if (lazy && this.findRowIndexOf(expandLazyLoadeds, row) === -1) {
4096
+ const rowid = getRowid(this, row)
4097
+ if (lazy && !rowExpandLazyLoadedMaps[rowid]) {
3967
4098
  this.clearRowExpandLoaded(row)
3968
4099
  .then(() => this.handleAsyncRowExpand(row))
3969
4100
  }
@@ -3980,10 +4111,11 @@ const Methods = {
3980
4111
  * 展开行事件
3981
4112
  */
3982
4113
  triggerRowExpandEvent (evnt, params) {
3983
- const { expandOpts, expandLazyLoadeds, expandColumn: column } = this
4114
+ const { expandOpts, rowExpandLazyLoadedMaps, expandColumn: column } = this
3984
4115
  const { row } = params
3985
4116
  const { lazy } = expandOpts
3986
- if (!lazy || this.findRowIndexOf(expandLazyLoadeds, row) === -1) {
4117
+ const rowid = getRowid(this, row)
4118
+ if (!lazy || !rowExpandLazyLoadedMaps[rowid]) {
3987
4119
  const expanded = !this.isExpandByRow(row)
3988
4120
  const columnIndex = this.getColumnIndex(column)
3989
4121
  const $columnIndex = this.getVMColumnIndex(column)
@@ -4021,29 +4153,48 @@ const Methods = {
4021
4153
  */
4022
4154
  setAllRowExpand (expanded) {
4023
4155
  const { treeConfig, treeOpts, tableFullData, tableFullTreeData } = this
4156
+ const childrenField = treeOpts.children || treeOpts.childrenField
4024
4157
  let expandedRows = []
4025
4158
  if (treeConfig) {
4026
4159
  XEUtils.eachTree(tableFullTreeData, (row) => {
4027
4160
  expandedRows.push(row)
4028
- }, treeOpts)
4161
+ }, { children: childrenField })
4029
4162
  } else {
4030
4163
  expandedRows = tableFullData
4031
4164
  }
4032
4165
  return this.setRowExpand(expandedRows, expanded)
4033
4166
  },
4034
4167
  handleAsyncRowExpand (row) {
4035
- const rest = this.fullAllDataRowMap.get(row)
4168
+ const { fullAllDataRowMap, expandOpts } = this
4169
+ const rest = fullAllDataRowMap.get(row)
4036
4170
  return new Promise(resolve => {
4037
- this.expandLazyLoadeds.push(row)
4038
- this.expandOpts.loadMethod({ $table: this, row, rowIndex: this.getRowIndex(row), $rowIndex: this.getVMRowIndex(row) }).then(() => {
4039
- rest.expandLoaded = true
4040
- this.rowExpandeds.push(row)
4041
- }).catch(() => {
4042
- rest.expandLoaded = false
4043
- }).finally(() => {
4044
- XEUtils.remove(this.expandLazyLoadeds, item => this.eqRow(item, row))
4045
- resolve(this.$nextTick().then(this.recalculate))
4046
- })
4171
+ const { loadMethod } = expandOpts
4172
+ if (loadMethod) {
4173
+ const { rowExpandLazyLoadedMaps } = this
4174
+ const rowTempExpandLazyLoadedMaps = { ...rowExpandLazyLoadedMaps }
4175
+ const rowid = getRowid(this, row)
4176
+ rowTempExpandLazyLoadedMaps[rowid] = row
4177
+ this.rowExpandLazyLoadedMaps = rowTempExpandLazyLoadedMaps
4178
+ loadMethod({ $table: this, row, rowIndex: this.getRowIndex(row), $rowIndex: this.getVMRowIndex(row) }).then(() => {
4179
+ rest.expandLoaded = true
4180
+ const { rowExpandedMaps } = this
4181
+ const rowTempExpandedMaps = { ...rowExpandedMaps }
4182
+ rowTempExpandedMaps[rowid] = row
4183
+ this.rowExpandedMaps = rowTempExpandedMaps
4184
+ }).catch(() => {
4185
+ rest.expandLoaded = false
4186
+ }).finally(() => {
4187
+ const { rowExpandLazyLoadedMaps } = this
4188
+ const rowTempExpandLazyLoadedMaps = { ...rowExpandLazyLoadedMaps }
4189
+ if (rowTempExpandLazyLoadedMaps[rowid]) {
4190
+ delete rowTempExpandLazyLoadedMaps[rowid]
4191
+ }
4192
+ this.rowExpandLazyLoadedMaps = rowTempExpandLazyLoadedMaps
4193
+ resolve(this.$nextTick().then(this.recalculate))
4194
+ })
4195
+ } else {
4196
+ resolve()
4197
+ }
4047
4198
  })
4048
4199
  },
4049
4200
  /**
@@ -4054,8 +4205,8 @@ const Methods = {
4054
4205
  * @param {Boolean} expanded 是否展开
4055
4206
  */
4056
4207
  setRowExpand (rows, expanded) {
4057
- const { fullAllDataRowMap, expandLazyLoadeds, expandOpts, expandColumn: column } = this
4058
- let { rowExpandeds } = this
4208
+ const { rowExpandedMaps, fullAllDataRowIdData, rowExpandLazyLoadedMaps, expandOpts, expandColumn: column } = this
4209
+ let rExpandedMaps = { ...rowExpandedMaps }
4059
4210
  const { reserve, lazy, accordion, toggleMethod } = expandOpts
4060
4211
  const lazyRests = []
4061
4212
  const columnIndex = this.getColumnIndex(column)
@@ -4066,30 +4217,36 @@ const Methods = {
4066
4217
  }
4067
4218
  if (accordion) {
4068
4219
  // 只能同时展开一个
4069
- rowExpandeds = []
4220
+ rExpandedMaps = {}
4070
4221
  rows = rows.slice(rows.length - 1, rows.length)
4071
4222
  }
4072
4223
  const validRows = toggleMethod ? rows.filter(row => toggleMethod({ expanded, column, columnIndex, $columnIndex, row, rowIndex: this.getRowIndex(row), $rowIndex: this.getVMRowIndex(row) })) : rows
4073
4224
  if (expanded) {
4074
4225
  validRows.forEach(row => {
4075
- if (this.findRowIndexOf(rowExpandeds, row) === -1) {
4076
- const rest = fullAllDataRowMap.get(row)
4077
- const isLoad = lazy && !rest.expandLoaded && this.findRowIndexOf(expandLazyLoadeds, row) === -1
4226
+ const rowid = getRowid(this, row)
4227
+ if (!rExpandedMaps[rowid]) {
4228
+ const rest = fullAllDataRowIdData[rowid]
4229
+ const isLoad = lazy && !rest.expandLoaded && !rowExpandLazyLoadedMaps[rowid]
4078
4230
  if (isLoad) {
4079
4231
  lazyRests.push(this.handleAsyncRowExpand(row))
4080
4232
  } else {
4081
- rowExpandeds.push(row)
4233
+ rExpandedMaps[rowid] = row
4082
4234
  }
4083
4235
  }
4084
4236
  })
4085
4237
  } else {
4086
- XEUtils.remove(rowExpandeds, row => this.findRowIndexOf(validRows, row) > -1)
4238
+ validRows.forEach(item => {
4239
+ const rowid = getRowid(this, item)
4240
+ if (rExpandedMaps[rowid]) {
4241
+ delete rExpandedMaps[rowid]
4242
+ }
4243
+ })
4087
4244
  }
4088
4245
  if (reserve) {
4089
4246
  validRows.forEach(row => this.handleRowExpandReserve(row, expanded))
4090
4247
  }
4091
4248
  }
4092
- this.rowExpandeds = rowExpandeds
4249
+ this.rowExpandedMaps = rExpandedMaps
4093
4250
  return Promise.all(lazyRests).then(this.recalculate)
4094
4251
  },
4095
4252
  /**
@@ -4097,22 +4254,23 @@ const Methods = {
4097
4254
  * @param {Row} row 行对象
4098
4255
  */
4099
4256
  isExpandByRow (row) {
4100
- const { rowExpandeds } = this
4101
- return this.findRowIndexOf(rowExpandeds, row) > -1
4257
+ const { rowExpandedMaps } = this
4258
+ const rowid = getRowid(this, row)
4259
+ return !!rowExpandedMaps[rowid]
4102
4260
  },
4103
4261
  /**
4104
4262
  * 手动清空展开行状态,数据会恢复成未展开的状态
4105
4263
  */
4106
4264
  clearRowExpand () {
4107
- const { expandOpts, rowExpandeds, tableFullData } = this
4265
+ const { expandOpts, tableFullData } = this
4108
4266
  const { reserve } = expandOpts
4109
- const isExists = rowExpandeds.length
4110
- this.rowExpandeds = []
4267
+ const expList = this.getRowExpandRecords()
4268
+ this.rowExpandedMaps = {}
4111
4269
  if (reserve) {
4112
4270
  tableFullData.forEach(row => this.handleRowExpandReserve(row, false))
4113
4271
  }
4114
4272
  return this.$nextTick().then(() => {
4115
- if (isExists) {
4273
+ if (expList.length) {
4116
4274
  this.recalculate()
4117
4275
  }
4118
4276
  })
@@ -4133,13 +4291,25 @@ const Methods = {
4133
4291
  }
4134
4292
  },
4135
4293
  getRowExpandRecords () {
4136
- return this.rowExpandeds.slice(0)
4294
+ const rest = []
4295
+ XEUtils.each(this.rowExpandedMaps, item => {
4296
+ if (item) {
4297
+ rest.push(item)
4298
+ }
4299
+ })
4300
+ return rest
4137
4301
  },
4138
4302
  getTreeExpandRecords () {
4139
- return this.treeExpandeds.slice(0)
4303
+ const rest = []
4304
+ XEUtils.each(this.treeExpandedMaps, item => {
4305
+ if (item) {
4306
+ rest.push(item)
4307
+ }
4308
+ })
4309
+ return rest
4140
4310
  },
4141
4311
  /**
4142
- * 获取数表格状态
4312
+ * 获取树表格状态
4143
4313
  */
4144
4314
  getTreeStatus () {
4145
4315
  if (this.treeConfig) {
@@ -4159,12 +4329,15 @@ const Methods = {
4159
4329
  return rest && rest.treeLoaded
4160
4330
  },
4161
4331
  clearTreeExpandLoaded (row) {
4162
- const { treeOpts, treeExpandeds, fullAllDataRowMap } = this
4332
+ const { treeOpts, treeExpandedMaps, fullAllDataRowMap } = this
4163
4333
  const { transform, lazy } = treeOpts
4334
+ const rowid = getRowid(this, row)
4164
4335
  const rest = fullAllDataRowMap.get(row)
4165
4336
  if (lazy && rest) {
4166
4337
  rest.treeLoaded = false
4167
- XEUtils.remove(treeExpandeds, item => row === item)
4338
+ if (treeExpandedMaps[rowid]) {
4339
+ delete treeExpandedMaps[rowid]
4340
+ }
4168
4341
  }
4169
4342
  if (transform) {
4170
4343
  this.handleVirtualTreeToList()
@@ -4177,10 +4350,11 @@ const Methods = {
4177
4350
  * @param {Row} row 行对象
4178
4351
  */
4179
4352
  reloadTreeExpand (row) {
4180
- const { treeOpts, treeLazyLoadeds } = this
4353
+ const { treeOpts, treeExpandLazyLoadedMaps } = this
4181
4354
  const { transform, lazy } = treeOpts
4182
4355
  const hasChildField = treeOpts.hasChild || treeOpts.hasChildField
4183
- if (lazy && row[hasChildField] && treeLazyLoadeds.indexOf(row) === -1) {
4356
+ const rowid = getRowid(this, row)
4357
+ if (lazy && row[hasChildField] && !treeExpandLazyLoadedMaps[rowid]) {
4184
4358
  this.clearTreeExpandLoaded(row).then(() => {
4185
4359
  return this.handleAsyncTreeExpandChilds(row)
4186
4360
  }).then(() => {
@@ -4205,10 +4379,11 @@ const Methods = {
4205
4379
  * 展开树节点事件
4206
4380
  */
4207
4381
  triggerTreeExpandEvent (evnt, params) {
4208
- const { treeOpts, treeLazyLoadeds } = this
4382
+ const { treeOpts, treeExpandLazyLoadedMaps } = this
4209
4383
  const { row, column } = params
4210
4384
  const { lazy } = treeOpts
4211
- if (!lazy || treeLazyLoadeds.indexOf(row) === -1) {
4385
+ const rowid = getRowid(this, row)
4386
+ if (!lazy || !treeExpandLazyLoadedMaps[rowid]) {
4212
4387
  const expanded = !this.isTreeExpandByRow(row)
4213
4388
  const columnIndex = this.getColumnIndex(column)
4214
4389
  const $columnIndex = this.getVMColumnIndex(column)
@@ -4229,13 +4404,14 @@ const Methods = {
4229
4404
  const { treeConfig, treeOpts, tableFullData } = this
4230
4405
  if (treeConfig) {
4231
4406
  const { expandAll, expandRowKeys } = treeOpts
4407
+ const childrenField = treeOpts.children || treeOpts.childrenField
4232
4408
  if (expandAll) {
4233
4409
  this.setAllTreeExpand(true)
4234
4410
  } else if (expandRowKeys) {
4235
4411
  const defExpandeds = []
4236
4412
  const rowkey = getRowkey(this)
4237
4413
  expandRowKeys.forEach(rowid => {
4238
- const matchObj = XEUtils.findTree(tableFullData, item => rowid === XEUtils.get(item, rowkey), treeOpts)
4414
+ const matchObj = XEUtils.findTree(tableFullData, item => rowid === XEUtils.get(item, rowkey), { children: childrenField })
4239
4415
  if (matchObj) {
4240
4416
  defExpandeds.push(matchObj.item)
4241
4417
  }
@@ -4245,42 +4421,56 @@ const Methods = {
4245
4421
  }
4246
4422
  },
4247
4423
  handleAsyncTreeExpandChilds (row) {
4248
- const { fullAllDataRowMap, treeExpandeds, treeOpts, treeLazyLoadeds, checkboxOpts } = this
4424
+ const { treeOpts, checkboxOpts } = this
4249
4425
  const { transform, loadMethod } = treeOpts
4250
4426
  const { checkStrictly } = checkboxOpts
4251
- const rest = fullAllDataRowMap.get(row)
4252
4427
  return new Promise(resolve => {
4253
- treeLazyLoadeds.push(row)
4254
- loadMethod({ $table: this, row }).then(childRecords => {
4255
- // 响应成功后则展开行,并将子节点挂载到该节点下
4256
- rest.treeLoaded = true
4257
- XEUtils.remove(treeLazyLoadeds, item => item === row)
4258
- if (!XEUtils.isArray(childRecords)) {
4259
- childRecords = []
4260
- }
4261
- if (childRecords) {
4262
- return this.loadTreeChildren(row, childRecords).then(childRows => {
4263
- if (childRows.length && treeExpandeds.indexOf(row) === -1) {
4264
- treeExpandeds.push(row)
4265
- }
4266
- // 如果当前节点已选中,则展开后子节点也被选中
4267
- if (!checkStrictly && this.isCheckedByCheckboxRow(row)) {
4268
- this.handleCheckedCheckboxRow(childRows, true, true)
4269
- }
4270
- return this.$nextTick().then(() => {
4271
- if (transform) {
4272
- return this.handleTableData()
4428
+ if (loadMethod) {
4429
+ const { fullAllDataRowMap, treeExpandLazyLoadedMaps } = this
4430
+ const rowid = getRowid(this, row)
4431
+ const rest = fullAllDataRowMap.get(row)
4432
+ treeExpandLazyLoadedMaps[rowid] = row
4433
+ loadMethod({ $table: this, row }).then(childRecords => {
4434
+ // 响应成功后则展开行,并将子节点挂载到该节点下
4435
+ rest.treeLoaded = true
4436
+ if (treeExpandLazyLoadedMaps[rowid]) {
4437
+ treeExpandLazyLoadedMaps[rowid] = null
4438
+ }
4439
+ if (!XEUtils.isArray(childRecords)) {
4440
+ childRecords = []
4441
+ }
4442
+ if (childRecords) {
4443
+ return this.loadTreeChildren(row, childRecords).then(childRows => {
4444
+ const { treeExpandedMaps } = this
4445
+ const treeTempExpandedMaps = { ...treeExpandedMaps }
4446
+ if (childRows.length && !treeTempExpandedMaps[rowid]) {
4447
+ treeTempExpandedMaps[rowid] = row
4448
+ this.treeExpandedMaps = treeTempExpandedMaps
4449
+ }
4450
+ // 如果当前节点已选中,则展开后子节点也被选中
4451
+ if (!checkStrictly && this.isCheckedByCheckboxRow(row)) {
4452
+ this.handleCheckedCheckboxRow(childRows, true, true)
4273
4453
  }
4454
+ return this.$nextTick().then(() => {
4455
+ if (transform) {
4456
+ return this.handleTableData()
4457
+ }
4458
+ })
4274
4459
  })
4275
- })
4276
- }
4277
- }).catch(() => {
4460
+ }
4461
+ }).catch(() => {
4278
4462
  // 如果响应异常,则不展开,再次点击后将重新触发懒加载
4279
- rest.treeLoaded = false
4280
- XEUtils.remove(treeLazyLoadeds, item => item === row)
4281
- }).finally(() => {
4282
- this.$nextTick().then(() => this.recalculate()).then(() => resolve())
4283
- })
4463
+ rest.treeLoaded = false
4464
+ const { treeExpandLazyLoadedMaps } = this
4465
+ if (treeExpandLazyLoadedMaps[rowid]) {
4466
+ treeExpandLazyLoadedMaps[rowid] = null
4467
+ }
4468
+ }).finally(() => {
4469
+ this.$nextTick().then(() => this.recalculate()).then(() => resolve())
4470
+ })
4471
+ } else {
4472
+ resolve()
4473
+ }
4284
4474
  })
4285
4475
  },
4286
4476
  /**
@@ -4297,7 +4487,7 @@ const Methods = {
4297
4487
  if (lazy || (rowChildren && rowChildren.length)) {
4298
4488
  expandeds.push(row)
4299
4489
  }
4300
- }, treeOpts)
4490
+ }, { children: childrenField })
4301
4491
  return this.setTreeExpand(expandeds, expanded)
4302
4492
  },
4303
4493
  /**
@@ -4307,8 +4497,9 @@ const Methods = {
4307
4497
  * @returns
4308
4498
  */
4309
4499
  handleBaseTreeExpand (rows, expanded) {
4310
- const { fullAllDataRowMap, tableFullData, treeExpandeds, treeOpts, treeLazyLoadeds, treeNodeColumn } = this
4500
+ const { fullAllDataRowMap, tableFullData, treeExpandedMaps, treeOpts, treeExpandLazyLoadedMaps, treeNodeColumn } = this
4311
4501
  const { reserve, lazy, accordion, toggleMethod } = treeOpts
4502
+ const treeTempExpandedMaps = { ...treeExpandedMaps }
4312
4503
  const childrenField = treeOpts.children || treeOpts.childrenField
4313
4504
  const hasChildField = treeOpts.hasChild || treeOpts.hasChildField
4314
4505
  const result = []
@@ -4318,32 +4509,44 @@ const Methods = {
4318
4509
  if (accordion) {
4319
4510
  validRows = validRows.length ? [validRows[validRows.length - 1]] : []
4320
4511
  // 同一级只能展开一个
4321
- const matchObj = XEUtils.findTree(tableFullData, item => item === validRows[0], treeOpts)
4512
+ const matchObj = XEUtils.findTree(tableFullData, item => item === validRows[0], { children: childrenField })
4322
4513
  if (matchObj) {
4323
- XEUtils.remove(treeExpandeds, item => matchObj.items.indexOf(item) > -1)
4514
+ matchObj.items.forEach(item => {
4515
+ const rowid = getRowid(this, item)
4516
+ if (treeTempExpandedMaps[rowid]) {
4517
+ delete treeTempExpandedMaps[rowid]
4518
+ }
4519
+ })
4324
4520
  }
4325
4521
  }
4326
4522
  if (expanded) {
4327
4523
  validRows.forEach(row => {
4328
- if (treeExpandeds.indexOf(row) === -1) {
4524
+ const rowid = getRowid(this, row)
4525
+ if (!treeTempExpandedMaps[rowid]) {
4329
4526
  const rest = fullAllDataRowMap.get(row)
4330
- const isLoad = lazy && row[(hasChildField)] && !rest.treeLoaded && treeLazyLoadeds.indexOf(row) === -1
4527
+ const isLoad = lazy && row[hasChildField] && !rest.treeLoaded && !treeExpandLazyLoadedMaps[rowid]
4331
4528
  // 是否使用懒加载
4332
4529
  if (isLoad) {
4333
4530
  result.push(this.handleAsyncTreeExpandChilds(row))
4334
4531
  } else {
4335
4532
  if (row[childrenField] && row[childrenField].length) {
4336
- treeExpandeds.push(row)
4533
+ treeTempExpandedMaps[rowid] = row
4337
4534
  }
4338
4535
  }
4339
4536
  }
4340
4537
  })
4341
4538
  } else {
4342
- XEUtils.remove(treeExpandeds, row => validRows.indexOf(row) > -1)
4539
+ validRows.forEach(item => {
4540
+ const rowid = getRowid(this, item)
4541
+ if (treeTempExpandedMaps[rowid]) {
4542
+ delete treeTempExpandedMaps[rowid]
4543
+ }
4544
+ })
4343
4545
  }
4344
4546
  if (reserve) {
4345
4547
  validRows.forEach(row => this.handleTreeExpandReserve(row, expanded))
4346
4548
  }
4549
+ this.treeExpandedMaps = treeTempExpandedMaps
4347
4550
  return Promise.all(result).then(this.recalculate)
4348
4551
  },
4349
4552
  /**
@@ -4390,18 +4593,20 @@ const Methods = {
4390
4593
  * @param {Row} row 行对象
4391
4594
  */
4392
4595
  isTreeExpandByRow (row) {
4393
- return this.treeExpandeds.indexOf(row) > -1
4596
+ const { treeExpandedMaps } = this
4597
+ return !!treeExpandedMaps[getRowid(this, row)]
4394
4598
  },
4395
4599
  /**
4396
4600
  * 手动清空树形节点的展开状态,数据会恢复成未展开的状态
4397
4601
  */
4398
4602
  clearTreeExpand () {
4399
- const { treeOpts, treeExpandeds, tableFullData } = this
4603
+ const { treeOpts, tableFullData } = this
4400
4604
  const { transform, reserve } = treeOpts
4401
- const isExists = treeExpandeds.length
4402
- this.treeExpandeds = []
4605
+ const childrenField = treeOpts.children || treeOpts.childrenField
4606
+ const expList = this.getTreeExpandRecords()
4607
+ this.treeExpandedMaps = {}
4403
4608
  if (reserve) {
4404
- XEUtils.eachTree(tableFullData, row => this.handleTreeExpandReserve(row, false), treeOpts)
4609
+ XEUtils.eachTree(tableFullData, row => this.handleTreeExpandReserve(row, false), { children: childrenField })
4405
4610
  }
4406
4611
  return this.handleTableData().then(() => {
4407
4612
  if (transform) {
@@ -4409,7 +4614,7 @@ const Methods = {
4409
4614
  return this.handleTableData()
4410
4615
  }
4411
4616
  }).then(() => {
4412
- if (isExists) {
4617
+ if (expList.length) {
4413
4618
  this.recalculate()
4414
4619
  }
4415
4620
  })
@@ -4678,9 +4883,10 @@ const Methods = {
4678
4883
  */
4679
4884
  scrollToTreeRow (row) {
4680
4885
  const { tableFullData, treeConfig, treeOpts } = this
4886
+ const childrenField = treeOpts.children || treeOpts.childrenField
4681
4887
  const rests = []
4682
4888
  if (treeConfig) {
4683
- const matchObj = XEUtils.findTree(tableFullData, item => item === row, treeOpts)
4889
+ const matchObj = XEUtils.findTree(tableFullData, item => item === row, { children: childrenField })
4684
4890
  if (matchObj) {
4685
4891
  const nodes = matchObj.nodes
4686
4892
  nodes.forEach((row, index) => {