Skip to content

优化并解决主题色替换问题 #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"opencollective-postinstall": "^2.0.2",
"vue-svg-icon-loader": "^2.1.1",
"vue-template-compiler": "^2.5.22",
"webpack-theme-color-replacer": "^1.1.5"
"webpack-theme-color-replacer": "^1.2.15"
},
"eslintConfig": {
"root": true,
Expand Down
13 changes: 5 additions & 8 deletions src/components/SettingDrawer/themeColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import client from 'webpack-theme-color-replacer/client'
import generate from '@ant-design/colors/lib/generate'

export default {
primaryColor: '#1890ff', // TODO 需要处理的暗坑
getAntdSerials (color) {
// 淡化(即less的tint)
const lightens = new Array(9).fill().map((t, i) => {
Expand All @@ -13,14 +12,12 @@ export default {
return lightens.concat(colorPalettes)
},
changeColor (newColor) {
var lastColor = this.lastColor || this.primaryColor
var options = {
cssUrl: '/css/theme-colors.css', // TODO 需要处理的暗坑
oldColors: this.getAntdSerials(lastColor), // current colors array. The same as `matchColors`
newColors: this.getAntdSerials(newColor) // new colors array, one-to-one corresponde with `oldColors`
newColors: this.getAntdSerials(newColor), // new colors array, one-to-one corresponde with `matchColors`
changeUrl (cssUrl) {
return `/${cssUrl}` // while router is not `hash` mode, it needs absolute path
}
}
var promise = client.changer.changeColor(options, Promise)
this.lastColor = lastColor
return promise
return client.changer.changeColor(options, Promise)
}
}
2 changes: 1 addition & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
// 生成仅包含颜色的替换样式(主题色等)
// TODO 需要增加根据环境不开启主题需求
new ThemeColorReplacer({
fileName: 'css/theme-colors.css', // TODO 需要处理的暗坑
fileName: 'css/theme-colors-[contenthash:8].css',
matchColors: getAntdSerials('#1890ff'), // 主色系列
// 改变样式选择器,解决样式覆盖问题
changeSelector (selector) {
Expand Down