forked from vueComponent/ant-design-vue-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
高性能方案实现ant-design-vue在运行时动态改变主题色(利用webpack-theme-color-replacer)
- Loading branch information
Showing
4 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const client = require('webpack-theme-color-replacer/client') | ||
|
||
export default { | ||
primaryColor: '#1890ff', | ||
getAntdSerials (color) { | ||
// 淡化(即less的tint) | ||
var lightens = new Array(9).fill().map((t, i) => { | ||
return client.varyColor.lighten(color, i / 10) | ||
}) | ||
// 此处为了简化,采用了darken。实际按color.less需求可以引入tinycolor, colorPalette变换得到颜色值 | ||
var darkens = new Array(6).fill().map((t, i) => { | ||
return client.varyColor.darken(color, i / 10) | ||
}) | ||
return lightens.concat(darkens) | ||
}, | ||
changeColor (newColor) { | ||
var lastColor = this.lastColor || this.primaryColor | ||
var options = { | ||
cssUrl: '/css/theme-colors.css', | ||
oldColors: this.getAntdSerials(lastColor), // current colors array. The same as `matchColors` | ||
newColors: this.getAntdSerials(newColor) // new colors array, one-to-one corresponde with `oldColors` | ||
} | ||
var promise = client.changer.changeColor(options) | ||
this.lastColor = lastColor | ||
return promise | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters