vxe-table 3.4.1 → 3.4.4

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.
@@ -325,11 +325,11 @@ const Methods = {
325
325
  // 树结构自动转换
326
326
  if (treeOpts.transform) {
327
327
  if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
328
- if (!treeOpts.rowtKey) {
329
- UtilTools.error('vxe.error.reqProp', ['table.tree-config.rowtKey'])
328
+ if (!treeOpts.rowField) {
329
+ UtilTools.error('vxe.error.reqProp', ['table.tree-config.rowField'])
330
330
  }
331
- if (!treeOpts.parentKey) {
332
- UtilTools.error('vxe.error.reqProp', ['table.tree-config.parentKey'])
331
+ if (!treeOpts.parentField) {
332
+ UtilTools.error('vxe.error.reqProp', ['table.tree-config.parentField'])
333
333
  }
334
334
  if (!treeOpts.children) {
335
335
  UtilTools.error('vxe.error.reqProp', ['tree-config.children'])
@@ -340,7 +340,7 @@ const Methods = {
340
340
  }
341
341
  })
342
342
  }
343
- treeData = XEUtils.toArrayTree(fullData, { key: treeOpts.rowtKey, parentKey: treeOpts.parentKey, children: treeOpts.children })
343
+ treeData = XEUtils.toArrayTree(fullData, { key: treeOpts.rowField, parentKey: treeOpts.parentField, children: treeOpts.children })
344
344
  fullData = treeData.slice(0)
345
345
  } else {
346
346
  treeData = fullData.slice(0)
@@ -464,16 +464,12 @@ const Methods = {
464
464
  const oRow = tableSourceData[rowIndex]
465
465
  if (oRow && row) {
466
466
  if (field) {
467
- XEUtils.set(oRow, field, XEUtils.get(record || row, field))
467
+ const newValue = XEUtils.get(record || row, field)
468
+ XEUtils.set(row, field, newValue)
469
+ XEUtils.set(oRow, field, newValue)
468
470
  } else {
469
- if (record) {
470
- tableSourceData[rowIndex] = record
471
- XEUtils.clear(row, undefined)
472
- Object.assign(row, this.defineField(Object.assign({}, record)))
473
- this.cacheRowMap(true)
474
- } else {
475
- XEUtils.destructuring(oRow, XEUtils.clone(row, true))
476
- }
471
+ const newRecord = XEUtils.clone({ ...record }, true)
472
+ XEUtils.destructuring(oRow, Object.assign(row, newRecord))
477
473
  }
478
474
  }
479
475
  this.tableData = tableData.slice(0)
@@ -2135,7 +2131,7 @@ const Methods = {
2135
2131
  // 该行为只对当前激活的表格有效
2136
2132
  if (this.isActivated) {
2137
2133
  this.preventEvent(evnt, 'event.keydown', null, () => {
2138
- const { filterStore, isCtxMenu, ctxMenuStore, editStore, editOpts, editConfig, mouseConfig, mouseOpts, keyboardConfig, keyboardOpts, treeConfig, treeOpts, highlightCurrentRow, currentRow, bodyCtxMenu } = this
2134
+ const { filterStore, isCtxMenu, ctxMenuStore, editStore, editOpts, editConfig, mouseConfig, mouseOpts, keyboardConfig, keyboardOpts, treeConfig, treeOpts, highlightCurrentRow, currentRow, bodyCtxMenu, rowOpts } = this
2139
2135
  const { selected, actived } = editStore
2140
2136
  const { keyCode } = evnt
2141
2137
  const isBack = keyCode === 8
@@ -2198,7 +2194,7 @@ const Methods = {
2198
2194
  this.keyCtxTimeout = setTimeout(() => {
2199
2195
  this._keyCtx = false
2200
2196
  }, 1000)
2201
- } else if (isEnter && !hasAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && highlightCurrentRow && currentRow))) {
2197
+ } else if (isEnter && !hasAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow))) {
2202
2198
  // 退出选中
2203
2199
  if (hasCtrlKey) {
2204
2200
  // 如果是激活编辑状态,则取消编辑
@@ -2227,7 +2223,7 @@ const Methods = {
2227
2223
  this.moveSelected(targetArgs, isLeftArrow, false, isRightArrow, true, evnt)
2228
2224
  }
2229
2225
  }
2230
- } else if (treeConfig && highlightCurrentRow && currentRow) {
2226
+ } else if (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2231
2227
  // 如果是树形表格当前行回车移动到子节点
2232
2228
  const childrens = currentRow[treeOpts.children]
2233
2229
  if (childrens && childrens.length) {
@@ -2245,7 +2241,7 @@ const Methods = {
2245
2241
  // 如果按下了方向键
2246
2242
  if (selected.row && selected.column) {
2247
2243
  this.moveSelected(selected.args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt)
2248
- } else if ((isUpArrow || isDwArrow) && highlightCurrentRow) {
2244
+ } else if ((isUpArrow || isDwArrow) && (rowOpts.isCurrent || highlightCurrentRow)) {
2249
2245
  // 当前行按键上下移动
2250
2246
  this.moveCurrentRow(isUpArrow, isDwArrow, evnt)
2251
2247
  }
@@ -2257,7 +2253,7 @@ const Methods = {
2257
2253
  } else if (actived.row || actived.column) {
2258
2254
  this.moveTabSelected(actived.args, hasShiftKey, evnt)
2259
2255
  }
2260
- } else if (keyboardConfig && (isDel || (treeConfig && highlightCurrentRow && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
2256
+ } else if (keyboardConfig && (isDel || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
2261
2257
  if (!isEditStatus) {
2262
2258
  const { delMethod, backMethod } = keyboardOpts
2263
2259
  // 如果是删除键
@@ -2289,7 +2285,7 @@ const Methods = {
2289
2285
  // 如果按下 del 键,更新表尾数据
2290
2286
  this.updateFooter()
2291
2287
  }
2292
- } else if (isBack && keyboardOpts.isArrow && treeConfig && highlightCurrentRow && currentRow) {
2288
+ } else if (isBack && keyboardOpts.isArrow && treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
2293
2289
  // 如果树形表格回退键关闭当前行返回父节点
2294
2290
  const { parent: parentRow } = XEUtils.findTree(this.afterFullData, item => item === currentRow, treeOpts)
2295
2291
  if (parentRow) {
@@ -3052,11 +3048,11 @@ const Methods = {
3052
3048
  * @param {Row} row 行对象
3053
3049
  */
3054
3050
  setCurrentRow (row) {
3055
- const { $el } = this
3051
+ const { $el, rowOpts } = this
3056
3052
  this.clearCurrentRow()
3057
3053
  this.clearCurrentColumn()
3058
3054
  this.currentRow = row
3059
- if (this.highlightCurrentRow) {
3055
+ if (rowOpts.isCurrent || this.highlightCurrentRow) {
3060
3056
  if ($el) {
3061
3057
  XEUtils.arrayEach($el.querySelectorAll(`[rowid="${getRowid(this, row)}"]`), elem => addClass(elem, 'row--current'))
3062
3058
  }
@@ -3102,7 +3098,7 @@ const Methods = {
3102
3098
  * 用于当前行,获取当前行的数据
3103
3099
  */
3104
3100
  getCurrentRecord () {
3105
- return this.highlightCurrentRow ? this.currentRow : null
3101
+ return this.rowOpts.isCurrent || this.highlightCurrentRow ? this.currentRow : null
3106
3102
  },
3107
3103
  /**
3108
3104
  * 用于单选行,获取当已选中的数据
@@ -3164,7 +3160,7 @@ const Methods = {
3164
3160
  this.triggerSortEvent(evnt, column, getNextSortOrder(this, column))
3165
3161
  }
3166
3162
  this.emitEvent('header-cell-click', Object.assign({ triggerResizable, triggerSort, triggerFilter, cell }, params), evnt)
3167
- if (this.highlightCurrentColumn) {
3163
+ if (this.columnOpts.isCurrent || this.highlightCurrentColumn) {
3168
3164
  return this.setCurrentColumn(column)
3169
3165
  }
3170
3166
  return this.$nextTick()
@@ -3173,7 +3169,7 @@ const Methods = {
3173
3169
  this.emitEvent('header-cell-dblclick', Object.assign({ cell: evnt.currentTarget }, params), evnt)
3174
3170
  },
3175
3171
  getCurrentColumn () {
3176
- return this.highlightCurrentColumn ? this.currentColumn : null
3172
+ return this.columnOpts.isCurrent || this.highlightCurrentColumn ? this.currentColumn : null
3177
3173
  },
3178
3174
  /**
3179
3175
  * 用于当前列,设置某列行为高亮状态
@@ -3220,7 +3216,7 @@ const Methods = {
3220
3216
  * 如果是双击模式,则单击后选中状态
3221
3217
  */
3222
3218
  triggerCellClickEvent (evnt, params) {
3223
- const { highlightCurrentRow, editStore, radioOpts, expandOpts, treeOpts, editConfig, editOpts, checkboxOpts } = this
3219
+ const { highlightCurrentRow, editStore, radioOpts, expandOpts, treeOpts, editConfig, editOpts, checkboxOpts, rowOpts } = this
3224
3220
  const { actived } = editStore
3225
3221
  const { row, column } = params
3226
3222
  const { type, treeNode } = column
@@ -3247,7 +3243,7 @@ const Methods = {
3247
3243
  if (!triggerTreeNode) {
3248
3244
  if (!triggerExpandNode) {
3249
3245
  // 如果是高亮行
3250
- if (highlightCurrentRow) {
3246
+ if (rowOpts.isCurrent || highlightCurrentRow) {
3251
3247
  if (!triggerCheckbox && !triggerRadio) {
3252
3248
  this.triggerCurrentRowEvent(evnt, params)
3253
3249
  }
@@ -3843,8 +3839,10 @@ const Methods = {
3843
3839
  updateVirtualTreeData () {
3844
3840
  const { scrollYLoad: oldScrollYLoad, treeExpandeds, treeOpts, treeFullData } = this
3845
3841
  const fullData = []
3842
+ const expandMaps = new Map()
3846
3843
  XEUtils.eachTree(treeFullData, (row, index, items, path, parent) => {
3847
- if (!parent || treeExpandeds.indexOf(parent) > -1) {
3844
+ if (!parent || (expandMaps.has(parent) && treeExpandeds.indexOf(parent) > -1)) {
3845
+ expandMaps.set(row, 1)
3848
3846
  fullData.push(row)
3849
3847
  }
3850
3848
  }, 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,
@@ -63,8 +63,8 @@ export default {
63
63
  showIcon: true
64
64
  },
65
65
  treeConfig: {
66
- rowtKey: 'id',
67
- parentKey: 'parentId',
66
+ rowField: 'id',
67
+ parentField: 'parentId',
68
68
  children: 'children',
69
69
  hasChild: 'hasChild',
70
70
  indent: 20,
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
 
package/types/table.d.ts CHANGED
@@ -803,9 +803,12 @@ export declare class Table extends VXETableComponent {
803
803
  */
804
804
  insert(records: RecordInfo | RecordInfo[]): Promise<{ row: RowInfo, rows: RowInfo[] }>;
805
805
  /**
806
- * 往表格插入临时数据,从指定位置插入一行或多行;第二个参数:row 指定位置、null从第一行插入、-1 从最后插入
807
- * @param records 新数据
808
- * @param row 指定行
806
+ * 往表格指定行中插入临时数据
807
+ * 如果 row 为空则从插入到顶部,如果为树结构,则插入到目标节点顶部
808
+ * 如果 row 为 -1 则从插入到底部,如果为树结构,则插入到目标节点底部
809
+ * 如果 row 为有效行则插入到该行的位置,如果为树结构,则有插入到效的目标节点该行的位置
810
+ * @param {Object/Array} records 新的数据
811
+ * @param {Row} row 指定行
809
812
  */
810
813
  insertAt(records: RecordInfo | RecordInfo[], row: RowInfo | -1 | null): Promise<{ row: RowInfo, rows: RowInfo[] }>;
811
814
  /**
@@ -859,9 +862,9 @@ export declare class Table extends VXETableComponent {
859
862
  */
860
863
  clearActived(): Promise<any>;
861
864
  /**
862
- * 用于 mouse-config.area,用于清除鼠标选择的区域
865
+ * 用于 mouse-config.area,用于清除鼠标选择的区域,可以指定清除的区域
863
866
  */
864
- clearCellAreas(): Promise<any>;
867
+ clearCellAreas(area?: number | MouseCellArea): Promise<any>;
865
868
  /**
866
869
  * 用于 edit-config,获取已激活的行数据
867
870
  */
@@ -901,9 +904,9 @@ export declare class Table extends VXETableComponent {
901
904
  * @param areaConfigs 指定区域
902
905
  */
903
906
  setCellAreas(areaConfigs: CellAreaConfig[], activeArea?: {
904
- area?: MouseCellArea;
905
- column: ColumnInfo;
906
- row: RowInfo;
907
+ area?: number | MouseCellArea;
908
+ column?: number | ColumnInfo;
909
+ row?: number | RowInfo;
907
910
  }): Promise<any>;
908
911
  /**
909
912
  * 用于 mouse-config.area,设置活动的区域的单元格
@@ -911,8 +914,8 @@ export declare class Table extends VXETableComponent {
911
914
  */
912
915
  setActiveCellArea(activeArea: {
913
916
  area: MouseCellArea;
914
- column: ColumnInfo;
915
- row: RowInfo;
917
+ column: number | ColumnInfo;
918
+ row: number | RowInfo;
916
919
  }): Promise<any>;
917
920
  /**
918
921
  * 临时合并单元格,如果为数组则合并多个