Skip to content

Commit

Permalink
releases 3.12.9
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Jan 9, 2025
1 parent 0907a78 commit d76e4d6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vxe-table",
"version": "3.12.8",
"version": "3.12.9",
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、拖拽排序,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand Down
32 changes: 19 additions & 13 deletions packages/table/src/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getOffsetSize, calcTreeLine, mergeBodyMethod, getRowid } from './util'
import { updateCellTitle, setScrollTop, setScrollLeft } from '../../ui/src/dom'
import { getSlotVNs } from '../../ui/src/vn'

import type { VxeTableConstructor, TableInternalData, VxeTablePrivateMethods } from '../../../types'

const { getI18n, renderer, renderEmptyElement } = VxeUI

const renderType = 'body'
Expand All @@ -15,24 +17,28 @@ function isVMScrollProcess ($xetable: any) {
return $xetable._isResize || ($xetable.lastScrollTime && Date.now() < $xetable.lastScrollTime + $xetable.delayHover)
}

function renderLine (h: CreateElement, _vm: any, $xetable: any, params: any) {
function renderLine (h: CreateElement, _vm: any, $xeTable: VxeTableConstructor & VxeTablePrivateMethods, params: any) {
const tableProps = $xeTable
const tableInternalData = $xeTable as unknown as TableInternalData

const { row, column } = params
const { afterFullData, treeOpts, treeConfig, fullAllDataRowIdData } = $xetable
const { afterFullData } = tableInternalData
const { treeConfig } = tableProps
const treeOpts = $xeTable.computeTreeOpts
const { slots, treeNode } = column
const rowid = getRowid($xetable, row)
const { fullAllDataRowIdData } = tableInternalData
if (slots && slots.line) {
return $xeTable.callSlot(slots.line, params, h)
}
const rowid = getRowid($xeTable, row)
const rest = fullAllDataRowIdData[rowid]
let rLevel = 0
let rIndex = 0
let items = []
let prevRow = null
if (rest) {
rLevel = rest.level
rIndex = rest._index
items = rest.items
}
if (slots && slots.line) {
return $xetable.callSlot(slots.line, params, h)
prevRow = rest.items[rest._index - 1]
}
const isFirstRow = $xetable.eqRow(afterFullData[0], row)
const isFirstRow = $xeTable.eqRow(afterFullData[0], row)
if (treeConfig && treeNode && (treeOpts.showLine || treeOpts.line)) {
return [
h('div', {
Expand All @@ -41,8 +47,8 @@ function renderLine (h: CreateElement, _vm: any, $xetable: any, params: any) {
h('div', {
class: 'vxe-tree--line',
style: {
height: `${isFirstRow ? 1 : calcTreeLine(params, items, rIndex)}px`,
left: `${(rLevel * treeOpts.indent) + (rLevel ? 2 - getOffsetSize($xetable) : 0) + 16}px`
height: `${isFirstRow ? 1 : calcTreeLine(params, prevRow)}px`,
left: `${(rLevel * treeOpts.indent) + (rLevel ? 2 - getOffsetSize($xeTable) : 0) + 16}px`
}
})
])
Expand Down
29 changes: 2 additions & 27 deletions packages/table/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2276,30 +2276,6 @@ const Methods = {
this.afterTreeFullData = tableTree
this.updateAfterDataIndex()
},
updateTreeDataIndex () {
const $xeTable = this
const props = $xeTable
const internalData = $xeTable

const { treeConfig } = props
const { afterFullData, fullDataRowIdData, fullAllDataRowIdData } = internalData
const treeOpts = $xeTable.computeTreeOpts
if (treeConfig) {
if (treeOpts.transform) {
afterFullData.forEach((row: any, index: number) => {
const rowid = getRowid($xeTable, row)
const rowRest = fullAllDataRowIdData[rowid]
if (rowRest) {
rowRest._index = index
} else {
const rest = { row, rowid, seq: '-1', index: -1, $index: -1, _index: index, items: [], parent: null, level: 0, height: 0, oTop: 0 }
fullAllDataRowIdData[rowid] = rest
fullDataRowIdData[rowid] = rest
}
})
}
}
},
/**
* 预编译
* 对渲染中的数据提前解析序号及索引。牺牲提前编译耗时换取渲染中额外损耗,使运行时更加流畅
Expand Down Expand Up @@ -2329,7 +2305,6 @@ const Methods = {
}
fullMaps[rowid] = row
}, { children: treeOpts.transform ? treeOpts.mapChildrenField : childrenField })
$xeTable.updateTreeDataIndex()
} else {
afterFullData.forEach((row: any, index: number) => {
const rowid = getRowid($xeTable, row)
Expand Down Expand Up @@ -6766,7 +6741,7 @@ const Methods = {
return this.$nextTick().then(() => {
if (transform) {
this.handleTableData()
this.updateTreeDataIndex()
this.updateAfterDataIndex()
return this.$nextTick()
}
})
Expand Down Expand Up @@ -6880,7 +6855,7 @@ const Methods = {
return this.handleBaseTreeExpand(rows, expanded).then(() => {
handleVirtualTreeToList($xeTable)
this.handleTableData()
this.updateTreeDataIndex()
this.updateAfterDataIndex()
}).then(() => {
return this.recalculate()
}).then(() => {
Expand Down
39 changes: 23 additions & 16 deletions packages/table/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ColumnInfo } from './columnInfo'
import { isScale, isPx } from '../../ui/src/dom'
import { warnLog, errLog } from '../../ui/src/log'

import type { VxeTableDefines, VxeTableConstructor, TableReactData } from '../../../types'

const getAllConvertColumns = (columns: any, parentColumn?: any) => {
const result: any[] = []
columns.forEach((column: any) => {
Expand Down Expand Up @@ -66,12 +68,6 @@ export const convertHeaderColumnToRows = (originColumns: any) => {
return rows
}

const lineOffsetSizes: any = {
mini: 3,
small: 2,
medium: 1
}

export function restoreScrollLocation ($xeTable: any, scrollLeft: any, scrollTop: any) {
const internalData = $xeTable

Expand Down Expand Up @@ -248,15 +244,22 @@ export function getColReMinWidth (params: any) {
return mWidth
}

function countTreeExpand (prevRow: any, params: any) {
const lineOffsetSizes: Record<string, any> = {
mini: 3,
small: 2,
medium: 1
}

function countTreeExpand (prevRow: any, params: VxeTableDefines.CellRenderBodyParams) {
let count = 1
if (!prevRow) {
return count
}
const { $table } = params
const { treeOpts } = $table
const treeOpts = $table.computeTreeOpts
const { transform, mapChildrenField } = treeOpts
const childrenField = treeOpts.children || treeOpts.childrenField
const rowChildren = prevRow[childrenField]
const rowChildren = prevRow[transform ? mapChildrenField : childrenField]
if (rowChildren && $table.isTreeExpandByRow(prevRow)) {
for (let index = 0; index < rowChildren.length; index++) {
count += countTreeExpand(rowChildren[index], params)
Expand All @@ -265,18 +268,22 @@ function countTreeExpand (prevRow: any, params: any) {
return count
}

export function getOffsetSize ($xetable: any) {
const vSize = $xetable.computeSize
return lineOffsetSizes[vSize] || 0
export function getOffsetSize ($xeTable: VxeTableConstructor) {
const vSize = $xeTable.computeSize
if (vSize) {
return lineOffsetSizes[vSize] || 0
}
return 0
}

export function calcTreeLine (params: any, items: any, rIndex: any) {
export function calcTreeLine (params: VxeTableDefines.CellRenderBodyParams, prevRow: any) {
const { $table } = params
const tableReactData = $table as unknown as TableReactData
let expandSize = 1
if (rIndex) {
expandSize = countTreeExpand(items[rIndex - 1], params)
if (prevRow) {
expandSize = countTreeExpand(prevRow, params)
}
return $table.rowHeight * expandSize - (rIndex ? 1 : (12 - getOffsetSize($table)))
return tableReactData.rowHeight * expandSize - (prevRow ? 1 : (12 - getOffsetSize($table)))
}

export function mergeBodyMethod (mergeList: any, _rowIndex: any, _columnIndex: any) {
Expand Down

0 comments on commit d76e4d6

Please sign in to comment.