Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
f07927f8
Commit
f07927f8
authored
Jul 01, 2018
by
ιεΈ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increase dynamic switching local
parent
5bf31a42
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
34 deletions
+85
-34
src/components/GlobalHeader/RightContent.js
src/components/GlobalHeader/RightContent.js
+16
-4
src/locale/localeContext.js
src/locale/localeContext.js
+53
-0
src/router.js
src/router.js
+16
-30
No files found.
src/components/GlobalHeader/RightContent.js
View file @
f07927f8
...
@@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
...
@@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
import
{
Spin
,
Tag
,
Menu
,
Icon
,
Dropdown
,
Avatar
,
Tooltip
,
Button
}
from
'
antd
'
;
import
{
Spin
,
Tag
,
Menu
,
Icon
,
Dropdown
,
Avatar
,
Tooltip
,
Button
}
from
'
antd
'
;
import
moment
from
'
moment
'
;
import
moment
from
'
moment
'
;
import
groupBy
from
'
lodash/groupBy
'
;
import
groupBy
from
'
lodash/groupBy
'
;
import
LocaleContext
from
'
../../locale/localeContext
'
;
import
NoticeIcon
from
'
../NoticeIcon
'
;
import
NoticeIcon
from
'
../NoticeIcon
'
;
import
HeaderSearch
from
'
../HeaderSearch
'
;
import
HeaderSearch
from
'
../HeaderSearch
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
...
@@ -47,7 +48,6 @@ export default class GlobalHeaderRight extends PureComponent {
...
@@ -47,7 +48,6 @@ export default class GlobalHeaderRight extends PureComponent {
}
else
{
}
else
{
localStorage
.
setItem
(
'
locale
'
,
'
zh-CN
'
);
localStorage
.
setItem
(
'
locale
'
,
'
zh-CN
'
);
}
}
location
.
reload
();
};
};
render
()
{
render
()
{
...
@@ -153,9 +153,21 @@ export default class GlobalHeaderRight extends PureComponent {
...
@@ -153,9 +153,21 @@ export default class GlobalHeaderRight extends PureComponent {
)
:
(
)
:
(
<
Spin
size
=
"
small
"
style
=
{{
marginLeft
:
8
,
marginRight
:
8
}}
/
>
<
Spin
size
=
"
small
"
style
=
{{
marginLeft
:
8
,
marginRight
:
8
}}
/
>
)}
)}
<
Button
size
=
"
small
"
onClick
=
{
this
.
changLang
}
>
<
LocaleContext
.
Consumer
>
<
FormattedMessage
id
=
"
navbar.lang
"
/>
{
context
=>
{
<
/Button
>
return
(
<
Button
size
=
"
small
"
onClick
=
{()
=>
{
this
.
changLang
();
context
.
changeLocal
();
}}
>
<
FormattedMessage
id
=
"
navbar.lang
"
/>
<
/Button
>
);
}}
<
/LocaleContext.Consumer
>
<
/div
>
<
/div
>
);
);
}
}
...
...
src/locale/localeContext.js
0 β 100644
View file @
f07927f8
import
React
from
'
react
'
;
import
{
addLocaleData
,
IntlProvider
}
from
'
react-intl
'
;
import
{
LocaleProvider
}
from
'
antd
'
;
import
enLocale
from
'
./en-US
'
;
import
cnLocale
from
'
./zh-CN
'
;
const
Context
=
React
.
createContext
();
function
getLang
()
{
if
(
window
.
localStorage
&&
localStorage
.
getItem
(
'
locale
'
))
{
return
localStorage
.
getItem
(
'
locale
'
);
}
return
(
navigator
.
language
||
navigator
.
browserLanguage
).
toLowerCase
()
===
'
en-us
'
?
'
en-US
'
:
'
zh-CN
'
;
}
export
class
LocalComponent
extends
React
.
PureComponent
{
state
=
{
locale
:
getLang
(),
};
changeLocal
=
()
=>
{
this
.
setState
({
locale
:
getLang
(),
});
};
render
()
{
const
{
children
}
=
this
.
props
;
const
{
locale
}
=
this
.
state
;
return
(
<
Context
.
Provider
value
=
{{
appLocale
:
locale
===
'
zh-CN
'
?
cnLocale
:
enLocale
,
changeLocal
:
this
.
changeLocal
,
}}
>
<
Context
.
Consumer
>
{({
appLocale
})
=>
{
addLocaleData
(
appLocale
.
data
);
return
(
<
IntlProvider
locale
=
{
appLocale
.
locale
}
messages
=
{
appLocale
.
messages
}
>
<
LocaleProvider
locale
=
{
appLocale
.
antd
}
>
{
children
}
<
/LocaleProvider
>
<
/IntlProvider
>
);
}}
<
/Context.Consumer
>
<
/Context.Provider
>
);
}
}
export
default
Context
;
src/router.js
View file @
f07927f8
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
{
Spin
}
from
'
antd
'
;
import
dynamic
from
'
dva/dynamic
'
;
import
dynamic
from
'
dva/dynamic
'
;
import
{
addLocaleData
,
IntlProvider
}
from
'
react-intl
'
;
import
{
LocalComponent
}
from
'
./locale/localeContext
'
;
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
;
...
@@ -17,37 +15,25 @@ dynamic.setDefaultLoadingComponent(() => {
...
@@ -17,37 +15,25 @@ dynamic.setDefaultLoadingComponent(() => {
return
<
Spin
size
=
"
large
"
className
=
{
styles
.
globalSpin
}
/>
;
return
<
Spin
size
=
"
large
"
className
=
{
styles
.
globalSpin
}
/>
;
});
});
function
getLang
()
{
if
(
window
.
localStorage
&&
localStorage
.
getItem
(
'
locale
'
))
{
return
localStorage
.
getItem
(
'
locale
'
);
}
return
(
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
(
<
IntlProvider
locale
=
{
appLocale
.
locale
}
messages
=
{
appLocale
.
messages
}
>
<
LocalComponent
>
<
LocaleProvider
locale
=
{
appLocale
.
antd
}
>
<
ConnectedRouter
history
=
{
history
}
>
<
ConnectedRouter
history
=
{
history
}
>
<
Switch
>
<
Switch
>
<
Route
path
=
"
/user
"
component
=
{
UserLayout
}
/
>
<
Route
path
=
"
/user
"
component
=
{
UserLayout
}
/
>
<
AuthorizedRoute
<
AuthorizedRoute
path
=
"
/
"
path
=
"
/
"
render
=
{
props
=>
<
BasicLayout
{...
props
}
/>
}
render
=
{
props
=>
<
BasicLayout
{...
props
}
/>
}
authority
=
{[
'
admin
'
,
'
user
'
]}
authority
=
{[
'
admin
'
,
'
user
'
]}
redirectPath
=
"
/user/login
"
redirectPath
=
"
/user/login
"
/>
/>
<
/Switch
>
<
/Switch
>
<
/ConnectedRouter
>
<
/ConnectedRouter
>
<
/LocalComponent
>
<
/LocaleProvider
>
<
/IntlProvider
>
);
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment