index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import React, { PureComponent } from 'react';
  2. import { Select, message, Drawer, List, Switch, Divider, Icon, Button, Alert } from 'antd';
  3. import { formatMessage } from 'umi/locale';
  4. import { CopyToClipboard } from 'react-copy-to-clipboard';
  5. import { connect } from 'dva';
  6. import styles from './index.less';
  7. import ThemeColor from './ThemeColor';
  8. import BlockChecbox from './BlockChecbox';
  9. const Body = ({ children, title, style }) => (
  10. <div
  11. style={{
  12. ...style,
  13. marginBottom: 24,
  14. }}
  15. >
  16. <h3 className={styles.title}>{title}</h3>
  17. {children}
  18. </div>
  19. );
  20. @connect(({ setting }) => ({ setting }))
  21. class SettingDrawer extends PureComponent {
  22. getLayOutSetting = () => {
  23. const {
  24. setting: { grid, fixedHeader, layout, autoHideHeader, fixSiderbar },
  25. } = this.props;
  26. return [
  27. {
  28. title: formatMessage({ id: 'app.setting.gridmode' }),
  29. action: [
  30. <Select
  31. value={grid}
  32. size="small"
  33. onSelect={value => this.changeSetting('grid', value)}
  34. style={{ width: 80 }}
  35. >
  36. <Select.Option value="Wide">
  37. {formatMessage({ id: 'app.setting.gridmode.wide' })}
  38. </Select.Option>
  39. <Select.Option value="Fluid">
  40. {formatMessage({ id: 'app.setting.gridmode.fluid' })}
  41. </Select.Option>
  42. </Select>,
  43. ],
  44. },
  45. {
  46. title: formatMessage({ id: 'app.setting.fixedheader' }),
  47. action: [
  48. <Switch
  49. size="small"
  50. checked={!!fixedHeader}
  51. onChange={checked => this.changeSetting('fixedHeader', checked)}
  52. />,
  53. ],
  54. },
  55. {
  56. title: formatMessage({ id: 'app.setting.hideheader' }),
  57. hide: !fixedHeader,
  58. action: [
  59. <Switch
  60. size="small"
  61. checked={!!autoHideHeader}
  62. onChange={checked => this.changeSetting('autoHideHeader', checked)}
  63. />,
  64. ],
  65. },
  66. {
  67. title: formatMessage({ id: 'app.setting.fixedsidebar' }),
  68. hide: layout === 'topmenu',
  69. action: [
  70. <Switch
  71. size="small"
  72. checked={!!fixSiderbar}
  73. onChange={checked => this.changeSetting('fixSiderbar', checked)}
  74. />,
  75. ],
  76. },
  77. ].filter(item => !item.hide);
  78. };
  79. changeSetting = (key, value) => {
  80. const { setting } = this.props;
  81. const nextState = { ...setting };
  82. nextState[key] = value;
  83. if (key === 'layout') {
  84. if (value === 'topmenu') {
  85. nextState.grid = 'Wide';
  86. } else {
  87. nextState.grid = 'Fluid';
  88. }
  89. }
  90. if (key === 'fixedHeader') {
  91. if (!value) {
  92. nextState.autoHideHeader = false;
  93. }
  94. }
  95. this.setState(nextState, () => {
  96. const { dispatch } = this.props;
  97. dispatch({
  98. type: 'setting/changeSetting',
  99. payload: this.state,
  100. });
  101. });
  102. };
  103. togglerContent = () => {
  104. const { setting } = this.props;
  105. this.changeSetting('collapse', !setting.collapse);
  106. };
  107. render() {
  108. const { setting } = this.props;
  109. const { collapse, navTheme, primaryColor, layout, colorWeak } = setting;
  110. return (
  111. <Drawer
  112. visible={collapse}
  113. width={300}
  114. onClose={this.togglerContent}
  115. placement="right"
  116. handler={
  117. <div className={styles.handle}>
  118. {!collapse ? (
  119. <Icon
  120. type="setting"
  121. style={{
  122. color: '#FFF',
  123. fontSize: 20,
  124. }}
  125. />
  126. ) : (
  127. <Icon
  128. type="close"
  129. style={{
  130. color: '#FFF',
  131. fontSize: 20,
  132. }}
  133. />
  134. )}
  135. </div>
  136. }
  137. onHandleClick={this.togglerContent}
  138. style={{
  139. zIndex: 999,
  140. }}
  141. >
  142. <div className={styles.content}>
  143. <Body title={formatMessage({ id: 'app.setting.pagestyle' })}>
  144. <BlockChecbox
  145. list={[
  146. {
  147. key: 'dark',
  148. url: 'https://gw.alipayobjects.com/zos/rmsportal/LCkqqYNmvBEbokSDscrm.svg',
  149. },
  150. {
  151. key: 'light',
  152. url: 'https://gw.alipayobjects.com/zos/rmsportal/jpRkZQMyYRryryPNtyIC.svg',
  153. },
  154. ]}
  155. value={navTheme}
  156. onChange={value => this.changeSetting('navTheme', value)}
  157. />
  158. </Body>
  159. <ThemeColor
  160. title={formatMessage({ id: 'app.setting.themecolor' })}
  161. value={primaryColor}
  162. onChange={color => this.changeSetting('primaryColor', color)}
  163. />
  164. <Divider />
  165. <Body title={formatMessage({ id: 'app.setting.navigationmode' })}>
  166. <BlockChecbox
  167. list={[
  168. {
  169. key: 'sidemenu',
  170. url: 'https://gw.alipayobjects.com/zos/rmsportal/JopDzEhOqwOjeNTXkoje.svg',
  171. },
  172. {
  173. key: 'topmenu',
  174. url: 'https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg',
  175. },
  176. ]}
  177. value={layout}
  178. onChange={value => this.changeSetting('layout', value)}
  179. />
  180. </Body>
  181. <List
  182. split={false}
  183. dataSource={this.getLayOutSetting()}
  184. renderItem={item => <List.Item actions={item.action}>{item.title}</List.Item>}
  185. />
  186. <Divider />
  187. <Body title={formatMessage({ id: 'app.setting.othersettings' })}>
  188. <List.Item
  189. actions={[
  190. <Switch
  191. size="small"
  192. checked={!!colorWeak}
  193. onChange={checked => this.changeSetting('colorWeak', checked)}
  194. />,
  195. ]}
  196. >
  197. {formatMessage({ id: 'app.setting.weakmode' })}
  198. </List.Item>
  199. </Body>
  200. <Divider />
  201. <CopyToClipboard
  202. text={JSON.stringify(setting)}
  203. onCopy={() => message.success(formatMessage({ id: 'app.setting.copyinfo' }))}
  204. >
  205. <Button block icon="copy">
  206. {formatMessage({ id: 'app.setting.copy' })}
  207. </Button>
  208. </CopyToClipboard>
  209. <Alert
  210. type="warning"
  211. className={styles.productionHint}
  212. message={formatMessage({ id: 'app.setting.production.hint' })}
  213. />
  214. </div>
  215. </Drawer>
  216. );
  217. }
  218. }
  219. export default SettingDrawer;