import React, { PureComponent } from 'react';
import { Select, message, Drawer, List, Switch, Divider, Icon, Button } from 'antd';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import { connect } from 'dva';
import styles from './index.less';
import ThemeColor from './ThemeColor';
import BlockChecbox from './BlockChecbox';
const Body = ({ children, title, style }) => (
{title}
{children}
);
@connect(({ setting }) => ({ setting }))
class SettingDarwer extends PureComponent {
componentDidMount() {
const {
setting: { themeColor, colorWeak },
} = this.props;
// Determine if the component is remounted
if (themeColor !== '#1890FF' && themeColor !== window['antd_pro_less_color']) {
window.less.refresh().then(() => {
this.colorChange(themeColor);
});
}
if (colorWeak === 'open') {
document.body.className = 'colorWeak';
}
}
getLayOutSetting = () => {
const {
setting: { grid, fixedHeader, autoHideHeader, fixSiderbar },
} = this.props;
return [
{
title: '栅格模式',
action: [
,
],
},
{
title: '固定 Header',
action: [
this.changeSetting('fixedHeader', checked)}
/>,
],
},
{
title: '下滑时隐藏 Header',
hide: !fixedHeader,
action: [
this.changeSetting('autoHideHeader', checked)}
/>,
],
},
{
title: '固定 Siderbar',
action: [
this.changeSetting('fixSiderbar', checked)}
/>,
],
},
].filter(item => {
return !item.hide;
});
};
changeSetting = (key, value) => {
const { setting } = this.props;
const nextState = { ...setting };
nextState[key] = value;
if (key === 'layout') {
if (value === 'topmenu') {
nextState.grid = 'Wide';
} else {
nextState.grid = 'Fluid';
}
}
if (key === 'fixedHeader') {
if (!value) {
nextState.autoHideHeader = false;
}
}
if (key === 'colorWeak') {
if (value) {
document.body.className = 'colorWeak';
} else {
document.body.className = '';
}
}
this.setState(nextState, () => {
const { dispatch } = this.props;
dispatch({
type: 'setting/changeSetting',
payload: this.state,
});
});
};
togglerContent = () => {
const { setting } = this.props;
this.changeSetting('collapse', !setting.collapse);
};
colorChange = color => {
this.changeSetting('themeColor', color);
const hideMessage = message.loading('正在编译主题!', 0);
setTimeout(() => {
window.less
.modifyVars({
'@primary-color': color,
'@input-hover-border-color': color,
})
.then(() => {
window['antd_pro_less_color'] = color;
hideMessage();
})
.catch(() => {
message.error(`Failed to update theme`);
});
}, 200);
};
render() {
const { setting } = this.props;
const { collapse, silderTheme, themeColor, layout, colorWeak } = setting;
return (
{!collapse ? (
) : (
)}
this.changeSetting('silderTheme', value)}
/>
this.changeSetting('layout', value)}
/>
{item.title}}
/>
this.changeSetting('colorWeak', checked)}
/>,
]}
>
色弱模式
message.success('copy success')}
>
);
}
}
export default SettingDarwer;