Commit 34f49bfd authored by ddcat1115's avatar ddcat1115

Merge branch 'master' into v2

parents f1874684 6844c413
...@@ -5,11 +5,7 @@ class Authorized extends React.Component { ...@@ -5,11 +5,7 @@ class Authorized extends React.Component {
render() { render() {
const { children, authority, noMatch = null } = this.props; const { children, authority, noMatch = null } = this.props;
const childrenRender = typeof children === 'undefined' ? null : children; const childrenRender = typeof children === 'undefined' ? null : children;
return CheckPermissions( return CheckPermissions(authority, childrenRender, noMatch);
authority,
childrenRender,
noMatch
);
} }
} }
......
...@@ -4,16 +4,28 @@ import Authorized from './Authorized'; ...@@ -4,16 +4,28 @@ import Authorized from './Authorized';
class AuthorizedRoute extends React.Component { class AuthorizedRoute extends React.Component {
render() { render() {
const { component: Component, render, authority, const {
redirectPath, ...rest } = this.props; component: Component,
render,
authority,
redirectPath,
...rest
} = this.props;
return ( return (
<Authorized <Authorized
authority={authority} authority={authority}
noMatch={<Route {...rest} render={() => <Redirect to={{ pathname: redirectPath }} />} />} noMatch={
<Route
{...rest}
render={() => <Redirect to={{ pathname: redirectPath }} />}
/>
}
> >
<Route <Route
{...rest} {...rest}
render={props => (Component ? <Component {...props} /> : render(props))} render={props =>
(Component ? <Component {...props} /> : render(props))
}
/> />
</Authorized> </Authorized>
); );
......
...@@ -3,7 +3,11 @@ import PromiseRender from './PromiseRender'; ...@@ -3,7 +3,11 @@ import PromiseRender from './PromiseRender';
import { CURRENT } from './index'; import { CURRENT } from './index';
function isPromise(obj) { function isPromise(obj) {
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; return (
!!obj &&
(typeof obj === 'object' || typeof obj === 'function') &&
typeof obj.then === 'function'
);
} }
/** /**
...@@ -38,9 +42,7 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => { ...@@ -38,9 +42,7 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => {
// Promise 处理 // Promise 处理
if (isPromise(authority)) { if (isPromise(authority)) {
return () => ( return <PromiseRender ok={target} error={Exception} promise={authority} />;
<PromiseRender ok={target} error={Exception} promise={authority} />
);
} }
// Function 处理 // Function 处理
......
...@@ -3,25 +3,37 @@ import { Spin } from 'antd'; ...@@ -3,25 +3,37 @@ import { Spin } from 'antd';
export default class PromiseRender extends React.PureComponent { export default class PromiseRender extends React.PureComponent {
state = { state = {
component: false, component: null,
}; };
async componentDidMount() { componentDidMount() {
const ok = this.checkIsInstantiation(this.props.ok);
const error = this.checkIsInstantiation(this.props.error);
this.props.promise this.props.promise
.then(() => { .then(() => {
this.setState({ this.setState({
component: this.props.ok, component: ok,
}); });
}) })
.catch(() => { .catch(() => {
this.setState({ this.setState({
component: this.props.error, component: error,
}); });
}); });
} }
// Determine whether the incoming component has been instantiated
// AuthorizedRoute is already instantiated
// Authorized render is already instantiated, children is no instantiated
// Secured is not instantiated
checkIsInstantiation = (target) => {
if (!React.isValidElement(target)) {
return target;
}
return () => target;
};
render() { render() {
const C = this.state.component; const Component = this.state.component;
return C ? ( return Component ? (
<C {...this.props} /> <Component {...this.props} />
) : ( ) : (
<div <div
style={{ style={{
......
...@@ -9,6 +9,17 @@ const Exception403 = () => ( ...@@ -9,6 +9,17 @@ const Exception403 = () => (
<Exception type="403" style={{ minHeight: 500, height: '80%' }} /> <Exception type="403" style={{ minHeight: 500, height: '80%' }} />
); );
// Determine whether the incoming component has been instantiated
// AuthorizedRoute is already instantiated
// Authorized render is already instantiated, children is no instantiated
// Secured is not instantiated
const checkIsInstantiation = (target) => {
if (!React.isValidElement(target)) {
return target;
}
return () => target;
};
/** /**
* 用于判断是否拥有权限访问此view权限 * 用于判断是否拥有权限访问此view权限
* authority 支持传入 string ,funtion:()=>boolean|Promise * authority 支持传入 string ,funtion:()=>boolean|Promise
...@@ -38,11 +49,8 @@ const authorize = (authority, error) => { ...@@ -38,11 +49,8 @@ const authorize = (authority, error) => {
throw new Error('authority is required'); throw new Error('authority is required');
} }
return function decideAuthority(targer) { return function decideAuthority(targer) {
return CheckPermissions( const component = CheckPermissions(authority, targer, classError || Exception403);
authority, return checkIsInstantiation(component);
targer,
classError || Exception403
);
}; };
}; };
......
...@@ -26,7 +26,16 @@ export default class Pie extends Component { ...@@ -26,7 +26,16 @@ export default class Pie extends Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (this.props.data !== nextProps.data) { if (this.props.data !== nextProps.data) {
this.getLengendData(); // because of charts data create when rendered
// so there is a trick for get rendered time
this.setState(
{
legendData: [...this.state.legendData],
},
() => {
this.getLengendData();
}
);
} }
} }
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { Layout, Menu, Icon, Spin, Tag, Dropdown, Avatar, Divider } from 'antd'; import { Menu, Icon, Spin, Tag, Dropdown, Avatar, Divider } from 'antd';
import moment from 'moment'; import moment from 'moment';
import groupBy from 'lodash/groupBy'; import groupBy from 'lodash/groupBy';
import Debounce from 'lodash-decorators/debounce'; import Debounce from 'lodash-decorators/debounce';
...@@ -8,8 +8,6 @@ import NoticeIcon from '../NoticeIcon'; ...@@ -8,8 +8,6 @@ import NoticeIcon from '../NoticeIcon';
import HeaderSearch from '../HeaderSearch'; import HeaderSearch from '../HeaderSearch';
import styles from './index.less'; import styles from './index.less';
const { Header } = Layout;
export default class GlobalHeader extends PureComponent { export default class GlobalHeader extends PureComponent {
componentWillUnmount() { componentWillUnmount() {
this.triggerResizeEvent.cancel(); this.triggerResizeEvent.cancel();
...@@ -68,7 +66,7 @@ export default class GlobalHeader extends PureComponent { ...@@ -68,7 +66,7 @@ export default class GlobalHeader extends PureComponent {
); );
const noticeData = this.getNoticeData(); const noticeData = this.getNoticeData();
return ( return (
<Header className={styles.header}> <div className={styles.header}>
{isMobile && ( {isMobile && (
[ [
( (
...@@ -135,7 +133,7 @@ export default class GlobalHeader extends PureComponent { ...@@ -135,7 +133,7 @@ export default class GlobalHeader extends PureComponent {
</Dropdown> </Dropdown>
) : <Spin size="small" style={{ marginLeft: 8 }} />} ) : <Spin size="small" style={{ marginLeft: 8 }} />}
</div> </div>
</Header> </div>
); );
} }
} }
@import "~antd/lib/style/themes/default.less"; @import "~antd/lib/style/themes/default.less";
.header { .header {
height: 64px;
padding: 0 12px 0 0; padding: 0 12px 0 0;
background: #fff; background: #fff;
box-shadow: 0 1px 4px rgba(0, 21, 41, .08); box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
......
...@@ -16,7 +16,7 @@ import Authorized from '../utils/Authorized'; ...@@ -16,7 +16,7 @@ import Authorized from '../utils/Authorized';
import { getMenuData } from '../common/menu'; import { getMenuData } from '../common/menu';
import logo from '../assets/logo.svg'; import logo from '../assets/logo.svg';
const { Content } = Layout; const { Content, Header, Footer } = Layout;
const { AuthorizedRoute } = Authorized; const { AuthorizedRoute } = Authorized;
/** /**
...@@ -164,18 +164,20 @@ class BasicLayout extends React.PureComponent { ...@@ -164,18 +164,20 @@ class BasicLayout extends React.PureComponent {
onCollapse={this.handleMenuCollapse} onCollapse={this.handleMenuCollapse}
/> />
<Layout> <Layout>
<GlobalHeader <Header style={{ padding: 0 }}>
logo={logo} <GlobalHeader
currentUser={currentUser} logo={logo}
fetchingNotices={fetchingNotices} currentUser={currentUser}
notices={notices} fetchingNotices={fetchingNotices}
collapsed={collapsed} notices={notices}
isMobile={this.state.isMobile} collapsed={collapsed}
onNoticeClear={this.handleNoticeClear} isMobile={this.state.isMobile}
onCollapse={this.handleMenuCollapse} onNoticeClear={this.handleNoticeClear}
onMenuClick={this.handleMenuClick} onCollapse={this.handleMenuCollapse}
onNoticeVisibleChange={this.handleNoticeVisibleChange} onMenuClick={this.handleMenuClick}
/> onNoticeVisibleChange={this.handleNoticeVisibleChange}
/>
</Header>
<Content style={{ margin: '24px 24px 0', height: '100%' }}> <Content style={{ margin: '24px 24px 0', height: '100%' }}>
<Switch> <Switch>
{ {
...@@ -201,29 +203,31 @@ class BasicLayout extends React.PureComponent { ...@@ -201,29 +203,31 @@ class BasicLayout extends React.PureComponent {
<Route render={NotFound} /> <Route render={NotFound} />
</Switch> </Switch>
</Content> </Content>
<GlobalFooter <Footer style={{ padding: 0 }}>
links={[{ <GlobalFooter
key: 'Pro 首页', links={[{
title: 'Pro 首页', key: 'Pro 首页',
href: 'http://pro.ant.design', title: 'Pro 首页',
blankTarget: true, href: 'http://pro.ant.design',
}, { blankTarget: true,
key: 'github', }, {
title: <Icon type="github" />, key: 'github',
href: 'https://github.com/ant-design/ant-design-pro', title: <Icon type="github" />,
blankTarget: true, href: 'https://github.com/ant-design/ant-design-pro',
}, { blankTarget: true,
key: 'Ant Design', }, {
title: 'Ant Design', key: 'Ant Design',
href: 'http://ant.design', title: 'Ant Design',
blankTarget: true, href: 'http://ant.design',
}]} blankTarget: true,
copyright={ }]}
<div> copyright={
Copyright <Icon type="copyright" /> 2018 蚂蚁金服体验技术部出品 <div>
</div> Copyright <Icon type="copyright" /> 2018 蚂蚁金服体验技术部出品
} </div>
/> }
/>
</Footer>
</Layout> </Layout>
</Layout> </Layout>
); );
......
import React from 'react'; import React from 'react';
import { routerRedux, Switch } from 'dva/router'; import { routerRedux, Route, Switch } from 'dva/router';
import { LocaleProvider, Spin } from 'antd'; import { LocaleProvider, Spin } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN'; import zhCN from 'antd/lib/locale-provider/zh_CN';
import dynamic from 'dva/dynamic'; import dynamic from 'dva/dynamic';
...@@ -21,10 +21,9 @@ function RouterConfig({ history, app }) { ...@@ -21,10 +21,9 @@ function RouterConfig({ history, app }) {
<LocaleProvider locale={zhCN}> <LocaleProvider locale={zhCN}>
<ConnectedRouter history={history}> <ConnectedRouter history={history}>
<Switch> <Switch>
<AuthorizedRoute <Route
path="/user" path="/user"
render={props => <UserLayout {...props} />} component={UserLayout}
redirectPath="/"
/> />
<AuthorizedRoute <AuthorizedRoute
path="/" path="/"
......
...@@ -107,7 +107,6 @@ export default class Monitor extends PureComponent { ...@@ -107,7 +107,6 @@ export default class Monitor extends PureComponent {
<Col xl={12} lg={24} sm={24} xs={24}> <Col xl={12} lg={24} sm={24} xs={24}>
<Card <Card
title="各品类占比" title="各品类占比"
style={{ marginBottom: 24 }}
bordered={false} bordered={false}
className={styles.pieCard} className={styles.pieCard}
> >
...@@ -147,7 +146,7 @@ export default class Monitor extends PureComponent { ...@@ -147,7 +146,7 @@ export default class Monitor extends PureComponent {
</Row> </Row>
</Card> </Card>
</Col> </Col>
<Col xl={6} lg={12} sm={24} xs={24} style={{ marginBottom: 24 }}> <Col xl={6} lg={12} sm={24} xs={24}>
<Card title="热门搜索" loading={loading} bordered={false} bodyStyle={{ overflow: 'hidden' }}> <Card title="热门搜索" loading={loading} bordered={false} bodyStyle={{ overflow: 'hidden' }}>
<TagCloud <TagCloud
data={tags} data={tags}
...@@ -155,7 +154,7 @@ export default class Monitor extends PureComponent { ...@@ -155,7 +154,7 @@ export default class Monitor extends PureComponent {
/> />
</Card> </Card>
</Col> </Col>
<Col xl={6} lg={12} sm={24} xs={24} style={{ marginBottom: 24 }}> <Col xl={6} lg={12} sm={24} xs={24}>
<Card title="资源剩余" bodyStyle={{ textAlign: 'center', fontSize: 0 }} bordered={false}> <Card title="资源剩余" bodyStyle={{ textAlign: 'center', fontSize: 0 }} bordered={false}>
<WaterWave <WaterWave
height={161} height={161}
......
...@@ -268,7 +268,7 @@ class AdvancedForm extends PureComponent { ...@@ -268,7 +268,7 @@ class AdvancedForm extends PureComponent {
</Row> </Row>
</Form> </Form>
</Card> </Card>
<Card title="成员管理" className={styles.card} bordered={false}> <Card title="成员管理" bordered={false}>
{getFieldDecorator('members', { {getFieldDecorator('members', {
initialValue: tableData, initialValue: tableData,
})(<TableForm />)} })(<TableForm />)}
......
...@@ -23,17 +23,6 @@ export default class TableForm extends PureComponent { ...@@ -23,17 +23,6 @@ export default class TableForm extends PureComponent {
} }
index = 0; index = 0;
cacheOriginData = {}; cacheOriginData = {};
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
this.props.dispatch({
type: 'form/submit',
payload: values,
});
}
});
}
toggleEditable=(e, key) => { toggleEditable=(e, key) => {
e.preventDefault(); e.preventDefault();
const newData = this.state.data.map(item => ({ ...item })); const newData = this.state.data.map(item => ({ ...item }));
...@@ -83,12 +72,7 @@ export default class TableForm extends PureComponent { ...@@ -83,12 +72,7 @@ export default class TableForm extends PureComponent {
this.setState({ this.setState({
loading: true, loading: true,
}); });
// save field when blur input
setTimeout(() => { setTimeout(() => {
if (document.activeElement.tagName === 'INPUT' &&
document.activeElement !== e.target) {
return;
}
if (this.clickedCancel) { if (this.clickedCancel) {
this.clickedCancel = false; this.clickedCancel = false;
return; return;
...@@ -121,6 +105,7 @@ export default class TableForm extends PureComponent { ...@@ -121,6 +105,7 @@ export default class TableForm extends PureComponent {
delete this.cacheOriginData[key]; delete this.cacheOriginData[key];
} }
this.setState({ data: newData }); this.setState({ data: newData });
this.clickedCancel = false;
} }
render() { render() {
const columns = [{ const columns = [{
...@@ -135,7 +120,6 @@ export default class TableForm extends PureComponent { ...@@ -135,7 +120,6 @@ export default class TableForm extends PureComponent {
value={text} value={text}
autoFocus autoFocus
onChange={e => this.handleFieldChange(e, 'name', record.key)} onChange={e => this.handleFieldChange(e, 'name', record.key)}
onBlur={e => this.saveRow(e, record.key)}
onKeyPress={e => this.handleKeyPress(e, record.key)} onKeyPress={e => this.handleKeyPress(e, record.key)}
placeholder="成员姓名" placeholder="成员姓名"
/> />
...@@ -154,7 +138,6 @@ export default class TableForm extends PureComponent { ...@@ -154,7 +138,6 @@ export default class TableForm extends PureComponent {
<Input <Input
value={text} value={text}
onChange={e => this.handleFieldChange(e, 'workId', record.key)} onChange={e => this.handleFieldChange(e, 'workId', record.key)}
onBlur={e => this.saveRow(e, record.key)}
onKeyPress={e => this.handleKeyPress(e, record.key)} onKeyPress={e => this.handleKeyPress(e, record.key)}
placeholder="工号" placeholder="工号"
/> />
...@@ -173,7 +156,6 @@ export default class TableForm extends PureComponent { ...@@ -173,7 +156,6 @@ export default class TableForm extends PureComponent {
<Input <Input
value={text} value={text}
onChange={e => this.handleFieldChange(e, 'department', record.key)} onChange={e => this.handleFieldChange(e, 'department', record.key)}
onBlur={e => this.saveRow(e, record.key)}
onKeyPress={e => this.handleKeyPress(e, record.key)} onKeyPress={e => this.handleKeyPress(e, record.key)}
placeholder="所属部门" placeholder="所属部门"
/> />
...@@ -192,7 +174,7 @@ export default class TableForm extends PureComponent { ...@@ -192,7 +174,7 @@ export default class TableForm extends PureComponent {
if (record.isNew) { if (record.isNew) {
return ( return (
<span> <span>
<a>保存</a> <a onClick={e => this.saveRow(e, record.key)}>添加</a>
<Divider type="vertical" /> <Divider type="vertical" />
<Popconfirm title="是否要删除此行?" onConfirm={() => this.remove(record.key)}> <Popconfirm title="是否要删除此行?" onConfirm={() => this.remove(record.key)}>
<a>删除</a> <a>删除</a>
...@@ -202,7 +184,7 @@ export default class TableForm extends PureComponent { ...@@ -202,7 +184,7 @@ export default class TableForm extends PureComponent {
} }
return ( return (
<span> <span>
<a>保存</a> <a onClick={e => this.saveRow(e, record.key)}>保存</a>
<Divider type="vertical" /> <Divider type="vertical" />
<a onClick={e => this.cancel(e, record.key)}>取消</a> <a onClick={e => this.cancel(e, record.key)}>取消</a>
</span> </span>
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
} }
.tabsCard { .tabsCard {
margin-bottom: 24px;
:global { :global {
.ant-card-head { .ant-card-head {
padding: 0 16px; padding: 0 16px;
......
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