import { ConnectProps, ConnectState, SettingModelState } from '@/models/connect'; import React, { Component } from 'react'; import { Select, message, Drawer, List, Switch, Divider, Icon, Button, Alert, Tooltip } from 'antd'; import { formatMessage } from 'umi-plugin-locale'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import { connect } from 'dva'; import omit from 'omit.js'; import styles from './index.less'; import ThemeColor from './ThemeColor'; import BlockCheckbox from './BlockCheckbox'; const { Option } = Select; interface BodyProps { title: string; style?: React.CSSProperties; } const Body: React.FC = ({ children, title, style }) => (

{title}

{children}
); interface SettingItemProps { title: React.ReactNode; action: React.ReactElement; disabled?: boolean; disabledReason?: React.ReactNode; } export interface SettingDrawerProps extends ConnectProps { setting?: SettingModelState; } export interface SettingDrawerState extends Partial { collapse: boolean; } @connect(({ setting }: ConnectState) => ({ setting })) class SettingDrawer extends Component { state: SettingDrawerState = { collapse: false, }; getLayoutSetting = (): SettingItemProps[] => { const { setting } = this.props; const { contentWidth, fixedHeader, layout, autoHideHeader, fixSiderbar } = setting!; return [ { title: formatMessage({ id: 'app.setting.content-width' }), action: ( ), }, { title: formatMessage({ id: 'app.setting.fixedheader' }), action: ( this.changeSetting('fixedHeader', checked)} /> ), }, { title: formatMessage({ id: 'app.setting.hideheader' }), disabled: !fixedHeader, disabledReason: formatMessage({ id: 'app.setting.hideheader.hint' }), action: ( this.changeSetting('autoHideHeader', checked)} /> ), }, { title: formatMessage({ id: 'app.setting.fixedsidebar' }), disabled: layout === 'topmenu', disabledReason: formatMessage({ id: 'app.setting.fixedsidebar.hint' }), action: ( this.changeSetting('fixSiderbar', checked)} /> ), }, ]; }; changeSetting = (key: string, value: any) => { const { setting } = this.props; const nextState = { ...setting! }; nextState[key] = value; if (key === 'layout') { nextState.contentWidth = value === 'topmenu' ? 'Fixed' : 'Fluid'; } else if (key === 'fixedHeader' && !value) { nextState.autoHideHeader = false; } this.setState(nextState, () => { const { dispatch } = this.props; dispatch!({ type: 'setting/changeSetting', payload: this.state, }); }); }; togglerContent = () => { const { collapse } = this.state; this.setState({ collapse: !collapse }); }; renderLayoutSettingItem = (item: SettingItemProps) => { const action = React.cloneElement(item.action, { disabled: item.disabled, }); return ( {item.title} ); }; render() { const { setting } = this.props; const { navTheme, primaryColor, layout, colorWeak } = setting!; const { collapse } = this.state; return ( } style={{ zIndex: 999 }} >
this.changeSetting('navTheme', value)} /> this.changeSetting('primaryColor', color)} /> this.changeSetting('layout', value)} /> this.changeSetting('colorWeak', checked)} />, ]} > {formatMessage({ id: 'app.setting.weakmode' })} message.success(formatMessage({ id: 'app.setting.copyinfo' }))} > {formatMessage({ id: 'app.setting.production.hint' })}{' '} src/defaultSettings.js
} />
); } } export default SettingDrawer;