diff --git a/src/components/CountDown/index.js b/src/components/CountDown/index.js index ce769121c3c731dcb93b4d60dc28dc42291e7cfd..4485b6e8f10ed5655525f309487abab05d688b4e 100644 --- a/src/components/CountDown/index.js +++ b/src/components/CountDown/index.js @@ -23,16 +23,6 @@ const initTime = props => { }; class CountDown extends Component { - static getDerivedStateFromProps(nextProps, preState) { - const { lastTime } = initTime(nextProps); - if (preState.lastTime !== lastTime) { - return { - lastTime, - }; - } - return null; - } - constructor(props) { super(props); @@ -43,6 +33,16 @@ class CountDown extends Component { }; } + static getDerivedStateFromProps(nextProps, preState) { + const { lastTime } = initTime(nextProps); + if (preState.lastTime !== lastTime) { + return { + lastTime, + }; + } + return null; + } + componentDidMount() { this.tick(); } diff --git a/src/components/SiderMenu/SiderMenu.js b/src/components/SiderMenu/SiderMenu.js index 6d64a4a3cc507561c8fc3b99d79c041b70ccecae..1f4c03397e860482d4cf2647779f3496787865e5 100644 --- a/src/components/SiderMenu/SiderMenu.js +++ b/src/components/SiderMenu/SiderMenu.js @@ -65,16 +65,6 @@ export const getMenuMatchKeys = (flatMenuKeys, paths) => ); export default class SiderMenu extends PureComponent { - static getDerivedStateFromProps(props, state) { - const { pathname } = state; - if (props.location.pathname !== pathname) { - return { - pathname: props.location.pathname, - openKeys: getDefaultCollapsedSubMenus(props), - }; - } - return null; - } constructor(props) { super(props); this.menus = props.menuData; @@ -85,6 +75,16 @@ export default class SiderMenu extends PureComponent { }; } + static getDerivedStateFromProps(props, state) { + const { pathname } = state; + if (props.location.pathname !== pathname) { + return { + pathname: props.location.pathname, + openKeys: getDefaultCollapsedSubMenus(props), + }; + } + return null; + } /** * Convert pathname to openKeys * /list/search/articles = > ['list','/list/search'] diff --git a/src/components/StandardTable/index.js b/src/components/StandardTable/index.js index ad3eb1ca7a1c37f51eec4eba97401b3d54aae50b..2f82ee35a73fec571d9a78d147f24a3ab33a037a 100644 --- a/src/components/StandardTable/index.js +++ b/src/components/StandardTable/index.js @@ -13,6 +13,16 @@ function initTotalList(columns) { } class StandardTable extends PureComponent { + constructor(props) { + super(props); + const { columns } = props; + const needTotalList = initTotalList(columns); + + this.state = { + selectedRowKeys: [], + needTotalList, + }; + } static getDerivedStateFromProps(nextProps) { // clean state if (nextProps.selectedRows.length === 0) { @@ -24,17 +34,6 @@ class StandardTable extends PureComponent { } return null; } - constructor(props) { - super(props); - const { columns } = props; - const needTotalList = initTotalList(columns); - - this.state = { - selectedRowKeys: [], - needTotalList, - }; - } - handleRowSelectChange = (selectedRowKeys, selectedRows) => { let needTotalList = [...this.state.needTotalList]; needTotalList = needTotalList.map(item => { @@ -63,7 +62,12 @@ class StandardTable extends PureComponent { render() { const { selectedRowKeys, needTotalList } = this.state; - const { data: { list, pagination }, loading, columns, rowKey } = this.props; + const { + data: { list, pagination }, + loading, + columns, + rowKey, + } = this.props; const paginationProps = { showSizeChanger: true, diff --git a/src/components/TagSelect/index.js b/src/components/TagSelect/index.js index 83acfa1fd615f8d4e1eb161a19125c9f18c6c2d2..9f3c57343ada7d10b512b65ba6648cc4a445b791 100644 --- a/src/components/TagSelect/index.js +++ b/src/components/TagSelect/index.js @@ -15,18 +15,17 @@ const TagSelectOption = ({ children, checked, onChange, value }) => ( TagSelectOption.isTagSelectOption = true; class TagSelect extends Component { + state = { + expand: false, + value: this.props.value || this.props.defaultValue || [], + }; + static getDerivedStateFromProps(nextProps) { if ('value' in nextProps && nextProps.value) { return { value: nextProps.value }; } return null; } - - state = { - expand: false, - value: this.props.value || this.props.defaultValue || [], - }; - onChange = value => { const { onChange } = this.props; if (!('value' in this.props)) { diff --git a/src/routes/Dashboard/Analysis.js b/src/routes/Dashboard/Analysis.js index d04c4570503095c4fe160494b609e496a0560bc3..da0fd7e76ee9e41817116ce66cb432118202801b 100644 --- a/src/routes/Dashboard/Analysis.js +++ b/src/routes/Dashboard/Analysis.js @@ -15,7 +15,6 @@ import { } from 'antd'; import { ChartCard, - yuan, MiniArea, MiniBar, MiniProgress, @@ -28,7 +27,7 @@ import Trend from 'components/Trend'; import NumberInfo from 'components/NumberInfo'; import numeral from 'numeral'; import GridContent from '../../layouts/GridContent'; - +import Yuan from '../../utils/Yuan'; import { getTimeDistance } from '../../utils/utils'; import styles from './Analysis.less'; @@ -44,12 +43,6 @@ for (let i = 0; i < 7; i += 1) { }); } -const Yuan = ({ children }) => ( - /* eslint-disable-line react/no-danger */ -); - @connect(({ chart, loading }) => ({ chart, loading: loading.effects['chart/fetch'], diff --git a/src/routes/Forms/TableForm.js b/src/routes/Forms/TableForm.js index 4775a9034cbd8164cf325fe5e41dce39c3d03dbe..38d3441c5883837e59ac35f8a146399084e214ed 100644 --- a/src/routes/Forms/TableForm.js +++ b/src/routes/Forms/TableForm.js @@ -3,14 +3,6 @@ import { Table, Button, Input, message, Popconfirm, Divider } from 'antd'; import styles from './style.less'; export default class TableForm extends PureComponent { - static getDerivedStateFromProps(nextProps) { - if ('value' in nextProps) { - return { - data: nextProps.value, - }; - } - return null; - } constructor(props) { super(props); @@ -21,6 +13,14 @@ export default class TableForm extends PureComponent { }; } + static getDerivedStateFromProps(nextProps) { + if ('value' in nextProps) { + return { + data: nextProps.value, + }; + } + return null; + } getRowByKey(key, newData) { return (newData || this.state.data).filter(item => item.key === key)[0]; } diff --git a/src/utils/Yuan.js b/src/utils/Yuan.js new file mode 100644 index 0000000000000000000000000000000000000000..ed05f6c38b551ff6dedfcaaf7fb17fa703dca067 --- /dev/null +++ b/src/utils/Yuan.js @@ -0,0 +1,27 @@ +import React from 'react'; +import { yuan } from 'components/Charts'; +/** + * 减少使用 dangerouslySetInnerHTML + */ +export default class Yuan extends React.PureComponent { + componentDidMount() { + this.rendertoHtml(); + } + componentDidUpdate() { + this.rendertoHtml(); + } + rendertoHtml = () => { + if (this.main) { + this.main.innerHTML = yuan(this.props.children); + } + }; + render() { + return ( + { + this.main = ref; + }} + /> + ); + } +}