批量更新,增加用户管理

This commit is contained in:
2025-11-01 17:57:34 +08:00
parent 186dcb86d9
commit bfba8d7ad6
28 changed files with 2307 additions and 2377 deletions
-72
View File
@@ -1,72 +0,0 @@
/**
* 主题管理工具
*/
const THEME_KEY = 'app-theme';
const THEME_LIGHT = 'light';
const THEME_DARK = 'dark';
/**
* 获取当前主题
* @returns {string} 'light' | 'dark'
*/
export function getTheme() {
// 优先从 localStorage 读取
const savedTheme = localStorage.getItem(THEME_KEY);
if (savedTheme === THEME_LIGHT || savedTheme === THEME_DARK) {
return savedTheme;
}
// 如果 localStorage 中没有,检查系统偏好
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
return THEME_DARK;
}
// 默认返回亮色主题
return THEME_LIGHT;
}
/**
* 设置主题
* @param {string} theme - 'light' | 'dark'
*/
export function setTheme(theme) {
if (theme !== THEME_LIGHT && theme !== THEME_DARK) {
console.warn(`Invalid theme: ${theme}, using default: ${THEME_LIGHT}`);
theme = THEME_LIGHT;
}
// 保存到 localStorage
localStorage.setItem(THEME_KEY, theme);
// 应用到 HTML 元素
const html = document.documentElement;
if (theme === THEME_DARK) {
html.setAttribute('data-theme', 'dark');
} else {
html.removeAttribute('data-theme');
}
// 触发主题变更事件
window.dispatchEvent(new CustomEvent('theme-change', { detail: { theme } }));
}
/**
* 切换主题
* @returns {string} 新的主题
*/
export function toggleTheme() {
const currentTheme = getTheme();
const newTheme = currentTheme === THEME_LIGHT ? THEME_DARK : THEME_LIGHT;
setTheme(newTheme);
return newTheme;
}
/**
* 初始化主题
*/
export function initTheme() {
const theme = getTheme();
setTheme(theme);
}