Skip to content

Commit

Permalink
fix: #1386
Browse files Browse the repository at this point in the history
  • Loading branch information
Wugaoliang committed Nov 30, 2020
1 parent fe98d2b commit c8ba1d3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 61 deletions.
4 changes: 2 additions & 2 deletions components/select-tree/SelectTreeHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const SelectTree = ({
* Remote load Data
* @param {*} id click node's id
*/
const loadNodes = useCallback((id) => {
const loadNodes = (id) => {
const _dataSource = typeof dataSource === 'function' ? dataSource(id || '') : dataSource
return HiRequest({
..._dataSource
Expand All @@ -267,7 +267,7 @@ const SelectTree = ({
})
return nArr
})
}, [])
}
/**
* 多选模式下复选框事件
* @param {*} checked 是否被选中
Expand Down
76 changes: 36 additions & 40 deletions components/select-tree/components/tree/NavTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,48 +108,44 @@ const NavTree = ({
{Object.keys(fullBreadData).length > 0 && (
<Bread datas={fullBreadData} localeDatas={localeDatas} onClick={onBreadClick} onReturnClick={onReturnClick} />
)}
<Loading size="small" visible={loadingState === 'loading'}>
{loadingState === 'empty' ? (
<span className="hi-select-tree--empty">{localeDatas.selectTree.emptyContent}</span>
) : (
<ul className="hi-breadtree__list">
{loadingState === 'empty' ? (
<li>
<span className="hi-select-tree--empty">{localeDatas.selectTree.emptyContent}</span>
</li>
) : (
renderData.map((node, index) => {
const children = getChildrenNodes(node, data)
const textCls = classNames(
'hi-breadtree__text',
selectedItems.find((n) => n.id === node.id) && 'hi-breadtree__text--selected'
)
return (
<li key={index} className="hi-breadtree__item">
{checkable && node.isLeaf ? (
<Checkbox
indeterminate={checkedNodes.semiChecked.includes(node.id)}
checked={checkedNodes.checked.includes(node.id)}
onChange={(e) => onCheck(e.target.checked, node)}
>
<span className={textCls}>{node.title}</span>
</Checkbox>
) : (
<span
className={textCls}
onClick={() => {
onNodeClick(node, children)
}}
>
{node.title}
</span>
)}
{(children.length > 0 || !node.isLeaf) && (
<Icon name={'right'} onClick={() => onNodeClick(node, children)} />
)}
</li>
)
})
)}
{renderData.map((node, index) => {
const children = getChildrenNodes(node, data)
const textCls = classNames(
'hi-breadtree__text',
selectedItems.find((n) => n.id === node.id) && 'hi-breadtree__text--selected'
)
return (
<li key={index} className="hi-breadtree__item">
{checkable && node.isLeaf ? (
<Checkbox
indeterminate={checkedNodes.semiChecked.includes(node.id)}
checked={checkedNodes.checked.includes(node.id)}
onChange={(e) => onCheck(e.target.checked, node)}
>
<span className={textCls}>{node.title}</span>
</Checkbox>
) : (
<span
className={textCls}
onClick={() => {
onNodeClick(node, children)
}}
>
{node.title}
</span>
)}
{(children.length > 0 || !node.isLeaf) && (
<Icon name={'right'} onClick={() => onNodeClick(node, children)} />
)}
</li>
)
})}
</ul>
</Loading>
)}
</div>
)
}
Expand Down
4 changes: 4 additions & 0 deletions components/select-tree/components/tree/style/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ $tree: 'hi-select-tree' !default;
width: 100%;
display: flex;
flex-direction: column;

.hi-select-tree--empty {
padding: 12px 0 0 12px;
}
}

&__list {
Expand Down
15 changes: 3 additions & 12 deletions docs/demo/select-tree/section-bread.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ const code = [
return res.map(r => {
return {
...r,
id: r.code,
title: r.name
id: r.id,
title: r.title
}
})
}
Expand Down Expand Up @@ -376,16 +376,7 @@ const code = [
method: 'GET',
key: 'id',
params: {pId: key},
url: 'http://localhost:8001/tree',
transformResponse: (res) => {
return res.map(r => {
return {
...r,
id: r.code,
title: r.name
}
})
}
url: 'http://my-json-server.typicode.com/hiui-group/db/fulldata',
}
}}
/>
Expand Down
8 changes: 1 addition & 7 deletions docs/demo/select-tree/section-nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ class Demo extends React.Component {
}
}`
const DemoType = () => (
<DocViewer
code={code}
scope={{ SelectTree }}
prefix={prefix}
rightOptions={rightOptions}
desc={desc}
/>
<DocViewer code={code} scope={{ SelectTree }} prefix={prefix} rightOptions={rightOptions} desc={desc} />
)
export default DemoType

0 comments on commit c8ba1d3

Please sign in to comment.