themeColor.js 872 B

123456789101112131415161718192021222324
  1. import client from 'webpack-theme-color-replacer/client'
  2. import generate from '@ant-design/colors/lib/generate'
  3. export default {
  4. getAntdSerials (color) {
  5. // 淡化(即less的tint)
  6. const lightens = new Array(9).fill().map((t, i) => {
  7. return client.varyColor.lighten(color, i / 10)
  8. })
  9. // colorPalette变换得到颜色值
  10. const colorPalettes = generate(color)
  11. const rgb = client.varyColor.toNum3(color.replace('#', '')).join(',')
  12. return lightens.concat(colorPalettes).concat(rgb)
  13. },
  14. changeColor (newColor) {
  15. var options = {
  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. }
  20. }
  21. return client.changer.changeColor(options, Promise)
  22. }
  23. }