|
|
@@ -4,26 +4,27 @@ import client from 'webpack-theme-color-replacer/client';
|
|
|
import generate from '@ant-design/colors/lib/generate';
|
|
|
|
|
|
export default {
|
|
|
- lastColor: '#1890ff',
|
|
|
- primaryColor: '#1890ff',
|
|
|
- getAntdSerials(color: string) {
|
|
|
+ getAntdSerials(color: string): string[] {
|
|
|
+ const lightCount = 9;
|
|
|
+ const divide = 10;
|
|
|
// 淡化(即less的tint)
|
|
|
- const lightens = new Array(9).fill(0).map((_, i) => client.varyColor.lighten(color, i / 10));
|
|
|
+ let lightens = new Array(lightCount).fill(0);
|
|
|
+ lightens = lightens.map((_, i) => client.varyColor.lighten(color, i / divide));
|
|
|
const colorPalettes = generate(color);
|
|
|
return lightens.concat(colorPalettes);
|
|
|
},
|
|
|
- changeColor(newColor?: string) {
|
|
|
- const lastColor = this.lastColor || this.primaryColor;
|
|
|
+ changeColor(color?: string): Promise<void> {
|
|
|
+ if (!color) {
|
|
|
+ return Promise.resolve();
|
|
|
+ }
|
|
|
const options = {
|
|
|
- // hash模式下用相对路径
|
|
|
- cssUrl: '/css/theme-colors.css',
|
|
|
- // current colors array. The same as `matchColors`
|
|
|
- oldColors: this.getAntdSerials(lastColor),
|
|
|
- // new colors array, one-to-one corresponde with `oldColors`
|
|
|
- newColors: this.getAntdSerials(newColor || this.primaryColor),
|
|
|
+ // new colors array, one-to-one corresponde with `matchColors`
|
|
|
+ newColors: this.getAntdSerials(color),
|
|
|
+ changeUrl(cssUrl: string): string {
|
|
|
+ // while router is not `hash` mode, it needs absolute path
|
|
|
+ return `/${cssUrl}`;
|
|
|
+ },
|
|
|
};
|
|
|
- const promise = client.changer.changeColor(options, Promise);
|
|
|
- this.lastColor = lastColor;
|
|
|
- return promise;
|
|
|
+ return client.changer.changeColor(options, Promise);
|
|
|
},
|
|
|
};
|