vxe-table 3.4.0 → 3.4.3

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vxe-table",
3
- "version": "3.4.0",
4
- "description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...",
3
+ "version": "3.4.3",
4
+ "description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
7
7
  "lint": "vue-cli-service lint",
@@ -3,6 +3,8 @@ import VXETable from '../../v-x-e-table'
3
3
  import { UtilTools, DomTools, isEnableConf } from '../../tools'
4
4
  import { browse } from '../../tools/src/dom'
5
5
 
6
+ const { getRowid } = UtilTools
7
+
6
8
  export default {
7
9
  methods: {
8
10
  /**
@@ -22,21 +24,51 @@ export default {
22
24
  * @param {Row} row 指定行
23
25
  */
24
26
  _insertAt (records, row) {
25
- const { mergeList, afterFullData, editStore, sYOpts, scrollYLoad, tableFullData, treeConfig } = this
27
+ const { treeFullData, mergeList, afterFullData, editStore, sYOpts, scrollYLoad, tableFullData, treeConfig, fullDataRowIdData, fullAllDataRowIdData, treeOpts } = this
26
28
  if (!XEUtils.isArray(records)) {
27
29
  records = [records]
28
30
  }
29
31
  const newRecords = records.map(record => this.defineField(Object.assign({}, record)))
30
32
  if (!row) {
31
- afterFullData.unshift(...newRecords)
32
- tableFullData.unshift(...newRecords)
33
- // 刷新单元格合并
34
- mergeList.forEach(mergeItem => {
35
- const { row: mergeRowIndex } = mergeItem
36
- if (mergeRowIndex > 0) {
37
- mergeItem.row = mergeRowIndex + newRecords.length
38
- }
39
- })
33
+ // 如果为虚拟树
34
+ if (treeConfig && treeOpts.transform) {
35
+ newRecords.forEach(item => {
36
+ const parentRowId = item[treeOpts.parentField]
37
+ const rowid = getRowid(this, item)
38
+ if (parentRowId) {
39
+ const matchObj = XEUtils.findTree(treeFullData, item => parentRowId === item[treeOpts.rowField], treeOpts)
40
+ if (matchObj) {
41
+ const { item: parentRow } = matchObj
42
+ const parentRest = fullAllDataRowIdData[getRowid(this, parentRow)]
43
+ const parentLevel = parentRest ? parentRest.level : 0
44
+ let parentChilds = parentRow[treeOpts.children]
45
+ if (!XEUtils.isArray(parentChilds)) {
46
+ parentChilds = parentRow[treeOpts.children] = []
47
+ }
48
+ parentChilds.push(item)
49
+ const rest = { row: item, rowid, index: -1, _index: -1, $index: -1, items: parentChilds, parent, level: parentLevel + 1 }
50
+ fullDataRowIdData[rowid] = rest
51
+ fullAllDataRowIdData[rowid] = rest
52
+ } else {
53
+ // 父节点不存在
54
+ }
55
+ } else {
56
+ afterFullData.unshift(item)
57
+ treeFullData.unshift(item)
58
+ }
59
+ })
60
+ this.updateVirtualTreeData()
61
+ } else {
62
+ afterFullData.unshift(...newRecords)
63
+ tableFullData.unshift(...newRecords)
64
+ // 刷新单元格合并
65
+ mergeList.forEach(mergeItem => {
66
+ const { row: mergeRowIndex } = mergeItem
67
+ if (mergeRowIndex > 0) {
68
+ mergeItem.row = mergeRowIndex + newRecords.length
69
+ }
70
+ })
71
+ }
40
72
  } else {
41
73
  if (row === -1) {
42
74
  afterFullData.push(...newRecords)
@@ -95,7 +127,7 @@ export default {
95
127
  * 如果为空则删除所有
96
128
  */
97
129
  _remove (rows) {
98
- const { afterFullData, tableFullData, treeConfig, mergeList, editStore, checkboxOpts, selection, isInsertByRow, sYOpts, scrollYLoad } = this
130
+ const { afterFullData, tableFullData, treeFullData, treeConfig, mergeList, editStore, checkboxOpts, selection, isInsertByRow, sYOpts, scrollYLoad, treeOpts } = this
99
131
  const { actived, removeList, insertList } = editStore
100
132
  const { checkField: property } = checkboxOpts
101
133
  let rest = []
@@ -126,26 +158,43 @@ export default {
126
158
  this.afterFullData = []
127
159
  this.clearMergeCells()
128
160
  } else {
129
- rows.forEach(row => {
130
- const tfIndex = tableFullData.indexOf(row)
131
- if (tfIndex > -1) {
132
- const rItems = tableFullData.splice(tfIndex, 1)
133
- rest.push(rItems[0])
134
- }
135
- const afIndex = afterFullData.indexOf(row)
136
- if (afIndex > -1) {
137
- // 刷新单元格合并
138
- mergeList.forEach(mergeItem => {
139
- const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
140
- if (mergeRowIndex > afIndex) {
141
- mergeItem.row = mergeRowIndex - 1
142
- } else if (mergeRowIndex + mergeRowspan > afIndex) {
143
- mergeItem.rowspan = mergeRowspan - 1
144
- }
145
- })
146
- afterFullData.splice(afIndex, 1)
147
- }
148
- })
161
+ // 如果为虚拟树
162
+ if (treeConfig && treeOpts.transform) {
163
+ rows.forEach((row) => {
164
+ const rowid = getRowid(this, row)
165
+ const matchObj = XEUtils.findTree(treeFullData, item => rowid === getRowid(this, item), treeOpts)
166
+ if (matchObj) {
167
+ const rItems = matchObj.items.splice(matchObj.index, 1)
168
+ rest.push(rItems[0])
169
+ }
170
+ const afIndex = afterFullData.indexOf(row)
171
+ if (afIndex > -1) {
172
+ afterFullData.splice(afIndex, 1)
173
+ }
174
+ this.updateVirtualTreeData()
175
+ })
176
+ } else {
177
+ rows.forEach(row => {
178
+ const tfIndex = tableFullData.indexOf(row)
179
+ if (tfIndex > -1) {
180
+ const rItems = tableFullData.splice(tfIndex, 1)
181
+ rest.push(rItems[0])
182
+ }
183
+ const afIndex = afterFullData.indexOf(row)
184
+ if (afIndex > -1) {
185
+ // 刷新单元格合并
186
+ mergeList.forEach(mergeItem => {
187
+ const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem
188
+ if (mergeRowIndex > afIndex) {
189
+ mergeItem.row = mergeRowIndex - 1
190
+ } else if (mergeRowIndex + mergeRowspan > afIndex) {
191
+ mergeItem.rowspan = mergeRowspan - 1
192
+ }
193
+ })
194
+ afterFullData.splice(afIndex, 1)
195
+ }
196
+ })
197
+ }
149
198
  }
150
199
  // 如果当前行被激活编辑,则清除激活状态
151
200
  if (actived.row && rows.indexOf(actived.row) > -1) {
@@ -216,14 +265,26 @@ export default {
216
265
  * 获取新增的临时数据
217
266
  */
218
267
  _getInsertRecords () {
268
+ const { treeConfig, treeFullData, tableFullData, treeOpts } = this
219
269
  const insertList = this.editStore.insertList
220
270
  const insertRecords = []
221
271
  if (insertList.length) {
222
- this.tableFullData.forEach(row => {
223
- if (insertList.indexOf(row) > -1) {
224
- insertRecords.push(row)
225
- }
226
- })
272
+ // 如果为虚拟树
273
+ if (treeConfig && treeOpts.transform) {
274
+ insertList.forEach(row => {
275
+ const rowid = getRowid(this, row)
276
+ const matchObj = XEUtils.findTree(treeFullData, item => rowid === getRowid(this, item), treeOpts)
277
+ if (matchObj) {
278
+ insertRecords.push(row)
279
+ }
280
+ })
281
+ } else {
282
+ insertList.forEach(row => {
283
+ if (tableFullData.indexOf(row) > -1) {
284
+ insertRecords.push(row)
285
+ }
286
+ })
287
+ }
227
288
  }
228
289
  return insertRecords
229
290
  },
@@ -121,7 +121,7 @@ export default {
121
121
  if (scrollXLoad && !hasEllipsis) {
122
122
  showEllipsis = hasEllipsis = true
123
123
  }
124
- if (highlightCurrentColumn || tableListeners['header-cell-click'] || sortOpts.trigger === 'cell') {
124
+ if (columnOpts.isCurrent || highlightCurrentColumn || tableListeners['header-cell-click'] || sortOpts.trigger === 'cell') {
125
125
  thOns.click = evnt => $xetable.triggerHeaderCellClickEvent(evnt, params)
126
126
  }
127
127
  if (tableListeners['header-cell-dblclick']) {
@@ -141,7 +141,7 @@ function renderColumn (h, _vm, $xetable, $seq, seq, rowid, fixedType, rowLevel,
141
141
  }
142
142
  }
143
143
  // 点击事件处理
144
- if (highlightCurrentRow ||
144
+ if ((rowOpts.isCurrent || highlightCurrentRow) ||
145
145
  tableListeners['cell-click'] ||
146
146
  (editRender && editConfig) ||
147
147
  (expandOpts.trigger === 'row' || (expandOpts.trigger === 'cell')) ||
@@ -287,7 +287,8 @@ function renderRows (h, _vm, $xetable, $seq, fixedType, tableData, tableColumn)
287
287
  checkboxOpts,
288
288
  expandColumn,
289
289
  hasFixedColumn,
290
- fullAllDataRowIdData
290
+ fullAllDataRowIdData,
291
+ rowOpts
291
292
  } = $xetable
292
293
  const rows = []
293
294
  tableData.forEach((row, $rowIndex) => {
@@ -301,7 +302,7 @@ function renderRows (h, _vm, $xetable, $seq, fixedType, tableData, tableColumn)
301
302
  // 确保任何情况下 rowIndex 都精准指向真实 data 索引
302
303
  rowIndex = $xetable.getRowIndex(row)
303
304
  // 事件绑定
304
- if (highlightHoverRow) {
305
+ if (rowOpts.isHover || highlightHoverRow) {
305
306
  trOn.mouseenter = evnt => {
306
307
  if (isOperateMouse($xetable)) {
307
308
  return
@@ -579,7 +580,7 @@ export default {
579
580
  */
580
581
  scrollEvent (evnt) {
581
582
  const { $el: scrollBodyElem, $parent: $xetable, fixedType } = this
582
- const { $refs, elemStore, highlightHoverRow, scrollXLoad, scrollYLoad, lastScrollTop, lastScrollLeft } = $xetable
583
+ const { $refs, elemStore, highlightHoverRow, scrollXLoad, scrollYLoad, lastScrollTop, lastScrollLeft, rowOpts } = $xetable
583
584
  const { tableHeader, tableBody, leftBody, rightBody, tableFooter, validTip } = $refs
584
585
  const headerElem = tableHeader ? tableHeader.$el : null
585
586
  const footerElem = tableFooter ? tableFooter.$el : null
@@ -597,7 +598,7 @@ export default {
597
598
  $xetable.lastScrollTop = scrollTop
598
599
  $xetable.lastScrollLeft = scrollLeft
599
600
  $xetable.lastScrollTime = Date.now()
600
- if (highlightHoverRow) {
601
+ if (rowOpts.isHover || highlightHoverRow) {
601
602
  $xetable.clearHoverRow()
602
603
  }
603
604
  if (leftElem && fixedType === 'left') {
@@ -683,7 +684,7 @@ export default {
683
684
  wheelEvent (evnt) {
684
685
  const { deltaY, deltaX } = evnt
685
686
  const { $el: scrollBodyElem, $parent: $xetable } = this
686
- const { $refs, highlightHoverRow, scrollYLoad, lastScrollTop, lastScrollLeft } = $xetable
687
+ const { $refs, highlightHoverRow, scrollYLoad, lastScrollTop, lastScrollLeft, rowOpts } = $xetable
687
688
  const { tableBody } = $refs
688
689
  const bodyElem = tableBody.$el
689
690
 
@@ -706,7 +707,7 @@ export default {
706
707
  $xetable.lastScrollTop = scrollTop
707
708
  $xetable.lastScrollLeft = scrollLeft
708
709
  $xetable.lastScrollTime = Date.now()
709
- if (highlightHoverRow) {
710
+ if (rowOpts.isHover || highlightHoverRow) {
710
711
  $xetable.clearHoverRow()
711
712
  }
712
713
  this.handleWheel(evnt, isTopWheel, deltaTop, isRollX, isRollY)
@@ -291,17 +291,18 @@ export const Cell = {
291
291
  const { $table, column, isHidden } = params
292
292
  const { radioOpts, selectRow } = $table
293
293
  const { slots } = column
294
- const { labelField, checkMethod } = radioOpts
294
+ const { labelField, checkMethod, visibleMethod } = radioOpts
295
295
  const { row } = params
296
296
  const defaultSlot = slots ? slots.default : null
297
297
  const radioSlot = slots ? slots.radio : null
298
298
  const isChecked = row === selectRow
299
+ const isVisible = !visibleMethod || visibleMethod({ row })
299
300
  let isDisabled = !!checkMethod
300
301
  let on
301
302
  if (!isHidden) {
302
303
  on = {
303
304
  click (evnt) {
304
- if (!isDisabled) {
305
+ if (!isDisabled && isVisible) {
305
306
  $table.triggerRadioRowEvent(evnt, params)
306
307
  }
307
308
  }
@@ -310,26 +311,36 @@ export const Cell = {
310
311
  isDisabled = !checkMethod({ row })
311
312
  }
312
313
  }
313
- const radioParams = { ...params, checked: isChecked, disabled: isDisabled }
314
- return radioSlot ? $table.callSlot(radioSlot, radioParams, h) : [
315
- h('span', {
316
- class: ['vxe-cell--radio', {
317
- 'is--checked': isChecked,
318
- 'is--disabled': isDisabled
319
- }],
320
- on
321
- }, [
314
+ const radioParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible }
315
+ if (radioSlot) {
316
+ return $table.callSlot(radioSlot, radioParams, h)
317
+ }
318
+ const radioVNs = []
319
+ if (isVisible) {
320
+ radioVNs.push(
322
321
  h('span', {
323
322
  class: 'vxe-radio--icon vxe-radio--checked-icon'
324
323
  }),
325
324
  h('span', {
326
325
  class: 'vxe-radio--icon vxe-radio--unchecked-icon'
327
326
  })
328
- ].concat(defaultSlot || labelField ? [
327
+ )
328
+ }
329
+ if (defaultSlot || labelField) {
330
+ radioVNs.push(
329
331
  h('span', {
330
332
  class: 'vxe-radio--label'
331
333
  }, defaultSlot ? $table.callSlot(defaultSlot, radioParams, h) : XEUtils.get(row, labelField))
332
- ] : []))
334
+ )
335
+ }
336
+ return [
337
+ h('span', {
338
+ class: ['vxe-cell--radio', {
339
+ 'is--checked': isChecked,
340
+ 'is--disabled': isDisabled
341
+ }],
342
+ on
343
+ }, radioVNs)
333
344
  ]
334
345
  },
335
346
  renderTreeRadioCell (h, params) {
@@ -401,19 +412,20 @@ export const Cell = {
401
412
  renderSelectionCell (h, params) {
402
413
  const { $table, row, column, isHidden } = params
403
414
  const { treeConfig, treeIndeterminates } = $table
404
- const { labelField, checkMethod } = $table.checkboxOpts
415
+ const { labelField, checkMethod, visibleMethod } = $table.checkboxOpts
405
416
  const { slots } = column
406
417
  const defaultSlot = slots ? slots.default : null
407
418
  const checkboxSlot = slots ? slots.checkbox : null
408
419
  let indeterminate = false
409
420
  let isChecked = false
421
+ const isVisible = !visibleMethod || visibleMethod({ row })
410
422
  let isDisabled = !!checkMethod
411
423
  let on
412
424
  if (!isHidden) {
413
425
  isChecked = $table.selection.indexOf(row) > -1
414
426
  on = {
415
427
  click (evnt) {
416
- if (!isDisabled) {
428
+ if (!isDisabled && isVisible) {
417
429
  $table.triggerCheckRowEvent(evnt, params, !isChecked)
418
430
  }
419
431
  }
@@ -425,16 +437,13 @@ export const Cell = {
425
437
  indeterminate = treeIndeterminates.indexOf(row) > -1
426
438
  }
427
439
  }
428
- const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, indeterminate }
429
- return checkboxSlot ? $table.callSlot(checkboxSlot, checkboxParams, h) : [
430
- h('span', {
431
- class: ['vxe-cell--checkbox', {
432
- 'is--checked': isChecked,
433
- 'is--disabled': isDisabled,
434
- 'is--indeterminate': indeterminate
435
- }],
436
- on
437
- }, [
440
+ const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible, indeterminate }
441
+ if (checkboxSlot) {
442
+ return $table.callSlot(checkboxSlot, checkboxParams, h)
443
+ }
444
+ const checkVNs = []
445
+ if (isVisible) {
446
+ checkVNs.push(
438
447
  h('span', {
439
448
  class: 'vxe-checkbox--icon vxe-checkbox--checked-icon'
440
449
  }),
@@ -444,11 +453,24 @@ export const Cell = {
444
453
  h('span', {
445
454
  class: 'vxe-checkbox--icon vxe-checkbox--indeterminate-icon'
446
455
  })
447
- ].concat(defaultSlot || labelField ? [
456
+ )
457
+ }
458
+ if (defaultSlot || labelField) {
459
+ checkVNs.push(
448
460
  h('span', {
449
461
  class: 'vxe-checkbox--label'
450
462
  }, defaultSlot ? $table.callSlot(defaultSlot, checkboxParams, h) : XEUtils.get(row, labelField))
451
- ] : []))
463
+ )
464
+ }
465
+ return [
466
+ h('span', {
467
+ class: ['vxe-cell--checkbox', {
468
+ 'is--checked': isChecked,
469
+ 'is--disabled': isDisabled,
470
+ 'is--indeterminate': indeterminate
471
+ }],
472
+ on
473
+ }, checkVNs)
452
474
  ]
453
475
  },
454
476
  renderTreeSelectionCell (h, params) {
@@ -457,19 +479,20 @@ export const Cell = {
457
479
  renderSelectionCellByProp (h, params) {
458
480
  const { $table, row, column, isHidden } = params
459
481
  const { treeConfig, treeIndeterminates } = $table
460
- const { labelField, checkField: property, halfField, checkMethod } = $table.checkboxOpts
482
+ const { labelField, checkField: property, halfField, checkMethod, visibleMethod } = $table.checkboxOpts
461
483
  const { slots } = column
462
484
  const defaultSlot = slots ? slots.default : null
463
485
  const checkboxSlot = slots ? slots.checkbox : null
464
486
  let indeterminate = false
465
487
  let isChecked = false
488
+ const isVisible = !visibleMethod || visibleMethod({ row })
466
489
  let isDisabled = !!checkMethod
467
490
  let on
468
491
  if (!isHidden) {
469
492
  isChecked = XEUtils.get(row, property)
470
493
  on = {
471
494
  click (evnt) {
472
- if (!isDisabled) {
495
+ if (!isDisabled && isVisible) {
473
496
  $table.triggerCheckRowEvent(evnt, params, !isChecked)
474
497
  }
475
498
  }
@@ -481,16 +504,13 @@ export const Cell = {
481
504
  indeterminate = treeIndeterminates.indexOf(row) > -1
482
505
  }
483
506
  }
484
- const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, indeterminate }
485
- return checkboxSlot ? $table.callSlot(checkboxSlot, checkboxParams, h) : [
486
- h('span', {
487
- class: ['vxe-cell--checkbox', {
488
- 'is--checked': isChecked,
489
- 'is--disabled': isDisabled,
490
- 'is--indeterminate': halfField && !isChecked ? row[halfField] : indeterminate
491
- }],
492
- on
493
- }, [
507
+ const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible, indeterminate }
508
+ if (checkboxSlot) {
509
+ return $table.callSlot(checkboxSlot, checkboxParams, h)
510
+ }
511
+ const checkVNs = []
512
+ if (isVisible) {
513
+ checkVNs.push(
494
514
  h('span', {
495
515
  class: 'vxe-checkbox--icon vxe-checkbox--checked-icon'
496
516
  }),
@@ -500,11 +520,24 @@ export const Cell = {
500
520
  h('span', {
501
521
  class: 'vxe-checkbox--icon vxe-checkbox--indeterminate-icon'
502
522
  })
503
- ].concat(defaultSlot || labelField ? [
523
+ )
524
+ }
525
+ if (defaultSlot || labelField) {
526
+ checkVNs.push(
504
527
  h('span', {
505
528
  class: 'vxe-checkbox--label'
506
529
  }, defaultSlot ? $table.callSlot(defaultSlot, checkboxParams, h) : XEUtils.get(row, labelField))
507
- ] : []))
530
+ )
531
+ }
532
+ return [
533
+ h('span', {
534
+ class: ['vxe-cell--checkbox', {
535
+ 'is--checked': isChecked,
536
+ 'is--disabled': isDisabled,
537
+ 'is--indeterminate': halfField && !isChecked ? row[halfField] : indeterminate
538
+ }],
539
+ on
540
+ }, checkVNs)
508
541
  ]
509
542
  },
510
543
  renderTreeSelectionCellByProp (h, params) {