vxe-table 4.1.2 → 4.1.5

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.
@@ -1812,11 +1812,11 @@ export default defineComponent({
1812
1812
  if (transform) {
1813
1813
  // 树结构自动转换
1814
1814
  if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
1815
- if (!treeOpts.rowtKey) {
1816
- errLog('vxe.error.reqProp', ['tree-config.rowtKey'])
1815
+ if (!treeOpts.rowField) {
1816
+ errLog('vxe.error.reqProp', ['tree-config.rowField'])
1817
1817
  }
1818
- if (!treeOpts.parentKey) {
1819
- errLog('vxe.error.reqProp', ['tree-config.parentKey'])
1818
+ if (!treeOpts.parentField) {
1819
+ errLog('vxe.error.reqProp', ['tree-config.parentField'])
1820
1820
  }
1821
1821
  if (!treeOpts.children) {
1822
1822
  errLog('vxe.error.reqProp', ['tree-config.children'])
@@ -1827,7 +1827,7 @@ export default defineComponent({
1827
1827
  }
1828
1828
  })
1829
1829
  }
1830
- treeData = XEUtils.toArrayTree(fullData, { key: treeOpts.rowtKey, parentKey: treeOpts.parentKey, children: treeOpts.children })
1830
+ treeData = XEUtils.toArrayTree(fullData, { key: treeOpts.rowField, parentKey: treeOpts.parentField, children: treeOpts.children })
1831
1831
  fullData = treeData.slice(0)
1832
1832
  } else {
1833
1833
  treeData = fullData.slice(0)
@@ -2121,8 +2121,10 @@ export default defineComponent({
2121
2121
  const { treeFullData } = internalData
2122
2122
  const treeOpts = computeTreeOpts.value
2123
2123
  const fullData: any[] = []
2124
+ const expandMaps: Map<any, number> = new Map()
2124
2125
  XEUtils.eachTree(treeFullData, (row, index, items, path, parent) => {
2125
- if (!parent || $xetable.findRowIndexOf(treeExpandeds, parent) > -1) {
2126
+ if (!parent || (expandMaps.has(parent) && $xetable.findRowIndexOf(treeExpandeds, parent) > -1)) {
2127
+ expandMaps.set(row, 1)
2126
2128
  fullData.push(row)
2127
2129
  }
2128
2130
  }, treeOpts)
@@ -2311,16 +2313,12 @@ export default defineComponent({
2311
2313
  const oRow = tableSourceData[rowIndex]
2312
2314
  if (oRow && row) {
2313
2315
  if (field) {
2314
- XEUtils.set(oRow, field, XEUtils.get(record || row, field))
2316
+ const newValue = XEUtils.get(record || row, field)
2317
+ XEUtils.set(row, field, newValue)
2318
+ XEUtils.set(oRow, field, newValue)
2315
2319
  } else {
2316
- if (record) {
2317
- tableSourceData[rowIndex] = record
2318
- XEUtils.clear(row, undefined)
2319
- Object.assign(row, tablePrivateMethods.defineField(Object.assign({}, record)))
2320
- tablePrivateMethods.cacheRowMap(true)
2321
- } else {
2322
- XEUtils.destructuring(oRow, XEUtils.clone(row, true))
2323
- }
2320
+ const newRecord = XEUtils.clone({ ...record }, true)
2321
+ XEUtils.destructuring(oRow, Object.assign(row, newRecord))
2324
2322
  }
2325
2323
  }
2326
2324
  reactData.tableData = tableData.slice(0)
@@ -2339,8 +2337,8 @@ export default defineComponent({
2339
2337
  const { tableSourceData, fullDataRowIdData, fullAllDataRowIdData } = internalData
2340
2338
  const treeOpts = computeTreeOpts.value
2341
2339
  const { children } = treeOpts
2342
- const rest = fullAllDataRowIdData[getRowid($xetable, row)]
2343
- const parentLevel = rest ? rest.level : 0
2340
+ const parentRest = fullAllDataRowIdData[getRowid($xetable, row)]
2341
+ const parentLevel = parentRest ? parentRest.level : 0
2344
2342
  return tableMethods.createData(childRecords).then((rows) => {
2345
2343
  if (keepSource) {
2346
2344
  const rowid = getRowid($xetable, row)
@@ -3152,11 +3150,12 @@ export default defineComponent({
3152
3150
  * @param {Row} row 行对象
3153
3151
  */
3154
3152
  setCurrentRow (row) {
3153
+ const rowOpts = computeRowOpts.value
3155
3154
  const el = refElem.value
3156
3155
  tableMethods.clearCurrentRow()
3157
3156
  tableMethods.clearCurrentColumn()
3158
3157
  reactData.currentRow = row
3159
- if (props.highlightCurrentRow) {
3158
+ if (rowOpts.isCurrent || props.highlightCurrentRow) {
3160
3159
  if (el) {
3161
3160
  XEUtils.arrayEach(el.querySelectorAll(`[rowid="${getRowid($xetable, row)}"]`), elem => addClass(elem, 'row--current'))
3162
3161
  }
@@ -3202,7 +3201,8 @@ export default defineComponent({
3202
3201
  * 用于当前行,获取当前行的数据
3203
3202
  */
3204
3203
  getCurrentRecord () {
3205
- return props.highlightCurrentRow ? reactData.currentRow : null
3204
+ const rowOpts = computeRowOpts.value
3205
+ return rowOpts.isCurrent || props.highlightCurrentRow ? reactData.currentRow : null
3206
3206
  },
3207
3207
  /**
3208
3208
  * 用于单选行,获取当已选中的数据
@@ -3235,7 +3235,8 @@ export default defineComponent({
3235
3235
  return null
3236
3236
  },
3237
3237
  getCurrentColumn () {
3238
- return props.highlightCurrentColumn ? reactData.currentColumn : null
3238
+ const columnOpts = computeColumnOpts.value
3239
+ return columnOpts.isCurrent || props.highlightCurrentColumn ? reactData.currentColumn : null
3239
3240
  },
3240
3241
  /**
3241
3242
  * 用于当前列,设置某列行为高亮状态
@@ -4032,6 +4033,7 @@ export default defineComponent({
4032
4033
  const editOpts = computeEditOpts.value
4033
4034
  const treeOpts = computeTreeOpts.value
4034
4035
  const menuList = computeMenuList.value
4036
+ const rowOpts = computeRowOpts.value
4035
4037
  const { selected, actived } = editStore
4036
4038
  const keyCode = evnt.keyCode
4037
4039
  const isEsc = hasEventKey(evnt, EVENT_KEYS.ESCAPE)
@@ -4104,7 +4106,7 @@ export default defineComponent({
4104
4106
  keyCtxTimeout = setTimeout(() => {
4105
4107
  internalData._keyCtx = false
4106
4108
  }, 1000)
4107
- } else if (isEnter && !isAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && highlightCurrentRow && currentRow))) {
4109
+ } else if (isEnter && !isAltKey && keyboardConfig && keyboardOpts.isEnter && (selected.row || actived.row || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow))) {
4108
4110
  // 退出选中
4109
4111
  if (hasCtrlKey) {
4110
4112
  // 如果是激活编辑状态,则取消编辑
@@ -4133,7 +4135,7 @@ export default defineComponent({
4133
4135
  $xetable.moveSelected(targetArgs, isLeftArrow, false, isRightArrow, true, evnt)
4134
4136
  }
4135
4137
  }
4136
- } else if (treeConfig && highlightCurrentRow && currentRow) {
4138
+ } else if (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
4137
4139
  // 如果是树形表格当前行回车移动到子节点
4138
4140
  const childrens = currentRow[treeOpts.children]
4139
4141
  if (childrens && childrens.length) {
@@ -4156,7 +4158,7 @@ export default defineComponent({
4156
4158
  // 如果按下了方向键
4157
4159
  if (selected.row && selected.column) {
4158
4160
  $xetable.moveSelected(selected.args, isLeftArrow, isUpArrow, isRightArrow, isDwArrow, evnt)
4159
- } else if ((isUpArrow || isDwArrow) && highlightCurrentRow) {
4161
+ } else if ((isUpArrow || isDwArrow) && (rowOpts.isCurrent || highlightCurrentRow)) {
4160
4162
  // 当前行按键上下移动
4161
4163
  $xetable.moveCurrentRow(isUpArrow, isDwArrow, evnt)
4162
4164
  }
@@ -4168,7 +4170,7 @@ export default defineComponent({
4168
4170
  } else if (actived.row || actived.column) {
4169
4171
  $xetable.moveTabSelected(actived.args, hasShiftKey, evnt)
4170
4172
  }
4171
- } else if (keyboardConfig && isEnableConf(editConfig) && (isDel || (treeConfig && highlightCurrentRow && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
4173
+ } else if (keyboardConfig && isEnableConf(editConfig) && (isDel || (treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow ? isBack && keyboardOpts.isArrow : isBack))) {
4172
4174
  if (!isEditStatus) {
4173
4175
  const { delMethod, backMethod } = keyboardOpts
4174
4176
  // 如果是删除键
@@ -4200,7 +4202,7 @@ export default defineComponent({
4200
4202
  // 如果按下 del 键,更新表尾数据
4201
4203
  tableMethods.updateFooter()
4202
4204
  }
4203
- } else if (isBack && keyboardOpts.isArrow && treeConfig && highlightCurrentRow && currentRow) {
4205
+ } else if (isBack && keyboardOpts.isArrow && treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
4204
4206
  // 如果树形表格回退键关闭当前行返回父节点
4205
4207
  const { parent: parentRow } = XEUtils.findTree(internalData.afterFullData, item => item === currentRow, treeOpts)
4206
4208
  if (parentRow) {
@@ -4825,6 +4827,7 @@ export default defineComponent({
4825
4827
  triggerHeaderCellClickEvent (evnt, params) {
4826
4828
  const { _lastResizeTime } = internalData
4827
4829
  const sortOpts = computeSortOpts.value
4830
+ const columnOpts = computeColumnOpts.value
4828
4831
  const { column } = params
4829
4832
  const cell = evnt.currentTarget
4830
4833
  const triggerResizable = _lastResizeTime && _lastResizeTime > Date.now() - 300
@@ -4834,7 +4837,7 @@ export default defineComponent({
4834
4837
  tablePrivateMethods.triggerSortEvent(evnt, column, getNextSortOrder(column))
4835
4838
  }
4836
4839
  tableMethods.dispatchEvent('header-cell-click', Object.assign({ triggerResizable, triggerSort, triggerFilter, cell }, params), evnt)
4837
- if (props.highlightCurrentColumn) {
4840
+ if (columnOpts.isCurrent || props.highlightCurrentColumn) {
4838
4841
  tableMethods.setCurrentColumn(column)
4839
4842
  }
4840
4843
  },
@@ -4854,6 +4857,7 @@ export default defineComponent({
4854
4857
  const treeOpts = computeTreeOpts.value
4855
4858
  const radioOpts = computeRadioOpts.value
4856
4859
  const checkboxOpts = computeCheckboxOpts.value
4860
+ const rowOpts = computeRowOpts.value
4857
4861
  const { actived } = editStore
4858
4862
  const { row, column } = params
4859
4863
  const { type, treeNode } = column
@@ -4880,7 +4884,7 @@ export default defineComponent({
4880
4884
  if (!triggerTreeNode) {
4881
4885
  if (!triggerExpandNode) {
4882
4886
  // 如果是高亮行
4883
- if (highlightCurrentRow) {
4887
+ if (rowOpts.isCurrent || highlightCurrentRow) {
4884
4888
  if (!triggerCheckbox && !triggerRadio) {
4885
4889
  tablePrivateMethods.triggerCurrentRowEvent(evnt, params)
4886
4890
  }
@@ -5187,6 +5191,7 @@ export default defineComponent({
5187
5191
  tablePrivateMethods.handleTableData()
5188
5192
  tablePrivateMethods.updateScrollYSpace()
5189
5193
  },
5194
+ updateVirtualTreeData,
5190
5195
  /**
5191
5196
  * 处理固定列的显示状态
5192
5197
  */
@@ -5675,6 +5680,8 @@ export default defineComponent({
5675
5680
  const { leftList, rightList } = columnStore
5676
5681
  const tooltipOpts = computeTooltipOpts.value
5677
5682
  const treeOpts = computeTreeOpts.value
5683
+ const rowOpts = computeRowOpts.value
5684
+ const columnOpts = computeColumnOpts.value
5678
5685
  const vSize = computeSize.value
5679
5686
  const tableBorder = computeTableBorder.value
5680
5687
  const mouseOpts = computeMouseOpts.value
@@ -5689,8 +5696,8 @@ export default defineComponent({
5689
5696
  'cell--highlight': highlightCell,
5690
5697
  'cell--selected': mouseConfig && mouseOpts.selected,
5691
5698
  'cell--area': mouseConfig && mouseOpts.area,
5692
- 'row--highlight': highlightHoverRow,
5693
- 'column--highlight': highlightHoverColumn,
5699
+ 'row--highlight': rowOpts.isHover || highlightHoverRow,
5700
+ 'column--highlight': columnOpts.isHover || highlightHoverColumn,
5694
5701
  'is--header': showHeader,
5695
5702
  'is--footer': showFooter,
5696
5703
  'is--group': isGroup,
@@ -65,8 +65,8 @@ const GlobalConfig: VXETableGlobalConfig = {
65
65
  showIcon: true
66
66
  },
67
67
  treeConfig: {
68
- rowtKey: 'id',
69
- parentKey: 'parentId',
68
+ rowField: 'id',
69
+ parentField: 'parentId',
70
70
  children: 'children',
71
71
  hasChild: 'hasChild',
72
72
  indent: 20,
package/types/edit.d.ts CHANGED
@@ -13,9 +13,12 @@ export interface TableEditMethods {
13
13
  */
14
14
  insert(records: RecordInfo | RecordInfo[]): Promise<{ row: any, rows: any[] }>;
15
15
  /**
16
- * 往表格插入临时数据,从指定位置插入一行或多行;第二个参数:row 指定位置、null从第一行插入、-1 从最后插入
17
- * @param records 新数据
18
- * @param row 指定行
16
+ * 往表格指定行中插入临时数据
17
+ * 如果 row 为空则从插入到顶部,如果为树结构,则插入到目标节点顶部
18
+ * 如果 row 为 -1 则从插入到底部,如果为树结构,则插入到目标节点底部
19
+ * 如果 row 为有效行则插入到该行的位置,如果为树结构,则有插入到效的目标节点该行的位置
20
+ * @param {Object/Array} records 新的数据
21
+ * @param {Row} row 指定行
19
22
  */
20
23
  insertAt(records: RecordInfo | RecordInfo[], row: any | -1 | null): Promise<{ row: any, rows: any[] }>;
21
24
  /**
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
 
@@ -28,9 +28,9 @@ export interface VxeTableProMethods {
28
28
  */
29
29
  pasteCellArea(): Promise<any>;
30
30
  /**
31
- * 用于 mouse-config.area,用于清除鼠标选择的区域
31
+ * 用于 mouse-config.area,用于清除鼠标选择的区域,可以指定清除的区域
32
32
  */
33
- clearCellAreas(): Promise<any>;
33
+ clearCellAreas(area?: number | VxeTableProDefines.MouseCellArea): Promise<any>;
34
34
  /**
35
35
  * 用于 mouse-config.area,手动清除标记为复制粘贴的区域
36
36
  */
@@ -40,9 +40,9 @@ export interface VxeTableProMethods {
40
40
  * @param areaConfigs 指定区域
41
41
  */
42
42
  setCellAreas(areaConfigs: VxeTableProDefines.CellAreaConfig[], activeArea?: {
43
- area?: VxeTableProDefines.CellAreaConfig;
44
- column: VxeTableDefines.ColumnInfo;
45
- row: any;
43
+ area?: number | VxeTableProDefines.CellAreaConfig;
44
+ column?: number | VxeTableDefines.ColumnInfo;
45
+ row?: any;
46
46
  }): Promise<any>;
47
47
  /**
48
48
  * 用于 mouse-config.area,设置活动的区域的单元格
@@ -148,7 +148,7 @@ export namespace VxeTableProDefines {
148
148
  }
149
149
 
150
150
  export interface ActiveCellAreaConfig {
151
- area: VxeTableProDefines.MouseCellArea;
151
+ area: VxeTableProDefines.MouseCellArea | number;
152
152
  column: VxeTableDefines.ColumnInfo | number;
153
153
  row: any;
154
154
  }
package/types/table.d.ts CHANGED
@@ -707,6 +707,7 @@ export interface TablePrivateMethods {
707
707
  updateScrollYSpace(): void;
708
708
  updateScrollXData(): void;
709
709
  updateScrollYData(): void;
710
+ updateVirtualTreeData(): Promise<any>;
710
711
  checkScrolling(): void;
711
712
  updateZindex(): void;
712
713
  updateCellAreas(): void;
@@ -1208,6 +1209,8 @@ export namespace VxeTablePropTypes {
1208
1209
  * 列配置信息
1209
1210
  */
1210
1211
  export interface ColumnConfig {
1212
+ isCurrent?: boolean;
1213
+ isHover?: boolean;
1211
1214
  resizable?: VxeColumnPropTypes.Resizable;
1212
1215
  width?: VxeColumnPropTypes.Width;
1213
1216
  minWidth?: VxeColumnPropTypes.MinWidth;
@@ -1218,6 +1221,8 @@ export namespace VxeTablePropTypes {
1218
1221
  * 行配置信息
1219
1222
  */
1220
1223
  export interface RowConfig {
1224
+ isCurrent?: boolean;
1225
+ isHover?: boolean;
1221
1226
  height?: number;
1222
1227
  }
1223
1228
  export interface RowOpts extends RowConfig { }
@@ -1321,6 +1326,9 @@ export namespace VxeTablePropTypes {
1321
1326
  checkMethod?(params: {
1322
1327
  row: any;
1323
1328
  }): boolean;
1329
+ visibleMethod?(params: {
1330
+ row: any;
1331
+ }): boolean;
1324
1332
  trigger?: 'default' | 'cell' | 'row';
1325
1333
  highlight?: boolean;
1326
1334
  strict?: boolean;
@@ -1343,6 +1351,9 @@ export namespace VxeTablePropTypes {
1343
1351
  checkMethod?(params: {
1344
1352
  row: any;
1345
1353
  }): boolean;
1354
+ visibleMethod?(params: {
1355
+ row: any;
1356
+ }): boolean;
1346
1357
  trigger?: 'default' | 'cell' | 'row';
1347
1358
  highlight?: boolean;
1348
1359
  range?: boolean;
@@ -1415,8 +1426,8 @@ export namespace VxeTablePropTypes {
1415
1426
  */
1416
1427
  export interface TreeConfig {
1417
1428
  transform?: boolean;
1418
- rowtKey?: string;
1419
- parentKey?: string;
1429
+ rowField?: string;
1430
+ parentField?: string;
1420
1431
  children?: string;
1421
1432
  indent?: number;
1422
1433
  line?: boolean;
@@ -1445,8 +1456,8 @@ export namespace VxeTablePropTypes {
1445
1456
  iconLoaded?: string;
1446
1457
  }
1447
1458
  export interface TreeOpts extends TreeConfig {
1448
- rowtKey: string;
1449
- parentKey: string;
1459
+ rowField: string;
1460
+ parentField: string;
1450
1461
  children: string;
1451
1462
  indent: number;
1452
1463
  hasChild: string;
@@ -1877,6 +1888,9 @@ export namespace VxeTablePropTypes {
1877
1888
  gt?: number;
1878
1889
  oSize?: number;
1879
1890
  enabled?: boolean;
1891
+ /**
1892
+ * @deprecated 请使用 row-config.height
1893
+ */
1880
1894
  rHeight?: number;
1881
1895
  adaptive?: boolean;
1882
1896
  }