diff --git a/.eslintrc.js b/.eslintrc.js index 3d024694320dde59bc622ac0c00008d733bbe4d6..9c1cf5f7fba297725d766633790417f120a9280d 100755 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,6 +10,7 @@ module.exports = { }, rules: { 'jsx-a11y/href-no-hash': [0], + 'react/sort-comp': 1, }, settings: { polyfills: ['fetch', 'promises'], diff --git a/src/components/CountDown/index.js b/src/components/CountDown/index.js index 4d63d3565fad39ff56143bccb029ee1a4c3f7404..53815c9eb81e2770cfc1e7f5352b3d5a40db13fb 100644 --- a/src/components/CountDown/index.js +++ b/src/components/CountDown/index.js @@ -23,9 +23,6 @@ const initTime = props => { }; class CountDown extends Component { - timer = 0; - - interval = 1000; constructor(props) { super(props); @@ -35,6 +32,16 @@ class CountDown extends Component { }; } + static getDerivedStateFromProps(nextProps, preState) { + const { lastTime } = initTime(nextProps); + if (preState.lastTime !== lastTime) { + return { + lastTime, + }; + } + return null; + } + componentDidMount() { this.tick(); } @@ -51,15 +58,9 @@ class CountDown extends Component { clearTimeout(this.timer); } - static getDerivedStateFromProps(nextProps, preState) { - const { lastTime } = initTime(nextProps); - if (preState.lastTime !== lastTime) { - return { - lastTime, - }; - } - return null; - } + timer = 0; + + interval = 1000; // defaultFormat = time => ( // {moment(time).format('hh:mm:ss')} diff --git a/src/components/TagSelect/index.js b/src/components/TagSelect/index.js index b7aea130fa5f2cf17e6e0ea5d80f1f7884c6d72a..dff382423f68fd0a2e6c125cff90e303d173faa4 100644 --- a/src/components/TagSelect/index.js +++ b/src/components/TagSelect/index.js @@ -26,6 +26,13 @@ class TagSelect extends Component { }; } + static getDerivedStateFromProps(nextProps) { + if ('value' in nextProps && nextProps.value) { + return { value: nextProps.value }; + } + return null; + } + onChange = value => { const { onChange } = this.props; if (!('value' in this.props)) { @@ -44,13 +51,6 @@ class TagSelect extends Component { this.onChange(checkedTags); }; - static getDerivedStateFromProps(nextProps) { - if ('value' in nextProps && nextProps.value) { - return { value: nextProps.value }; - } - return null; - } - getAllTags() { let { children } = this.props; children = React.Children.toArray(children); diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 148092c90b18df79caebb19a11acd81b6c62491a..9754ebd203df1fe79a3f28e7fd7f7be17f581f6f 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -64,9 +64,6 @@ const query = { }; class BasicLayout extends React.PureComponent { - state = { - rendering: true, - }; constructor(props) { super(props); const { menuData } = this.props; @@ -74,6 +71,28 @@ class BasicLayout extends React.PureComponent { // Because there are many places to be. So put it here this.breadcrumbNameMap = getBreadcrumbNameMap(menuData); } + + state = { + rendering: true, + }; + + componentDidMount() { + this.renderRef = requestAnimationFrame(() => { + this.setState({ + rendering: false, + }); + }); + } + + componentDidUpdate() { + const { menuData } = this.props; + this.breadcrumbNameMap = getBreadcrumbNameMap(menuData); + } + + componentWillUnmount() { + cancelAnimationFrame(this.renderRef); + } + getContext() { const { location } = this.props; return { @@ -81,10 +100,7 @@ class BasicLayout extends React.PureComponent { breadcrumbNameMap: this.breadcrumbNameMap, }; } - componentDidUpdate() { - const { menuData } = this.props; - this.breadcrumbNameMap = getBreadcrumbNameMap(menuData); - } + getPageTitle = pathname => { let currRouterData = null; // match params path @@ -149,16 +165,7 @@ class BasicLayout extends React.PureComponent { payload: collapsed, }); }; - componentDidMount() { - this.renderRef = requestAnimationFrame(() => { - this.setState({ - rendering: false, - }); - }); - } - componentWillUnmount() { - cancelAnimationFrame(this.renderRef); - } + render() { const { isMobile, diff --git a/src/pages/Account/Settings/Info.js b/src/pages/Account/Settings/Info.js index 23cedd8d3dca594c98edfce0209d988ab3f3003d..948349b7be55949ed6056c8afebd904810687d61 100644 --- a/src/pages/Account/Settings/Info.js +++ b/src/pages/Account/Settings/Info.js @@ -41,15 +41,6 @@ export default class Info extends Component { }); } - componentDidMount() { - window.addEventListener('resize', this.resize); - this.resize(); - } - - componentWillUnmount() { - window.removeEventListener('resize', this.resize); - } - static getDerivedStateFromProps(props, state) { const { match, location } = props; let selectKey = location.pathname.replace(`${match.path}/`, ''); @@ -60,6 +51,15 @@ export default class Info extends Component { return null; } + componentDidMount() { + window.addEventListener('resize', this.resize); + this.resize(); + } + + componentWillUnmount() { + window.removeEventListener('resize', this.resize); + } + getmenu = () => { const { menuMap } = this.state; return Object.keys(menuMap).map(item => {menuMap[item]}); diff --git a/src/pages/Forms/TableForm.js b/src/pages/Forms/TableForm.js index 068fe0154141069c712e81cfbec8786ad8bf7eb5..3ad0a79126acd66794f5fbb908a4a99e17181a5b 100644 --- a/src/pages/Forms/TableForm.js +++ b/src/pages/Forms/TableForm.js @@ -4,9 +4,6 @@ import isEqual from 'lodash.isequal'; import styles from './style.less'; export default class TableForm extends PureComponent { - index = 0; - - cacheOriginData = {}; constructor(props) { super(props); @@ -29,6 +26,10 @@ export default class TableForm extends PureComponent { }; } + index = 0; + + cacheOriginData = {}; + getRowByKey(key, newData) { const { data } = this.state; return (newData || data).filter(item => item.key === key)[0]; diff --git a/src/pages/List/BasicList.js b/src/pages/List/BasicList.js index 3e95a1f301577bf05a3dafc04830230f09508272..3c80c72a99a9cb4ba0f721924af9ba37b7b1c0d8 100644 --- a/src/pages/List/BasicList.js +++ b/src/pages/List/BasicList.js @@ -38,10 +38,6 @@ const { Search, TextArea } = Input; })) @Form.create() export default class BasicList extends PureComponent { - formLayout = { - labelCol: { span: 7 }, - wrapperCol: { span: 13 }, - }; state = { visible: false, done: false }; @@ -55,6 +51,11 @@ export default class BasicList extends PureComponent { }); } + formLayout = { + labelCol: { span: 7 }, + wrapperCol: { span: 13 }, + }; + showModal = () => { this.setState({ visible: true, diff --git a/src/pages/List/TableList.js b/src/pages/List/TableList.js index 531fc7c71e2202fd0a9124472deb4df5bb2e0651..60c5abebe64acf66677ce7218df01e3ac2cf82a3 100644 --- a/src/pages/List/TableList.js +++ b/src/pages/List/TableList.js @@ -272,6 +272,22 @@ class UpdateForm extends PureComponent { })) @Form.create() export default class TableList extends PureComponent { + state = { + modalVisible: false, + updateModalVisible: false, + expandForm: false, + selectedRows: [], + formValues: {}, + stepFormValues: {}, + }; + + componentDidMount() { + const { dispatch } = this.props; + dispatch({ + type: 'rule/fetch', + }); + } + columns = [ { title: '规则名称', @@ -333,22 +349,6 @@ export default class TableList extends PureComponent { }, ]; - state = { - modalVisible: false, - updateModalVisible: false, - expandForm: false, - selectedRows: [], - formValues: {}, - stepFormValues: {}, - }; - - componentDidMount() { - const { dispatch } = this.props; - dispatch({ - type: 'rule/fetch', - }); - } - handleStandardTableChange = (pagination, filtersArg, sorter) => { const { dispatch } = this.props; const { formValues } = this.state;