generateModifyVars.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { primaryColor } from '../config/themeConfig';
  2. // import { getThemeVariables } from 'ant-design-vue/dist/theme';
  3. import { resolve } from 'path';
  4. import { generate } from '@ant-design/colors';
  5. import { theme } from 'ant-design-vue/lib';
  6. import convertLegacyToken from 'ant-design-vue/lib/theme/convertLegacyToken';
  7. const { defaultAlgorithm, defaultSeed } = theme;
  8. function generateAntColors(color: string, theme: 'default' | 'dark' = 'default') {
  9. return generate(color, {
  10. theme,
  11. });
  12. }
  13. /**
  14. * less global variable
  15. */
  16. export function generateModifyVars() {
  17. const palettes = generateAntColors(primaryColor);
  18. const primary = palettes[5];
  19. const primaryColorObj: Record<string, string> = {};
  20. for (let index = 0; index < 10; index++) {
  21. primaryColorObj[`primary-${index + 1}`] = palettes[index];
  22. }
  23. const mapToken = defaultAlgorithm(defaultSeed);
  24. const v3Token = convertLegacyToken(mapToken);
  25. return {
  26. ...v3Token,
  27. // ...modifyVars,
  28. // Used for global import to avoid the need to import each style file separately
  29. // reference: Avoid repeated references
  30. hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
  31. 'primary-color': primary,
  32. ...primaryColorObj,
  33. 'info-color': primary,
  34. 'processing-color': primary,
  35. 'success-color': '#55D187', // Success color
  36. 'error-color': '#ED6F6F', // False color
  37. 'warning-color': '#EFBD47', // Warning color
  38. //'border-color-base': '#EEEEEE',
  39. 'font-size-base': '14px', // Main font size
  40. 'border-radius-base': '2px', // Component/float fillet
  41. 'link-color': primary, // Link color
  42. 'app-content-background': '#fafafa', // Link color
  43. };
  44. }