mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 20:19:44 +08:00
fix: localStorage
This commit is contained in:
parent
7acab87a03
commit
60eca31754
@ -34,7 +34,6 @@
|
||||
&,
|
||||
.code-box-demo {
|
||||
background-color: @component-background;
|
||||
border-bottom: 1px solid @border-color-base;
|
||||
}
|
||||
.markdown {
|
||||
code {
|
||||
|
@ -53,6 +53,8 @@ enquireScreen(b => {
|
||||
isMobile = b;
|
||||
});
|
||||
|
||||
const SITE_THEME_STORE_KEY = 'site-theme';
|
||||
|
||||
export default class Layout extends React.Component {
|
||||
static contextTypes = {
|
||||
router: PropTypes.object.isRequired,
|
||||
@ -72,7 +74,10 @@ export default class Layout extends React.Component {
|
||||
this.state = {
|
||||
appLocale,
|
||||
isMobile,
|
||||
theme: 'default',
|
||||
theme:
|
||||
typeof localStorage !== 'undefined'
|
||||
? localStorage.getItem(SITE_THEME_STORE_KEY) || 'default'
|
||||
: 'default',
|
||||
setTheme: this.setTheme,
|
||||
};
|
||||
}
|
||||
@ -83,6 +88,7 @@ export default class Layout extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { theme } = this.state;
|
||||
const { router } = this.context;
|
||||
router.listen(loc => {
|
||||
if (typeof window.ga !== 'undefined') {
|
||||
@ -95,6 +101,8 @@ export default class Layout extends React.Component {
|
||||
}
|
||||
});
|
||||
|
||||
this.setTheme(theme);
|
||||
|
||||
const nprogressHiddenStyle = document.getElementById('nprogress-style');
|
||||
if (nprogressHiddenStyle) {
|
||||
this.timer = setTimeout(() => {
|
||||
@ -122,7 +130,7 @@ export default class Layout extends React.Component {
|
||||
if (dom) {
|
||||
dom.remove();
|
||||
}
|
||||
localStorage.removeItem('site-theme');
|
||||
localStorage.removeItem(SITE_THEME_STORE_KEY);
|
||||
} else {
|
||||
const style = document.createElement('link');
|
||||
style.type = 'text/css';
|
||||
@ -130,7 +138,7 @@ export default class Layout extends React.Component {
|
||||
style.id = 'theme-style';
|
||||
style.href = '/dark.css';
|
||||
|
||||
localStorage.setItem('site-theme', 'dark');
|
||||
localStorage.setItem(SITE_THEME_STORE_KEY, 'dark');
|
||||
document.body.append(style);
|
||||
}
|
||||
document.body.setAttribute('data-theme', theme);
|
||||
|
Loading…
Reference in New Issue
Block a user