Commit 3086f720 authored by jim's avatar jim

fix eslint error

parent e6e305d5
...@@ -23,16 +23,6 @@ const initTime = props => { ...@@ -23,16 +23,6 @@ const initTime = props => {
}; };
class CountDown extends Component { class CountDown extends Component {
static getDerivedStateFromProps(nextProps, preState) {
const { lastTime } = initTime(nextProps);
if (preState.lastTime !== lastTime) {
return {
lastTime,
};
}
return null;
}
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -43,6 +33,16 @@ class CountDown extends Component { ...@@ -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() { componentDidMount() {
this.tick(); this.tick();
} }
......
...@@ -65,16 +65,6 @@ export const getMenuMatchKeys = (flatMenuKeys, paths) => ...@@ -65,16 +65,6 @@ export const getMenuMatchKeys = (flatMenuKeys, paths) =>
); );
export default class SiderMenu extends PureComponent { 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) { constructor(props) {
super(props); super(props);
this.menus = props.menuData; this.menus = props.menuData;
...@@ -85,6 +75,16 @@ export default class SiderMenu extends PureComponent { ...@@ -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 * Convert pathname to openKeys
* /list/search/articles = > ['list','/list/search'] * /list/search/articles = > ['list','/list/search']
......
...@@ -13,6 +13,16 @@ function initTotalList(columns) { ...@@ -13,6 +13,16 @@ function initTotalList(columns) {
} }
class StandardTable extends PureComponent { class StandardTable extends PureComponent {
constructor(props) {
super(props);
const { columns } = props;
const needTotalList = initTotalList(columns);
this.state = {
selectedRowKeys: [],
needTotalList,
};
}
static getDerivedStateFromProps(nextProps) { static getDerivedStateFromProps(nextProps) {
// clean state // clean state
if (nextProps.selectedRows.length === 0) { if (nextProps.selectedRows.length === 0) {
...@@ -24,17 +34,6 @@ class StandardTable extends PureComponent { ...@@ -24,17 +34,6 @@ class StandardTable extends PureComponent {
} }
return null; return null;
} }
constructor(props) {
super(props);
const { columns } = props;
const needTotalList = initTotalList(columns);
this.state = {
selectedRowKeys: [],
needTotalList,
};
}
handleRowSelectChange = (selectedRowKeys, selectedRows) => { handleRowSelectChange = (selectedRowKeys, selectedRows) => {
let needTotalList = [...this.state.needTotalList]; let needTotalList = [...this.state.needTotalList];
needTotalList = needTotalList.map(item => { needTotalList = needTotalList.map(item => {
...@@ -63,7 +62,12 @@ class StandardTable extends PureComponent { ...@@ -63,7 +62,12 @@ class StandardTable extends PureComponent {
render() { render() {
const { selectedRowKeys, needTotalList } = this.state; 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 = { const paginationProps = {
showSizeChanger: true, showSizeChanger: true,
......
...@@ -15,18 +15,17 @@ const TagSelectOption = ({ children, checked, onChange, value }) => ( ...@@ -15,18 +15,17 @@ const TagSelectOption = ({ children, checked, onChange, value }) => (
TagSelectOption.isTagSelectOption = true; TagSelectOption.isTagSelectOption = true;
class TagSelect extends Component { class TagSelect extends Component {
state = {
expand: false,
value: this.props.value || this.props.defaultValue || [],
};
static getDerivedStateFromProps(nextProps) { static getDerivedStateFromProps(nextProps) {
if ('value' in nextProps && nextProps.value) { if ('value' in nextProps && nextProps.value) {
return { value: nextProps.value }; return { value: nextProps.value };
} }
return null; return null;
} }
state = {
expand: false,
value: this.props.value || this.props.defaultValue || [],
};
onChange = value => { onChange = value => {
const { onChange } = this.props; const { onChange } = this.props;
if (!('value' in this.props)) { if (!('value' in this.props)) {
......
...@@ -15,7 +15,6 @@ import { ...@@ -15,7 +15,6 @@ import {
} from 'antd'; } from 'antd';
import { import {
ChartCard, ChartCard,
yuan,
MiniArea, MiniArea,
MiniBar, MiniBar,
MiniProgress, MiniProgress,
...@@ -28,7 +27,7 @@ import Trend from 'components/Trend'; ...@@ -28,7 +27,7 @@ import Trend from 'components/Trend';
import NumberInfo from 'components/NumberInfo'; import NumberInfo from 'components/NumberInfo';
import numeral from 'numeral'; import numeral from 'numeral';
import GridContent from '../../layouts/GridContent'; import GridContent from '../../layouts/GridContent';
import Yuan from '../../utils/Yuan';
import { getTimeDistance } from '../../utils/utils'; import { getTimeDistance } from '../../utils/utils';
import styles from './Analysis.less'; import styles from './Analysis.less';
...@@ -44,12 +43,6 @@ for (let i = 0; i < 7; i += 1) { ...@@ -44,12 +43,6 @@ for (let i = 0; i < 7; i += 1) {
}); });
} }
const Yuan = ({ children }) => (
<span
dangerouslySetInnerHTML={{ __html: yuan(children) }}
/> /* eslint-disable-line react/no-danger */
);
@connect(({ chart, loading }) => ({ @connect(({ chart, loading }) => ({
chart, chart,
loading: loading.effects['chart/fetch'], loading: loading.effects['chart/fetch'],
......
...@@ -3,14 +3,6 @@ import { Table, Button, Input, message, Popconfirm, Divider } from 'antd'; ...@@ -3,14 +3,6 @@ import { Table, Button, Input, message, Popconfirm, Divider } from 'antd';
import styles from './style.less'; import styles from './style.less';
export default class TableForm extends PureComponent { export default class TableForm extends PureComponent {
static getDerivedStateFromProps(nextProps) {
if ('value' in nextProps) {
return {
data: nextProps.value,
};
}
return null;
}
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -21,6 +13,14 @@ export default class TableForm extends PureComponent { ...@@ -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) { getRowByKey(key, newData) {
return (newData || this.state.data).filter(item => item.key === key)[0]; return (newData || this.state.data).filter(item => item.key === key)[0];
} }
......
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 (
<span
ref={ref => {
this.main = ref;
}}
/>
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment