From 8b83a6f527f05c22273574d005733675088a5a46 Mon Sep 17 00:00:00 2001 From: jim Date: Fri, 9 Feb 2018 17:16:07 +0800 Subject: [PATCH] responsive support for user information interface --- src/routes/Userinfo/BaseView.js | 33 +++++++++++++++++++++++-- src/routes/Userinfo/BaseView.less | 12 ++++++++- src/routes/Userinfo/GeographicView.js | 9 ++++--- src/routes/Userinfo/GeographicView.less | 17 +++++++++++++ src/routes/Userinfo/Info.js | 2 +- src/routes/Userinfo/Info.less | 14 +++++++++++ src/routes/Userinfo/PhoneView.js | 5 ++-- src/routes/Userinfo/PhoneView.less | 20 +++++++++++++++ 8 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 src/routes/Userinfo/GeographicView.less create mode 100644 src/routes/Userinfo/PhoneView.less diff --git a/src/routes/Userinfo/BaseView.js b/src/routes/Userinfo/BaseView.js index 960e18c6..b73275c8 100644 --- a/src/routes/Userinfo/BaseView.js +++ b/src/routes/Userinfo/BaseView.js @@ -1,5 +1,7 @@ import React, { Component, Fragment } from 'react'; import { Form, Input, Upload, Select, Button } from 'antd'; +import Debounce from 'lodash-decorators/debounce'; +import Bind from 'lodash-decorators/bind'; import styles from './BaseView.less'; import GeographicView from './GeographicView'; import PhoneView from './PhoneView'; @@ -46,8 +48,16 @@ const validatorPhone = (rule, value, callback) => { @Form.create() export default class BaseView extends Component { + state = { + md: false, + }; componentDidMount() { this.setBaseInfo(); + this.resize(); + window.addEventListener('resize', this.resize); + } + componentWillUnmount() { + window.removeEventListener('resize', this.resize); } setBaseInfo = () => { const { currentUser } = this.props; @@ -65,10 +75,29 @@ export default class BaseView extends Component { 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'; return url; } + getViewDom = (ref) => { + this.view = ref; + }; + @Bind() + @Debounce(200) + resize() { + if (this.view.offsetWidth > 696) { + this.setState({ + md: false, + }); + return; + } + this.setState({ + md: true, + }); + } render() { const { getFieldDecorator } = this.props.form; return ( -
+
@@ -98,7 +127,7 @@ export default class BaseView extends Component { { required: true, message: 'Please input your country!' }, ], })( - diff --git a/src/routes/Userinfo/BaseView.less b/src/routes/Userinfo/BaseView.less index e8e3ab1d..c0bc53a2 100644 --- a/src/routes/Userinfo/BaseView.less +++ b/src/routes/Userinfo/BaseView.less @@ -2,8 +2,18 @@ .baseView { display: flex; + &.md { + flex-direction: column-reverse; + .right { + padding: 20px; + display: flex; + flex-direction: column; + align-items: center; + } + } .left { - width: 448px; + max-width: 448px; + min-width: 224px; } .right { flex: 1; diff --git a/src/routes/Userinfo/GeographicView.js b/src/routes/Userinfo/GeographicView.js index 15be9314..345e6bb2 100644 --- a/src/routes/Userinfo/GeographicView.js +++ b/src/routes/Userinfo/GeographicView.js @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; import { Select, Spin } from 'antd'; import { connect } from 'dva'; +import styles from './GeographicView.less'; const { Option } = Select; @@ -17,7 +18,7 @@ const nullSlectItem = { isLoading, }; }) -export default class ProvinceSelect extends PureComponent { +export default class GeographicView extends PureComponent { componentDidMount = () => { this.props.dispatch({ type: 'geographic/fetchProvince', @@ -78,22 +79,22 @@ export default class ProvinceSelect extends PureComponent { render() { const { province, city } = this.conversionObject(); return ( - + diff --git a/src/routes/Userinfo/GeographicView.less b/src/routes/Userinfo/GeographicView.less new file mode 100644 index 00000000..046d9345 --- /dev/null +++ b/src/routes/Userinfo/GeographicView.less @@ -0,0 +1,17 @@ +@import '~antd/lib/style/themes/default.less'; + +.row { + .item { + width: 220px; + } + .item:first-child { + margin-right: 8px; + } +} + +@media screen and (max-width: @screen-sm) { + .item:first-child { + margin: 0; + margin-bottom: 8px; + } +} diff --git a/src/routes/Userinfo/Info.js b/src/routes/Userinfo/Info.js index a978ecd5..68683b9e 100644 --- a/src/routes/Userinfo/Info.js +++ b/src/routes/Userinfo/Info.js @@ -48,7 +48,7 @@ export default class Info extends PureComponent {
diff --git a/src/routes/Userinfo/Info.less b/src/routes/Userinfo/Info.less index b419400e..d0f245e1 100644 --- a/src/routes/Userinfo/Info.less +++ b/src/routes/Userinfo/Info.less @@ -7,6 +7,7 @@ display: flex; padding-top: 16px; padding-bottom: 16px; + overflow: auto; .leftmenu { width: 224px; border-right: 1px solid #e8e8e8; @@ -69,3 +70,16 @@ color: red; } } + +@media screen and (max-width: @screen-md) { + .main { + flex-direction: column; + .leftmenu { + width: 100%; + border: none; + } + .right { + padding: 40px; + } + } +} diff --git a/src/routes/Userinfo/PhoneView.js b/src/routes/Userinfo/PhoneView.js index 5e5a920a..75430f30 100644 --- a/src/routes/Userinfo/PhoneView.js +++ b/src/routes/Userinfo/PhoneView.js @@ -1,5 +1,6 @@ import React, { Fragment, PureComponent } from 'react'; import { Input } from 'antd'; +import styles from './PhoneView.less'; class PhoneView extends PureComponent { render() { @@ -11,18 +12,18 @@ class PhoneView extends PureComponent { return ( { onChange(`${e.target.value}-${values[1]}`); }} - style={{ width: 128, marginRight: 8 }} /> { onChange(`${values[0]}-${e.target.value}`); }} value={values[1]} - style={{ width: 312 }} /> ); diff --git a/src/routes/Userinfo/PhoneView.less b/src/routes/Userinfo/PhoneView.less new file mode 100644 index 00000000..bc1e3a43 --- /dev/null +++ b/src/routes/Userinfo/PhoneView.less @@ -0,0 +1,20 @@ +@import '~antd/lib/style/themes/default.less'; + +.area_code { + width: 128px; + margin-right: 8px; +} +.phone_number { + width: 312px; +} + +@media screen and (max-width: @screen-sm) { + .area_code { + width: 100%; + margin: 0; + margin-bottom: 8px; + } + .phone_number { + width: 100%; + } +} -- GitLab