Skip to content

Commit 4d33fae

Browse files
committed
引入@ant-design/colors得到colorPalette变换的颜色值
1 parent 4582b94 commit 4d33fae

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"wangeditor": "^3.1.1"
3737
},
3838
"devDependencies": {
39+
"@ant-design/colors": "^3.1.0",
3940
"@babel/polyfill": "^7.2.5",
4041
"@vue/cli-plugin-babel": "^3.7.0",
4142
"@vue/cli-plugin-eslint": "^3.7.0",
@@ -56,7 +57,7 @@
5657
"opencollective-postinstall": "^2.0.2",
5758
"vue-svg-icon-loader": "^2.1.1",
5859
"vue-template-compiler": "^2.5.22",
59-
"webpack-theme-color-replacer": "^1.1.4"
60+
"webpack-theme-color-replacer": "^1.1.5"
6061
},
6162
"eslintConfig": {
6263
"root": true,

src/components/SettingDrawer/themeColor.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
const client = require('webpack-theme-color-replacer/client')
1+
import client from 'webpack-theme-color-replacer/client'
2+
import generate from '@ant-design/colors/lib/generate'
23

34
export default {
45
primaryColor: '#1890ff',
56
getAntdSerials (color) {
67
// 淡化(即less的tint)
7-
var lightens = new Array(9).fill().map((t, i) => {
8+
const lightens = new Array(9).fill().map((t, i) => {
89
return client.varyColor.lighten(color, i / 10)
910
})
10-
// 此处为了简化,采用了darken。实际按color.less需求可以引入tinycolor, colorPalette变换得到颜色值
11-
var darkens = new Array(6).fill().map((t, i) => {
12-
return client.varyColor.darken(color, i / 10)
13-
})
14-
return lightens.concat(darkens)
11+
// colorPalette变换得到颜色值
12+
const colorPalettes = generate(color)
13+
return lightens.concat(colorPalettes)
1514
},
1615
changeColor (newColor) {
1716
var lastColor = this.lastColor || this.primaryColor

vue.config.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path')
22
const webpack = require('webpack')
33
const ThemeColorReplacer = require('webpack-theme-color-replacer')
4+
const generate = require('@ant-design/colors/lib/generate').default
45

56
function resolve (dir) {
67
return path.join(__dirname, dir)
@@ -29,7 +30,20 @@ module.exports = {
2930
// 生成仅包含颜色的替换样式(主题色等)
3031
new ThemeColorReplacer({
3132
fileName: 'css/theme-colors.css',
32-
matchColors: getAntdSerials('#1890ff') // 主色系列
33+
matchColors: getAntdSerials('#1890ff'), // 主色系列
34+
// 改变样式选择器,解决样式覆盖问题
35+
changeSelector (selector) {
36+
switch (selector) {
37+
case '.ant-calendar-today .ant-calendar-date':
38+
return ':not(.ant-calendar-selected-date)' + selector
39+
case '.ant-btn:focus,.ant-btn:hover':
40+
return '.ant-btn:focus:not(.ant-btn-primary),.ant-btn:hover:not(.ant-btn-primary)'
41+
case '.ant-btn.active,.ant-btn:active':
42+
return '.ant-btn.active:not(.ant-btn-primary),.ant-btn:active:not(.ant-btn-primary)'
43+
default :
44+
return selector
45+
}
46+
}
3347
})
3448
]
3549
},
@@ -106,12 +120,10 @@ module.exports = {
106120
}
107121

108122
function getAntdSerials (color) {
109-
var lightens = new Array(9).fill().map((t, i) => {
123+
// 淡化(即less的tint)
124+
const lightens = new Array(9).fill().map((t, i) => {
110125
return ThemeColorReplacer.varyColor.lighten(color, i / 10)
111126
})
112-
// 此处为了简化,采用了darken。实际按color.less需求可以引入tinycolor, colorPalette变换得到颜色值
113-
var darkens = new Array(6).fill().map((t, i) => {
114-
return ThemeColorReplacer.varyColor.darken(color, i / 10)
115-
})
116-
return lightens.concat(darkens)
127+
const colorPalettes = generate(color)
128+
return lightens.concat(colorPalettes)
117129
}

0 commit comments

Comments
 (0)