import { createMuiTheme } from '@material-ui/core/styles' ; import { ThemeOptions , Theme } from '@material-ui/core/styles/createMuiTheme' ; import blue from '@material-ui/core/colors/blue' ; import pink from '@material-ui/core/colors/pink' ; import green from '@material-ui/core/colors/lightGreen' ; export enum ThemeEnum { DEFAULT , SPRING , SUMMER , FALL , WINTER } export enum ModeEnum { LIGHT , DARK } const blueLight = { palette : { primary : { main : blue [ 400 ] , contrastText : '#fff' , } , secondary : pink , } , } ; const blueDark = { palette : { primary : { main : blue [ 400 ] , contrastText : '#fff' , } , secondary : pink , type : 'dark' , } , } ; const greenLight = { palette : { primary : { main : green [ 300 ] , } , secondary : pink , } , } ; const greenDark = { palette : { primary : { main : green [ 300 ] , contrastText : '#fff' , } , secondary : pink , type : 'dark' , } , } ; const themeMap = { [ ModeEnum . LIGHT ] : { [ ThemeEnum . DEFAULT ] : blueLight , [ ThemeEnum . SPRING ] : greenLight , } , [ ModeEnum . DARK ] : { [ ThemeEnum . DEFAULT ] : blueDark , [ ThemeEnum . SPRING ] : greenDark , } , } ; /**
 * 获取主题
 */ function _getTheme ( theme , mode ) { const safeMode = ModeEnum [ mode ] ? mode : ModeEnum . LIGHT ; const safeTheme = ThemeEnum [ theme ] ? theme : ThemeEnum . DEFAULT ; return themeMap [ safeMode ] [ safeTheme ] ; } /**
 * 根据设置的主题和模式获取 MUI Theme
 */ export function getTheme ( themeColor , mode ) { const theme = { ... _getTheme ( themeColor , mode ) , } ; return createMuiTheme ( theme ) ; }