diff --git a/.eslintrc.js b/.eslintrc.js index e29c1a8a6221f03d61414a04824b100e0e46a6b7..c20a185d2d289f0a3c16702e83b7c484aca02e49 100755 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,7 @@ module.exports = { 'react/jsx-no-bind': [0], 'react/prop-types': [0], 'react/prefer-stateless-function': [0], + 'react/jsx-one-expression-per-line': [0], 'react/jsx-wrap-multilines': [ 'error', { diff --git a/src/components/ActiveChart/index.js b/src/components/ActiveChart/index.js index 07e29619f309072f0e6a3a1c99b0a5d12a09be36..433ea2eb8fb7ff3830640f251483125256304c2b 100644 --- a/src/components/ActiveChart/index.js +++ b/src/components/ActiveChart/index.js @@ -32,6 +32,7 @@ export default class ActiveChart extends Component { componentWillUnmount() { clearTimeout(this.timer); } + loopData = () => { this.timer = setTimeout(() => { this.setState( @@ -46,6 +47,7 @@ export default class ActiveChart extends Component { ); }, 1000); }; + render() { const { activeData = [] } = this.state; diff --git a/src/components/Authorized/PromiseRender.js b/src/components/Authorized/PromiseRender.js index db86efd68531ce096e5e58d116aef3085bcb5a88..62b24808258ad36e90a8637f5256bc2f9caaf874 100644 --- a/src/components/Authorized/PromiseRender.js +++ b/src/components/Authorized/PromiseRender.js @@ -5,13 +5,16 @@ export default class PromiseRender extends React.PureComponent { state = { component: null, }; + componentDidMount() { this.setRenderComponent(this.props); } + componentDidUpdate(nextProps) { // new Props enter this.setRenderComponent(nextProps); } + // set render Component : ok or error setRenderComponent(props) { const ok = this.checkIsInstantiation(props.ok); @@ -28,6 +31,7 @@ export default class PromiseRender extends React.PureComponent { }); }); } + // Determine whether the incoming component has been instantiated // AuthorizedRoute is already instantiated // Authorized render is already instantiated, children is no instantiated @@ -38,10 +42,11 @@ export default class PromiseRender extends React.PureComponent { } return () => target; }; + render() { - const Component = this.state.component; - return Component ? ( - + const { component } = this.state; + return component ? ( + ) : (
{ this.root = n; }; @@ -112,6 +92,29 @@ export default class Pie extends Component { }); }; + // for window resize auto responsive legend + @Bind() + @Debounce(300) + resize() { + const { hasLegend } = this.props; + const { legendBlock } = this.state; + if (!hasLegend || !this.root) { + window.removeEventListener('resize', this.resize); + return; + } + if (this.root.parentNode.clientWidth <= 380) { + if (!legendBlock) { + this.setState({ + legendBlock: true, + }); + } + } else if (legendBlock) { + this.setState({ + legendBlock: false, + }); + } + } + render() { const { valueFormat, @@ -137,9 +140,10 @@ export default class Pie extends Component { }); const defaultColors = colors; - let data = this.props.data || []; - let selected = this.props.selected || true; - let tooltip = this.props.tooltip || true; + let { data, selected, tooltip } = this.props; + data = data || []; + selected = selected || true; + tooltip = tooltip || true; let formatColor; const scale = { diff --git a/src/components/CountDown/index.js b/src/components/CountDown/index.js index 4485b6e8f10ed5655525f309487abab05d688b4e..0b1560e20c4a3142a8c851de7a7091c94fb996b5 100644 --- a/src/components/CountDown/index.js +++ b/src/components/CountDown/index.js @@ -23,32 +23,25 @@ const initTime = props => { }; class CountDown extends Component { + timer = 0; + + interval = 1000; + constructor(props) { super(props); - const { lastTime } = initTime(props); - this.state = { lastTime, }; } - static getDerivedStateFromProps(nextProps, preState) { - const { lastTime } = initTime(nextProps); - if (preState.lastTime !== lastTime) { - return { - lastTime, - }; - } - return null; - } - componentDidMount() { this.tick(); } componentDidUpdate(prevProps) { - if (this.props.target !== prevProps.target) { + const { target } = this.props; + if (target !== prevProps.target) { clearTimeout(this.timer); this.tick(); } @@ -58,8 +51,16 @@ class CountDown extends Component { clearTimeout(this.timer); } - timer = 0; - interval = 1000; + static getDerivedStateFromProps(nextProps, preState) { + const { lastTime } = initTime(nextProps); + if (preState.lastTime !== lastTime) { + return { + lastTime, + }; + } + return null; + } + // defaultFormat = time => ( // {moment(time).format('hh:mm:ss')} // ); @@ -76,6 +77,7 @@ class CountDown extends Component { ); }; + tick = () => { const { onEnd } = this.props; let { lastTime } = this.state; diff --git a/src/components/EditableItem/index.js b/src/components/EditableItem/index.js index fcda844e3f5af30970b2b8b58b4e4d6a9dcfe8c7..5b2ef0028ba92cc04039c9259e16fdac6f2f9078 100644 --- a/src/components/EditableItem/index.js +++ b/src/components/EditableItem/index.js @@ -3,23 +3,32 @@ import { Input, Icon } from 'antd'; import styles from './index.less'; export default class EditableItem extends PureComponent { - state = { - value: this.props.value, - editable: false, - }; + constructor(props) { + super(props); + this.state = { + value: props.value, + editable: false, + }; + } + handleChange = e => { const { value } = e.target; this.setState({ value }); }; + check = () => { this.setState({ editable: false }); - if (this.props.onChange) { - this.props.onChange(this.state.value); + const { value } = this.state; + const { onChange } = this.state; + if (onChange) { + onChange(value); } }; + edit = () => { this.setState({ editable: true }); }; + render() { const { value, editable } = this.state; return ( diff --git a/src/components/EditableLinkGroup/index.js b/src/components/EditableLinkGroup/index.js index 2d0b4aa83a34921f6936c24b104d4933475c969d..ae3d93c712b8b019078fe37bd07286716349ef3f 100644 --- a/src/components/EditableLinkGroup/index.js +++ b/src/components/EditableLinkGroup/index.js @@ -17,6 +17,7 @@ class EditableLinkGroup extends PureComponent { onAdd: () => {}, linkElement: 'a', }; + render() { const { links, linkElement, onAdd } = this.props; return ( diff --git a/src/components/GlobalHeader/RightContent.js b/src/components/GlobalHeader/RightContent.js index 15511f9a93c12b602624d2803a657348897b38ee..7b4f98c684e8ef6453bac3e52e25658d8cacf995 100644 --- a/src/components/GlobalHeader/RightContent.js +++ b/src/components/GlobalHeader/RightContent.js @@ -38,6 +38,7 @@ export default class GlobalHeaderRight extends PureComponent { }); return groupBy(newNotices, 'type'); } + render() { const { currentUser, @@ -45,6 +46,7 @@ export default class GlobalHeaderRight extends PureComponent { onNoticeVisibleChange, onMenuClick, onNoticeClear, + theme, } = this.props; const menu = ( @@ -65,7 +67,7 @@ export default class GlobalHeaderRight extends PureComponent { ); const noticeData = this.getNoticeData(); let className = styles.right; - if (this.props.theme === 'dark') { + if (theme === 'dark') { className = `${styles.right} ${styles.dark}`; } return ( diff --git a/src/components/HeaderSearch/index.js b/src/components/HeaderSearch/index.js index a7fb0e7756eab2a74eb9368337105bfb34afa3a5..3033265efd7708b2af52e575dfc99f6f7f6b110c 100644 --- a/src/components/HeaderSearch/index.js +++ b/src/components/HeaderSearch/index.js @@ -25,44 +25,58 @@ export default class HeaderSearch extends PureComponent { defaultOpen: false, }; - state = { - searchMode: this.props.defaultOpen, - value: '', - }; + constructor(props) { + super(props); + this.state = { + searchMode: props.defaultOpen, + value: '', + }; + } + componentWillUnmount() { clearTimeout(this.timeout); } + onKeyDown = e => { if (e.key === 'Enter') { + const { onPressEnter } = this.props; + const { value } = this.state; this.timeout = setTimeout(() => { - this.props.onPressEnter(this.state.value); // Fix duplicate onPressEnter + onPressEnter(value); // Fix duplicate onPressEnter }, 0); } }; + onChange = value => { + const { onChange } = this.props; this.setState({ value }); - if (this.props.onChange) { - this.props.onChange(); + if (onChange) { + onChange(); } }; + enterSearchMode = () => { this.setState({ searchMode: true }, () => { - if (this.state.searchMode) { + const { searchMode } = this.state; + if (searchMode) { this.input.focus(); } }); }; + leaveSearchMode = () => { this.setState({ searchMode: false, value: '', }); }; + render() { const { className, placeholder, ...restProps } = this.props; delete restProps.defaultOpen; // for rc-select not affected + const { searchMode, value } = this.state; const inputClass = classNames(styles.input, { - [styles.show]: this.state.searchMode, + [styles.show]: searchMode, }); return ( @@ -71,7 +85,7 @@ export default class HeaderSearch extends PureComponent { key="AutoComplete" {...restProps} className={inputClass} - value={this.state.value} + value={value} onChange={this.onChange} > { const { onGetCaptcha } = this.props; const result = onGetCaptcha ? onGetCaptcha() : null; @@ -34,6 +38,7 @@ class WarpFormItem extends Component { this.runGetCaptchaCountDown(); } }; + getFormItemOptions = ({ onChange, defaultValue, rules }) => { const options = { rules: rules || this.customprops.rules, @@ -46,8 +51,10 @@ class WarpFormItem extends Component { } return options; }; + runGetCaptchaCountDown = () => { - let count = this.props.countDown || 59; + const { countDown } = this.props; + let count = countDown || 59; this.setState({ count }); this.interval = setInterval(() => { count -= 1; @@ -57,10 +64,13 @@ class WarpFormItem extends Component { } }, 1000); }; + render() { const { count } = this.state; - const { getFieldDecorator } = this.props.form; + const { + form: { getFieldDecorator }, + } = this.props; // 这么写是为了防止restProps中 带入 onChange, defaultValue, rules props const { @@ -70,6 +80,7 @@ class WarpFormItem extends Component { rules, name, updateActive, + type, ...restProps } = this.props; @@ -77,15 +88,13 @@ class WarpFormItem extends Component { const options = this.getFormItemOptions(this.props); const otherProps = restProps || {}; - if (this.props.type === 'Captcha') { + if (type === 'Captcha') { const inputProps = omit(otherProps, ['onGetCaptcha']); return ( - {getFieldDecorator(name, options)( - - )} + {getFieldDecorator(name, options)()}