Commit 663e34ab authored by ddcat1115's avatar ddcat1115 Committed by 陈帅

base framework

parent 85e9fa71
import appLocaleData from 'react-intl/locale-data/en';
import antdEn from 'antd/lib/locale-provider/en_US';
// import enMessages from '../../locales/en.json';
export default {
locale: 'en-US',
data: appLocaleData,
antd: antdEn,
messages: {
'app.home.introduce': 'introduce',
'app.analysis.test': 'Gongzhuan road No.{no} shop',
// ...enMessages,
},
};
import appLocaleData from 'react-intl/locale-data/zh';
import antdZh from 'antd/lib/locale-provider/zh_CN';
// import zhMessages from '../../locales/zh.json';
export default {
locale: 'zh-CN',
data: appLocaleData,
antd: antdZh,
messages: {
'app.home.introduce': '介绍',
'app.analysis.test': '工专路 {no} 号店',
// ...zhMessages,
},
};
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'dva'; import { connect } from 'dva';
import { injectIntl } from 'react-intl';
import { import {
Row, Row,
Col, Col,
...@@ -47,7 +48,23 @@ for (let i = 0; i < 7; i += 1) { ...@@ -47,7 +48,23 @@ for (let i = 0; i < 7; i += 1) {
chart, chart,
loading: loading.effects['chart/fetch'], loading: loading.effects['chart/fetch'],
})) }))
export default class Analysis extends Component { class Analysis extends Component {
constructor(props) {
super(props);
const { intl } = props;
this.rankingListData = [];
for (let i = 0; i < 7; i += 1) {
this.rankingListData.push({
title: intl.formatMessage({ id: 'app.analysis.test' }, { no: i }),
total: 323234,
});
}
this.state = {
salesType: 'all',
currentTabKey: '',
rangePickerValue: getTimeDistance('year'),
};
}
state = { state = {
salesType: 'all', salesType: 'all',
currentTabKey: '', currentTabKey: '',
...@@ -354,7 +371,7 @@ export default class Analysis extends Component { ...@@ -354,7 +371,7 @@ export default class Analysis extends Component {
<div className={styles.salesRank}> <div className={styles.salesRank}>
<h4 className={styles.rankingTitle}>门店销售额排名</h4> <h4 className={styles.rankingTitle}>门店销售额排名</h4>
<ul className={styles.rankingList}> <ul className={styles.rankingList}>
{rankingListData.map((item, i) => ( {this.rankingListData.map((item, i) => (
<li key={item.title}> <li key={item.title}>
<span className={i < 3 ? styles.active : ''}>{i + 1}</span> <span className={i < 3 ? styles.active : ''}>{i + 1}</span>
<span>{item.title}</span> <span>{item.title}</span>
...@@ -377,7 +394,7 @@ export default class Analysis extends Component { ...@@ -377,7 +394,7 @@ export default class Analysis extends Component {
<div className={styles.salesRank}> <div className={styles.salesRank}>
<h4 className={styles.rankingTitle}>门店访问量排名</h4> <h4 className={styles.rankingTitle}>门店访问量排名</h4>
<ul className={styles.rankingList}> <ul className={styles.rankingList}>
{rankingListData.map((item, i) => ( {this.rankingListData.map((item, i) => (
<li key={item.title}> <li key={item.title}>
<span className={i < 3 ? styles.active : ''}>{i + 1}</span> <span className={i < 3 ? styles.active : ''}>{i + 1}</span>
<span>{item.title}</span> <span>{item.title}</span>
...@@ -503,3 +520,5 @@ export default class Analysis extends Component { ...@@ -503,3 +520,5 @@ export default class Analysis extends Component {
); );
} }
} }
export default injectIntl(Analysis);
import React from 'react'; import React from 'react';
import { routerRedux, Route, 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 dynamic from 'dva/dynamic'; import dynamic from 'dva/dynamic';
import { addLocaleData, IntlProvider } from 'react-intl';
import { getRouterData } from './common/router'; import { getRouterData } from './common/router';
import Authorized from './utils/Authorized'; import Authorized from './utils/Authorized';
import { getQueryPath } from './utils/utils'; import { getQueryPath } from './utils/utils';
import styles from './index.less'; import styles from './index.less';
import enLocale from './locale/en-US';
import cnLocale from './locale/zh-CN';
const { ConnectedRouter } = routerRedux; const { ConnectedRouter } = routerRedux;
const { AuthorizedRoute } = Authorized; const { AuthorizedRoute } = Authorized;
...@@ -14,12 +16,22 @@ dynamic.setDefaultLoadingComponent(() => { ...@@ -14,12 +16,22 @@ dynamic.setDefaultLoadingComponent(() => {
return <Spin size="large" className={styles.globalSpin} />; return <Spin size="large" className={styles.globalSpin} />;
}); });
function getLang() {
return (window.localStorage && localStorage.getItem('locale')) ||
(navigator.language || navigator.browserLanguage).toLowerCase() === 'en-us'
? 'en-US'
: 'zh-CN';
}
function RouterConfig({ history, app }) { function RouterConfig({ history, app }) {
const routerData = getRouterData(app); const routerData = getRouterData(app);
const UserLayout = routerData['/user'].component; const UserLayout = routerData['/user'].component;
const BasicLayout = routerData['/'].component; const BasicLayout = routerData['/'].component;
const appLocale = getLang() === 'zh-CN' ? cnLocale : enLocale;
addLocaleData(appLocale.data);
return ( return (
<LocaleProvider locale={zhCN}> <IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
<LocaleProvider locale={appLocale.antd}>
<ConnectedRouter history={history}> <ConnectedRouter history={history}>
<Switch> <Switch>
<Route path="/user" component={UserLayout} /> <Route path="/user" component={UserLayout} />
...@@ -27,13 +39,12 @@ function RouterConfig({ history, app }) { ...@@ -27,13 +39,12 @@ function RouterConfig({ history, app }) {
path="/" path="/"
render={props => <BasicLayout {...props} />} render={props => <BasicLayout {...props} />}
authority={['admin', 'user']} authority={['admin', 'user']}
redirectPath={getQueryPath('/user/login', { redirectPath="/user/login"
redirect: window.location.href,
})}
/> />
</Switch> </Switch>
</ConnectedRouter> </ConnectedRouter>
</LocaleProvider> </LocaleProvider>
</IntlProvider>
); );
} }
......
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