mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
refactor: 重构用户信息存储和主题管理逻辑 fix: 修正登录类型字段缺失问题 style: 统一页面导航栏样式和布局 docs: 更新README和文档内容 chore: 清理无用代码和资源文件 perf: 优化网络请求和错误处理逻辑 test: 更新API测试用例 build: 更新依赖版本和构建配置 ci: 调整CI/CD脚本配置
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { useThemeStore, ThemeMode, ThemeColorOption } from "@/store";
|
|
|
|
export function useTheme() {
|
|
const store = useThemeStore();
|
|
|
|
/**
|
|
* 切换暗黑模式
|
|
* @param mode 指定主题模式,不传则自动切换
|
|
*/
|
|
function toggleTheme(mode?: ThemeMode) {
|
|
store.toggleTheme(mode);
|
|
}
|
|
|
|
/**
|
|
* 设置主题色
|
|
* @param option 主题色选项
|
|
*/
|
|
function setThemeColor(option: ThemeColorOption) {
|
|
store.setCurrentThemeColor(option);
|
|
}
|
|
|
|
/**
|
|
* 初始化主题
|
|
*/
|
|
function initTheme() {
|
|
store.initTheme();
|
|
}
|
|
|
|
// 注意:全局主题管理已在App.vue中处理
|
|
// 包括:系统主题监听、导航栏颜色同步等
|
|
// 组件中一般不需要再调用initTheme(),除非有特殊需求
|
|
|
|
return {
|
|
// 状态
|
|
theme: computed(() => store.theme),
|
|
isDark: computed(() => store.isDark),
|
|
currentThemeColor: computed(() => store.currentThemeColor),
|
|
themeVars: computed(() => store.themeVars),
|
|
|
|
// 主题选项
|
|
themeColorOptions: computed(() => store.themeColorOptions),
|
|
|
|
// 方法
|
|
initTheme,
|
|
toggleTheme,
|
|
setThemeColor,
|
|
};
|
|
}
|