Commit 8cf518a8 authored by 愚道's avatar 愚道 Committed by 偏右

use airbnb eslint config and fix some rule

parent fc9c88a1
/functions/mock /functions/mock
\ No newline at end of file
module.exports = { module.exports = {
extends: ['eslint-config-umi', 'prettier'], parser: 'babel-eslint',
extends: ['airbnb', 'prettier'],
env: { env: {
browser: true, browser: true,
node: true, node: true,
...@@ -9,8 +10,20 @@ module.exports = { ...@@ -9,8 +10,20 @@ module.exports = {
jasmine: true, jasmine: true,
}, },
rules: { rules: {
'jsx-a11y/href-no-hash': [0], 'react/jsx-filename-extension': [1, { extensions: ['.js'] }],
'react/sort-comp': 1, 'import/no-unresolved': 0,
'jsx-a11y/anchor-is-valid': 0,
'react/jsx-wrap-multilines': 0,
'import/no-extraneous-dependencies': 0,
'consistent-return': 0,
'import/no-extraneous-dependencies': 0,
'react/prop-types': 0,
'jsx-a11y/click-events-have-key-events': 0,
'jsx-a11y/no-static-element-interactions': 0,
'react/prefer-stateless-function': 0,
'jsx-a11y/no-noninteractive-element-interactions': 0,
'react/forbid-prop-types': 0,
'react/jsx-one-expression-per-line': 0,
}, },
settings: { settings: {
polyfills: ['fetch', 'promises'], polyfills: ['fetch', 'promises'],
......
...@@ -82,8 +82,7 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => { ...@@ -82,8 +82,7 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => {
export { checkPermissions }; export { checkPermissions };
const check = (authority, target, Exception) => { const check = (authority, target, Exception) =>
return checkPermissions(authority, CURRENT, target, Exception); checkPermissions(authority, CURRENT, target, Exception);
};
export default check; export default check;
import { checkPermissions } from './CheckPermissions.js'; import { checkPermissions } from './CheckPermissions';
const target = 'ok'; const target = 'ok';
const error = 'error'; const error = 'error';
......
import Authorized from './Authorized'; import Authorized from './Authorized';
import AuthorizedRoute from './AuthorizedRoute'; import AuthorizedRoute from './AuthorizedRoute';
import Secured from './Secured'; import Secured from './Secured';
import check from './CheckPermissions.js'; import check from './CheckPermissions';
import renderAuthorize from './renderAuthorize'; import renderAuthorize from './renderAuthorize';
Authorized.Secured = Secured; Authorized.Secured = Secured;
......
...@@ -4,23 +4,21 @@ let CURRENT = 'NULL'; ...@@ -4,23 +4,21 @@ let CURRENT = 'NULL';
* use authority or getAuthority * use authority or getAuthority
* @param {string|()=>String} currentAuthority * @param {string|()=>String} currentAuthority
*/ */
const renderAuthorize = Authorized => { const renderAuthorize = Authorized => currentAuthority => {
return currentAuthority => { if (currentAuthority) {
if (currentAuthority) { if (currentAuthority.constructor.name === 'Function') {
if (currentAuthority.constructor.name === 'Function') { CURRENT = currentAuthority();
CURRENT = currentAuthority();
}
if (
currentAuthority.constructor.name === 'String' ||
currentAuthority.constructor.name === 'Array'
) {
CURRENT = currentAuthority;
}
} else {
CURRENT = 'NULL';
} }
return Authorized; if (
}; currentAuthority.constructor.name === 'String' ||
currentAuthority.constructor.name === 'Array'
) {
CURRENT = currentAuthority;
}
} else {
CURRENT = 'NULL';
}
return Authorized;
}; };
export { CURRENT }; export { CURRENT };
......
...@@ -142,15 +142,13 @@ export default class Gauge extends React.Component { ...@@ -142,15 +142,13 @@ export default class Gauge extends React.Component {
/> />
<Html <Html
position={['50%', '95%']} position={['50%', '95%']}
html={() => { html={() => `
return `
<div style="width: 300px;text-align: center;font-size: 12px!important;"> <div style="width: 300px;text-align: center;font-size: 12px!important;">
<p style="font-size: 14px; color: rgba(0,0,0,0.43);margin: 0;">${title}</p> <p style="font-size: 14px; color: rgba(0,0,0,0.43);margin: 0;">${title}</p>
<p style="font-size: 24px;color: rgba(0,0,0,0.85);margin: 0;"> <p style="font-size: 24px;color: rgba(0,0,0,0.85);margin: 0;">
${data[0].value * 10}% ${data[0].value * 10}%
</p> </p>
</div>`; </div>`}
}}
/> />
</Guide> </Guide>
<Geom <Geom
......
...@@ -172,9 +172,8 @@ export default class Pie extends Component { ...@@ -172,9 +172,8 @@ export default class Pie extends Component {
formatColor = value => { formatColor = value => {
if (value === '占比') { if (value === '占比') {
return color || 'rgba(24, 144, 255, 0.85)'; return color || 'rgba(24, 144, 255, 0.85)';
} else {
return '#F0F2F5';
} }
return '#F0F2F5';
}; };
data = [ data = [
...@@ -257,7 +256,7 @@ export default class Pie extends Component { ...@@ -257,7 +256,7 @@ export default class Pie extends Component {
<span className={styles.legendTitle}>{item.x}</span> <span className={styles.legendTitle}>{item.x}</span>
<Divider type="vertical" /> <Divider type="vertical" />
<span className={styles.percent}> <span className={styles.percent}>
{`${(isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`} {`${(Number.isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`}
</span> </span>
<span className={styles.value}>{valueFormat ? valueFormat(item.y) : item.y}</span> <span className={styles.value}>{valueFormat ? valueFormat(item.y) : item.y}</span>
</li> </li>
......
...@@ -30,8 +30,8 @@ function getAutoHeight(n) { ...@@ -30,8 +30,8 @@ function getAutoHeight(n) {
return height; return height;
} }
const autoHeight = () => WrappedComponent => { const autoHeight = () => WrappedComponent =>
return class extends React.Component { class extends React.Component {
state = { state = {
computedHeight: 0, computedHeight: 0,
}; };
...@@ -58,6 +58,5 @@ const autoHeight = () => WrappedComponent => { ...@@ -58,6 +58,5 @@ const autoHeight = () => WrappedComponent => {
); );
} }
}; };
};
export default autoHeight; export default autoHeight;
...@@ -23,6 +23,9 @@ const initTime = props => { ...@@ -23,6 +23,9 @@ const initTime = props => {
}; };
class CountDown extends Component { class CountDown extends Component {
timer = 0;
interval = 1000;
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -58,10 +61,6 @@ class CountDown extends Component { ...@@ -58,10 +61,6 @@ class CountDown extends Component {
clearTimeout(this.timer); clearTimeout(this.timer);
} }
timer = 0;
interval = 1000;
// defaultFormat = time => ( // defaultFormat = time => (
// <span>{moment(time).format('hh:mm:ss')}</span> // <span>{moment(time).format('hh:mm:ss')}</span>
// ); // );
...@@ -74,11 +73,7 @@ class CountDown extends Component { ...@@ -74,11 +73,7 @@ class CountDown extends Component {
const s = Math.floor((time - h * hours - m * minutes) / 1000); const s = Math.floor((time - h * hours - m * minutes) / 1000);
return ( return (
<span> <span>
{fixedZero(h)} {fixedZero(h)}:{fixedZero(m)}:{fixedZero(s)}
:
{fixedZero(m)}
:
{fixedZero(s)}
</span> </span>
); );
}; };
......
...@@ -13,16 +13,14 @@ const TooltipOverlayStyle = { ...@@ -13,16 +13,14 @@ const TooltipOverlayStyle = {
wordWrap: 'break-word', wordWrap: 'break-word',
}; };
export const getStrFullLength = (str = '') => { export const getStrFullLength = (str = '') =>
return str.split('').reduce((pre, cur) => { str.split('').reduce((pre, cur) => {
const charCode = cur.charCodeAt(0); const charCode = cur.charCodeAt(0);
if (charCode >= 0 && charCode <= 128) { if (charCode >= 0 && charCode <= 128) {
return pre + 1; return pre + 1;
} else {
return pre + 2;
} }
return pre + 2;
}, 0); }, 0);
};
export const cutStrByFullLength = (str = '', maxLength) => { export const cutStrByFullLength = (str = '', maxLength) => {
let showLength = 0; let showLength = 0;
...@@ -35,9 +33,8 @@ export const cutStrByFullLength = (str = '', maxLength) => { ...@@ -35,9 +33,8 @@ export const cutStrByFullLength = (str = '', maxLength) => {
} }
if (showLength <= maxLength) { if (showLength <= maxLength) {
return pre + cur; return pre + cur;
} else {
return pre;
} }
return pre;
}, ''); }, '');
}; };
...@@ -139,29 +136,26 @@ export default class Ellipsis extends Component { ...@@ -139,29 +136,26 @@ export default class Ellipsis extends Component {
sh = shadowNode.offsetHeight; sh = shadowNode.offsetHeight;
if (sh > th || mid === begin) { if (sh > th || mid === begin) {
return mid; return mid;
} else {
begin = mid;
if (end - begin === 1) {
mid = 1 + begin;
} else {
mid = Math.floor((end - begin) / 2) + begin;
}
return this.bisection(th, mid, begin, end, text, shadowNode);
}
} else {
if (mid - 1 < 0) {
return mid;
} }
shadowNode.innerHTML = text.substring(0, mid - 1) + suffix; begin = mid;
sh = shadowNode.offsetHeight; if (end - begin === 1) {
if (sh <= th) { mid = 1 + begin;
return mid - 1;
} else { } else {
end = mid;
mid = Math.floor((end - begin) / 2) + begin; mid = Math.floor((end - begin) / 2) + begin;
return this.bisection(th, mid, begin, end, text, shadowNode);
} }
return this.bisection(th, mid, begin, end, text, shadowNode);
}
if (mid - 1 < 0) {
return mid;
}
shadowNode.innerHTML = text.substring(0, mid - 1) + suffix;
sh = shadowNode.offsetHeight;
if (sh <= th) {
return mid - 1;
} }
end = mid;
mid = Math.floor((end - begin) / 2) + begin;
return this.bisection(th, mid, begin, end, text, shadowNode);
}; };
handleRoot = n => { handleRoot = n => {
......
import { getStrFullLength, cutStrByFullLength } from './index.js'; import { getStrFullLength, cutStrByFullLength } from './index';
describe('test calculateShowLength', () => { describe('test calculateShowLength', () => {
it('get full length', () => { it('get full length', () => {
......
...@@ -8,10 +8,12 @@ class Excrption extends React.PureComponent { ...@@ -8,10 +8,12 @@ class Excrption extends React.PureComponent {
static defaultProps = { static defaultProps = {
backText: 'back to home', backText: 'back to home',
}; };
constructor(props) { constructor(props) {
super(props); super(props);
this.state = {}; this.state = {};
} }
render() { render() {
const { const {
className, className,
......
...@@ -122,22 +122,20 @@ class WarpFormItem extends Component { ...@@ -122,22 +122,20 @@ class WarpFormItem extends Component {
const LoginItem = {}; const LoginItem = {};
Object.keys(ItemMap).forEach(key => { Object.keys(ItemMap).forEach(key => {
const item = ItemMap[key]; const item = ItemMap[key];
LoginItem[key] = props => { LoginItem[key] = props => (
return ( <LoginContext.Consumer>
<LoginContext.Consumer> {context => (
{context => ( <WarpFormItem
<WarpFormItem customprops={item.props}
customprops={item.props} {...props}
{...props} rules={item.rules}
rules={item.rules} type={key}
type={key} updateActive={context.updateActive}
updateActive={context.updateActive} form={context.form}
form={context.form} />
/> )}
)} </LoginContext.Consumer>
</LoginContext.Consumer> );
);
};
}); });
export default LoginItem; export default LoginItem;
...@@ -29,15 +29,11 @@ class LoginTab extends Component { ...@@ -29,15 +29,11 @@ class LoginTab extends Component {
} }
} }
const warpContext = props => { const warpContext = props => (
return ( <LoginContext.Consumer>
<LoginContext.Consumer> {value => <LoginTab tabUtil={value.tabUtil} {...props} />}
{value => { </LoginContext.Consumer>
return <LoginTab tabUtil={value.tabUtil} {...props} />; );
}}
</LoginContext.Consumer>
);
};
// 标志位 用来判断是不是自定义组件 // 标志位 用来判断是不是自定义组件
warpContext.typeName = 'LoginTab'; warpContext.typeName = 'LoginTab';
......
...@@ -28,6 +28,7 @@ export default function NoticeList({ ...@@ -28,6 +28,7 @@ export default function NoticeList({
const itemCls = classNames(styles.item, { const itemCls = classNames(styles.item, {
[styles.read]: item.read, [styles.read]: item.read,
}); });
// eslint-disable-next-line no-nested-ternary
const leftIcon = item.avatar ? ( const leftIcon = item.avatar ? (
typeof item.avatar === 'string' ? ( typeof item.avatar === 'string' ? (
<Avatar className={styles.avatar} src={item.avatar} /> <Avatar className={styles.avatar} src={item.avatar} />
......
...@@ -26,22 +26,18 @@ describe('test getBreadcrumb', () => { ...@@ -26,22 +26,18 @@ describe('test getBreadcrumb', () => {
expect(getBreadcrumb(routerData, '/userinfo/2144/addr').name).toEqual('收货订单'); expect(getBreadcrumb(routerData, '/userinfo/2144/addr').name).toEqual('收货订单');
}); });
it('Loop through the parameters', () => { it('Loop through the parameters', () => {
const urlNameList = urlToList('/userinfo/2144/addr').map(url => { const urlNameList = urlToList('/userinfo/2144/addr').map(
return getBreadcrumb(routerData, url).name; url => getBreadcrumb(routerData, url).name
}); );
expect(urlNameList).toEqual(['用户列表', '用户信息', '收货订单']); expect(urlNameList).toEqual(['用户列表', '用户信息', '收货订单']);
}); });
it('a path', () => { it('a path', () => {
const urlNameList = urlToList('/userinfo').map(url => { const urlNameList = urlToList('/userinfo').map(url => getBreadcrumb(routerData, url).name);
return getBreadcrumb(routerData, url).name;
});
expect(urlNameList).toEqual(['用户列表']); expect(urlNameList).toEqual(['用户列表']);
}); });
it('Secondary path', () => { it('Secondary path', () => {
const urlNameList = urlToList('/userinfo/2144').map(url => { const urlNameList = urlToList('/userinfo/2144').map(url => getBreadcrumb(routerData, url).name);
return getBreadcrumb(routerData, url).name;
});
expect(urlNameList).toEqual(['用户列表', '用户信息']); expect(urlNameList).toEqual(['用户列表', '用户信息']);
}); });
}); });
...@@ -2,32 +2,28 @@ import { Icon } from 'antd'; ...@@ -2,32 +2,28 @@ import { Icon } from 'antd';
import React from 'react'; import React from 'react';
import style from './index.less'; import style from './index.less';
const BlockChecbox = ({ value, onChange, list }) => { const BlockChecbox = ({ value, onChange, list }) => (
return ( <div className={style.blockChecbox} key={value}>
<div className={style.blockChecbox} key={value}> {list.map(item => (
{list.map(item => { <div
return ( key={item.key}
<div className={style.item}
key={item.key} onClick={() => {
className={style.item} onChange(item.key);
onClick={() => { }}
onChange(item.key); >
}} <img src={item.url} alt={item.key} />
> <div
<img src={item.url} alt={item.key} /> className={style.selectIcon}
<div style={{
className={style.selectIcon} display: value === item.key ? 'block' : 'none',
style={{ }}
display: value === item.key ? 'block' : 'none', >
}} <Icon type="check" />
> </div>
<Icon type="check" /> </div>
</div> ))}
</div> </div>
); );
})}
</div>
);
};
export default BlockChecbox; export default BlockChecbox;
...@@ -2,18 +2,16 @@ import { Icon } from 'antd'; ...@@ -2,18 +2,16 @@ import { Icon } from 'antd';
import React from 'react'; import React from 'react';
import styles from './ThemeColor.less'; import styles from './ThemeColor.less';
const Tag = ({ color, check, ...rest }) => { const Tag = ({ color, check, ...rest }) => (
return ( <div
<div {...rest}
{...rest} style={{
style={{ backgroundColor: color,
backgroundColor: color, }}
}} >
> {check ? <Icon type="check" /> : ''}
{check ? <Icon type="check" /> : ''} </div>
</div> );
);
};
const ThemeColor = ({ colors, title, value, onChange }) => { const ThemeColor = ({ colors, title, value, onChange }) => {
let colorList = colors; let colorList = colors;
...@@ -33,17 +31,15 @@ const ThemeColor = ({ colors, title, value, onChange }) => { ...@@ -33,17 +31,15 @@ const ThemeColor = ({ colors, title, value, onChange }) => {
<div className={styles.themeColor}> <div className={styles.themeColor}>
<h3 className={styles.title}>{title}</h3> <h3 className={styles.title}>{title}</h3>
<div className={styles.content}> <div className={styles.content}>
{colorList.map(color => { {colorList.map(color => (
return ( <Tag
<Tag className={styles.colorBlock}
className={styles.colorBlock} key={color}
key={color} color={color}
color={color} check={value === color}
check={value === color} onClick={() => onChange && onChange(color)}
onClick={() => onChange && onChange(color)} />
/> ))}
);
})}
</div> </div>
</div> </div>
); );
......
...@@ -76,9 +76,7 @@ class SettingDrawer extends PureComponent { ...@@ -76,9 +76,7 @@ class SettingDrawer extends PureComponent {
/>, />,
], ],
}, },
].filter(item => { ].filter(item => !item.hide);
return !item.hide;
});
}; };
changeSetting = (key, value) => { changeSetting = (key, value) => {
......
...@@ -22,11 +22,8 @@ const getIcon = icon => { ...@@ -22,11 +22,8 @@ const getIcon = icon => {
return icon; return icon;
}; };
export const getMenuMatches = (flatMenuKeys, path) => { export const getMenuMatches = (flatMenuKeys, path) =>
return flatMenuKeys.filter(item => { flatMenuKeys.filter(item => pathToRegexp(item).test(path));
return pathToRegexp(item).test(path);
});
};
export default class BaseMenu extends PureComponent { export default class BaseMenu extends PureComponent {
constructor(props) { constructor(props) {
...@@ -100,9 +97,8 @@ export default class BaseMenu extends PureComponent { ...@@ -100,9 +97,8 @@ export default class BaseMenu extends PureComponent {
{this.getNavMenuItems(item.children)} {this.getNavMenuItems(item.children)}
</SubMenu> </SubMenu>
); );
} else {
return <Menu.Item key={item.path}>{this.getMenuItemPath(item)}</Menu.Item>;
} }
return <Menu.Item key={item.path}>{this.getMenuItemPath(item)}</Menu.Item>;
}; };
/** /**
...@@ -143,6 +139,7 @@ export default class BaseMenu extends PureComponent { ...@@ -143,6 +139,7 @@ export default class BaseMenu extends PureComponent {
</Link> </Link>
); );
}; };
// permission to check // permission to check
checkPermissionItem = (authority, ItemDom) => { checkPermissionItem = (authority, ItemDom) => {
const { Authorized } = this.props; const { Authorized } = this.props;
...@@ -156,9 +153,8 @@ export default class BaseMenu extends PureComponent { ...@@ -156,9 +153,8 @@ export default class BaseMenu extends PureComponent {
conversionPath = path => { conversionPath = path => {
if (path && path.indexOf('http') === 0) { if (path && path.indexOf('http') === 0) {
return path; return path;
} else {
return `/${path || ''}`.replace(/\/+/g, '/');
} }
return `/${path || ''}`.replace(/\/+/g, '/');
}; };
render() { render() {
......
...@@ -18,9 +18,7 @@ const getDefaultCollapsedSubMenus = props => { ...@@ -18,9 +18,7 @@ const getDefaultCollapsedSubMenus = props => {
flatMenuKeys, flatMenuKeys,
} = props; } = props;
return urlToList(pathname) return urlToList(pathname)
.map(item => { .map(item => getMenuMatches(flatMenuKeys, item)[0])
return getMenuMatches(flatMenuKeys, item)[0];
})
.filter(item => item); .filter(item => item);
}; };
...@@ -69,6 +67,7 @@ export default class SiderMenu extends PureComponent { ...@@ -69,6 +67,7 @@ export default class SiderMenu extends PureComponent {
} }
return null; return null;
} }
isMainMenu = key => { isMainMenu = key => {
const { menuData } = this.props; const { menuData } = this.props;
return menuData.some(item => { return menuData.some(item => {
...@@ -78,12 +77,14 @@ export default class SiderMenu extends PureComponent { ...@@ -78,12 +77,14 @@ export default class SiderMenu extends PureComponent {
return false; return false;
}); });
}; };
handleOpenChange = openKeys => { handleOpenChange = openKeys => {
const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1; const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1;
this.setState({ this.setState({
openKeys: moreThanOne ? [openKeys.pop()] : [...openKeys], openKeys: moreThanOne ? [openKeys.pop()] : [...openKeys],
}); });
}; };
render() { render() {
const { logo, collapsed, onCollapse, fixSiderbar, theme } = this.props; const { logo, collapsed, onCollapse, fixSiderbar, theme } = this.props;
const { openKeys } = this.state; const { openKeys } = this.state;
......
...@@ -38,14 +38,10 @@ class StandardTable extends PureComponent { ...@@ -38,14 +38,10 @@ class StandardTable extends PureComponent {
handleRowSelectChange = (selectedRowKeys, selectedRows) => { handleRowSelectChange = (selectedRowKeys, selectedRows) => {
let { needTotalList } = this.state; let { needTotalList } = this.state;
needTotalList = needTotalList.map(item => { needTotalList = needTotalList.map(item => ({
return { ...item,
...item, total: selectedRows.reduce((sum, val) => sum + parseFloat(val[item.dataIndex], 10), 0),
total: selectedRows.reduce((sum, val) => { }));
return sum + parseFloat(val[item.dataIndex], 10);
}, 0),
};
});
const { onSelectRow } = this.props; const { onSelectRow } = this.props;
if (onSelectRow) { if (onSelectRow) {
onSelectRow(selectedRows); onSelectRow(selectedRows);
......
...@@ -18,6 +18,7 @@ class TagSelect extends Component { ...@@ -18,6 +18,7 @@ class TagSelect extends Component {
static defaultProps = { static defaultProps = {
hideCheckAll: false, hideCheckAll: false,
}; };
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
...@@ -80,13 +81,10 @@ class TagSelect extends Component { ...@@ -80,13 +81,10 @@ class TagSelect extends Component {
}); });
}; };
isTagSelectOption = node => { isTagSelectOption = node =>
return ( node &&
node && node.type &&
node.type && (node.type.isTagSelectOption || node.type.displayName === 'TagSelectOption');
(node.type.isTagSelectOption || node.type.displayName === 'TagSelectOption')
);
};
render() { render() {
const { value, expand } = this.state; const { value, expand } = this.state;
......
// /userinfo/2144/id => ['/userinfo','/useinfo/2144,'/userindo/2144/id'] // /userinfo/2144/id => ['/userinfo','/useinfo/2144,'/userindo/2144/id']
// eslint-disable-next-line import/prefer-default-export
export function urlToList(url) { export function urlToList(url) {
const urllist = url.split('/').filter(i => i); const urllist = url.split('/').filter(i => i);
return urllist.map((urlItem, index) => { return urllist.map((urlItem, index) => `/${urllist.slice(0, index + 1).join('/')}`);
return `/${urllist.slice(0, index + 1).join('/')}`;
});
} }
...@@ -174,6 +174,7 @@ class BasicLayout extends React.PureComponent { ...@@ -174,6 +174,7 @@ class BasicLayout extends React.PureComponent {
children, children,
location: { pathname }, location: { pathname },
} = this.props; } = this.props;
const { rendering } = this.state;
const isTop = PropsLayout === 'topmenu'; const isTop = PropsLayout === 'topmenu';
const layout = ( const layout = (
<Layout> <Layout>
...@@ -209,7 +210,7 @@ class BasicLayout extends React.PureComponent { ...@@ -209,7 +210,7 @@ class BasicLayout extends React.PureComponent {
)} )}
</ContainerQuery> </ContainerQuery>
</DocumentTitle> </DocumentTitle>
{this.state.rendering && process.env.NODE_ENV === 'production' ? null : ( // Do show SettingDrawer in production {rendering && process.env.NODE_ENV === 'production' ? null : ( // Do show SettingDrawer in production
<SettingDrawer /> <SettingDrawer />
)} )}
</React.Fragment> </React.Fragment>
......
...@@ -71,7 +71,7 @@ class HeaderView extends PureComponent { ...@@ -71,7 +71,7 @@ class HeaderView extends PureComponent {
} }
}; };
handScroll = e => { handScroll = () => {
const { autoHideHeader } = this.props; const { autoHideHeader } = this.props;
const { visible } = this.state; const { visible } = this.state;
if (!autoHideHeader) { if (!autoHideHeader) {
...@@ -99,7 +99,6 @@ class HeaderView extends PureComponent { ...@@ -99,7 +99,6 @@ class HeaderView extends PureComponent {
} }
this.oldScrollTop = scrollTop; this.oldScrollTop = scrollTop;
this.ticking = false; this.ticking = false;
return;
}); });
} }
this.ticking = false; this.ticking = false;
......
...@@ -2,33 +2,31 @@ import React from 'react'; ...@@ -2,33 +2,31 @@ import React from 'react';
import { FormattedMessage } from 'umi/locale'; import { FormattedMessage } from 'umi/locale';
import Link from 'umi/link'; import Link from 'umi/link';
import PageHeader from '@/components/PageHeader'; import PageHeader from '@/components/PageHeader';
import { connect } from 'dva';
import GridContent from './GridContent'; import GridContent from './GridContent';
import styles from './PageHeaderLayout.less'; import styles from './PageHeaderLayout.less';
import MenuContext from './MenuContext'; import MenuContext from './MenuContext';
import { connect } from 'dva';
const PageHeaderLayout = ({ children, grid, wrapperClassName, top, ...restProps }) => ( const PageHeaderLayout = ({ children, grid, wrapperClassName, top, ...restProps }) => (
<div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}> <div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}>
{top} {top}
<MenuContext.Consumer> <MenuContext.Consumer>
{value => { {value => (
return ( <PageHeader
<PageHeader wide={grid === 'Wide'}
wide={grid === 'Wide'} home={<FormattedMessage id="menu.home" defaultMessage="Home" />}
home={<FormattedMessage id="menu.home" defaultMessage="Home" />} {...value}
{...value} key="pageheader"
key="pageheader" {...restProps}
{...restProps} linkElement={Link}
linkElement={Link} itemRender={item => {
itemRender={item => { if (item.locale) {
if (item.locale) { return <FormattedMessage id={item.locale} defaultMessage={item.name} />;
return <FormattedMessage id={item.locale} defaultMessage={item.name} />; }
} return item.name;
return item.name; }}
}} />
/> )}
);
}}
</MenuContext.Consumer> </MenuContext.Consumer>
{children ? ( {children ? (
<div className={styles.content}> <div className={styles.content}>
......
...@@ -24,7 +24,8 @@ export default class Center extends PureComponent { ...@@ -24,7 +24,8 @@ export default class Center extends PureComponent {
<div className={stylesArticles.description}>{content}</div> <div className={stylesArticles.description}>{content}</div>
<div className={stylesArticles.extra}> <div className={stylesArticles.extra}>
<Avatar src={avatar} size="small" /> <Avatar src={avatar} size="small" />
<a href={href}>{owner}</a> 发布在 <a href={href}>{href}</a> <a href={href}>{owner}</a> 发布
<a href={href}>{href}</a>
<em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em> <em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em>
</div> </div>
</div> </div>
......
...@@ -3,40 +3,38 @@ import { formatMessage, FormattedMessage } from 'umi/locale'; ...@@ -3,40 +3,38 @@ import { formatMessage, FormattedMessage } from 'umi/locale';
import { Icon, List } from 'antd'; import { Icon, List } from 'antd';
class BindingView extends Component { class BindingView extends Component {
getData = () => { getData = () => [
return [ {
{ title: formatMessage({ id: 'app.settings.binding.taobao' }, {}),
title: formatMessage({ id: 'app.settings.binding.taobao' }, {}), description: formatMessage({ id: 'app.settings.binding.taobao-description' }, {}),
description: formatMessage({ id: 'app.settings.binding.taobao-description' }, {}), actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
<FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" /> </a>,
</a>, ],
], avatar: <Icon type="taobao" className="taobao" />,
avatar: <Icon type="taobao" className="taobao" />, },
}, {
{ title: formatMessage({ id: 'app.settings.binding.alipay' }, {}),
title: formatMessage({ id: 'app.settings.binding.alipay' }, {}), description: formatMessage({ id: 'app.settings.binding.alipay-description' }, {}),
description: formatMessage({ id: 'app.settings.binding.alipay-description' }, {}), actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
<FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" /> </a>,
</a>, ],
], avatar: <Icon type="alipay" className="alipay" />,
avatar: <Icon type="alipay" className="alipay" />, },
}, {
{ title: formatMessage({ id: 'app.settings.binding.dingding' }, {}),
title: formatMessage({ id: 'app.settings.binding.dingding' }, {}), description: formatMessage({ id: 'app.settings.binding.dingding-description' }, {}),
description: formatMessage({ id: 'app.settings.binding.dingding-description' }, {}), actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
<FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" /> </a>,
</a>, ],
], avatar: <Icon type="dingding" className="dingding" />,
avatar: <Icon type="dingding" className="dingding" />, },
}, ];
];
};
render() { render() {
return ( return (
......
...@@ -55,13 +55,11 @@ export default class GeographicView extends PureComponent { ...@@ -55,13 +55,11 @@ export default class GeographicView extends PureComponent {
</Option> </Option>
); );
} }
return list.map(item => { return list.map(item => (
return ( <Option key={item.id} value={item.id}>
<Option key={item.id} value={item.id}> {item.name}
{item.name} </Option>
</Option> ));
);
});
}; };
selectProvinceItem = item => { selectProvinceItem = item => {
......
...@@ -23,66 +23,64 @@ const passwordStrength = { ...@@ -23,66 +23,64 @@ const passwordStrength = {
}; };
class SecurityView extends Component { class SecurityView extends Component {
getData = () => { getData = () => [
return [ {
{ title: formatMessage({ id: 'app.settings.security.password' }, {}),
title: formatMessage({ id: 'app.settings.security.password' }, {}), description: (
description: ( <Fragment>
<Fragment> {formatMessage({ id: 'app.settings.security.password-description' }, {})}
{formatMessage({ id: 'app.settings.security.password-description' }, {})} {passwordStrength.strong}
{passwordStrength.strong} </Fragment>
</Fragment> ),
), actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
<FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" /> </a>,
</a>, ],
], },
}, {
{ title: formatMessage({ id: 'app.settings.security.phone' }, {}),
title: formatMessage({ id: 'app.settings.security.phone' }, {}), description: `${formatMessage(
description: `${formatMessage( { id: 'app.settings.security.phone-description' },
{ id: 'app.settings.security.phone-description' }, {}
{} )}:138****8293`,
)}:138****8293`, actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
<FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" /> </a>,
</a>, ],
], },
}, {
{ title: formatMessage({ id: 'app.settings.security.question' }, {}),
title: formatMessage({ id: 'app.settings.security.question' }, {}), description: formatMessage({ id: 'app.settings.security.question-description' }, {}),
description: formatMessage({ id: 'app.settings.security.question-description' }, {}), actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.security.set" defaultMessage="Set" />
<FormattedMessage id="app.settings.security.set" defaultMessage="Set" /> </a>,
</a>, ],
], },
}, {
{ title: formatMessage({ id: 'app.settings.security.email' }, {}),
title: formatMessage({ id: 'app.settings.security.email' }, {}), description: `${formatMessage(
description: `${formatMessage( { id: 'app.settings.security.email-description' },
{ id: 'app.settings.security.email-description' }, {}
{} )}:ant***sign.com`,
)}:ant***sign.com`, actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
<FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" /> </a>,
</a>, ],
], },
}, {
{ title: formatMessage({ id: 'app.settings.security.mfa' }, {}),
title: formatMessage({ id: 'app.settings.security.mfa' }, {}), description: formatMessage({ id: 'app.settings.security.mfa-description' }, {}),
description: formatMessage({ id: 'app.settings.security.mfa-description' }, {}), actions: [
actions: [ <a>
<a> <FormattedMessage id="app.settings.security.bind" defaultMessage="Bind" />
<FormattedMessage id="app.settings.security.bind" defaultMessage="Bind" /> </a>,
</a>, ],
], },
}, ];
];
};
render() { render() {
return ( return (
......
...@@ -157,13 +157,12 @@ class Analysis extends Component { ...@@ -157,13 +157,12 @@ class Analysis extends Component {
salesTypeDataOffline, salesTypeDataOffline,
} = chart; } = chart;
const loading = propsLoding || stateLoading; const loading = propsLoding || stateLoading;
const salesPieData = let salesPieData;
salesType === 'all' if (salesType === 'all') {
? salesTypeData salesPieData = salesTypeData;
: salesType === 'online' } else {
? salesTypeDataOnline salesPieData = salesType === 'online' ? salesTypeDataOnline : salesTypeDataOffline;
: salesTypeDataOffline; }
const menu = ( const menu = (
<Menu> <Menu>
<Menu.Item>操作一</Menu.Item> <Menu.Item>操作一</Menu.Item>
......
...@@ -124,9 +124,13 @@ export default class Workplace extends PureComponent { ...@@ -124,9 +124,13 @@ export default class Workplace extends PureComponent {
<Avatar size="large" src={currentUser.avatar} /> <Avatar size="large" src={currentUser.avatar} />
</div> </div>
<div className={styles.content}> <div className={styles.content}>
<div className={styles.contentTitle}>早安{currentUser.name}祝你开心每一天</div> <div className={styles.contentTitle}>
早安
{currentUser.name}
祝你开心每一天
</div>
<div> <div>
{currentUser.title} | {currentUser.group} {currentUser.title} |{currentUser.group}
</div> </div>
</div> </div>
</div> </div>
...@@ -141,8 +145,7 @@ export default class Workplace extends PureComponent { ...@@ -141,8 +145,7 @@ export default class Workplace extends PureComponent {
<div className={styles.statItem}> <div className={styles.statItem}>
<p>团队内排名</p> <p>团队内排名</p>
<p> <p>
8 8<span> / 24</span>
<span> / 24</span>
</p> </p>
</div> </div>
<div className={styles.statItem}> <div className={styles.statItem}>
......
...@@ -4,6 +4,9 @@ import isEqual from 'lodash.isequal'; ...@@ -4,6 +4,9 @@ import isEqual from 'lodash.isequal';
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);
...@@ -26,10 +29,6 @@ export default class TableForm extends PureComponent { ...@@ -26,10 +29,6 @@ export default class TableForm extends PureComponent {
}; };
} }
index = 0;
cacheOriginData = {};
getRowByKey(key, newData) { getRowByKey(key, newData) {
const { data } = this.state; const { data } = this.state;
return (newData || data).filter(item => item.key === key)[0]; return (newData || data).filter(item => item.key === key)[0];
...@@ -244,9 +243,7 @@ export default class TableForm extends PureComponent { ...@@ -244,9 +243,7 @@ export default class TableForm extends PureComponent {
columns={columns} columns={columns}
dataSource={data} dataSource={data}
pagination={false} pagination={false}
rowClassName={record => { rowClassName={record => (record.editable ? styles.editable : '')}
return record.editable ? styles.editable : '';
}}
/> />
<Button <Button
style={{ width: '100%', marginTop: 16, marginBottom: 8 }} style={{ width: '100%', marginTop: 16, marginBottom: 8 }}
......
...@@ -38,9 +38,13 @@ const { Search, TextArea } = Input; ...@@ -38,9 +38,13 @@ const { Search, TextArea } = Input;
})) }))
@Form.create() @Form.create()
export default class BasicList extends PureComponent { export default class BasicList extends PureComponent {
state = { visible: false, done: false }; state = { visible: false, done: false };
formLayout = {
labelCol: { span: 7 },
wrapperCol: { span: 13 },
};
componentDidMount() { componentDidMount() {
const { dispatch } = this.props; const { dispatch } = this.props;
dispatch({ dispatch({
...@@ -51,11 +55,6 @@ export default class BasicList extends PureComponent { ...@@ -51,11 +55,6 @@ export default class BasicList extends PureComponent {
}); });
} }
formLayout = {
labelCol: { span: 7 },
wrapperCol: { span: 13 },
};
showModal = () => { showModal = () => {
this.setState({ this.setState({
visible: true, visible: true,
......
...@@ -66,6 +66,67 @@ const CreateForm = Form.create()(props => { ...@@ -66,6 +66,67 @@ const CreateForm = Form.create()(props => {
@Form.create() @Form.create()
class UpdateForm extends PureComponent { class UpdateForm extends PureComponent {
columns = [
{
title: '规则名称',
dataIndex: 'name',
},
{
title: '描述',
dataIndex: 'desc',
},
{
title: '服务调用次数',
dataIndex: 'callNo',
sorter: true,
align: 'right',
render: val => `${val} 万`,
// mark to display a total number
needTotal: true,
},
{
title: '状态',
dataIndex: 'status',
filters: [
{
text: status[0],
value: 0,
},
{
text: status[1],
value: 1,
},
{
text: status[2],
value: 2,
},
{
text: status[3],
value: 3,
},
],
render(val) {
return <Badge status={statusMap[val]} text={status[val]} />;
},
},
{
title: '上次调度时间',
dataIndex: 'updatedAt',
sorter: true,
render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>,
},
{
title: '操作',
render: (text, record) => (
<Fragment>
<a onClick={() => this.handleUpdateModalVisible(true, record)}>配置</a>
<Divider type="vertical" />
<a href="">订阅警报</a>
</Fragment>
),
},
];
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -288,67 +349,6 @@ export default class TableList extends PureComponent { ...@@ -288,67 +349,6 @@ export default class TableList extends PureComponent {
}); });
} }
columns = [
{
title: '规则名称',
dataIndex: 'name',
},
{
title: '描述',
dataIndex: 'desc',
},
{
title: '服务调用次数',
dataIndex: 'callNo',
sorter: true,
align: 'right',
render: val => `${val} 万`,
// mark to display a total number
needTotal: true,
},
{
title: '状态',
dataIndex: 'status',
filters: [
{
text: status[0],
value: 0,
},
{
text: status[1],
value: 1,
},
{
text: status[2],
value: 2,
},
{
text: status[3],
value: 3,
},
],
render(val) {
return <Badge status={statusMap[val]} text={status[val]} />;
},
},
{
title: '上次调度时间',
dataIndex: 'updatedAt',
sorter: true,
render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>,
},
{
title: '操作',
render: (text, record) => (
<Fragment>
<a onClick={() => this.handleUpdateModalVisible(true, record)}>配置</a>
<Divider type="vertical" />
<a href="">订阅警报</a>
</Fragment>
),
},
];
handleStandardTableChange = (pagination, filtersArg, sorter) => { handleStandardTableChange = (pagination, filtersArg, sorter) => {
const { dispatch } = this.props; const { dispatch } = this.props;
const { formValues } = this.state; const { formValues } = this.state;
......
...@@ -21,8 +21,8 @@ export default class LoginPage extends Component { ...@@ -21,8 +21,8 @@ export default class LoginPage extends Component {
this.setState({ type }); this.setState({ type });
}; };
onGetCaptcha = () => { onGetCaptcha = () =>
return new Promise((resolve, reject) => { new Promise((resolve, reject) => {
this.loginForm.validateFields(['mobile'], {}, (err, values) => { this.loginForm.validateFields(['mobile'], {}, (err, values) => {
if (err) { if (err) {
reject(err); reject(err);
...@@ -37,7 +37,6 @@ export default class LoginPage extends Component { ...@@ -37,7 +37,6 @@ export default class LoginPage extends Component {
} }
}); });
}); });
};
handleSubmit = (err, values) => { handleSubmit = (err, values) => {
const { type } = this.state; const { type } = this.state;
...@@ -59,9 +58,9 @@ export default class LoginPage extends Component { ...@@ -59,9 +58,9 @@ export default class LoginPage extends Component {
}); });
}; };
renderMessage = content => { renderMessage = content => (
return <Alert style={{ marginBottom: 24 }} message={content} type="error" showIcon />; <Alert style={{ marginBottom: 24 }} message={content} type="error" showIcon />
}; );
render() { render() {
const { login, submitting } = this.props; const { login, submitting } = this.props;
......
...@@ -24,7 +24,8 @@ const RegisterResult = ({ location }) => ( ...@@ -24,7 +24,8 @@ const RegisterResult = ({ location }) => (
title={ title={
<div className={styles.title}> <div className={styles.title}>
你的账户 你的账户
{location.state ? location.state.account : 'AntDesign@example.com'} 注册成功 {location.state ? location.state.account : 'AntDesign@example.com'}
注册成功
</div> </div>
} }
description="激活邮件已发送到你的邮箱中,邮件有效期为24小时。请及时登录邮箱,点击邮件中的链接激活帐户。" description="激活邮件已发送到你的邮箱中,邮件有效期为24小时。请及时登录邮箱,点击邮件中的链接激活帐户。"
......
import request from '@/utils/request'; import request from '@/utils/request';
export async function query(code) { export default async function query(code) {
return request(`/api/${code}`); return request(`/api/${code}`);
} }
...@@ -2,6 +2,7 @@ import fetch from 'dva/fetch'; ...@@ -2,6 +2,7 @@ import fetch from 'dva/fetch';
import { notification } from 'antd'; import { notification } from 'antd';
import router from 'umi/router'; import router from 'umi/router';
import hash from 'hash.js'; import hash from 'hash.js';
const codeMessage = { const codeMessage = {
200: '服务器成功返回请求的数据。', 200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。', 201: '新建或修改数据成功。',
...@@ -19,6 +20,7 @@ const codeMessage = { ...@@ -19,6 +20,7 @@ const codeMessage = {
503: '服务不可用,服务器暂时过载或维护。', 503: '服务不可用,服务器暂时过载或维护。',
504: '网关超时。', 504: '网关超时。',
}; };
const checkStatus = response => { const checkStatus = response => {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {
return response; return response;
...@@ -39,7 +41,7 @@ const cachedSave = (response, hashcode) => { ...@@ -39,7 +41,7 @@ const cachedSave = (response, hashcode) => {
* Clone a response data and store it in sessionStorage * Clone a response data and store it in sessionStorage
* Does not support data other than json, Cache only json * Does not support data other than json, Cache only json
*/ */
let contentType = response.headers.get('Content-Type'); const contentType = response.headers.get('Content-Type');
if (contentType && contentType.match(/application\/json/i)) { if (contentType && contentType.match(/application\/json/i)) {
// All data is saved as text // All data is saved as text
response response
...@@ -47,7 +49,7 @@ const cachedSave = (response, hashcode) => { ...@@ -47,7 +49,7 @@ const cachedSave = (response, hashcode) => {
.text() .text()
.then(content => { .then(content => {
sessionStorage.setItem(hashcode, content); sessionStorage.setItem(hashcode, content);
sessionStorage.setItem(hashcode + ':timestamp', Date.now()); sessionStorage.setItem(`${hashcode}:timestamp`, Date.now());
}); });
} }
return response; return response;
...@@ -99,17 +101,16 @@ export default function request(url, options = {}) { ...@@ -99,17 +101,16 @@ export default function request(url, options = {}) {
const expirys = options.expirys || 60; const expirys = options.expirys || 60;
// options.expirys !== false, return the cache, // options.expirys !== false, return the cache,
if (options.expirys !== false) { if (options.expirys !== false) {
let cached = sessionStorage.getItem(hashcode); const cached = sessionStorage.getItem(hashcode);
let whenCached = sessionStorage.getItem(hashcode + ':timestamp'); const whenCached = sessionStorage.getItem(`${hashcode}:timestamp`);
if (cached !== null && whenCached !== null) { if (cached !== null && whenCached !== null) {
let age = (Date.now() - whenCached) / 1000; const age = (Date.now() - whenCached) / 1000;
if (age < expirys) { if (age < expirys) {
let response = new Response(new Blob([cached])); const response = new Response(new Blob([cached]));
return response.json(); return response.json();
} else {
sessionStorage.removeItem(hashcode);
sessionStorage.removeItem(hashcode + ':timestamp');
} }
sessionStorage.removeItem(hashcode);
sessionStorage.removeItem(`${hashcode}:timestamp`);
} }
} }
return fetch(url, newOptions) return fetch(url, newOptions)
......
...@@ -115,7 +115,8 @@ function getRelation(str1, str2) { ...@@ -115,7 +115,8 @@ function getRelation(str1, str2) {
const arr2 = str2.split('/'); const arr2 = str2.split('/');
if (arr2.every((item, index) => item === arr1[index])) { if (arr2.every((item, index) => item === arr1[index])) {
return 1; return 1;
} else if (arr1.every((item, index) => item === arr2[index])) { }
if (arr1.every((item, index) => item === arr2[index])) {
return 2; return 2;
} }
return 3; return 3;
...@@ -184,7 +185,7 @@ export function isUrl(path) { ...@@ -184,7 +185,7 @@ export function isUrl(path) {
export function formatWan(val) { export function formatWan(val) {
const v = val * 1; const v = val * 1;
if (!v || isNaN(v)) return ''; if (!v || Number.isNaN(v)) return '';
let result = val; let result = val;
if (val > 10000) { if (val > 10000) {
......
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