fix: honor selected glass theme color

This commit is contained in:
jxxghp
2026-07-22 15:12:35 +08:00
parent b66bc353b3
commit c5f3a4db44
5 changed files with 10 additions and 11 deletions
+1 -1
View File
@@ -325,7 +325,7 @@
}, },
glass: { glass: {
background: '#0B1322', background: '#0B1322',
primary: '#E4B863', primary: '#8D51F9',
}, },
} }
+5 -6
View File
@@ -72,7 +72,6 @@ export interface ThemeCustomizerSettings {
type VuetifyThemeApi = ReturnType<typeof useTheme> type VuetifyThemeApi = ReturnType<typeof useTheme>
const defaultPrimaryColor = themeCustomizerPrimaryColors[0].value const defaultPrimaryColor = themeCustomizerPrimaryColors[0].value
const glassDefaultPrimaryColor = '#E4B863'
const validLayouts: ThemeCustomizerLayout[] = ['vertical', 'collapsed', 'horizontal'] const validLayouts: ThemeCustomizerLayout[] = ['vertical', 'collapsed', 'horizontal']
const validRadii: ThemeCustomizerRadius[] = ['none', 'small', 'default', 'large', 'extra'] const validRadii: ThemeCustomizerRadius[] = ['none', 'small', 'default', 'large', 'extra']
const validShadows: readonly ThemeCustomizerShadow[] = themeCustomizerShadowLevels const validShadows: readonly ThemeCustomizerShadow[] = themeCustomizerShadowLevels
@@ -206,15 +205,15 @@ function getTextColorForHex(backgroundColor: string) {
return luminance > 0.68 ? '#3A3541' : '#FFFFFF' return luminance > 0.68 ? '#3A3541' : '#FFFFFF'
} }
/** 将主色写入 Vuetify 运行时主题,默认主色下保留玻璃主题的香槟强调色。 */ /** 将主色写入所有 Vuetify 运行时主题。 */
export function applyPrimaryColorToVuetify(color: string, themeApi: VuetifyThemeApi) { export function applyPrimaryColorToVuetify(color: string, themeApi: VuetifyThemeApi) {
if (!isHexColor(color)) return if (!isHexColor(color)) return
for (const [themeName, themeDefinition] of Object.entries(themeApi.themes.value)) { const onPrimaryColor = getTextColorForHex(color)
const themePrimaryColor = themeName === 'glass' && color === defaultPrimaryColor ? glassDefaultPrimaryColor : color
themeDefinition.colors.primary = themePrimaryColor for (const themeDefinition of Object.values(themeApi.themes.value)) {
themeDefinition.colors['on-primary'] = getTextColorForHex(themePrimaryColor) themeDefinition.colors.primary = color
themeDefinition.colors['on-primary'] = onPrimaryColor
} }
const activePrimaryColor = themeApi.current.value.colors.primary const activePrimaryColor = themeApi.current.value.colors.primary
+2 -2
View File
@@ -213,14 +213,14 @@ const theme: VuetifyOptions['theme'] = {
glass: { glass: {
dark: true, dark: true,
colors: { colors: {
'primary': '#E4B863', 'primary': '#8D51F9',
'secondary': '#7C9CC4', 'secondary': '#7C9CC4',
'on-secondary': '#07101C', 'on-secondary': '#07101C',
'success': '#69C59A', 'success': '#69C59A',
'info': '#7C9CC4', 'info': '#7C9CC4',
'warning': '#E4B863', 'warning': '#E4B863',
'error': '#FF7B7B', 'error': '#FF7B7B',
'on-primary': '#171106', 'on-primary': '#FFFFFF',
'on-success': '#07150F', 'on-success': '#07150F',
'on-warning': '#171106', 'on-warning': '#171106',
'background': '#0B1322', 'background': '#0B1322',
+1 -1
View File
@@ -13,7 +13,7 @@ describe('theme palette', () => {
expect(getThemeColorScheme('glass')).toBe('dark') expect(getThemeColorScheme('glass')).toBe('dark')
expect(themeRootPalettes.glass).toEqual({ expect(themeRootPalettes.glass).toEqual({
background: '#0B1322', background: '#0B1322',
primary: '#E4B863', primary: '#8D51F9',
}) })
}) })
+1 -1
View File
@@ -35,7 +35,7 @@ export const themeRootPalettes: Record<ResolvedThemeName, ThemeRootPalette> = {
}, },
glass: { glass: {
background: '#0B1322', background: '#0B1322',
primary: '#E4B863', primary: '#8D51F9',
}, },
} }