vxe-table 3.4.2 → 3.4.3-beta.0

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.
@@ -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)
@@ -2135,7 +2135,7 @@ const Methods = {
2135
2135
  // 该行为只对当前激活的表格有效
2136
2136
  if (this.isActivated) {
2137
2137
  this.preventEvent(evnt, 'event.keydown', null, () => {
2138
- const { filterStore, isCtxMenu, ctxMenuStore, editStore, editOpts, editConfig, mouseConfig, mouseOpts, keyboardConfig, keyboardOpts, treeConfig, treeOpts, highlightCurrentRow, currentRow, bodyCtxMenu } = this
2138
+ const { filterStore, isCtxMenu, ctxMenuStore, editStore, editOpts, editConfig, mouseConfig, mouseOpts, keyboardConfig, keyboardOpts, treeConfig, treeOpts, highlightCurrentRow, currentRow, bodyCtxMenu, rowOpts } = this
2139
2139
  const { selected, actived } = editStore
2140
2140
  const { keyCode } = evnt
2141
2141
  const isBack = keyCode === 8
@@ -2198,7 +2198,7 @@ const Methods = {
2198
2198
  this.keyCtxTimeout = setTimeout(() => {
2199
2199
  this._keyCtx = false
2200
2200
  }, 1000)
2201
- } else if (isEnter && !hasAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && highlightCurrentRow && currentRow))) {
2201
+ } else if (isEnter && !hasAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow))) {
2202
2202
  // 退出选中
2203
2203
  if (hasCtrlKey) {
2204
2204
  // 如果是激活编辑状态,则取消编辑
@@ -2227,7 +2227,7 @@ const Methods = {
2227
2227
  this.moveSelected(targetArgs, isLeftArrow, false, isRightArrow, true, evnt)
2228
2228
  }
2229
2229
  }
2230
- } else if (treeConfig && highlightCurrentRow && currentRow) {
2230
+ } else if (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2231
2231
  // 如果是树形表格当前行回车移动到子节点
2232
2232
  const childrens = currentRow[treeOpts.children]
2233
2233
  if (childrens && childrens.length) {
@@ -2245,7 +2245,7 @@ const Methods = {
2245
2245
  // 如果按下了方向键
2246
2246
  if (selected.row && selected.column) {
2247
2247
  this.moveSelected(selected.args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt)
2248
- } else if ((isUpArrow || isDwArrow) && highlightCurrentRow) {
2248
+ } else if ((isUpArrow || isDwArrow) && (rowOpts.isCurrent || highlightCurrentRow)) {
2249
2249
  // 当前行按键上下移动
2250
2250
  this.moveCurrentRow(isUpArrow, isDwArrow, evnt)
2251
2251
  }
@@ -2257,7 +2257,7 @@ const Methods = {
2257
2257
  } else if (actived.row || actived.column) {
2258
2258
  this.moveTabSelected(actived.args, hasShiftKey, evnt)
2259
2259
  }
2260
- } else if (keyboardConfig && (isDel || (treeConfig && highlightCurrentRow && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
2260
+ } else if (keyboardConfig && (isDel || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
2261
2261
  if (!isEditStatus) {
2262
2262
  const { delMethod, backMethod } = keyboardOpts
2263
2263
  // 如果是删除键
@@ -2289,7 +2289,7 @@ const Methods = {
2289
2289
  // 如果按下 del 键,更新表尾数据
2290
2290
  this.updateFooter()
2291
2291
  }
2292
- } else if (isBack && keyboardOpts.isArrow && treeConfig && highlightCurrentRow && currentRow) {
2292
+ } else if (isBack && keyboardOpts.isArrow && treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2293
2293
  // 如果树形表格回退键关闭当前行返回父节点
2294
2294
  const { parent: parentRow } = XEUtils.findTree(this.afterFullData, item => item === currentRow, treeOpts)
2295
2295
  if (parentRow) {
@@ -3052,11 +3052,11 @@ const Methods = {
3052
3052
  * @param {Row} row 行对象
3053
3053
  */
3054
3054
  setCurrentRow (row) {
3055
- const { $el } = this
3055
+ const { $el, rowOpts } = this
3056
3056
  this.clearCurrentRow()
3057
3057
  this.clearCurrentColumn()
3058
3058
  this.currentRow = row
3059
- if (this.highlightCurrentRow) {
3059
+ if (rowOpts.isCurrent || this.highlightCurrentRow) {
3060
3060
  if ($el) {
3061
3061
  XEUtils.arrayEach($el.querySelectorAll(`[rowid="${getRowid(this, row)}"]`), elem => addClass(elem, 'row--current'))
3062
3062
  }
@@ -3102,7 +3102,7 @@ const Methods = {
3102
3102
  * 用于当前行,获取当前行的数据
3103
3103
  */
3104
3104
  getCurrentRecord () {
3105
- return this.highlightCurrentRow ? this.currentRow : null
3105
+ return this.rowOpts.isCurrent || this.highlightCurrentRow ? this.currentRow : null
3106
3106
  },
3107
3107
  /**
3108
3108
  * 用于单选行,获取当已选中的数据
@@ -3164,7 +3164,7 @@ const Methods = {
3164
3164
  this.triggerSortEvent(evnt, column, getNextSortOrder(this, column))
3165
3165
  }
3166
3166
  this.emitEvent('header-cell-click', Object.assign({ triggerResizable, triggerSort, triggerFilter, cell }, params), evnt)
3167
- if (this.highlightCurrentColumn) {
3167
+ if (this.columnOpts.isCurrent || this.highlightCurrentColumn) {
3168
3168
  return this.setCurrentColumn(column)
3169
3169
  }
3170
3170
  return this.$nextTick()
@@ -3173,7 +3173,7 @@ const Methods = {
3173
3173
  this.emitEvent('header-cell-dblclick', Object.assign({ cell: evnt.currentTarget }, params), evnt)
3174
3174
  },
3175
3175
  getCurrentColumn () {
3176
- return this.highlightCurrentColumn ? this.currentColumn : null
3176
+ return this.columnOpts.isCurrent || this.highlightCurrentColumn ? this.currentColumn : null
3177
3177
  },
3178
3178
  /**
3179
3179
  * 用于当前列,设置某列行为高亮状态
@@ -3220,7 +3220,7 @@ const Methods = {
3220
3220
  * 如果是双击模式,则单击后选中状态
3221
3221
  */
3222
3222
  triggerCellClickEvent (evnt, params) {
3223
- const { highlightCurrentRow, editStore, radioOpts, expandOpts, treeOpts, editConfig, editOpts, checkboxOpts } = this
3223
+ const { highlightCurrentRow, editStore, radioOpts, expandOpts, treeOpts, editConfig, editOpts, checkboxOpts, rowOpts } = this
3224
3224
  const { actived } = editStore
3225
3225
  const { row, column } = params
3226
3226
  const { type, treeNode } = column
@@ -3247,7 +3247,7 @@ const Methods = {
3247
3247
  if (!triggerTreeNode) {
3248
3248
  if (!triggerExpandNode) {
3249
3249
  // 如果是高亮行
3250
- if (highlightCurrentRow) {
3250
+ if (rowOpts.isCurrent || highlightCurrentRow) {
3251
3251
  if (!triggerCheckbox && !triggerRadio) {
3252
3252
  this.triggerCurrentRowEvent(evnt, params)
3253
3253
  }
@@ -3843,8 +3843,10 @@ const Methods = {
3843
3843
  updateVirtualTreeData () {
3844
3844
  const { scrollYLoad: oldScrollYLoad, treeExpandeds, treeOpts, treeFullData } = this
3845
3845
  const fullData = []
3846
+ const expandMaps = new Map()
3846
3847
  XEUtils.eachTree(treeFullData, (row, index, items, path, parent) => {
3847
- if (!parent || treeExpandeds.indexOf(parent) > -1) {
3848
+ if (!parent || (expandMaps.has(parent) && treeExpandeds.indexOf(parent) > -1)) {
3849
+ expandMaps.set(row, 1)
3848
3850
  fullData.push(row)
3849
3851
  }
3850
3852
  }, treeOpts)
@@ -976,7 +976,9 @@ export default {
976
976
  ctxMenuStore,
977
977
  ctxMenuOpts,
978
978
  footerTableData,
979
- hasTip
979
+ hasTip,
980
+ columnOpts,
981
+ rowOpts
980
982
  } = this
981
983
  const { leftList, rightList } = columnStore
982
984
  return h('div', {
@@ -985,8 +987,8 @@ export default {
985
987
  'cell--highlight': highlightCell,
986
988
  'cell--selected': mouseConfig && mouseOpts.selected,
987
989
  'cell--area': mouseConfig && mouseOpts.area,
988
- 'row--highlight': highlightHoverRow,
989
- 'column--highlight': highlightHoverColumn,
990
+ 'row--highlight': rowOpts.isHover || highlightHoverRow,
991
+ 'column--highlight': columnOpts.isHover || highlightHoverColumn,
990
992
  'is--header': showHeader,
991
993
  'is--footer': showFooter,
992
994
  'is--group': isGroup,
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as VXETableExport from './all'
2
2
 
3
3
  /**
4
- * 一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
4
+ * 一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
5
5
  */
6
6
  declare const VXETable: typeof VXETableExport
7
7