Commit 1d0def2a authored by 陈帅's avatar 陈帅

Migrate AccountSettings and AdvancedForm

parent ac17ede7
...@@ -63,7 +63,7 @@ const validatorPhone = (rule: any, value: string, callback: (message?: string) = ...@@ -63,7 +63,7 @@ const validatorPhone = (rule: any, value: string, callback: (message?: string) =
}; };
interface BaseViewProps extends FormComponentProps { interface BaseViewProps extends FormComponentProps {
currentUser: CurrentUser; currentUser?: CurrentUser;
} }
@connect(({ BLOCK_NAME_CAMEL_CASE }: { BLOCK_NAME_CAMEL_CASE: { currentUser: CurrentUser } }) => ({ @connect(({ BLOCK_NAME_CAMEL_CASE }: { BLOCK_NAME_CAMEL_CASE: { currentUser: CurrentUser } }) => ({
...@@ -76,21 +76,26 @@ class BaseView extends Component<BaseViewProps> { ...@@ -76,21 +76,26 @@ class BaseView extends Component<BaseViewProps> {
setBaseInfo = () => { setBaseInfo = () => {
const { currentUser, form } = this.props; const { currentUser, form } = this.props;
if (currentUser) {
Object.keys(form.getFieldsValue()).forEach(key => { Object.keys(form.getFieldsValue()).forEach(key => {
const obj = {}; const obj = {};
obj[key] = currentUser[key] || null; obj[key] = currentUser[key] || null;
form.setFieldsValue(obj); form.setFieldsValue(obj);
}); });
}
}; };
getAvatarURL() { getAvatarURL() {
const { currentUser } = this.props; const { currentUser } = this.props;
if (currentUser) {
if (currentUser.avatar) { if (currentUser.avatar) {
return currentUser.avatar; return currentUser.avatar;
} }
const url = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'; const url = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png';
return url; return url;
} }
return '';
}
view: HTMLDivElement | undefined; view: HTMLDivElement | undefined;
getViewDom = (ref: HTMLDivElement) => { getViewDom = (ref: HTMLDivElement) => {
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'dva'; import { connect } from 'dva';
import { Dispatch } from 'redux';
import { FormattedMessage } from 'umi-plugin-react/locale'; import { FormattedMessage } from 'umi-plugin-react/locale';
import { Menu } from 'antd'; import { Menu } from 'antd';
import styles from './style.less'; import styles from './style.less';
...@@ -7,14 +8,31 @@ import BaseView from './components/base'; ...@@ -7,14 +8,31 @@ import BaseView from './components/base';
import SecurityView from './components/security'; import SecurityView from './components/security';
import BindingView from './components/binding'; import BindingView from './components/binding';
import NotificationView from './components/notification'; import NotificationView from './components/notification';
import { CurrentUser } from './data';
const { Item } = Menu; const { Item } = Menu;
@connect(({ BLOCK_NAME_CAMEL_CASE }) => ({ interface PAGE_NAME_UPPER_CAMEL_CASEProps {
dispatch: Dispatch;
currentUser: CurrentUser;
}
type PAGE_NAME_UPPER_CAMEL_CASEStateKeys = 'base' | 'security' | 'binding' | 'notification';
interface PAGE_NAME_UPPER_CAMEL_CASEState {
mode: 'inline' | 'horizontal';
menuMap: {
[key: string]: React.ReactNode;
};
selectKey: PAGE_NAME_UPPER_CAMEL_CASEStateKeys;
}
@connect(({ BLOCK_NAME_CAMEL_CASE }: { BLOCK_NAME_CAMEL_CASE: { currentUser: CurrentUser } }) => ({
currentUser: BLOCK_NAME_CAMEL_CASE.currentUser, currentUser: BLOCK_NAME_CAMEL_CASE.currentUser,
})) }))
class PAGE_NAME_UPPER_CAMEL_CASE extends Component { class PAGE_NAME_UPPER_CAMEL_CASE extends Component<
constructor(props) { PAGE_NAME_UPPER_CAMEL_CASEProps,
PAGE_NAME_UPPER_CAMEL_CASEState
> {
constructor(props: PAGE_NAME_UPPER_CAMEL_CASEProps) {
super(props); super(props);
const menuMap = { const menuMap = {
base: <FormattedMessage id="BLOCK_NAME.menuMap.basic" defaultMessage="Basic Settings" />, base: <FormattedMessage id="BLOCK_NAME.menuMap.basic" defaultMessage="Basic Settings" />,
...@@ -38,6 +56,8 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -38,6 +56,8 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
}; };
} }
main: HTMLDivElement | undefined;
componentDidMount() { componentDidMount() {
const { dispatch } = this.props; const { dispatch } = this.props;
dispatch({ dispatch({
...@@ -51,7 +71,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -51,7 +71,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
window.removeEventListener('resize', this.resize); window.removeEventListener('resize', this.resize);
} }
getmenu = () => { getMenu = () => {
const { menuMap } = this.state; const { menuMap } = this.state;
return Object.keys(menuMap).map(item => <Item key={item}>{menuMap[item]}</Item>); return Object.keys(menuMap).map(item => <Item key={item}>{menuMap[item]}</Item>);
}; };
...@@ -61,7 +81,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -61,7 +81,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
return menuMap[selectKey]; return menuMap[selectKey];
}; };
selectKey = ({ key }) => { selectKey = (key: PAGE_NAME_UPPER_CAMEL_CASEStateKeys) => {
this.setState({ this.setState({
selectKey: key, selectKey: key,
}); });
...@@ -75,7 +95,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -75,7 +95,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
if (!this.main) { if (!this.main) {
return; return;
} }
let mode = 'inline'; let mode: 'inline' | 'horizontal' = 'inline';
const { offsetWidth } = this.main; const { offsetWidth } = this.main;
if (this.main.offsetWidth < 641 && offsetWidth > 400) { if (this.main.offsetWidth < 641 && offsetWidth > 400) {
mode = 'horizontal'; mode = 'horizontal';
...@@ -117,12 +137,18 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component { ...@@ -117,12 +137,18 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends Component {
<div <div
className={styles.main} className={styles.main}
ref={ref => { ref={ref => {
if (ref) {
this.main = ref; this.main = ref;
}
}} }}
> >
<div className={styles.leftmenu}> <div className={styles.leftMenu}>
<Menu mode={mode} selectedKeys={[selectKey]} onClick={this.selectKey}> <Menu
{this.getmenu()} mode={mode}
selectedKeys={[selectKey]}
onClick={({ key }) => this.selectKey(key as PAGE_NAME_UPPER_CAMEL_CASEStateKeys)}
>
{this.getMenu()}
</Menu> </Menu>
</div> </div>
<div className={styles.right}> <div className={styles.right}>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
padding-top: 16px; padding-top: 16px;
padding-bottom: 16px; padding-bottom: 16px;
overflow: auto; overflow: auto;
.leftmenu { .leftMenu {
width: 224px; width: 224px;
border-right: @border-width-base @border-style-base @border-color-split; border-right: @border-width-base @border-style-base @border-color-split;
:global { :global {
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
@media screen and (max-width: @screen-md) { @media screen and (max-width: @screen-md) {
.main { .main {
flex-direction: column; flex-direction: column;
.leftmenu { .leftMenu {
width: 100%; width: 100%;
border: none; border: none;
} }
......
import React from 'react';
import { FormattedMessage } from 'umi-plugin-react/locale';
import Link from 'umi/link';
import { PageHeader } from 'ant-design-pro';
import styles from './index.less';
const PageHeaderWrapper = ({ children, wrapperClassName, ...restProps }) => (
<div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}>
<PageHeader
home={<FormattedMessage id="BLOCK_NAME.menu.home" defaultMessage="Home" />}
key="pageheader"
{...restProps}
linkElement={Link}
itemRender={item => {
if (item.locale) {
return <FormattedMessage id={item.locale} defaultMessage={item.title} />;
}
return item.title;
}}
/>
{children ? <div className={styles.content}>{children}</div> : null}
</div>
);
export default PageHeaderWrapper;
@import '~antd/lib/style/themes/default.less';
.content {
margin: 24px 24px 0;
}
@media screen and (max-width: @screen-sm) {
.content {
margin: 24px 0 0;
}
}
import React, { PureComponent } from 'react'; import React, { Component } from 'react';
import { import { Card, Form, Icon, Col, Row, DatePicker, TimePicker, Input, Select, Popover } from 'antd';
Card,
Button,
Form,
Icon,
Col,
Row,
DatePicker,
TimePicker,
Input,
Select,
Popover,
} from 'antd';
import { connect } from 'dva'; import { connect } from 'dva';
import { FooterToolbar } from 'ant-design-pro';
import PageHeaderWrapper from './components/PageHeaderWrapper';
import TableForm from './components/TableForm'; import TableForm from './components/TableForm';
import styles from './style.less'; import styles from './style.less';
import { FormComponentProps } from 'antd/lib/form';
import { Dispatch } from 'redux';
const { Option } = Select; const { Option } = Select;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
...@@ -57,11 +45,14 @@ const tableData = [ ...@@ -57,11 +45,14 @@ const tableData = [
}, },
]; ];
@connect(({ loading }) => ({ interface PAGE_NAME_UPPER_CAMEL_CASEProps extends FormComponentProps {
dispatch: Dispatch;
}
@connect(({ loading }: { loading: { effects: any } }) => ({
submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/submitAdvancedForm'], submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/submitAdvancedForm'],
})) }))
@Form.create() class PAGE_NAME_UPPER_CAMEL_CASE extends Component<PAGE_NAME_UPPER_CAMEL_CASEProps> {
class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
state = { state = {
width: '100%', width: '100%',
}; };
...@@ -83,7 +74,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { ...@@ -83,7 +74,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
if (!errors || errorCount === 0) { if (!errors || errorCount === 0) {
return null; return null;
} }
const scrollToField = fieldKey => { const scrollToField = (fieldKey: string) => {
const labelNode = document.querySelector(`label[for="${fieldKey}"]`); const labelNode = document.querySelector(`label[for="${fieldKey}"]`);
if (labelNode) { if (labelNode) {
labelNode.scrollIntoView(true); labelNode.scrollIntoView(true);
...@@ -119,7 +110,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { ...@@ -119,7 +110,7 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
resizeFooterToolbar = () => { resizeFooterToolbar = () => {
requestAnimationFrame(() => { requestAnimationFrame(() => {
const sider = document.querySelectorAll('.ant-layout-sider')[0]; const sider = document.querySelectorAll('.ant-layout-sider')[0] as HTMLDivElement;
if (sider) { if (sider) {
const width = `calc(100% - ${sider.style.width})`; const width = `calc(100% - ${sider.style.width})`;
const { width: stateWidth } = this.state; const { width: stateWidth } = this.state;
...@@ -149,16 +140,10 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { ...@@ -149,16 +140,10 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
render() { render() {
const { const {
form: { getFieldDecorator }, form: { getFieldDecorator },
submitting,
} = this.props; } = this.props;
const { width } = this.state;
return ( return (
<PageHeaderWrapper <>
title="高级表单"
content="高级表单常见于一次性输入和提交大批量数据的场景。"
wrapperClassName={styles.advancedForm}
>
<Card title="仓库管理" className={styles.card} bordered={false}> <Card title="仓库管理" className={styles.card} bordered={false}>
<Form layout="vertical" hideRequiredMark> <Form layout="vertical" hideRequiredMark>
<Row gutter={16}> <Row gutter={16}>
...@@ -309,15 +294,15 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent { ...@@ -309,15 +294,15 @@ class PAGE_NAME_UPPER_CAMEL_CASE extends PureComponent {
initialValue: tableData, initialValue: tableData,
})(<TableForm />)} })(<TableForm />)}
</Card> </Card>
<FooterToolbar style={{ width }}> {/* <FooterToolbar style={{ width }}>
{this.getErrorInfo()} {this.getErrorInfo()}
<Button type="primary" onClick={this.validate} loading={submitting}> <Button type="primary" onClick={this.validate} loading={submitting}>
提交 提交
</Button> </Button>
</FooterToolbar> </FooterToolbar> */}
</PageHeaderWrapper> </>
); );
} }
} }
export default PAGE_NAME_UPPER_CAMEL_CASE; export default Form.create()(PAGE_NAME_UPPER_CAMEL_CASE);
{ {
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "PAGES_PATH='AccountCenter/src' umi dev", "dev": "PAGES_PATH='AdvancedForm/src' umi dev",
"lint:style": "stylelint \"src/**/*.less\" --syntax less", "lint:style": "stylelint \"src/**/*.less\" --syntax less",
"lint": "eslint --ext .js src mock tests && npm run lint:style", "lint": "eslint --ext .js src mock tests && npm run lint:style",
"lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style", "lint:fix": "eslint --fix --ext .js src mock tests && npm run lint:style",
......
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