Browse Source

fix some other eslint error , close #1722

pull/1738/head
yoyo837 8 years ago
committed by 陈帅
parent
commit
d1b424df1c
  1. 16
      src/components/Charts/Bar/index.js
  2. 63
      src/components/Charts/Pie/index.js
  3. 3
      src/components/Charts/Radar/index.js
  4. 3
      src/components/Charts/TagCloud/index.js
  5. 11
      src/components/CountDown/index.js
  6. 17
      src/components/EditableItem/index.js
  7. 3
      src/components/Ellipsis/index.js
  8. 46
      src/components/HeaderSearch/index.js
  9. 14
      src/components/Login/LoginItem.js
  10. 5
      src/components/Login/LoginTab.js
  11. 29
      src/components/Login/index.js
  12. 11
      src/components/NoticeIcon/index.js
  13. 26
      src/components/PageHeader/index.js
  14. 15
      src/components/SiderMenu/SiderMenu.js
  15. 12
      src/components/SiderMenu/index.js
  16. 11
      src/components/StandardTable/index.js
  17. 17
      src/components/TagSelect/index.js
  18. 22
      src/layouts/BasicLayout.js
  19. 13
      src/routes/Dashboard/Analysis.js
  20. 3
      src/routes/Dashboard/Monitor.js
  21. 6
      src/routes/Exception/triggerException.js
  22. 6
      src/routes/Forms/AdvancedForm.js
  23. 9
      src/routes/Forms/BasicForm.js
  24. 50
      src/routes/Forms/TableForm.js
  25. 3
      src/routes/List/Applications.js
  26. 3
      src/routes/List/Articles.js
  27. 3
      src/routes/List/BasicList.js
  28. 3
      src/routes/List/CardList.js
  29. 3
      src/routes/List/Projects.js
  30. 15
      src/routes/List/TableList.js
  31. 4
      src/routes/Profile/AdvancedProfile.js
  32. 7
      src/routes/User/Login.js
  33. 27
      src/routes/User/Register.js

16
src/components/Charts/Bar/index.js

@ -19,6 +19,14 @@ class Bar extends Component {
window.removeEventListener('resize', this.resize); window.removeEventListener('resize', this.resize);
} }
handleRoot = n => {
this.root = n;
};
handleRef = n => {
this.node = n;
};
@Bind() @Bind()
@Debounce(400) @Debounce(400)
resize() { resize() {
@ -46,14 +54,6 @@ class Bar extends Component {
} }
} }
handleRoot = n => {
this.root = n;
};
handleRef = n => {
this.node = n;
};
render() { render() {
const { const {
height, height,

63
src/components/Charts/Pie/index.js

@ -25,12 +25,14 @@ export default class Pie extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.data !== nextProps.data) { const { data } = this.props;
if (data !== nextProps.data) {
// because of charts data create when rendered // because of charts data create when rendered
// so there is a trick for get rendered time // so there is a trick for get rendered time
const { legendData } = this.state;
this.setState( this.setState(
{ {
legendData: [...this.state.legendData], legendData: [...legendData],
}, },
() => { () => {
this.getLegendData(); this.getLegendData();
@ -67,28 +69,6 @@ export default class Pie extends Component {
}); });
}; };
// for window resize auto responsive legend
@Bind()
@Debounce(300)
resize() {
const { hasLegend } = this.props;
if (!hasLegend || !this.root) {
window.removeEventListener('resize', this.resize);
return;
}
if (this.root.parentNode.clientWidth <= 380) {
if (!this.state.legendBlock) {
this.setState({
legendBlock: true,
});
}
} else if (this.state.legendBlock) {
this.setState({
legendBlock: false,
});
}
}
handleRoot = n => { handleRoot = n => {
this.root = n; this.root = n;
}; };
@ -111,6 +91,29 @@ export default class Pie extends Component {
}); });
}; };
// for window resize auto responsive legend
@Bind()
@Debounce(300)
resize() {
const { hasLegend } = this.props;
if (!hasLegend || !this.root) {
window.removeEventListener('resize', this.resize);
return;
}
const { legendBlock } = this.state;
if (this.root.parentNode.clientWidth <= 380) {
if (!legendBlock) {
this.setState({
legendBlock: true,
});
}
} else if (legendBlock) {
this.setState({
legendBlock: false,
});
}
}
render() { render() {
const { const {
valueFormat, valueFormat,
@ -135,10 +138,16 @@ export default class Pie extends Component {
[styles.legendBlock]: legendBlock, [styles.legendBlock]: legendBlock,
}); });
const { data: d, selected: s, tooltip: t } = this.props;
let data = d || [];
let selected = s || true;
let tooltip = t || true;
const defaultColors = colors; const defaultColors = colors;
let data = this.props.data || []; // let data = this.props.data || [];
let selected = this.props.selected || true; // let selected = this.props.selected || true;
let tooltip = this.props.tooltip || true; // let tooltip = this.props.tooltip || true;
let formatColor; let formatColor;
const scale = { const scale = {

3
src/components/Charts/Radar/index.js

@ -16,7 +16,8 @@ export default class Radar extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.data !== nextProps.data) { const { data } = this.props;
if (data !== nextProps.data) {
this.getLengendData(); this.getLengendData();
} }
} }

3
src/components/Charts/TagCloud/index.js

@ -25,7 +25,8 @@ class TagCloud extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (JSON.stringify(nextProps.data) !== JSON.stringify(this.props.data)) { const { data } = this.props;
if (JSON.stringify(nextProps.data) !== JSON.stringify(data)) {
this.renderChart(nextProps); this.renderChart(nextProps);
} }
} }

