jim 7 anni fa
parent
commit
c0bf754654
4 ha cambiato i file con 36 aggiunte e 11 eliminazioni
  1. 2 1
      package.json
  2. 2 5
      src/components/Sidebar/ThemeColor.js
  3. 13 5
      src/components/Sidebar/index.js
  4. 19 0
      webpack.config.js

+ 2 - 1
package.json

@@ -25,11 +25,12 @@
     "@babel/polyfill": "^7.0.0-beta.36",
     "@types/react": "^16.3.8",
     "@types/react-dom": "^16.0.5",
-    "bizcharts-plugin-slider": "^2.0.3",
     "antd": "^3.4.3",
+    "antd-theme-webpack-plugin": "^1.0.8",
     "babel-plugin-transform-decorators-legacy": "^1.3.4",
     "babel-runtime": "^6.9.2",
     "bizcharts": "^3.1.5",
+    "bizcharts-plugin-slider": "^2.0.3",
     "classnames": "^2.2.5",
     "dva": "^2.2.3",
     "dva-loading": "^1.0.4",

+ 2 - 5
src/components/Sidebar/ThemeColor.js

@@ -30,15 +30,12 @@ const ThemeColor = ({ colors, value, onChange }) => {
       '#EB2F96',
     ];
   }
-
   return (
     <div className={styles.themeColor}>
       <h3 className={styles.title}>主题颜色</h3>
-      {colorList.map((color) => {
+      {colorList.map(color => {
         const classname =
-          value === color
-            ? `${styles.colorBlock} ${styles.active}`
-            : styles.colorBlock;
+          value === color ? `${styles.colorBlock} ${styles.active}` : styles.colorBlock;
         return (
           <Tag
             className={classname}

+ 13 - 5
src/components/Sidebar/index.js

@@ -1,5 +1,5 @@
 import React, { PureComponent, Fragment } from 'react';
-import { Select, List, Switch, Divider, Radio } from 'antd';
+import { Select, message, List, Switch, Divider, Radio } from 'antd';
 import DrawerMenu from 'rc-drawer-menu';
 import styles from './index.less';
 import ThemeColor from './ThemeColor';
@@ -133,6 +133,17 @@ class Sidebar extends PureComponent {
   togglerContent = () => {
     this.changeSetting('collapse', !this.state.collapse);
   };
+  colorChange = color => {
+    window.less
+      .modifyVars({
+        '@primary-color': color,
+      })
+      .then(() => {})
+      .catch(() => {
+        message.error(`Failed to update theme`);
+      });
+    this.changeSetting('themeColor', color);
+  };
   render() {
     const radioStyle = {
       display: 'block',
@@ -174,10 +185,7 @@ class Sidebar extends PureComponent {
                   <ColorBlock color="#E9E9E9" title="浅色导航" />
                 </Radio>
               </RadioGroup>
-              <ThemeColor
-                value={this.state.themeColor}
-                onChange={color => this.changeSetting('themeColor', color)}
-              />
+              <ThemeColor value={this.state.themeColor} onChange={this.colorChange} />
             </Body>
             <Divider style={{ margin: 0 }} />
             <Body title="导航设置 ">

+ 19 - 0
webpack.config.js

@@ -0,0 +1,19 @@
+import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
+
+const path = require('path');
+
+export default webpackConfig => {
+  const options = {
+    antDir: path.join(__dirname, './node_modules/antd'),
+    stylesDir: path.join(__dirname, './src'),
+    varFile: path.join(__dirname, './node_modules/antd/lib/style/themes/default.less'),
+    mainLessFile: path.join(__dirname, './src/index.less'),
+    themeVariables: ['@primary-color'],
+    indexFileName: 'index.html',
+  };
+
+  const themePlugin = new AntDesignThemePlugin(options);
+  // in config object
+  webpackConfig.plugins.push(themePlugin);
+  return webpackConfig;
+};