mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-17 10:27:30 +08:00
20 lines
516 B
TypeScript
20 lines
516 B
TypeScript
export type ThemeType = 'dark' | 'light';
|
|
|
|
// 应用主题
|
|
export const applyTheme = (theme: ThemeType) => {
|
|
// 使用 Tailwind 的暗色主题类
|
|
if (theme === 'dark') {
|
|
document.documentElement.classList.add('dark');
|
|
} else {
|
|
document.documentElement.classList.remove('dark');
|
|
}
|
|
|
|
// 保存主题到本地存储
|
|
localStorage.setItem('theme', theme);
|
|
};
|
|
|
|
// 获取当前主题
|
|
export const getCurrentTheme = (): ThemeType => {
|
|
return (localStorage.getItem('theme') as ThemeType) || 'light';
|
|
};
|