feat: 新增动态主题功能 & 统一设置不同 layout 的主题

This commit is contained in:
Utopia
2025-08-19 17:44:26 +08:00
parent 1f9b6fae53
commit d1c5124b82
5 changed files with 56 additions and 16 deletions

View File

@@ -13,5 +13,6 @@ store.use(
export default store
export * from './theme'
// 模块统一导出
export * from './user'

42
src/store/theme.ts Normal file
View File

@@ -0,0 +1,42 @@
import type { ConfigProviderThemeVars } from 'wot-design-uni'
import { defineStore } from 'pinia'
export const useThemeStore = defineStore(
'theme-store',
() => {
/** 主题 */
const theme = ref<'light' | 'dark'>('light')
/** 主题变量 */
const themeVars = ref<ConfigProviderThemeVars>({
// colorTheme: 'red',
// buttonPrimaryBgColor: '#07c160',
// buttonPrimaryColor: '#07c160',
})
/** 设置主题变量 */
const setThemeVars = (partialVars: Partial<ConfigProviderThemeVars>) => {
themeVars.value = { ...themeVars.value, ...partialVars }
}
/** 切换主题 */
const toggleTheme = () => {
theme.value = theme.value === 'light' ? 'dark' : 'light'
}
return {
/** 设置主题变量 */
setThemeVars,
/** 切换主题 */
toggleTheme,
/** 主题变量 */
themeVars,
/** 主题 */
theme,
}
},
{
persist: true,
},
)