Skip to content

Commit

Permalink
releases 4.10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Jan 9, 2025
1 parent 9a943cc commit 9c90132
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 82 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": "4.10.4",
"version": "4.10.5",
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、拖拽排序,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...",
"scripts": {
"update": "npm install --legacy-peer-deps",
Expand Down
14 changes: 12 additions & 2 deletions packages/grid/src/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ export default defineComponent({
const tableOns = Object.assign({}, tableCompEvents)
const emptySlot = slots.empty
const loadingSlot = slots.loading
const rowDragIconSlot = slots.rowDragIcon || slots['row-drag-icon']
const columnDragIconSlot = slots.columnDragIcon || slots['column-drag-icon']
if (proxyConfig && isEnableConf(proxyOpts)) {
if (proxyOpts.sort) {
tableOns.onSortChange = sortChangeEvent
Expand All @@ -618,12 +620,20 @@ export default defineComponent({
const slotObj: {
empty?(params: any): any
loading?(params: any): any
rowDragIcon?(params: any): any
columnDragIcon?(params: any): any
} = {}
if (emptySlot) {
slotObj.empty = () => emptySlot({ $grid: $xeGrid })
slotObj.empty = emptySlot
}
if (loadingSlot) {
slotObj.loading = () => loadingSlot({ $grid: $xeGrid })
slotObj.loading = loadingSlot
}
if (rowDragIconSlot) {
slotObj.rowDragIcon = rowDragIconSlot
}
if (columnDragIconSlot) {
slotObj.columnDragIcon = columnDragIconSlot
}
return h('div', {
class: 'vxe-grid--table-wrapper'
Expand Down
64 changes: 10 additions & 54 deletions packages/table/src/body.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { defineComponent, TransitionGroup, h, ref, Ref, PropType, inject, nextTick, ComputedRef, onBeforeUnmount, onMounted, onUnmounted } from 'vue'
import { defineComponent, TransitionGroup, h, ref, Ref, PropType, inject, nextTick, onBeforeUnmount, onMounted, onUnmounted } from 'vue'
import XEUtils from 'xe-utils'
import { VxeUI } from '../../ui'
import { mergeBodyMethod, getRowid, getRefElem } from './util'
import { getOffsetSize, calcTreeLine, mergeBodyMethod, getRowid, getRefElem } from './util'
import { updateCellTitle, getPropClass, setScrollTop, setScrollLeft } from '../../ui/src/dom'
import { isEnableConf } from '../../ui/src/utils'
import { getSlotVNs } from '../../ui/src/vn'

import type { VxeTablePrivateMethods, VxeTableConstructor, VxeTableDefines, VxeTableMethods, VxeComponentSlotType, VxeComponentSizeType } from '../../../types'
import type { VxeTablePrivateMethods, VxeTableConstructor, VxeTableDefines, VxeTableMethods, VxeComponentSlotType } from '../../../types'

const { getI18n, renderer, renderEmptyElement } = VxeUI

const renderType = 'body'

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

export default defineComponent({
name: 'VxeTableBody',
props: {
Expand All @@ -32,8 +26,6 @@ export default defineComponent({
setup (props) {
const $xeTable = inject('$xeTable', {} as VxeTableConstructor & VxeTableMethods & VxeTablePrivateMethods)

const xesize = inject('xesize', null as ComputedRef<VxeComponentSizeType> | null)

const { xID, props: tableProps, context: tableContext, reactData: tableReactData, internalData: tableInternalData } = $xeTable
const { refTableBody, refTableHeader, refTableFooter, refTableLeftBody, refTableRightBody, refScrollXHandleElem, refScrollYHandleElem } = $xeTable.getRefMaps()
const { computeEditOpts, computeMouseOpts, computeAreaOpts, computeSYOpts, computeEmptyOpts, computeTooltipOpts, computeRadioOpts, computeExpandOpts, computeTreeOpts, computeCheckboxOpts, computeCellOpts, computeValidOpts, computeRowOpts, computeColumnOpts, computeRowDragOpts, computeColumnDragOpts } = $xeTable.getComputeMaps()
Expand All @@ -46,66 +38,30 @@ export default defineComponent({
const refBodyYSpace = ref() as Ref<HTMLDivElement>
const refBodyEmptyBlock = ref() as Ref<HTMLDivElement>

const getOffsetSize = () => {
if (xesize) {
const vSize = xesize.value
if (vSize) {
return lineOffsetSizes[vSize] || 0
}
}
return 0
}

// 滚动、拖动过程中不需要触发
const isVMScrollProcess = () => {
const { delayHover } = tableProps
const { lastScrollTime, _isResize } = tableReactData
return !!(_isResize || (lastScrollTime && Date.now() < lastScrollTime + (delayHover as number)))
}

const countTreeExpand = (prevRow: any, params: any) => {
let count = 1
if (!prevRow) {
return count
}
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const rowChildren = prevRow[childrenField]
if (rowChildren && $xeTable.isTreeExpandByRow(prevRow)) {
for (let index = 0; index < rowChildren.length; index++) {
count += countTreeExpand(rowChildren[index], params)
}
}
return count
}

const calcTreeLine = (params: any, items: any[], rIndex: number) => {
let expandSize = 1
if (rIndex) {
expandSize = countTreeExpand(items[rIndex - 1], params)
}
return tableReactData.rowHeight * expandSize - (rIndex ? 1 : (12 - getOffsetSize()))
}

const renderLine = (params: any) => {
const { row, column } = params
const { afterFullData } = tableInternalData
const { treeConfig } = tableProps
const treeOpts = computeTreeOpts.value
const { slots, treeNode } = column
const { fullAllDataRowIdData } = tableInternalData
if (slots && slots.line) {
return $xeTable.callSlot(slots.line, params)
}
const rowid = getRowid($xeTable, row)
const rest = fullAllDataRowIdData[rowid]
let rLevel = 0
let rIndex = 0
let items: any[] = []
let prevRow = null
if (rest) {
rLevel = rest.level
rIndex = rest._index
items = rest.items
}
if (slots && slots.line) {
return $xeTable.callSlot(slots.line, params)
prevRow = rest.items[rest._index - 1]
}
const isFirstRow = $xeTable.eqRow(afterFullData[0], row)
if (treeConfig && treeNode && (treeOpts.showLine || treeOpts.line)) {
Expand All @@ -116,8 +72,8 @@ export default defineComponent({
h('div', {
class: 'vxe-tree--line',
style: {
height: `${isFirstRow ? 1 : calcTreeLine(params, items, rIndex)}px`,
left: `${(rLevel * treeOpts.indent) + (rLevel ? 2 - getOffsetSize() : 0) + 16}px`
height: `${isFirstRow ? 1 : calcTreeLine(params, prevRow)}px`,
left: `${(rLevel * treeOpts.indent) + (rLevel ? 2 - getOffsetSize($xeTable) : 0) + 16}px`
}
})
])
Expand Down
1 change: 0 additions & 1 deletion packages/table/src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ export const Cell = {
$table.triggerTreeExpandEvent(evnt, params)
}
}
console.log(row.name, hasChild)
return [
h('div', {
class: ['vxe-cell--tree-node', {
Expand Down
27 changes: 3 additions & 24 deletions packages/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1502,27 +1502,6 @@ export default defineComponent({
}
}

const updateTreeDataIndex = () => {
const { treeConfig } = props
const { afterFullData, fullDataRowIdData, fullAllDataRowIdData } = internalData
const treeOpts = computeTreeOpts.value
if (treeConfig) {
if (treeOpts.transform) {
afterFullData.forEach((row, index) => {
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 All @@ -1540,14 +1519,14 @@ export default defineComponent({
const seq = path.map((num, i) => i % 2 === 0 ? (Number(num) + 1) : '.').join('')
if (rowRest) {
rowRest.seq = seq
rowRest._index = index
} else {
const rest = { row, rowid, seq, index: -1, $index: -1, _index: -1, items: [], parent: null, level: 0, height: 0, oTop: 0 }
fullAllDataRowIdData[rowid] = rest
fullDataRowIdData[rowid] = rest
}
fullMaps[rowid] = row
}, { children: treeOpts.transform ? treeOpts.mapChildrenField : childrenField })
updateTreeDataIndex()
} else {
afterFullData.forEach((row, index) => {
const rowid = getRowid($xeTable, row)
Expand Down Expand Up @@ -2396,7 +2375,7 @@ export default defineComponent({
return nextTick().then(() => {
if (transform) {
tablePrivateMethods.handleTableData()
updateTreeDataIndex()
updateAfterDataIndex()
return nextTick()
}
})
Expand Down Expand Up @@ -3027,7 +3006,7 @@ export default defineComponent({
return handleBaseTreeExpand(rows, expanded).then(() => {
handleVirtualTreeToList()
tablePrivateMethods.handleTableData()
updateTreeDataIndex()
updateAfterDataIndex()
}).then(() => {
return tableMethods.recalculate()
}).then(() => {
Expand Down
44 changes: 44 additions & 0 deletions packages/table/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,50 @@ export function getRootColumn ($xeTable: VxeTableConstructor & VxeTablePrivateMe
return column
}

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

const countTreeExpand = (prevRow: any, params: VxeTableDefines.CellRenderBodyParams) => {
let count = 1
if (!prevRow) {
return count
}
const { $table } = params
const { computeTreeOpts } = $table.getComputeMaps()
const treeOpts = computeTreeOpts.value
const { transform, mapChildrenField } = treeOpts
const childrenField = treeOpts.children || treeOpts.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)
}
}
return count
}

export const getOffsetSize = ($xeTable: VxeTableConstructor) => {
const { computeSize } = $xeTable.getComputeMaps()
const vSize = computeSize.value
if (vSize) {
return lineOffsetSizes[vSize] || 0
}
return 0
}

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

export function mergeBodyMethod (mergeList: VxeTableDefines.MergeItem[], _rowIndex: number, _columnIndex: number) {
for (let mIndex = 0; mIndex < mergeList.length; mIndex++) {
const { row: mergeRowIndex, col: mergeColIndex, rowspan: mergeRowspan, colspan: mergeColspan } = mergeList[mIndex]
Expand Down

0 comments on commit 9c90132

Please sign in to comment.