Skip to content

Commit f46ec30

Browse files
authored
fix: theme mode follow the system only auto (vbenjs#5923)
* 修复主题在未设置为auto时,仍然会跟随系统主题变化的问题。
1 parent 9bd5a19 commit f46ec30

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/@core/preferences/src/preferences.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,16 @@ class PreferenceManager {
198198
window
199199
.matchMedia('(prefers-color-scheme: dark)')
200200
.addEventListener('change', ({ matches: isDark }) => {
201-
this.updatePreferences({
202-
theme: { mode: isDark ? 'dark' : 'light' },
203-
});
201+
// 如果偏好设置中主题模式为auto,则跟随系统更新
202+
if (this.state.theme.mode === 'auto') {
203+
this.updatePreferences({
204+
theme: { mode: isDark ? 'dark' : 'light' },
205+
});
206+
// 恢复为auto模式
207+
this.updatePreferences({
208+
theme: { mode: 'auto' },
209+
});
210+
}
204211
});
205212
}
206213

packages/effects/plugins/src/vxe-table/init.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ export function setupVbenVxeTable(setupOptions: SetupVxeTable) {
106106
initVxeTable();
107107
useTableForm = useVbenForm;
108108

109-
const preference = usePreferences();
109+
const { isDark, locale } = usePreferences();
110110

111111
const localMap = {
112112
'zh-CN': zhCN,
113113
'en-US': enUS,
114114
};
115115

116116
watch(
117-
[() => preference.theme.value, () => preference.locale.value],
118-
([theme, locale]) => {
119-
VxeUI.setTheme(theme === 'dark' ? 'dark' : 'light');
120-
VxeUI.setI18n(locale, localMap[locale]);
121-
VxeUI.setLanguage(locale);
117+
[() => isDark.value, () => locale.value],
118+
([isDarkValue, localeValue]) => {
119+
VxeUI.setTheme(isDarkValue ? 'dark' : 'light');
120+
VxeUI.setI18n(localeValue, localMap[localeValue]);
121+
VxeUI.setLanguage(localeValue);
122122
},
123123
{
124124
immediate: true,

0 commit comments

Comments
 (0)