Skip to content

Commit c0a7ea1

Browse files
committed
优化并解决主题色替换问题
1 parent 4d33fae commit c0a7ea1

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.13"
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',
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',
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
@@ -29,7 +29,7 @@ module.exports = {
2929
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
3030
// 生成仅包含颜色的替换样式(主题色等)
3131
new ThemeColorReplacer({
32-
fileName: 'css/theme-colors.css',
32+
fileName: 'css/theme-colors-[contenthash:8].css',
3333
matchColors: getAntdSerials('#1890ff'), // 主色系列
3434
// 改变样式选择器,解决样式覆盖问题
3535
changeSelector (selector) {

0 commit comments

Comments
 (0)