From 152e3eb434f3741a3d7759bcf6d184747290bb53 Mon Sep 17 00:00:00 2001 From: 502218 <810158465@qq.com> Date: Wed, 5 Dec 2018 10:31:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0noData=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E7=BD=AE=E5=BC=82=E6=AD=A5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=B0=E7=9A=84=E5=AD=90=E8=8A=82=E7=82=B9=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E6=8F=90=E7=A4=BA=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/index.less | 7 +++++++ examples/dynamic-options.js | 24 +++++++++++++++++------- src/Menus.jsx | 16 ++++++++++++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/assets/index.less b/assets/index.less index b93d9bab..7f290a93 100644 --- a/assets/index.less +++ b/assets/index.less @@ -65,6 +65,13 @@ padding: 0; border-right: 1px solid #e9e9e9; overflow: auto; + &-no-data { + position: relative; + text-align: center; + top: 50%; + transform: translateY(-50%); + color: #d9d9d9; + } &:last-child { border-right: 0; } diff --git a/examples/dynamic-options.js b/examples/dynamic-options.js index 726405d4..8f185e1f 100644 --- a/examples/dynamic-options.js +++ b/examples/dynamic-options.js @@ -12,6 +12,10 @@ const addressOptions = [{ label: '浙江', isLeaf: false, value: 'zj', +}, { + label: '北京', + isLeaf: false, + value: 'bj', }]; class Demo extends React.Component { @@ -33,13 +37,18 @@ class Demo extends React.Component { // 动态加载下级数据 setTimeout(() => { targetOption.loading = false; - targetOption.children = [{ - label: `${targetOption.label}动态加载1`, - value: 'dynamic1', - }, { - label: `${targetOption.label}动态加载2`, - value: 'dynamic2', - }]; + + if (targetOption.value === 'bj') { + targetOption.children = []; + } else { + targetOption.children = [{ + label: `${targetOption.label}动态加载1`, + value: 'dynamic1', + }, { + label: `${targetOption.label}动态加载2`, + value: 'dynamic2', + }]; + } this.setState({ options: [...this.state.options], }); @@ -53,6 +62,7 @@ class Demo extends React.Component { loadData={this.loadData} onChange={this.onChange} changeOnSelect + noData={'无数据'} > diff --git a/src/Menus.jsx b/src/Menus.jsx index 40e5057b..8539bee2 100644 --- a/src/Menus.jsx +++ b/src/Menus.jsx @@ -137,12 +137,22 @@ class Menus extends React.Component { } render() { - const { prefixCls, dropdownMenuColumnStyle } = this.props; + const { prefixCls, dropdownMenuColumnStyle, noData } = this.props; + + const getItem = (options, menuIndex) => { + if (Array.isArray(options) && options.length === 0) { + return ( +
  • {noData}
  • + ); + } + return options.map(option => this.getOption(option, menuIndex)); + }; + return (
    {this.getShowOptions().map((options, menuIndex) => )}
    @@ -158,6 +168,7 @@ Menus.defaultProps = { prefixCls: 'rc-cascader-menus', visible: false, expandTrigger: 'click', + noData: '', }; Menus.propTypes = { @@ -173,6 +184,7 @@ Menus.propTypes = { fieldNames: PropTypes.object, expandIcon: PropTypes.node, loadingIcon: PropTypes.node, + noData: PropTypes.string, }; export default Menus; From d60cdaa8db943268e1daea06ed40eb9f9dcd5922 Mon Sep 17 00:00:00 2001 From: 502218 <502217@nd.com> Date: Tue, 25 Dec 2018 14:21:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?noData=E6=94=B9=E4=B8=BAnotFountContent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/index.less | 4 ++-- examples/dynamic-options.js | 2 +- src/Menus.jsx | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/index.less b/assets/index.less index 7f290a93..c92cea08 100644 --- a/assets/index.less +++ b/assets/index.less @@ -65,7 +65,7 @@ padding: 0; border-right: 1px solid #e9e9e9; overflow: auto; - &-no-data { + &-not-fount { position: relative; text-align: center; top: 50%; @@ -170,4 +170,4 @@ transform-origin: 0% 100%; transform: scaleY(0.8); } -} \ No newline at end of file +} diff --git a/examples/dynamic-options.js b/examples/dynamic-options.js index 8f185e1f..1609bc3b 100644 --- a/examples/dynamic-options.js +++ b/examples/dynamic-options.js @@ -62,7 +62,7 @@ class Demo extends React.Component { loadData={this.loadData} onChange={this.onChange} changeOnSelect - noData={'无数据'} + notFoundContent={'无数据'} > diff --git a/src/Menus.jsx b/src/Menus.jsx index 8539bee2..8c904bd9 100644 --- a/src/Menus.jsx +++ b/src/Menus.jsx @@ -137,12 +137,12 @@ class Menus extends React.Component { } render() { - const { prefixCls, dropdownMenuColumnStyle, noData } = this.props; + const { prefixCls, dropdownMenuColumnStyle, notFoundContent } = this.props; const getItem = (options, menuIndex) => { if (Array.isArray(options) && options.length === 0) { return ( -
  • {noData}
  • +
  • {notFoundContent}
  • ); } return options.map(option => this.getOption(option, menuIndex)); @@ -168,7 +168,7 @@ Menus.defaultProps = { prefixCls: 'rc-cascader-menus', visible: false, expandTrigger: 'click', - noData: '', + notFoundContent: '', }; Menus.propTypes = { @@ -184,7 +184,7 @@ Menus.propTypes = { fieldNames: PropTypes.object, expandIcon: PropTypes.node, loadingIcon: PropTypes.node, - noData: PropTypes.string, + notFoundContent: PropTypes.string, }; export default Menus;