From 3086f7200f6f7a2aba8f9d330fb367da7e04aac8 Mon Sep 17 00:00:00 2001 From: jim Date: Tue, 5 Jun 2018 10:34:50 +0800 Subject: [PATCH] fix eslint error --- src/components/CountDown/index.js | 20 +++++++++---------- src/components/SiderMenu/SiderMenu.js | 20 +++++++++---------- src/components/StandardTable/index.js | 28 +++++++++++++++------------ src/components/TagSelect/index.js | 11 +++++------ src/routes/Dashboard/Analysis.js | 9 +-------- src/routes/Forms/TableForm.js | 16 +++++++-------- src/utils/Yuan.js | 27 ++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 54 deletions(-) create mode 100644 src/utils/Yuan.js diff --git a/src/components/CountDown/index.js b/src/components/CountDown/index.js index ce769121..4485b6e8 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 6d64a4a3..1f4c0339 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 ad3eb1ca..2f82ee35 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 83acfa1f..9f3c5734 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 d04c4570..da0fd7e7 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 4775a903..38d3441c 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 00000000..ed05f6c3 --- /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; + }} + /> + ); + } +} -- GitLab