提交 5363cd73637b3d7d4767c23ef2082139f482e499

作者 愚道
1 个父辈 98a2c25b

refact: ant design pro SearchList

1 export default { 1 export default {
2 plugins: [ 2 plugins: [
3 - ['umi-plugin-block-dev', {}], 3 + ['umi-plugin-block-dev', {
  4 + layout: 'ant-design-pro',
  5 + }],
4 ['umi-plugin-react', { 6 ['umi-plugin-react', {
5 dva: true, 7 dva: true,
6 locale: true, 8 locale: true,
1 -import React, { PureComponent } from 'react';  
2 -import { connect } from 'dva';  
3 -import styles from './GridContent.less';  
4 -  
5 -class GridContent extends PureComponent {  
6 - render() {  
7 - const { contentWidth, children } = this.props;  
8 - let className = `${styles.main}`;  
9 - if (contentWidth === 'Fixed') {  
10 - className = `${styles.main} ${styles.wide}`;  
11 - }  
12 - return <div className={className}>{children}</div>;  
13 - }  
14 -}  
15 -  
16 -export default connect(({ setting }) => ({  
17 - contentWidth: setting.contentWidth,  
18 -}))(GridContent);  
1 -.main {  
2 - width: 100%;  
3 - height: 100%;  
4 - min-height: 100%;  
5 - transition: 0.3s;  
6 - &.wide {  
7 - max-width: 1200px;  
8 - margin: 0 auto;  
9 - }  
10 -}  
1 -import { createContext } from 'react';  
2 -  
3 -export default createContext();  
@@ -11,10 +11,11 @@ @@ -11,10 +11,11 @@
11 "url": "https://github.com/umijs/umi-blocks/searchlist" 11 "url": "https://github.com/umijs/umi-blocks/searchlist"
12 }, 12 },
13 "dependencies": { 13 "dependencies": {
14 - "react": "^16.6.3",  
15 - "dva": "^2.4.0", 14 + "ant-design-pro": "^2.1.1",
16 "antd": "^3.10.9", 15 "antd": "^3.10.9",
17 - "ant-design-pro": "^2.1.1" 16 + "dva": "^2.4.0",
  17 + "react": "^16.6.3",
  18 + "umi-request": "^1.0.0"
18 }, 19 },
19 "devDependencies": { 20 "devDependencies": {
20 "umi": "^2.3.0-beta.1", 21 "umi": "^2.3.0-beta.1",
1 import React from 'react'; 1 import React from 'react';
2 import { FormattedMessage } from 'umi/locale'; 2 import { FormattedMessage } from 'umi/locale';
3 import Link from 'umi/link'; 3 import Link from 'umi/link';
4 -import PageHeader from 'ant-design-pro/lib/PageHeader';  
5 -import { connect } from 'dva';  
6 -import GridContent from './GridContent'; 4 +import { PageHeader } from 'ant-design-pro';
7 import styles from './index.less'; 5 import styles from './index.less';
8 -import MenuContext from '@/layouts/MenuContext';  
9 6
10 -const PageHeaderWrapper = ({ children, contentWidth, wrapperClassName, top, ...restProps }) => ( 7 +const PageHeaderWrapper = ({ children, wrapperClassName, ...restProps }) => (
11 <div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}> 8 <div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}>
12 - {top}  
13 - <MenuContext.Consumer>  
14 - {value => (  
15 - <PageHeader  
16 - wide={contentWidth === 'Fixed'}  
17 - home={<FormattedMessage id="menu.home" defaultMessage="Home" />}  
18 - {...value}  
19 - key="pageheader"  
20 - {...restProps}  
21 - linkElement={Link}  
22 - itemRender={item => {  
23 - if (item.locale) {  
24 - return <FormattedMessage id={item.locale} defaultMessage={item.title} />;  
25 - }  
26 - return item.title;  
27 - }}  
28 - />  
29 - )}  
30 - </MenuContext.Consumer> 9 + <PageHeader
  10 + home={<FormattedMessage id="menu.home" defaultMessage="Home" />}
  11 + key="pageheader"
  12 + {...restProps}
  13 + linkElement={Link}
  14 + itemRender={item => {
  15 + if (item.locale) {
  16 + return <FormattedMessage id={item.locale} defaultMessage={item.title} />;
  17 + }
  18 + return item.title;
  19 + }}
  20 + />
31 {children ? ( 21 {children ? (
32 <div className={styles.content}> 22 <div className={styles.content}>
33 - <GridContent>{children}</GridContent> 23 + {children}
34 </div> 24 </div>
35 ) : null} 25 ) : null}
36 </div> 26 </div>
37 ); 27 );
38 28
39 -export default connect(({ setting }) => ({  
40 - contentWidth: setting.contentWidth,  
41 -}))(PageHeaderWrapper); 29 +export default PageHeaderWrapper;
1 -module.exports = {  
2 - navTheme: 'dark', // theme for nav menu  
3 - primaryColor: '#1890FF', // primary color of ant design  
4 - layout: 'sidemenu', // nav menu position: sidemenu or topmenu  
5 - contentWidth: 'Fluid', // layout of content: Fluid or Fixed, only works when layout is topmenu  
6 - fixedHeader: false, // sticky header  
7 - autoHideHeader: false, // auto hide header  
8 - fixSiderbar: false, // sticky siderbar  
9 -};  
@@ -2,7 +2,7 @@ import React, { Component } from 'react'; @@ -2,7 +2,7 @@ import React, { Component } from 'react';
2 import router from 'umi/router'; 2 import router from 'umi/router';
3 import { connect } from 'dva'; 3 import { connect } from 'dva';
4 import { Input } from 'antd'; 4 import { Input } from 'antd';
5 -import PageHeaderWrapper from '@/components/PageHeaderWrapper'; 5 +import PageHeaderWrapper from './components/PageHeaderWrapper';
6 6
7 @connect() 7 @connect()
8 class SearchList extends Component { 8 class SearchList extends Component {
@@ -67,11 +67,6 @@ class SearchList extends Component { @@ -67,11 +67,6 @@ class SearchList extends Component {
67 onTabChange={this.handleTabChange} 67 onTabChange={this.handleTabChange}
68 > 68 >
69 {children} 69 {children}
70 - {/* <Switch>  
71 - {routes.map(item => (  
72 - <Route key={item.key} path={item.path} component={item.component} exact={item.exact} />  
73 - ))}  
74 - </Switch> */}  
75 </PageHeaderWrapper> 70 </PageHeaderWrapper>
76 ); 71 );
77 } 72 }
1 -import { message } from 'antd';  
2 -import defaultSettings from '../defaultSettings';  
3 -  
4 -let lessNodesAppended;  
5 -const updateTheme = primaryColor => {  
6 - // Don't compile less in production!  
7 - if (APP_TYPE !== 'site') {  
8 - return;  
9 - }  
10 - // Determine if the component is remounted  
11 - if (!primaryColor) {  
12 - return;  
13 - }  
14 - const hideMessage = message.loading('正在编译主题!', 0);  
15 - function buildIt() {  
16 - if (!window.less) {  
17 - return;  
18 - }  
19 - setTimeout(() => {  
20 - window.less  
21 - .modifyVars({  
22 - '@primary-color': primaryColor,  
23 - })  
24 - .then(() => {  
25 - hideMessage();  
26 - })  
27 - .catch(() => {  
28 - message.error('Failed to update theme');  
29 - hideMessage();  
30 - });  
31 - }, 200);  
32 - }  
33 - if (!lessNodesAppended) {  
34 - // insert less.js and color.less  
35 - const lessStyleNode = document.createElement('link');  
36 - const lessConfigNode = document.createElement('script');  
37 - const lessScriptNode = document.createElement('script');  
38 - lessStyleNode.setAttribute('rel', 'stylesheet/less');  
39 - lessStyleNode.setAttribute('href', '/color.less');  
40 - lessConfigNode.innerHTML = `  
41 - window.less = {  
42 - async: true,  
43 - env: 'production',  
44 - javascriptEnabled: true  
45 - };  
46 - `;  
47 - lessScriptNode.src = 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js';  
48 - lessScriptNode.async = true;  
49 - lessScriptNode.onload = () => {  
50 - buildIt();  
51 - lessScriptNode.onload = null;  
52 - };  
53 - document.body.appendChild(lessStyleNode);  
54 - document.body.appendChild(lessConfigNode);  
55 - document.body.appendChild(lessScriptNode);  
56 - lessNodesAppended = true;  
57 - } else {  
58 - buildIt();  
59 - }  
60 -};  
61 -  
62 -const updateColorWeak = colorWeak => {  
63 - document.body.className = colorWeak ? 'colorWeak' : '';  
64 -};  
65 -  
66 -export default {  
67 - namespace: 'setting',  
68 - state: defaultSettings,  
69 - reducers: {  
70 - getSetting(state) {  
71 - const setting = {};  
72 - const urlParams = new URL(window.location.href);  
73 - Object.keys(state).forEach(key => {  
74 - if (urlParams.searchParams.has(key)) {  
75 - const value = urlParams.searchParams.get(key);  
76 - setting[key] = value === '1' ? true : value;  
77 - }  
78 - });  
79 - const { primaryColor, colorWeak } = setting;  
80 - if (state.primaryColor !== primaryColor) {  
81 - updateTheme(primaryColor);  
82 - }  
83 - updateColorWeak(colorWeak);  
84 - return {  
85 - ...state,  
86 - ...setting,  
87 - };  
88 - },  
89 - changeSetting(state, { payload }) {  
90 - const urlParams = new URL(window.location.href);  
91 - Object.keys(defaultSettings).forEach(key => {  
92 - if (urlParams.searchParams.has(key)) {  
93 - urlParams.searchParams.delete(key);  
94 - }  
95 - });  
96 - Object.keys(payload).forEach(key => {  
97 - if (key === 'collapse') {  
98 - return;  
99 - }  
100 - let value = payload[key];  
101 - if (value === true) {  
102 - value = 1;  
103 - }  
104 - if (defaultSettings[key] !== value) {  
105 - urlParams.searchParams.set(key, value);  
106 - }  
107 - });  
108 - const { primaryColor, colorWeak, contentWidth } = payload;  
109 - if (state.primaryColor !== primaryColor) {  
110 - updateTheme(primaryColor);  
111 - }  
112 - if (state.contentWidth !== contentWidth && window.dispatchEvent) {  
113 - window.dispatchEvent(new Event('resize'));  
114 - }  
115 - updateColorWeak(colorWeak);  
116 - window.history.replaceState(null, 'setting', urlParams.href);  
117 - return {  
118 - ...state,  
119 - ...payload,  
120 - };  
121 - },  
122 - },  
123 -};  
注册登录 后发表评论