Skip to content

Commit a2fb64e

Browse files
author
cole
committed
refactor: genColNodes
1 parent f416e84 commit a2fb64e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/packages/form/layouts/query-filter/hooks/useQueryFilter.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,29 @@ function useQueryFilter (size, props) {
5656
collapsed.value = value
5757
}
5858

59-
function genColNodes (children, callback) {
60-
// 添加计数 解决位置不对问题
59+
function createNodes (children) {
60+
const maxIndex = unref(showNumber) - 1
61+
// 计数器
6162
let hiddenCount = 0
63+
const isChildHidden = (propsHidden, index) => {
64+
propsHidden && (hiddenCount += 1)
65+
const cHidden = unref(collapsed) && (index - hiddenCount) > maxIndex
66+
return showCollapse ? (propsHidden || cHidden) : propsHidden
67+
}
6268

63-
const nodes = filterEmptyElement(children).map((child, index) => {
69+
return children.map((child, index) => {
6470
const propsHidden = child.props && child.props.hidden || false
65-
propsHidden && (hiddenCount += 1)
66-
const colHidden = propsHidden || unref(collapsed) && (index - hiddenCount > unref(showNumber) - 1)
67-
const hidden = showCollapse ? colHidden : propsHidden
71+
const hidden = isChildHidden(propsHidden, index)
6872
const key = (isValidElement(child) && child.key) || index
6973
return { key: key, child: child, hidden: hidden }
7074
})
71-
const { length } = nodes.filter((c) => !c.hidden)
72-
const offset = getOffset(length, unref(span))
75+
}
76+
77+
function genColNodes (children, callback) {
78+
const validChildren = filterEmptyElement(children || [])
79+
const nodes = createNodes(validChildren)
80+
const showNodes = nodes.filter((c) => !c.hidden)
81+
const offset = getOffset(showNodes.length, unref(span))
7382
const haveRow = unref(span) + offset === 24
7483
return { nodes: map(nodes, callback), offset, haveRow }
7584
}

0 commit comments

Comments
 (0)