Skip to content

Commit dea146c

Browse files
authored
Merge pull request #293 from hzsrc/master
fix: 优化并解决主题色替换问题 fix(package): webpack-theme-color-replacer
2 parents 3e24d0e + 1b9d554 commit dea146c

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"opencollective-postinstall": "^2.0.2",
5858
"vue-svg-icon-loader": "^2.1.1",
5959
"vue-template-compiler": "^2.5.22",
60-
"webpack-theme-color-replacer": "^1.1.5"
60+
"webpack-theme-color-replacer": "^1.2.15"
6161
},
6262
"eslintConfig": {
6363
"root": true,

src/components/SettingDrawer/themeColor.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import client from 'webpack-theme-color-replacer/client'
22
import generate from '@ant-design/colors/lib/generate'
33

44
export default {
5-
primaryColor: '#1890ff', // TODO 需要处理的暗坑
65
getAntdSerials (color) {
76
// 淡化(即less的tint)
87
const lightens = new Array(9).fill().map((t, i) => {
@@ -13,14 +12,12 @@ export default {
1312
return lightens.concat(colorPalettes)
1413
},
1514
changeColor (newColor) {
16-
var lastColor = this.lastColor || this.primaryColor
1715
var options = {
18-
cssUrl: '/css/theme-colors.css', // TODO 需要处理的暗坑
19-
oldColors: this.getAntdSerials(lastColor), // current colors array. The same as `matchColors`
20-
newColors: this.getAntdSerials(newColor) // new colors array, one-to-one corresponde with `oldColors`
16+
newColors: this.getAntdSerials(newColor), // new colors array, one-to-one corresponde with `matchColors`
17+
changeUrl (cssUrl) {
18+
return `/${cssUrl}` // while router is not `hash` mode, it needs absolute path
19+
}
2120
}
22-
var promise = client.changer.changeColor(options, Promise)
23-
this.lastColor = lastColor
24-
return promise
21+
return client.changer.changeColor(options, Promise)
2522
}
2623
}

vue.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
// 生成仅包含颜色的替换样式(主题色等)
1717
// TODO 需要增加根据环境不开启主题需求
1818
new ThemeColorReplacer({
19-
fileName: 'css/theme-colors.css', // TODO 需要处理的暗坑
19+
fileName: 'css/theme-colors-[contenthash:8].css',
2020
matchColors: getAntdSerials('#1890ff'), // 主色系列
2121
// 改变样式选择器,解决样式覆盖问题
2222
changeSelector (selector) {

0 commit comments

Comments
 (0)