Commit 3086f720 authored by jim's avatar jim

fix eslint error

parent e6e305d5
......@@ -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();
}
......
......@@ -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']
......
......@@ -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,
......
......@@ -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)) {
......
......@@ -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 }) => (
<span
dangerouslySetInnerHTML={{ __html: yuan(children) }}
/> /* eslint-disable-line react/no-danger */
);
@connect(({ chart, loading }) => ({
chart,
loading: loading.effects['chart/fetch'],
......
......@@ -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];
}
......
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