Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
钟摆人-Puppet゜
ant-design-pro
提交
f07927f8
A
ant-design-pro
项目概览
钟摆人-Puppet゜
/
ant-design-pro
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ant-design-pro
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f07927f8
编写于
7月 01, 2018
作者:
陈
陈帅
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Increase dynamic switching local
上级
5bf31a42
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
34 deletion
+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
未找到文件。
src/components/GlobalHeader/RightContent.js
浏览文件 @
f07927f8
...
...
@@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
import
{
Spin
,
Tag
,
Menu
,
Icon
,
Dropdown
,
Avatar
,
Tooltip
,
Button
}
from
'
antd
'
;
import
moment
from
'
moment
'
;
import
groupBy
from
'
lodash/groupBy
'
;
import
LocaleContext
from
'
../../locale/localeContext
'
;
import
NoticeIcon
from
'
../NoticeIcon
'
;
import
HeaderSearch
from
'
../HeaderSearch
'
;
import
styles
from
'
./index.less
'
;
...
...
@@ -47,7 +48,6 @@ export default class GlobalHeaderRight extends PureComponent {
}
else
{
localStorage
.
setItem
(
'
locale
'
,
'
zh-CN
'
);
}
location
.
reload
();
};
render
()
{
...
...
@@ -153,9 +153,21 @@ export default class GlobalHeaderRight extends PureComponent {
)
:
(
<
Spin
size
=
"
small
"
style
=
{{
marginLeft
:
8
,
marginRight
:
8
}}
/
>
)}
<
Button
size
=
"
small
"
onClick
=
{
this
.
changLang
}
>
<
FormattedMessage
id
=
"
navbar.lang
"
/>
<
/Button
>
<
LocaleContext
.
Consumer
>
{
context
=>
{
return
(
<
Button
size
=
"
small
"
onClick
=
{()
=>
{
this
.
changLang
();
context
.
changeLocal
();
}}
>
<
FormattedMessage
id
=
"
navbar.lang
"
/>
<
/Button
>
);
}}
<
/LocaleContext.Consumer
>
<
/div
>
);
}
...
...
src/locale/localeContext.js
0 → 100644
浏览文件 @
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
浏览文件 @
f07927f8
import
React
from
'
react
'
;
import
{
routerRedux
,
Route
,
Switch
}
from
'
dva/router
'
;
import
{
LocaleProvider
,
Spin
}
from
'
antd
'
;
import
{
Spin
}
from
'
antd
'
;
import
dynamic
from
'
dva/dynamic
'
;
import
{
addLocaleData
,
IntlProvider
}
from
'
react-intl
'
;
import
{
LocalComponent
}
from
'
./locale/localeContext
'
;
import
{
getRouterData
}
from
'
./common/router
'
;
import
Authorized
from
'
./utils/Authorized
'
;
import
{
getQueryPath
}
from
'
./utils/utils
'
;
import
styles
from
'
./index.less
'
;
import
enLocale
from
'
./locale/en-US
'
;
import
cnLocale
from
'
./locale/zh-CN
'
;
const
{
ConnectedRouter
}
=
routerRedux
;
const
{
AuthorizedRoute
}
=
Authorized
;
...
...
@@ -17,37 +15,25 @@ dynamic.setDefaultLoadingComponent(() => {
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
})
{
const
routerData
=
getRouterData
(
app
);
const
UserLayout
=
routerData
[
'
/user
'
].
component
;
const
BasicLayout
=
routerData
[
'
/
'
].
component
;
const
appLocale
=
getLang
()
===
'
zh-CN
'
?
cnLocale
:
enLocale
;
addLocaleData
(
appLocale
.
data
);
return
(
<
IntlProvider
locale
=
{
appLocale
.
locale
}
messages
=
{
appLocale
.
messages
}
>
<
LocaleProvider
locale
=
{
appLocale
.
antd
}
>
<
ConnectedRouter
history
=
{
history
}
>
<
Switch
>
<
Route
path
=
"
/user
"
component
=
{
UserLayout
}
/
>
<
AuthorizedRoute
path
=
"
/
"
render
=
{
props
=>
<
BasicLayout
{...
props
}
/>
}
authority
=
{[
'
admin
'
,
'
user
'
]}
redirectPath
=
"
/user/login
"
/>
<
/Switch
>
<
/ConnectedRouter
>
<
/LocaleProvider
>
<
/IntlProvider
>
<
LocalComponent
>
<
ConnectedRouter
history
=
{
history
}
>
<
Switch
>
<
Route
path
=
"
/user
"
component
=
{
UserLayout
}
/
>
<
AuthorizedRoute
path
=
"
/
"
render
=
{
props
=>
<
BasicLayout
{...
props
}
/>
}
authority
=
{[
'
admin
'
,
'
user
'
]}
redirectPath
=
"
/user/login
"
/>
<
/Switch
>
<
/ConnectedRouter
>
<
/LocalComponent
>
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录