|
|
@@ -26,6 +26,7 @@ moment.locale('en');
|
|
|
class App extends Component {
|
|
|
constructor() {
|
|
|
super();
|
|
|
+ sessionStorage.setItem("language","English");
|
|
|
this.state = {
|
|
|
menuLevel1: "trail",
|
|
|
sideBar: "e-commerce",
|
|
|
@@ -37,7 +38,8 @@ class App extends Component {
|
|
|
},
|
|
|
collapsed: false,
|
|
|
inlineCollapsed: false,
|
|
|
- locale: null,
|
|
|
+ locale: undefined,
|
|
|
+ language: sessionStorage.getItem("language")
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -54,9 +56,19 @@ class App extends Component {
|
|
|
};
|
|
|
|
|
|
changeLocale = (e) => {
|
|
|
- const localeValue = e.target.value;
|
|
|
- this.setState({locale: localeValue});
|
|
|
- if (!localeValue) {
|
|
|
+ e.stopPropagation();
|
|
|
+ let language = sessionStorage.getItem("language");
|
|
|
+ console.log('now language',language);
|
|
|
+ let local = language === "中文" ? zhCN : undefined;
|
|
|
+ console.log('local',local);
|
|
|
+ let changeLanguage = language === "中文" ? "English" : "中文";
|
|
|
+ console.log('changeLanguage',changeLanguage);
|
|
|
+ sessionStorage.setItem("language",changeLanguage);
|
|
|
+ this.setState({
|
|
|
+ language:changeLanguage,
|
|
|
+ locale:local
|
|
|
+ });
|
|
|
+ if (!local) {
|
|
|
moment.locale('en');
|
|
|
} else {
|
|
|
moment.locale('zh-cn');
|
|
|
@@ -117,6 +129,8 @@ class App extends Component {
|
|
|
};
|
|
|
|
|
|
render() {
|
|
|
+ const { locale,language } = this.state;
|
|
|
+ console.log('locale1',locale);
|
|
|
return (
|
|
|
<Router>
|
|
|
<Layout style={{minHeight: '100vh'}}>
|
|
|
@@ -136,38 +150,34 @@ class App extends Component {
|
|
|
<Menu.Item key="cloud-function"><Link to="/cloud-function">Cloud Function</Link></Menu.Item>
|
|
|
<Menu.Item key="data-storage"><Link to="/data-storage/">Data Storage</Link></Menu.Item>
|
|
|
<Menu.Item key="data-analysis"><Link to="/data-analysis/">Data Analysis</Link></Menu.Item>
|
|
|
- <Menu.Item key="monitor-notification"><Link to="/monitor-notification/">Monitor
|
|
|
- Notification</Link></Menu.Item>
|
|
|
+ <Menu.Item key="monitor-notification"><Link to="/monitor-notification/">Monitor Notification</Link></Menu.Item>
|
|
|
</Menu>
|
|
|
|
|
|
- {/*<div className="change-locale">*/}
|
|
|
- {/*<span style={{ marginRight: 16 }}>Change locale of components: </span>*/}
|
|
|
- {/*<Radio.Group defaultValue={undefined} onChange={this.changeLocale}>*/}
|
|
|
- {/*<Radio.Button key="en" value={undefined}>English</Radio.Button>*/}
|
|
|
- {/*<Radio.Button key="cn" value={zhCN}>中文</Radio.Button>*/}
|
|
|
- {/*</Radio.Group>*/}
|
|
|
- {/*</div>*/}
|
|
|
+ <div className="change-locale">
|
|
|
+ <Button size="small" onClick={(e)=>this.changeLocale(e)}>{language}</Button>
|
|
|
+ </div>
|
|
|
+
|
|
|
{/*<div className='login'>*/}
|
|
|
- {/*{*/}
|
|
|
- {/*this.state.hasLogin ?*/}
|
|
|
- {/*this.login(this.state.userID)*/}
|
|
|
- {/*:*/}
|
|
|
- {/*<div>*/}
|
|
|
- {/*<span style={{marginRight: 20}}>login:</span>*/}
|
|
|
- {/*<Input*/}
|
|
|
- {/*placeholder="id, eg: 'xy_1'"*/}
|
|
|
- {/*onChange={(e) => {*/}
|
|
|
- {/*// antd 获取不到 target,百度来的下面这句代码*/}
|
|
|
- {/*e.persist();*/}
|
|
|
- {/*this.setState({userID: e.target.value});*/}
|
|
|
- {/*}}*/}
|
|
|
- {/*onPressEnter={() => {*/}
|
|
|
- {/*this.setState({hasLogin: true})*/}
|
|
|
- {/*}}*/}
|
|
|
- {/*style={{width: 200}}*/}
|
|
|
- {/*/>*/}
|
|
|
- {/*</div>*/}
|
|
|
- {/*}*/}
|
|
|
+ {/*{*/}
|
|
|
+ {/*this.state.hasLogin ?*/}
|
|
|
+ {/*this.login(this.state.userID)*/}
|
|
|
+ {/*:*/}
|
|
|
+ {/*<div>*/}
|
|
|
+ {/*<span style={{marginRight: 20}}>login:</span>*/}
|
|
|
+ {/*<Input*/}
|
|
|
+ {/*placeholder="id, eg: 'xy_1'"*/}
|
|
|
+ {/*onChange={(e) => {*/}
|
|
|
+ {/*// antd 获取不到 target,百度来的下面这句代码*/}
|
|
|
+ {/*e.persist();*/}
|
|
|
+ {/*this.setState({userID: e.target.value});*/}
|
|
|
+ {/*}}*/}
|
|
|
+ {/*onPressEnter={() => {*/}
|
|
|
+ {/*this.setState({hasLogin: true})*/}
|
|
|
+ {/*}}*/}
|
|
|
+ {/*style={{width: 200}}*/}
|
|
|
+ {/*/>*/}
|
|
|
+ {/*</div>*/}
|
|
|
+ {/*}*/}
|
|
|
{/*</div>*/}
|
|
|
</Header>
|
|
|
|
|
|
@@ -266,16 +276,19 @@ class App extends Component {
|
|
|
</Menu>
|
|
|
</Sider>
|
|
|
|
|
|
- <Layout style={{marginTop: '64px', zIndex: '0'}}>
|
|
|
- <Switch>
|
|
|
- <Route path="/" exact component={TrialCase}/>
|
|
|
- <Route path="/cloud-function" component={CloudFunction}/>
|
|
|
- <Route path="/data-storage/" component={DataStorage}/>
|
|
|
- <Route path="/data-analysis/" component={DataAnalysis}/>
|
|
|
- <Route path="/monitor-notification/" component={MonitorNotify}/>
|
|
|
- <Redirect path="*" to="/"/>
|
|
|
- </Switch>
|
|
|
- </Layout>
|
|
|
+ <LocaleProvider locale={locale}>
|
|
|
+ <Layout style={{marginTop: '64px', zIndex: '0'}} key={locale ? locale.locale : 'en'/* Have to refresh for production environment */} >
|
|
|
+ <Switch>
|
|
|
+ <Route path="/" exact component={TrialCase}/>
|
|
|
+ <Route path="/cloud-function" component={CloudFunction}/>
|
|
|
+ <Route path="/data-storage/" component={DataStorage}/>
|
|
|
+ <Route path="/data-analysis/" component={DataAnalysis}/>
|
|
|
+ <Route path="/monitor-notification/" component={MonitorNotify}/>
|
|
|
+ <Redirect path="*" to="/"/>
|
|
|
+ </Switch>
|
|
|
+ </Layout>
|
|
|
+ </LocaleProvider>
|
|
|
+
|
|
|
</Layout>
|
|
|
</Router>
|
|
|
);
|