11
src/components/CountDown/index.js

@ -5,6 +5,10 @@ function fixedZero(val) {
} }
class CountDown extends Component { class CountDown extends Component {
timer = 0;
interval = 1000;
constructor(props) { constructor(props) {
super(props); super(props);
@ -20,7 +24,8 @@ class CountDown extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.target !== nextProps.target) { const { target } = this.props;
if (target !== nextProps.target) {
clearTimeout(this.timer); clearTimeout(this.timer);
const { lastTime } = this.initTime(nextProps); const { lastTime } = this.initTime(nextProps);
this.setState( this.setState(
@ -38,10 +43,6 @@ class CountDown extends Component {
clearTimeout(this.timer); clearTimeout(this.timer);
} }
timer = 0;
interval = 1000;
initTime = props => { initTime = props => {
let lastTime = 0; let lastTime = 0;
let targetTime = 0; let targetTime = 0;

17
src/components/EditableItem/index.js

@ -3,10 +3,13 @@ import { Input, Icon } from 'antd';
import styles from './index.less'; import styles from './index.less';
export default class EditableItem extends PureComponent { export default class EditableItem extends PureComponent {
state = { constructor(props) {
value: this.props.value, super(props);
editable: false, this.state = {
}; value: props.value,
editable: false,
};
}
handleChange = e => { handleChange = e => {
const { value } = e.target; const { value } = e.target;
@ -15,8 +18,10 @@ export default class EditableItem extends PureComponent {
check = () => { check = () => {
this.setState({ editable: false }); this.setState({ editable: false });
if (this.props.onChange) { const { onChange } = this.props;
this.props.onChange(this.state.value); const { value } = this.state;
if (onChange) {
onChange(value);
} }
}; };

3
src/components/Ellipsis/index.js

@ -84,7 +84,8 @@ export default class Ellipsis extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.lines !== nextProps.lines) { const { lines } = this.props;
if (lines !== nextProps.lines) {
this.computeLine(); this.computeLine();
} }
} }

46
src/components/HeaderSearch/index.js

@ -27,10 +27,13 @@ export default class HeaderSearch extends PureComponent {
defaultOpen: false, defaultOpen: false,
}; };
state = { constructor(props) {
searchMode: this.props.defaultOpen, super(props);
value: '', this.state = {
}; searchMode: props.defaultOpen,
value: '',
};
}
onKeyDown = e => { onKeyDown = e => {
if (e.key === 'Enter') { if (e.key === 'Enter') {
@ -40,24 +43,16 @@ export default class HeaderSearch extends PureComponent {
onChange = value => { onChange = value => {
this.setState({ value }); this.setState({ value });
if (this.props.onChange) { const { onChange } = this.props;
this.props.onChange(); if (onChange) {
onChange();
} }
}; };
// NOTE: 不能小于500,如果长按某键,第一次触发auto repeat的间隔是500ms,小于500会导致触发2次
@Bind()
@Debounce(500, {
leading: true,
trailing: false,
})
debouncePressEnter() {
this.props.onPressEnter(this.state.value);
}
enterSearchMode = () => { enterSearchMode = () => {
this.setState({ searchMode: true }, () => { this.setState({ searchMode: true }, () => {
if (this.state.searchMode) { const { searchMode } = this.state;
if (searchMode) {
this.input.focus(); this.input.focus();
} }
}); });
@ -70,11 +65,24 @@ export default class HeaderSearch extends PureComponent {
}); });
}; };
debouncePressEnter() {
const { onPressEnter } = this.props;
const { value } = this.state;
onPressEnter(value);
}
// NOTE: 不能小于500,如果长按某键,第一次触发auto repeat的间隔是500ms,小于500会导致触发2次
@Bind()
@Debounce(500, {
leading: true,
trailing: false,
})
render() { render() {
const { className, placeholder, ...restProps } = this.props; const { className, placeholder, ...restProps } = this.props;
const { searchMode, value } = this.state;
delete restProps.defaultOpen; // for rc-select not affected delete restProps.defaultOpen; // for rc-select not affected
const inputClass = classNames(styles.input, { const inputClass = classNames(styles.input, {
[styles.show]: this.state.searchMode, [styles.show]: searchMode,
}); });
return ( return (
<span className={classNames(className, styles.headerSearch)} onClick={this.enterSearchMode}> <span className={classNames(className, styles.headerSearch)} onClick={this.enterSearchMode}>
@ -83,7 +91,7 @@ export default class HeaderSearch extends PureComponent {
key="AutoComplete" key="AutoComplete"
{...restProps} {...restProps}
className={inputClass} className={inputClass}
value={this.state.value} value={value}
onChange={this.onChange} onChange={this.onChange}
> >
<Input <Input

14
src/components/Login/LoginItem.js

@ -23,8 +23,10 @@ function generator({ defaultProps, defaultRules, type }) {
} }
componentDidMount() { componentDidMount() {
if (this.context.updateActive) { const { updateActive } = this.context;
this.context.updateActive(this.props.name); const { name } = this.props;
if (updateActive) {
updateActive(name);
} }
} }
@ -35,8 +37,9 @@ function generator({ defaultProps, defaultRules, type }) {
onGetCaptcha = () => { onGetCaptcha = () => {
let count = 59; let count = 59;
this.setState({ count }); this.setState({ count });
if (this.props.onGetCaptcha) { const { onGetCaptcha } = this.props;
this.props.onGetCaptcha(); if (onGetCaptcha) {
onGetCaptcha();
} }
this.interval = setInterval(() => { this.interval = setInterval(() => {
count -= 1; count -= 1;
@ -48,7 +51,8 @@ function generator({ defaultProps, defaultRules, type }) {
}; };
render() { render() {
const { getFieldDecorator } = this.context.form; const { form } = this.context;
const { getFieldDecorator } = form;
const options = {}; const options = {};
let otherProps = {}; let otherProps = {};
const { onChange, defaultValue, rules, name, ...restProps } = this.props; const { onChange, defaultValue, rules, name, ...restProps } = this.props;

5
src/components/Login/LoginTab.js

@ -25,8 +25,9 @@ export default class LoginTab extends Component {
} }
componentWillMount() { componentWillMount() {
if (this.context.tabUtil) { const { tabUtil } = this.context;
this.context.tabUtil.addTab(this.uniqueId); if (tabUtil) {
tabUtil.addTab(this.uniqueId);
} }
} }

29
src/components/Login/index.js

@ -28,27 +28,32 @@ class Login extends Component {
onSubmit: () => {}, onSubmit: () => {},
}; };
state = { constructor(props) {
type: this.props.defaultActiveKey, super(props);
tabs: [], this.state = {
active: {}, type: props.defaultActiveKey,
}; tabs: [],
active: {},
};
}
getChildContext() { getChildContext() {
const { tabs } = this.state;
const { form } = this.props;
return { return {
tabUtil: { tabUtil: {
addTab: id => { addTab: id => {
this.setState({ this.setState({
tabs: [...this.state.tabs, id], tabs: [...tabs, id],
}); });
}, },
removeTab: id => { removeTab: id => {
this.setState({ this.setState({
tabs: this.state.tabs.filter(currentId => currentId !== id), tabs: tabs.filter(currentId => currentId !== id),
}); });
}, },
}, },
form: this.props.form, form,
updateActive: activeItem => { updateActive: activeItem => {
const { type, active } = this.state; const { type, active } = this.state;
if (active[type]) { if (active[type]) {
@ -64,18 +69,20 @@ class Login extends Component {
} }
onSwitch = type => { onSwitch = type => {
const { onTabChange } = this.props;
this.setState({ this.setState({
type, type,
}); });
this.props.onTabChange(type); onTabChange(type);
}; };
handleSubmit = e => { handleSubmit = e => {
e.preventDefault(); e.preventDefault();
const { active, type } = this.state; const { active, type } = this.state;
const { form, onSubmit } = this.props;
const activeFileds = active[type]; const activeFileds = active[type];
this.props.form.validateFields(activeFileds, { force: true }, (err, values) => { form.validateFields(activeFileds, { force: true }, (err, values) => {
this.props.onSubmit(err, values); onSubmit(err, values);
}); });
}; };

11
src/components/NoticeIcon/index.js

@ -37,11 +37,12 @@ export default class NoticeIcon extends PureComponent {
onTabChange = tabType => { onTabChange = tabType => {
this.setState({ tabType }); this.setState({ tabType });
this.props.onTabChange(tabType); const { onTabChange } = this.state;
onTabChange(tabType);
}; };
getNotificationBox() { getNotificationBox() {
const { children, loading, locale } = this.props; const { children, loading, locale, onClear } = this.props;
if (!children) { if (!children) {
return null; return null;
} }
@ -56,7 +57,7 @@ export default class NoticeIcon extends PureComponent {
{...child.props} {...child.props}
data={child.props.list} data={child.props.list}
onClick={item => this.onItemClick(item, child.props)} onClick={item => this.onItemClick(item, child.props)}
onClear={() => this.props.onClear(child.props.title)} onClear={() => onClear(child.props.title)}
title={child.props.title} title={child.props.title}
locale={locale} locale={locale}
/> />
@ -73,7 +74,7 @@ export default class NoticeIcon extends PureComponent {
} }
render() { render() {
const { className, count, popupAlign, onPopupVisibleChange } = this.props; const { className, count, popupAlign, onPopupVisibleChange, popupVisible } = this.props;
const noticeButtonClass = classNames(className, styles.noticeButton); const noticeButtonClass = classNames(className, styles.noticeButton);
const notificationBox = this.getNotificationBox(); const notificationBox = this.getNotificationBox();
const trigger = ( const trigger = (
@ -88,7 +89,7 @@ export default class NoticeIcon extends PureComponent {
} }
const popoverProps = {}; const popoverProps = {};
if ('popupVisible' in this.props) { if ('popupVisible' in this.props) {
popoverProps.visible = this.props.popupVisible; popoverProps.visible = popupVisible;
} }
return ( return (
<Popover <Popover

26
src/components/PageHeader/index.js

@ -36,23 +36,32 @@ export default class PageHeader extends PureComponent {
} }
componentDidUpdate(preProps) { componentDidUpdate(preProps) {
if (preProps.tabActiveKey !== this.props.tabActiveKey) { const { tabActiveKey } = this.props;
if (preProps.tabActiveKey !== tabActiveKey) {
this.getBreadcrumbDom(); this.getBreadcrumbDom();
} }
} }
onChange = key => { onChange = key => {
if (this.props.onTabChange) { const { onTabChange } = this.props;
this.props.onTabChange(key); if (onTabChange) {
onTabChange(key);
} }
}; };
getBreadcrumbProps = () => { getBreadcrumbProps = () => {
const { routes, params, location, breadcrumbNameMap } = this.props;
const {
routes: croutes,
params: cparams,
location: clocation,
breadcrumbNameMap: cbreadcrumbNameMap,
} = this.context;
return { return {
routes: this.props.routes || this.context.routes, routes: routes || croutes,
params: this.props.params || this.context.params, params: params || cparams,
routerLocation: this.props.location || this.context.location, routerLocation: location || clocation,
breadcrumbNameMap: this.props.breadcrumbNameMap || this.context.breadcrumbNameMap, breadcrumbNameMap: breadcrumbNameMap || cbreadcrumbNameMap,
}; };
}; };
@ -185,6 +194,7 @@ export default class PageHeader extends PureComponent {
tabDefaultActiveKey, tabDefaultActiveKey,
tabBarExtraContent, tabBarExtraContent,
} = this.props; } = this.props;
const { breadcrumb } = this.state;
const clsString = classNames(styles.pageHeader, className); const clsString = classNames(styles.pageHeader, className);
const activeKeyProps = {}; const activeKeyProps = {};
@ -197,7 +207,7 @@ export default class PageHeader extends PureComponent {
return ( return (
<div className={clsString}> <div className={clsString}>
{this.state.breadcrumb} {breadcrumb}
<div className={styles.detail}> <div className={styles.detail}>
{logo && <div className={styles.logo}>{logo}</div>} {logo && <div className={styles.logo}>{logo}</div>}
<div className={styles.main}> <div className={styles.main}>

15
src/components/SiderMenu/SiderMenu.js

@ -59,7 +59,8 @@ export default class SiderMenu extends PureComponent {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (nextProps.location.pathname !== this.props.location.pathname) { const { location } = this.props;
if (nextProps.location.pathname !== location.pathname) {
this.setState({ this.setState({
openKeys: this.getDefaultCollapsedSubMenus(nextProps), openKeys: this.getDefaultCollapsedSubMenus(nextProps),
}); });
@ -97,15 +98,16 @@ export default class SiderMenu extends PureComponent {
</a> </a>
); );
} }
const { location, isMobile, onCollapse } = this.props;
return ( return (
<Link <Link
to={itemPath} to={itemPath}
target={target} target={target}
replace={itemPath === this.props.location.pathname} replace={itemPath === location.pathname}
onClick={ onClick={
this.props.isMobile isMobile
? () => { ? () => {
this.props.onCollapse(true); onCollapse(true);
} }
: undefined : undefined
} }
@ -186,8 +188,9 @@ export default class SiderMenu extends PureComponent {
// permission to check // permission to check
checkPermissionItem = (authority, ItemDom) => { checkPermissionItem = (authority, ItemDom) => {
if (this.props.Authorized && this.props.Authorized.check) { const { Authorized } = this.props;
const { check } = this.props.Authorized; if (Authorized && Authorized.check) {
const { check } = Authorized;
return check(authority, ItemDom); return check(authority, ItemDom);
} }
return ItemDom; return ItemDom;

12
src/components/SiderMenu/index.js

@ -3,24 +3,26 @@ import React from 'react';
import DrawerMenu from 'rc-drawer'; import DrawerMenu from 'rc-drawer';
import SiderMenu from './SiderMenu'; import SiderMenu from './SiderMenu';
const SiderMenuWrapper = props => const SiderMenuWrapper = props => {
props.isMobile ? ( const { isMobile, collapsed } = props;
return isMobile ? (
<DrawerMenu <DrawerMenu
getContainer={null} getContainer={null}
level={null} level={null}
handleChild={<i className="drawer-handle-icon" />} handleChild={<i className="drawer-handle-icon" />}
onHandleClick={() => { onHandleClick={() => {
props.onCollapse(!props.collapsed); props.onCollapse(!collapsed);
}} }}
open={!props.collapsed} open={!collapsed}
onMaskClick={() => { onMaskClick={() => {
props.onCollapse(true); props.onCollapse(true);
}} }}
> >
<SiderMenu {...props} collapsed={props.isMobile ? false : props.collapsed} /> <SiderMenu {...props} collapsed={isMobile ? false : collapsed} />
</DrawerMenu> </DrawerMenu>
) : ( ) : (
<SiderMenu {...props} /> <SiderMenu {...props} />
); );
};
export default SiderMenuWrapper; export default SiderMenuWrapper;

11
src/components/StandardTable/index.js

@ -36,7 +36,9 @@ class StandardTable extends PureComponent {
} }
handleRowSelectChange = (selectedRowKeys, selectedRows) => { handleRowSelectChange = (selectedRowKeys, selectedRows) => {
let needTotalList = [...this.state.needTotalList]; const { needTotalList: list } = this.state;
const { onSelectRow } = this.props;
let needTotalList = [...list];
needTotalList = needTotalList.map(item => { needTotalList = needTotalList.map(item => {
return { return {
...item, ...item,
@ -46,15 +48,16 @@ class StandardTable extends PureComponent {
}; };
}); });
if (this.props.onSelectRow) { if (onSelectRow) {
this.props.onSelectRow(selectedRows); onSelectRow(selectedRows);
} }
this.setState({ selectedRowKeys, needTotalList }); this.setState({ selectedRowKeys, needTotalList });
}; };
handleTableChange = (pagination, filters, sorter) => { handleTableChange = (pagination, filters, sorter) => {
this.props.onChange(pagination, filters, sorter); const { onChange } = this.props;
onChange(pagination, filters, sorter);
}; };
cleanSelectedKeys = () => { cleanSelectedKeys = () => {

17
src/components/TagSelect/index.js

@ -15,10 +15,13 @@ const TagSelectOption = ({ children, checked, onChange, value }) => (
TagSelectOption.isTagSelectOption = true; TagSelectOption.isTagSelectOption = true;
class TagSelect extends Component { class TagSelect extends Component {
state = { constructor(props) {
expand: false, super(props);
value: this.props.value || this.props.defaultValue || [], this.state = {
}; expand: false,
value: props.value || props.defaultValue || [],
};
}
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if ('value' in nextProps && nextProps.value) { if ('value' in nextProps && nextProps.value) {
@ -54,7 +57,8 @@ class TagSelect extends Component {
} }
handleTagChange = (value, checked) => { handleTagChange = (value, checked) => {
const checkedTags = [...this.state.value]; const { value: v } = this.state;
const checkedTags = [...v];
const index = checkedTags.indexOf(value); const index = checkedTags.indexOf(value);
if (checked && index === -1) { if (checked && index === -1) {
@ -66,8 +70,9 @@ class TagSelect extends Component {
}; };
handleExpand = () => { handleExpand = () => {
const { expand } = this.state;
this.setState({ this.setState({
expand: !this.state.expand, expand: !expand,
}); });
}; };

22
src/layouts/BasicLayout.js

@ -108,7 +108,8 @@ class BasicLayout extends React.PureComponent {
isMobile: mobile, isMobile: mobile,
}); });
}); });
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'user/fetchCurrent', type: 'user/fetchCurrent',
}); });
} }
@ -156,7 +157,8 @@ class BasicLayout extends React.PureComponent {
}; };
handleMenuCollapse = collapsed => { handleMenuCollapse = collapsed => {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'global/changeLayoutCollapsed', type: 'global/changeLayoutCollapsed',
payload: collapsed, payload: collapsed,
}); });
@ -164,27 +166,30 @@ class BasicLayout extends React.PureComponent {
handleNoticeClear = type => { handleNoticeClear = type => {
message.success(`清空了${type}`); message.success(`清空了${type}`);
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'global/clearNotices', type: 'global/clearNotices',
payload: type, payload: type,
}); });
}; };
handleMenuClick = ({ key }) => { handleMenuClick = ({ key }) => {
const { dispatch } = this.props;
if (key === 'triggerError') { if (key === 'triggerError') {
this.props.dispatch(routerRedux.push('/exception/trigger')); dispatch(routerRedux.push('/exception/trigger'));
return; return;
} }
if (key === 'logout') { if (key === 'logout') {
this.props.dispatch({ dispatch({
type: 'login/logout', type: 'login/logout',
}); });
} }
}; };
handleNoticeVisibleChange = visible => { handleNoticeVisibleChange = visible => {
const { dispatch } = this.props;
if (visible) { if (visible) {
this.props.dispatch({ dispatch({
type: 'global/fetchNotices', type: 'global/fetchNotices',
}); });
} }
@ -200,6 +205,7 @@ class BasicLayout extends React.PureComponent {
match, match,
location, location,
} = this.props; } = this.props;
const { isMobile: mb } = this.state;
const bashRedirect = this.getBaseRedirect(); const bashRedirect = this.getBaseRedirect();
const layout = ( const layout = (
<Layout> <Layout>
@ -212,7 +218,7 @@ class BasicLayout extends React.PureComponent {
menuData={getMenuData()} menuData={getMenuData()}
collapsed={collapsed} collapsed={collapsed}
location={location} location={location}
isMobile={this.state.isMobile} isMobile={mb}
onCollapse={this.handleMenuCollapse} onCollapse={this.handleMenuCollapse}
/> />
<Layout> <Layout>
@ -223,7 +229,7 @@ class BasicLayout extends React.PureComponent {
fetchingNotices={fetchingNotices} fetchingNotices={fetchingNotices}
notices={notices} notices={notices}
collapsed={collapsed} collapsed={collapsed}
isMobile={this.state.isMobile} isMobile={mb}
onNoticeClear={this.handleNoticeClear} onNoticeClear={this.handleNoticeClear}
onCollapse={this.handleMenuCollapse} onCollapse={this.handleMenuCollapse}
onMenuClick={this.handleMenuClick} onMenuClick={this.handleMenuClick}

13
src/routes/Dashboard/Analysis.js

@ -44,8 +44,8 @@ for (let i = 0; i < 7; i += 1) {
const Yuan = ({ children }) => ( const Yuan = ({ children }) => (
<span <span
dangerouslySetInnerHTML={{ __html: yuan(children) }} dangerouslySetInnerHTML={{ __html: yuan(children) }} /* eslint-disable-line react/no-danger */
/> /* eslint-disable-line react/no-danger */ />
); );
@connect(({ chart, loading }) => ({ @connect(({ chart, loading }) => ({
@ -60,7 +60,8 @@ export default class Analysis extends Component {
}; };
componentDidMount() { componentDidMount() {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'chart/fetch', type: 'chart/fetch',
}); });
} }
@ -89,7 +90,8 @@ export default class Analysis extends Component {
rangePickerValue, rangePickerValue,
}); });
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'chart/fetchSalesData', type: 'chart/fetchSalesData',
}); });
}; };
@ -99,7 +101,8 @@ export default class Analysis extends Component {
rangePickerValue: getTimeDistance(type), rangePickerValue: getTimeDistance(type),
}); });
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'chart/fetchSalesData', type: 'chart/fetchSalesData',
}); });
}; };

3
src/routes/Dashboard/Monitor.js

@ -25,7 +25,8 @@ const havePermissionAsync = new Promise(resolve => {
})) }))
export default class Monitor extends PureComponent { export default class Monitor extends PureComponent {
componentDidMount() { componentDidMount() {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'monitor/fetchTags', type: 'monitor/fetchTags',
}); });
} }

6
src/routes/Exception/triggerException.js

@ -15,7 +15,8 @@ export default class TriggerException extends PureComponent {
this.setState({ this.setState({
isloading: true, isloading: true,
}); });
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'error/query', type: 'error/query',
payload: { payload: {
code, code,
@ -24,9 +25,10 @@ export default class TriggerException extends PureComponent {
}; };
render() { render() {
const { isloading } = this.state;
return ( return (
<Card> <Card>
<Spin spinning={this.state.isloading} wrapperClassName={styles.trigger}> <Spin spinning={isloading} wrapperClassName={styles.trigger}>
<Button type="danger" onClick={() => this.triggerError(401)}> <Button type="danger" onClick={() => this.triggerError(401)}>
触发401 触发401
</Button> </Button>

6
src/routes/Forms/AdvancedForm.js

@ -73,12 +73,14 @@ class AdvancedForm extends PureComponent {
resizeFooterToolbar = () => { resizeFooterToolbar = () => {
const sider = document.querySelectorAll('.ant-layout-sider')[0]; const sider = document.querySelectorAll('.ant-layout-sider')[0];
const width = `calc(100% - ${sider.style.width})`; const width = `calc(100% - ${sider.style.width})`;
if (this.state.width !== width) { const { width: w } = this.state;
if (w !== width) {
this.setState({ width }); this.setState({ width });
} }
}; };
render() { render() {
const { width: w } = this.state;
const { form, dispatch, submitting } = this.props; const { form, dispatch, submitting } = this.props;
const { getFieldDecorator, validateFieldsAndScroll, getFieldsError } = form; const { getFieldDecorator, validateFieldsAndScroll, getFieldsError } = form;
const validate = () => { const validate = () => {
@ -287,7 +289,7 @@ class AdvancedForm extends PureComponent {
initialValue: tableData, initialValue: tableData,
})(<TableForm />)} })(<TableForm />)}
</Card> </Card>
<FooterToolbar style={{ width: this.state.width }}> <FooterToolbar style={{ width: w }}>
{getErrorInfo()} {getErrorInfo()}
<Button type="primary" onClick={validate} loading={submitting}> <Button type="primary" onClick={validate} loading={submitting}>
提交 提交

9
src/routes/Forms/BasicForm.js

@ -27,9 +27,10 @@ const { TextArea } = Input;
export default class BasicForms extends PureComponent { export default class BasicForms extends PureComponent {
handleSubmit = e => { handleSubmit = e => {
e.preventDefault(); e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => { const { form, dispatch } = this.props;
form.validateFieldsAndScroll((err, values) => {
if (!err) { if (!err) {
this.props.dispatch({ dispatch({
type: 'form/submitRegularForm', type: 'form/submitRegularForm',
payload: values, payload: values,
}); });
@ -38,8 +39,8 @@ export default class BasicForms extends PureComponent {
}; };
render() { render() {
const { submitting } = this.props; const { submitting, form } = this.props;
const { getFieldDecorator, getFieldValue } = this.props.form; const { getFieldDecorator, getFieldValue } = form;
const formItemLayout = { const formItemLayout = {
labelCol: { labelCol: {

50
src/routes/Forms/TableForm.js

@ -3,6 +3,10 @@ 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 {
index = 0;
cacheOriginData = {};
constructor(props) { constructor(props) {
super(props); super(props);
@ -21,16 +25,14 @@ export default class TableForm extends PureComponent {
} }
getRowByKey(key, newData) { getRowByKey(key, newData) {
return (newData || this.state.data).filter(item => item.key === key)[0]; const { data } = this.state;
return (newData || data).filter(item => item.key === key)[0];
} }
index = 0;
cacheOriginData = {};
toggleEditable = (e, key) => { toggleEditable = (e, key) => {
e.preventDefault(); e.preventDefault();
const newData = this.state.data.map(item => ({ ...item })); const { data } = this.state;
const newData = data.map(item => ({ ...item }));
const target = this.getRowByKey(key, newData); const target = this.getRowByKey(key, newData);
if (target) { if (target) {
// 进入编辑状态时保存原始数据 // 进入编辑状态时保存原始数据
@ -42,14 +44,9 @@ export default class TableForm extends PureComponent {
} }
}; };
remove(key) {
const newData = this.state.data.filter(item => item.key !== key);
this.setState({ data: newData });
this.props.onChange(newData);
}
newMember = () => { newMember = () => {
const newData = this.state.data.map(item => ({ ...item })); const { data } = this.state;
const newData = data.map(item => ({ ...item }));
newData.push({ newData.push({
key: `NEW_TEMP_ID_${this.index}`, key: `NEW_TEMP_ID_${this.index}`,
workId: '', workId: '',
@ -62,6 +59,14 @@ export default class TableForm extends PureComponent {
this.setState({ data: newData }); this.setState({ data: newData });
}; };
remove(key) {
const { data } = this.state;
const { onChange } = this.props;
const newData = data.filter(item => item.key !== key);
this.setState({ data: newData });
onChange(newData);
}
handleKeyPress(e, key) { handleKeyPress(e, key) {
if (e.key === 'Enter') { if (e.key === 'Enter') {
this.saveRow(e, key); this.saveRow(e, key);
@ -69,7 +74,8 @@ export default class TableForm extends PureComponent {
} }
handleFieldChange(e, fieldName, key) { handleFieldChange(e, fieldName, key) {
const newData = this.state.data.map(item => ({ ...item })); const { data } = this.state;
const newData = data.map(item => ({ ...item }));
const target = this.getRowByKey(key, newData); const target = this.getRowByKey(key, newData);
if (target) { if (target) {
target[fieldName] = e.target.value; target[fieldName] = e.target.value;
@ -96,9 +102,11 @@ export default class TableForm extends PureComponent {
}); });
return; return;
} }
const { data } = this.state;
const { onChange } = this.props;
delete target.isNew; delete target.isNew;
this.toggleEditable(e, key); this.toggleEditable(e, key);
this.props.onChange(this.state.data); onChange(data);
this.setState({ this.setState({
loading: false, loading: false,
}); });
@ -108,7 +116,8 @@ export default class TableForm extends PureComponent {
cancel(e, key) { cancel(e, key) {
this.clickedCancel = true; this.clickedCancel = true;
e.preventDefault(); e.preventDefault();
const newData = this.state.data.map(item => ({ ...item })); const { data } = this.state;
const newData = data.map(item => ({ ...item }));
const target = this.getRowByKey(key, newData); const target = this.getRowByKey(key, newData);
if (this.cacheOriginData[key]) { if (this.cacheOriginData[key]) {
Object.assign(target, this.cacheOriginData[key]); Object.assign(target, this.cacheOriginData[key]);
@ -183,7 +192,8 @@ export default class TableForm extends PureComponent {
title: '操作', title: '操作',
key: 'action', key: 'action',
render: (text, record) => { render: (text, record) => {
if (!!record.editable && this.state.loading) { const { loading } = this.state;
if (!!record.editable && loading) {
return null; return null;
} }
if (record.editable) { if (record.editable) {
@ -219,12 +229,14 @@ export default class TableForm extends PureComponent {
}, },
]; ];
const { loading, data } = this.state;
return ( return (
<Fragment> <Fragment>
<Table <Table
loading={this.state.loading} loading={loading}
columns={columns} columns={columns}
dataSource={this.state.data} dataSource={data}
pagination={false} pagination={false}
rowClassName={record => { rowClassName={record => {
return record.editable ? styles.editable : ''; return record.editable ? styles.editable : '';

3
src/routes/List/Applications.js

@ -36,7 +36,8 @@ const formatWan = val => {
})) }))
export default class FilterCardList extends PureComponent { export default class FilterCardList extends PureComponent {
componentDidMount() { componentDidMount() {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'list/fetch', type: 'list/fetch',
payload: { payload: {
count: 8, count: 8,

3
src/routes/List/Articles.js

@ -30,7 +30,8 @@ export default class SearchList extends Component {
}; };
fetchMore = () => { fetchMore = () => {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'list/appendFetch', type: 'list/appendFetch',
payload: { payload: {
count: pageSize, count: pageSize,

3
src/routes/List/BasicList.js

@ -30,7 +30,8 @@ const { Search } = Input;
})) }))
export default class BasicList extends PureComponent { export default class BasicList extends PureComponent {
componentDidMount() { componentDidMount() {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'list/fetch', type: 'list/fetch',
payload: { payload: {
count: 5, count: 5,

3
src/routes/List/CardList.js

@ -13,7 +13,8 @@ import styles from './CardList.less';
})) }))
export default class CardList extends PureComponent { export default class CardList extends PureComponent {
componentDidMount() { componentDidMount() {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'list/fetch', type: 'list/fetch',
payload: { payload: {
count: 8, count: 8,

3
src/routes/List/Projects.js

@ -21,7 +21,8 @@ const FormItem = Form.Item;
})) }))
export default class CoverCardList extends PureComponent { export default class CoverCardList extends PureComponent {
componentDidMount() { componentDidMount() {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'list/fetch', type: 'list/fetch',
payload: { payload: {
count: 8, count: 8,

15
src/routes/List/TableList.js

@ -117,8 +117,9 @@ export default class TableList extends PureComponent {
}; };
toggleForm = () => { toggleForm = () => {
const { expandForm } = this.state;
this.setState({ this.setState({
expandForm: !this.state.expandForm, expandForm: !expandForm,
}); });
}; };
@ -184,7 +185,8 @@ export default class TableList extends PureComponent {
}; };
handleAdd = fields => { handleAdd = fields => {
this.props.dispatch({ const { dispatch } = this.props;
dispatch({
type: 'rule/add', type: 'rule/add',
payload: { payload: {
description: fields.desc, description: fields.desc,
@ -198,7 +200,8 @@ export default class TableList extends PureComponent {
}; };
renderSimpleForm() { renderSimpleForm() {
const { getFieldDecorator } = this.props.form; const { form } = this.props;
const { getFieldDecorator } = form;
return ( return (
<Form onSubmit={this.handleSearch} layout="inline"> <Form onSubmit={this.handleSearch} layout="inline">
<Row gutter={{ md: 8, lg: 24, xl: 48 }}> <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
@ -236,7 +239,8 @@ export default class TableList extends PureComponent {
} }
renderAdvancedForm() { renderAdvancedForm() {
const { getFieldDecorator } = this.props.form; const { form } = this.props;
const { getFieldDecorator } = form;
return ( return (
<Form onSubmit={this.handleSearch} layout="inline"> <Form onSubmit={this.handleSearch} layout="inline">
<Row gutter={{ md: 8, lg: 24, xl: 48 }}> <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
@ -308,7 +312,8 @@ export default class TableList extends PureComponent {
} }
renderForm() { renderForm() {
return this.state.expandForm ? this.renderAdvancedForm() : this.renderSimpleForm(); const { expandForm } = this.state;
return expandForm ? this.renderAdvancedForm() : this.renderSimpleForm();
} }
render() { render() {

4
src/routes/Profile/AdvancedProfile.js

@ -226,7 +226,7 @@ export default class AdvancedProfile extends Component {
} }
render() { render() {
const { stepDirection } = this.state; const { stepDirection, operationkey } = this.state;
const { profile, loading } = this.props; const { profile, loading } = this.props;
const { advancedOperation1, advancedOperation2, advancedOperation3 } = profile; const { advancedOperation1, advancedOperation2, advancedOperation3 } = profile;
const contentList = { const contentList = {
@ -343,7 +343,7 @@ export default class AdvancedProfile extends Component {
tabList={operationTabList} tabList={operationTabList}
onTabChange={this.onOperationTabChange} onTabChange={this.onOperationTabChange}
> >
{contentList[this.state.operationkey]} {contentList[operationkey]}
</Card> </Card>
</PageHeaderLayout> </PageHeaderLayout>
); );

7
src/routes/User/Login.js

@ -23,8 +23,9 @@ export default class LoginPage extends Component {
handleSubmit = (err, values) => { handleSubmit = (err, values) => {
const { type } = this.state; const { type } = this.state;
const { dispatch } = this.props;
if (!err) { if (!err) {
this.props.dispatch({ dispatch({
type: 'login/login', type: 'login/login',
payload: { payload: {
...values, ...values,
@ -46,7 +47,7 @@ export default class LoginPage extends Component {
render() { render() {
const { login, submitting } = this.props; const { login, submitting } = this.props;
const { type } = this.state; const { type, autoLogin } = this.state;
return ( return (
<div className={styles.main}> <div className={styles.main}>
<Login defaultActiveKey={type} onTabChange={this.onTabChange} onSubmit={this.handleSubmit}> <Login defaultActiveKey={type} onTabChange={this.onTabChange} onSubmit={this.handleSubmit}>
@ -67,7 +68,7 @@ export default class LoginPage extends Component {
<Captcha name="captcha" /> <Captcha name="captcha" />
</Tab> </Tab>
<div> <div>
<Checkbox checked={this.state.autoLogin} onChange={this.changeAutoLogin}> <Checkbox checked={autoLogin} onChange={this.changeAutoLogin}>
自动登录 自动登录
</Checkbox> </Checkbox>
<a style={{ float: 'right' }} href=""> <a style={{ float: 'right' }} href="">

27
src/routes/User/Register.js

@ -35,9 +35,10 @@ export default class Register extends Component {
}; };
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const account = this.props.form.getFieldValue('mail'); const { form, dispatch } = this.props;
const account = form.getFieldValue('mail');
if (nextProps.register.status === 'ok') { if (nextProps.register.status === 'ok') {
this.props.dispatch( dispatch(
routerRedux.push({ routerRedux.push({
pathname: '/user/register-result', pathname: '/user/register-result',
state: { state: {
@ -78,13 +79,15 @@ export default class Register extends Component {
handleSubmit = e => { handleSubmit = e => {
e.preventDefault(); e.preventDefault();
this.props.form.validateFields({ force: true }, (err, values) => { const { form, dispatch } = this.props;
form.validateFields({ force: true }, (err, values) => {
const { prefix } = this.state;
if (!err) { if (!err) {
this.props.dispatch({ dispatch({
type: 'register/submit', type: 'register/submit',
payload: { payload: {
...values, ...values,
prefix: this.state.prefix, prefix,
}, },
}); });
} }
@ -93,7 +96,8 @@ export default class Register extends Component {
handleConfirmBlur = e => { handleConfirmBlur = e => {
const { value } = e.target; const { value } = e.target;
this.setState({ confirmDirty: this.state.confirmDirty || !!value }); const { confirmDirty } = this.state;
this.setState({ confirmDirty: confirmDirty || !!value });
}; };
checkConfirm = (rule, value, callback) => { checkConfirm = (rule, value, callback) => {
@ -116,7 +120,8 @@ export default class Register extends Component {
this.setState({ this.setState({
help: '', help: '',
}); });
if (!this.state.visible) { const { visible, confirmDirty } = this.state;
if (!visible) {
this.setState({ this.setState({
visible: !!value, visible: !!value,
}); });
@ -125,7 +130,7 @@ export default class Register extends Component {
callback('error'); callback('error');
} else { } else {
const { form } = this.props; const { form } = this.props;
if (value && this.state.confirmDirty) { if (value && confirmDirty) {
form.validateFields(['confirm'], { force: true }); form.validateFields(['confirm'], { force: true });
} }
callback(); callback();
@ -159,7 +164,7 @@ export default class Register extends Component {
render() { render() {
const { form, submitting } = this.props; const { form, submitting } = this.props;
const { getFieldDecorator } = form; const { getFieldDecorator } = form;
const { count, prefix } = this.state; const { count, prefix, help, visible } = this.state;
return ( return (
<div className={styles.main}> <div className={styles.main}>
<h3>注册</h3> <h3>注册</h3>
@ -178,7 +183,7 @@ export default class Register extends Component {
], ],
})(<Input size="large" placeholder="邮箱" />)} })(<Input size="large" placeholder="邮箱" />)}
</FormItem> </FormItem>
<FormItem help={this.state.help}> <FormItem help={help}>
<Popover <Popover
content={ content={
<div style={{ padding: '4px 0' }}> <div style={{ padding: '4px 0' }}>
@ -191,7 +196,7 @@ export default class Register extends Component {
} }
overlayStyle={{ width: 240 }} overlayStyle={{ width: 240 }}
placement="right" placement="right"
visible={this.state.visible} visible={visible}
> >
{getFieldDecorator('password', { {getFieldDecorator('password', {
rules: [ rules: [

Loading…
Cancel
Save