vxe-table 3.4.7-beta.1 → 3.4.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.
@@ -2,7 +2,7 @@ import XEUtils from 'xe-utils'
2
2
  import GlobalConfig from '../../v-x-e-table/src/conf'
3
3
  import VXETable from '../../v-x-e-table'
4
4
  import { UtilTools } from '../../tools'
5
- import { mergeBodyMethod, toTreePathSeq } from '../../table/src/util'
5
+ import { mergeBodyMethod } from '../../table/src/util'
6
6
  import { browse } from '../../tools/src/dom'
7
7
 
8
8
  const { formatText } = UtilTools
@@ -40,16 +40,13 @@ function hasTreeChildren ($xetable, row) {
40
40
  return row[treeOpts.children] && row[treeOpts.children].length > 0
41
41
  }
42
42
 
43
- function getSeq ($xetable, row, rowIndex, column, columnIndex, path) {
43
+ function getSeq ($xetable, row, rowIndex, column, columnIndex) {
44
44
  const seqOpts = $xetable.seqOpts
45
45
  const seqMethod = seqOpts.seqMethod || column.seqMethod
46
46
  if (seqMethod) {
47
47
  return seqMethod({ row, rowIndex, column, columnIndex })
48
48
  }
49
- if (path) {
50
- return toTreePathSeq(path)
51
- }
52
- return seqOpts.startIndex + rowIndex + 1
49
+ return $xetable.getRowSeq(row)
53
50
  }
54
51
 
55
52
  function defaultFilterExportColumn (column) {
@@ -106,7 +103,7 @@ function getLabelData ($xetable, opts, columns, datas) {
106
103
  } else {
107
104
  switch (column.type) {
108
105
  case 'seq':
109
- cellValue = getSeq($xetable, row, rowIndex, column, columnIndex, path)
106
+ cellValue = getSeq($xetable, row, rowIndex, column, columnIndex)
110
107
  break
111
108
  case 'checkbox':
112
109
  cellValue = toBooleanValue($xetable.isCheckedByCheckboxRow(row))
@@ -162,7 +159,7 @@ function getLabelData ($xetable, opts, columns, datas) {
162
159
  } else {
163
160
  switch (column.type) {
164
161
  case 'seq':
165
- cellValue = getSeq($xetable, row, rowIndex, column, columnIndex, null)
162
+ cellValue = getSeq($xetable, row, rowIndex, column, columnIndex)
166
163
  break
167
164
  case 'checkbox':
168
165
  cellValue = toBooleanValue($xetable.isCheckedByCheckboxRow(row))
@@ -12,10 +12,20 @@ function isOperateMouse ($xetable) {
12
12
  return $xetable._isResize || ($xetable.lastScrollTime && Date.now() < $xetable.lastScrollTime + $xetable.delayHover)
13
13
  }
14
14
 
15
- function renderLine (h, _vm, $xetable, rowLevel, items, params) {
16
- const column = params.column
17
- const { treeOpts, treeConfig } = $xetable
15
+ function renderLine (h, _vm, $xetable, params) {
16
+ const { row, column } = params
17
+ const { treeOpts, treeConfig, fullAllDataRowIdData } = $xetable
18
18
  const { slots, treeNode } = column
19
+ const rowid = UtilTools.getRowid($xetable, row)
20
+ const rest = fullAllDataRowIdData[rowid]
21
+ let rLevel = 0
22
+ let rIndex = 0
23
+ let items = []
24
+ if (rest) {
25
+ rLevel = rest.level
26
+ rIndex = rest._index
27
+ items = rest.items
28
+ }
19
29
  if (slots && slots.line) {
20
30
  return $xetable.callSlot(slots.line, params, h)
21
31
  }
@@ -27,8 +37,8 @@ function renderLine (h, _vm, $xetable, rowLevel, items, params) {
27
37
  h('div', {
28
38
  class: 'vxe-tree--line',
29
39
  style: {
30
- height: `${calcTreeLine(params, items)}px`,
31
- left: `${(rowLevel * treeOpts.indent) + (rowLevel ? 2 - getOffsetSize($xetable) : 0) + 16}px`
40
+ height: `${calcTreeLine(params, items, rIndex)}px`,
41
+ left: `${(rLevel * treeOpts.indent) + (rLevel ? 2 - getOffsetSize($xetable) : 0) + 16}px`
32
42
  }
33
43
  })
34
44
  ])
@@ -213,7 +223,7 @@ function renderColumn (h, _vm, $xetable, seq, rowid, fixedType, rowLevel, row, r
213
223
  } else {
214
224
  // 渲染单元格
215
225
  tdVNs.push(
216
- ...renderLine(h, _vm, $xetable, rowLevel, items, params),
226
+ ...renderLine(h, _vm, $xetable, params),
217
227
  h('div', {
218
228
  class: ['vxe-cell', {
219
229
  'c--title': showTitle,
@@ -286,7 +296,7 @@ function renderRows (h, _vm, $xetable, fixedType, tableData, tableColumn) {
286
296
  checkboxOpts,
287
297
  expandColumn,
288
298
  hasFixedColumn,
289
- fullDataRowIdData,
299
+ fullAllDataRowIdData,
290
300
  rowOpts
291
301
  } = $xetable
292
302
  const rows = []
@@ -312,7 +322,7 @@ function renderRows (h, _vm, $xetable, fixedType, tableData, tableColumn) {
312
322
  }
313
323
  }
314
324
  const rowid = UtilTools.getRowid($xetable, row)
315
- const rest = fullDataRowIdData[rowid]
325
+ const rest = fullAllDataRowIdData[rowid]
316
326
  const rowLevel = rest ? rest.level : 0
317
327
  const seq = rest ? rest.seq : -1
318
328
  const params = { $table: $xetable, seq, rowid, fixed: fixedType, type: renderType, level: rowLevel, row, rowIndex, $rowIndex }
@@ -283,7 +283,7 @@ const Methods = {
283
283
  return clearTableAllStatus(this)
284
284
  },
285
285
  /**
286
- * 同步 data 数据
286
+ * 同步 data 数据(即将废弃)
287
287
  * 如果用了该方法,那么组件将不再记录增删改的状态,只能自行实现对应逻辑
288
288
  * 对于某些特殊的场景,比如深层树节点元素发生变动时可能会用到
289
289
  */
@@ -301,23 +301,14 @@ const Methods = {
301
301
  return this.handleTableData(true).then(this.updateFooter).then(this.recalculate)
302
302
  },
303
303
  handleTableData (force) {
304
- const { treeConfig, scrollYLoad, scrollYStore, fullDataRowIdData, treeExpandeds, treeOpts } = this
305
- let fullList = []
304
+ const { scrollYLoad, scrollYStore, fullDataRowIdData, afterFullData } = this
305
+ let fullList = afterFullData
306
306
  // 是否进行数据处理
307
307
  if (force) {
308
+ // 更新数据,处理筛选和排序
308
309
  this.updateAfterFullData()
309
- }
310
- // 如果为虚拟树,将树结构拍平
311
- if (treeConfig && treeOpts.transform) {
312
- const expandMaps = new Map()
313
- XEUtils.eachTree(this.afterTreeFullData, (row, index, items, path, parent) => {
314
- if (!parent || (expandMaps.has(parent) && treeExpandeds.indexOf(parent) > -1)) {
315
- expandMaps.set(row, 1)
316
- fullList.push(row)
317
- }
318
- }, { children: treeOpts.mapChildren })
319
- } else {
320
- fullList = this.afterFullData
310
+ // 如果为虚拟树,将树结构拍平
311
+ fullList = this.handleVirtualTreeToList()
321
312
  }
322
313
  const tableData = scrollYLoad ? fullList.slice(scrollYStore.startIndex, scrollYStore.endIndex) : fullList.slice(0)
323
314
  tableData.forEach((row, $index) => {
@@ -602,7 +593,7 @@ const Methods = {
602
593
  },
603
594
  loadTreeChildren (row, childRecords) {
604
595
  const { keepSource, tableSourceData, treeOpts, fullDataRowIdData, fullDataRowMap, fullAllDataRowMap, fullAllDataRowIdData } = this
605
- const { children } = treeOpts
596
+ const { transform, children, mapChildren } = treeOpts
606
597
  const rest = fullAllDataRowIdData[getRowid(this, row)]
607
598
  const parentLevel = rest ? rest.level : 0
608
599
  return this.createData(childRecords).then((rows) => {
@@ -622,6 +613,9 @@ const Methods = {
622
613
  fullAllDataRowMap.set(childRow, rest)
623
614
  }, treeOpts)
624
615
  row[children] = rows
616
+ if (transform) {
617
+ row[mapChildren] = rows
618
+ }
625
619
  return rows
626
620
  })
627
621
  },
@@ -1108,6 +1102,27 @@ const Methods = {
1108
1102
  }
1109
1103
  return rowList
1110
1104
  },
1105
+ /**
1106
+ * 如果为虚拟树,将树结构拍平
1107
+ * @returns
1108
+ */
1109
+ handleVirtualTreeToList () {
1110
+ const { treeOpts, treeConfig, treeExpandeds, afterTreeFullData, afterFullData } = this
1111
+ if (treeConfig && treeOpts.transform) {
1112
+ const fullData = []
1113
+ const expandMaps = new Map()
1114
+ XEUtils.eachTree(afterTreeFullData, (row, index, items, path, parent) => {
1115
+ if (!parent || (expandMaps.has(parent) && treeExpandeds.indexOf(parent) > -1)) {
1116
+ expandMaps.set(row, 1)
1117
+ fullData.push(row)
1118
+ }
1119
+ }, { children: treeOpts.mapChildren })
1120
+ this.afterFullData = fullData
1121
+ this.updateScrollYStatus(fullData)
1122
+ return fullData
1123
+ }
1124
+ return afterFullData
1125
+ },
1111
1126
  /**
1112
1127
  * 获取处理后全量的表格数据
1113
1128
  * 如果存在筛选条件,继续处理
@@ -1164,34 +1179,53 @@ const Methods = {
1164
1179
  })
1165
1180
  }
1166
1181
  if (treeConfig && transform) {
1182
+ // 筛选虚拟树
1167
1183
  tableTree = XEUtils.searchTree(tableFullTreeData, handleFilter, { ...treeOpts, original: true })
1184
+ tableData = tableTree
1168
1185
  } else {
1169
1186
  tableData = treeConfig ? tableFullTreeData.filter(handleFilter) : tableFullData.filter(handleFilter)
1170
1187
  tableTree = tableData
1171
1188
  }
1172
1189
  } else {
1173
- tableData = treeConfig ? tableFullTreeData.slice(0) : tableFullData.slice(0)
1174
- tableTree = tableData
1190
+ if (treeConfig && transform) {
1191
+ // 还原虚拟树
1192
+ tableTree = XEUtils.searchTree(tableFullTreeData, () => true, { ...treeOpts, original: true })
1193
+ tableData = tableTree
1194
+ } else {
1195
+ tableData = treeConfig ? tableFullTreeData.slice(0) : tableFullData.slice(0)
1196
+ tableTree = tableData
1197
+ }
1175
1198
  }
1176
1199
  const firstOrderColumn = orderColumns[0]
1177
1200
  if (!allRemoteSort && firstOrderColumn) {
1178
- if (allSortMethod) {
1179
- const sortRests = allSortMethod({ data: tableData, column: firstOrderColumn.column, property: firstOrderColumn.property, order: firstOrderColumn.order, sortList: orderColumns, $table: this })
1180
- tableData = XEUtils.isArray(sortRests) ? sortRests : tableData
1201
+ if (treeConfig && transform) {
1202
+ // 虚拟树和列表一样,只能排序根级节点
1203
+ if (allSortMethod) {
1204
+ const sortRests = allSortMethod({ data: tableTree, sortList: orderColumns, $table: this })
1205
+ tableTree = XEUtils.isArray(sortRests) ? sortRests : tableTree
1206
+ } else {
1207
+ tableTree = XEUtils.orderBy(tableTree, orderColumns.map(({ column, order }) => [getOrderField(this, column), order]))
1208
+ }
1209
+ tableData = tableTree
1181
1210
  } else {
1182
- // 兼容 v4
1183
- if (sortMultiple) {
1184
- tableData = XEUtils.orderBy(tableData, orderColumns.map(({ column, order }) => [getOrderField(this, column), order]))
1211
+ if (allSortMethod) {
1212
+ const sortRests = allSortMethod({ data: tableData, column: firstOrderColumn.column, property: firstOrderColumn.property, order: firstOrderColumn.order, sortList: orderColumns, $table: this })
1213
+ tableData = XEUtils.isArray(sortRests) ? sortRests : tableData
1185
1214
  } else {
1186
- // 兼容 v2,在 v4 中废弃, sortBy 不能为数组
1187
- let sortByConfs
1188
- if (XEUtils.isArray(firstOrderColumn.sortBy)) {
1189
- sortByConfs = firstOrderColumn.sortBy.map(item => [item, firstOrderColumn.order])
1215
+ // 兼容 v4
1216
+ if (sortMultiple) {
1217
+ tableData = XEUtils.orderBy(tableData, orderColumns.map(({ column, order }) => [getOrderField(this, column), order]))
1218
+ } else {
1219
+ // 兼容 v2,在 v4 中废弃, sortBy 不能为数组
1220
+ let sortByConfs
1221
+ if (XEUtils.isArray(firstOrderColumn.sortBy)) {
1222
+ sortByConfs = firstOrderColumn.sortBy.map(item => [item, firstOrderColumn.order])
1223
+ }
1224
+ tableData = XEUtils.orderBy(tableData, sortByConfs || [firstOrderColumn].map(({ column, order }) => [getOrderField(this, column), order]))
1190
1225
  }
1191
- tableData = XEUtils.orderBy(tableData, sortByConfs || [firstOrderColumn].map(({ column, order }) => [getOrderField(this, column), order]))
1192
1226
  }
1227
+ tableTree = tableData
1193
1228
  }
1194
- tableTree = tableData
1195
1229
  }
1196
1230
  this.afterFullData = tableData
1197
1231
  this.afterTreeFullData = tableTree
@@ -1207,33 +1241,28 @@ const Methods = {
1207
1241
  XEUtils.eachTree(afterTreeFullData, (row, index, items, path) => {
1208
1242
  const rowid = getRowid(this, row)
1209
1243
  const allrest = fullAllDataRowIdData[rowid]
1210
- const fullrest = fullDataRowIdData[rowid]
1211
1244
  const seq = path.map((num, i) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
1212
1245
  if (allrest) {
1213
1246
  allrest.seq = seq
1214
- }
1215
- if (fullrest) {
1216
- fullrest.seq = seq
1247
+ allrest._index = index
1217
1248
  } else {
1218
- fullAllDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1219
- fullDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1249
+ const rest = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1250
+ fullAllDataRowIdData[rowid] = rest
1251
+ fullDataRowIdData[rowid] = rest
1220
1252
  }
1221
- }, treeOpts)
1253
+ }, { children: treeOpts.mapChildren })
1222
1254
  } else {
1223
1255
  afterFullData.forEach((row, index) => {
1224
1256
  const rowid = getRowid(this, row)
1225
1257
  const allrest = fullAllDataRowIdData[rowid]
1226
- const fullrest = fullDataRowIdData[rowid]
1227
1258
  const seq = index + 1
1228
1259
  if (allrest) {
1229
1260
  allrest.seq = seq
1230
- }
1231
- if (fullrest) {
1232
- fullrest.seq = seq
1233
- fullrest._index = index
1261
+ allrest._index = index
1234
1262
  } else {
1235
- fullAllDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1236
- fullDataRowIdData[rowid] = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1263
+ const rest = { row, rowid, seq, index: -1, $index: -1, _index: index, items: [], parent: null, level: 0 }
1264
+ fullAllDataRowIdData[rowid] = rest
1265
+ fullDataRowIdData[rowid] = rest
1237
1266
  }
1238
1267
  })
1239
1268
  }
@@ -3782,12 +3811,16 @@ const Methods = {
3782
3811
  },
3783
3812
  clearTreeExpandLoaded (row) {
3784
3813
  const { treeOpts, treeExpandeds, fullAllDataRowMap } = this
3785
- const { lazy } = treeOpts
3814
+ const { transform, lazy } = treeOpts
3786
3815
  const rest = fullAllDataRowMap.get(row)
3787
3816
  if (lazy && rest) {
3788
3817
  rest.treeLoaded = false
3789
3818
  XEUtils.remove(treeExpandeds, item => row === item)
3790
3819
  }
3820
+ if (transform) {
3821
+ this.handleVirtualTreeToList()
3822
+ return this.handleTableData()
3823
+ }
3791
3824
  return this.$nextTick()
3792
3825
  },
3793
3826
  /**
@@ -3802,6 +3835,7 @@ const Methods = {
3802
3835
  return this.handleAsyncTreeExpandChilds(row)
3803
3836
  }).then(() => {
3804
3837
  if (transform) {
3838
+ this.handleVirtualTreeToList()
3805
3839
  return this.handleTableData()
3806
3840
  }
3807
3841
  }).then(() => {
@@ -3862,7 +3896,7 @@ const Methods = {
3862
3896
  },
3863
3897
  handleAsyncTreeExpandChilds (row) {
3864
3898
  const { fullAllDataRowMap, treeExpandeds, treeOpts, treeLazyLoadeds, checkboxOpts } = this
3865
- const { loadMethod } = treeOpts
3899
+ const { transform, loadMethod } = treeOpts
3866
3900
  const { checkStrictly } = checkboxOpts
3867
3901
  const rest = fullAllDataRowMap.get(row)
3868
3902
  return new Promise(resolve => {
@@ -3882,9 +3916,17 @@ const Methods = {
3882
3916
  if (!checkStrictly && this.isCheckedByCheckboxRow(row)) {
3883
3917
  this.setCheckboxRow(childRows, true)
3884
3918
  }
3919
+ this.$nextTick().then(() => {
3920
+ if (transform) {
3921
+ return this.handleTableData()
3922
+ }
3923
+ }).then(() => {
3924
+ return this.recalculate()
3925
+ }).then(() => resolve())
3885
3926
  })
3927
+ } else {
3928
+ this.$nextTick().then(() => this.recalculate()).then(() => resolve())
3886
3929
  }
3887
- resolve(this.$nextTick().then(this.recalculate))
3888
3930
  })
3889
3931
  })
3890
3932
  },
@@ -3956,6 +3998,7 @@ const Methods = {
3956
3998
  */
3957
3999
  handleVirtualTreeExpand (rows, expanded) {
3958
4000
  return this.handleBaseTreeExpand(rows, expanded).then(() => {
4001
+ this.handleVirtualTreeToList()
3959
4002
  return this.handleTableData()
3960
4003
  }).then(() => {
3961
4004
  return this.recalculate()
@@ -3998,13 +4041,18 @@ const Methods = {
3998
4041
  */
3999
4042
  clearTreeExpand () {
4000
4043
  const { treeOpts, treeExpandeds, tableFullData } = this
4001
- const { reserve } = treeOpts
4044
+ const { transform, reserve } = treeOpts
4002
4045
  const isExists = treeExpandeds.length
4003
4046
  this.treeExpandeds = []
4004
4047
  if (reserve) {
4005
4048
  XEUtils.eachTree(tableFullData, row => this.handleTreeExpandReserve(row, false), treeOpts)
4006
4049
  }
4007
4050
  return this.handleTableData().then(() => {
4051
+ if (transform) {
4052
+ this.handleVirtualTreeToList()
4053
+ return this.handleTableData()
4054
+ }
4055
+ }).then(() => {
4008
4056
  if (isExists) {
4009
4057
  this.recalculate()
4010
4058
  }
@@ -115,9 +115,12 @@ export function getColMinWidth (params) {
115
115
  }
116
116
 
117
117
  function countTreeExpand (prevRow, params) {
118
+ let count = 1
119
+ if (!prevRow) {
120
+ return count
121
+ }
118
122
  const { $table } = params
119
123
  const rowChildren = prevRow[$table.treeOpts.children]
120
- let count = 1
121
124
  if ($table.isTreeExpandByRow(prevRow)) {
122
125
  for (let index = 0; index < rowChildren.length; index++) {
123
126
  count += countTreeExpand(rowChildren[index], params)
@@ -130,13 +133,13 @@ export function getOffsetSize ($xetable) {
130
133
  return lineOffsetSizes[$xetable.vSize] || 0
131
134
  }
132
135
 
133
- export function calcTreeLine (params, items) {
134
- const { $table, $rowIndex } = params
136
+ export function calcTreeLine (params, items, rIndex) {
137
+ const { $table } = params
135
138
  let expandSize = 1
136
- if ($rowIndex) {
137
- expandSize = countTreeExpand(items[$rowIndex - 1], params)
139
+ if (rIndex) {
140
+ expandSize = countTreeExpand(items[rIndex - 1], params)
138
141
  }
139
- return $table.rowHeight * expandSize - ($rowIndex ? 1 : (12 - getOffsetSize($table)))
142
+ return $table.rowHeight * expandSize - (rIndex ? 1 : (12 - getOffsetSize($table)))
140
143
  }
141
144
 
142
145
  export function mergeBodyMethod (mergeList, _rowIndex, _columnIndex) {
@@ -151,7 +151,7 @@ export default {
151
151
  const ruleProps = Object.keys(validRest)
152
152
  return this.$nextTick().then(() => {
153
153
  if (ruleProps.length) {
154
- return validRest[ruleProps[0]][0]
154
+ return Promise.reject(validRest[ruleProps[0]][0])
155
155
  }
156
156
  if (cb) {
157
157
  cb()
package/types/table.d.ts CHANGED
@@ -272,6 +272,7 @@ export declare class Table extends VXETableComponent {
272
272
  /**
273
273
  * 同步 data 数据;如果用了该方法,那么组件将不再记录增删改的状态,只能自行实现对应逻辑
274
274
  * 对于某些特殊的场景,比如深层树节点元素发生变动时可能会用到
275
+ * @deprecated
275
276
  */
276
277
  syncData(): Promise<any>;
277
278
  /**