Commit 88764675 authored by 徐乐's avatar 徐乐

perf: 修改3个设备树组件初始骨架屏问题

parent 048a5f5b
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import { Input, Tree, Divider, ConfigProvider } from 'antd'; import { Input, Tree, Divider, ConfigProvider, Skeleton } from 'antd';
import { SearchOutlined } from '@ant-design/icons'; import { SearchOutlined } from '@ant-design/icons';
import Empty from '@wisdom-components/empty'; import Empty from '@wisdom-components/empty';
import './index.less'; import './index.less';
const DeviceTree = (props) => { const DeviceTree = (props) => {
const { prefix, placeholder, treeData, first, onSearch } = props; const { prefix, placeholder, treeData, first, onSearch } = props;
console.log(first, treeData)
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('device-tree'); const prefixCls = getPrefixCls('device-tree');
...@@ -23,8 +22,16 @@ const DeviceTree = (props) => { ...@@ -23,8 +22,16 @@ const DeviceTree = (props) => {
/> />
<Divider /> <Divider />
<div className={classNames(`${prefixCls}-content`)}> <div className={classNames(`${prefixCls}-content`)}>
{!!treeData.length && <Tree {...props} />} {/* {!!treeData.length && <Skeleton loading={first} active><Tree {...props} /></Skeleton>}
{!treeData.length && !first ? <Empty /> : ''} {!treeData.length && !first ? <Empty /> : ''} */}
{
first || !!treeData.length ?
<Skeleton loading={first} active>
<Tree {...props} />
</Skeleton>
:
<Empty />
}
</div> </div>
</div> </div>
); );
......
import React, { useContext, useEffect, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import { Spin, Input, Tree, Divider, message, Pagination, ConfigProvider } from 'antd'; import { Spin, Input, Tree, Divider, message, Pagination, ConfigProvider, Skeleton } from 'antd';
import { SearchOutlined } from '@ant-design/icons'; import { SearchOutlined } from '@ant-design/icons';
import Empty from '@wisdom-components/empty'; import Empty from '@wisdom-components/empty';
import './index.less'; import './index.less';
...@@ -127,8 +127,8 @@ const DeviceTree = (props) => { ...@@ -127,8 +127,8 @@ const DeviceTree = (props) => {
/> />
<Divider className={classNames(`${prefixCls}-divider`)} /> <Divider className={classNames(`${prefixCls}-divider`)} />
<div className={classNames(`${prefixCls}-content`)}> <div className={classNames(`${prefixCls}-content`)}>
<Spin delay={1000} spinning={loading}> {loading || (!!treeData.length) ? (
{!!treeData.length && ( <Skeleton loading={loading} active>
<Tree <Tree
checkedKeys={checkedKeys} checkedKeys={checkedKeys}
expandedKeys={expandedKeys} expandedKeys={expandedKeys}
...@@ -140,9 +140,9 @@ const DeviceTree = (props) => { ...@@ -140,9 +140,9 @@ const DeviceTree = (props) => {
checkStrictly checkStrictly
{...props} {...props}
/> />
)} </Skeleton>
{!treeData.length && !loading && <Empty />}
</Spin> ) : <Empty />}
</div> </div>
{pagination && ( {pagination && (
<div className={classNames(`${prefixCls}-pagination`)}> <div className={classNames(`${prefixCls}-pagination`)}>
...@@ -170,8 +170,8 @@ DeviceTree.defaultProps = { ...@@ -170,8 +170,8 @@ DeviceTree.defaultProps = {
placeholder: '搜索设备名称', placeholder: '搜索设备名称',
pagination: true, pagination: true,
serviceParams: {}, serviceParams: {},
onTreeCheck: () => {}, onTreeCheck: () => { },
onTreeSelect: () => {}, onTreeSelect: () => { },
}; };
DeviceTree.propTypes = { DeviceTree.propTypes = {
......
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Input, Layout, Spin, Tree, ConfigProvider } from 'antd'; import { Input, Layout, Spin, Tree, ConfigProvider, Skeleton } from 'antd';
// import { SearchOutlined } from '@ant-design/icons'; // import { SearchOutlined } from '@ant-design/icons';
import React, { useCallback, useEffect, useMemo, useRef, useState, useContext } from 'react'; import React, { useCallback, useEffect, useMemo, useRef, useState, useContext } from 'react';
import PandaEmpty from '@wisdom-components/empty'; import PandaEmpty from '@wisdom-components/empty';
...@@ -249,8 +249,9 @@ const DeviceTree = (props) => { ...@@ -249,8 +249,9 @@ const DeviceTree = (props) => {
<div className={classNames(prefixCls, 'wkt-scroll-light')}> <div className={classNames(prefixCls, 'wkt-scroll-light')}>
<Input.Search placeholder="搜索设备名称" onSearch={onSearch} allowClear /> <Input.Search placeholder="搜索设备名称" onSearch={onSearch} allowClear />
<div className={classnames(`${prefixCls}-tree-wrap`, 'wkt-scroll-light-plus')} ref={ref}> <div className={classnames(`${prefixCls}-tree-wrap`, 'wkt-scroll-light-plus')} ref={ref}>
<Spin spinning={loading}> {/* <Spin spinning={loading}> */}
{data && data.length ? ( {loading || (data && data.length) ? (
<Skeleton loading={loading} active>
<Tree <Tree
checkStrictly checkStrictly
checkedKeys={checkedKeys} checkedKeys={checkedKeys}
...@@ -263,10 +264,12 @@ const DeviceTree = (props) => { ...@@ -263,10 +264,12 @@ const DeviceTree = (props) => {
onCheck={handleCheck} onCheck={handleCheck}
onSelect={handleSelect} onSelect={handleSelect}
/> />
) : ( </Skeleton>
<PandaEmpty />
)} ) : (
</Spin> <PandaEmpty />
)}
{/* </Spin> */}
</div> </div>
</div> </div>
); );
...@@ -283,10 +286,10 @@ DeviceTree.defaultProps = { ...@@ -283,10 +286,10 @@ DeviceTree.defaultProps = {
selectable: false, selectable: false,
checkable: false, checkable: false,
keepChecked: false, keepChecked: false,
onSelect: () => {}, onSelect: () => { },
onCheck: () => {}, onCheck: () => { },
setDeviceList: () => {}, setDeviceList: () => { },
setSearchStr: () => {}, setSearchStr: () => { },
}; };
DeviceTree.propTypes = { DeviceTree.propTypes = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment