fix: 解决主题颜色切换失败的问题 (#5218)

pull/5221/head
ssongliu 6 months ago committed by GitHub
parent 9df8f13fa7
commit c133f39b5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -8,6 +8,10 @@ export const useTheme = () => {
body.setAttribute('class', 'dark-gold'); body.setAttribute('class', 'dark-gold');
return; return;
} }
if (globalStore.themeConfig.theme === 'auto') {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
globalStore.themeConfig.theme = prefersDark.matches ? 'dark' : 'light';
}
const body = document.documentElement as HTMLElement; const body = document.documentElement as HTMLElement;
if (globalStore.themeConfig.theme === 'dark') body.setAttribute('class', 'dark'); if (globalStore.themeConfig.theme === 'dark') body.setAttribute('class', 'dark');
else body.setAttribute('class', ''); else body.setAttribute('class', '');

@ -28,8 +28,8 @@ export async function getXpackSetting() {
return res; return res;
} }
export async function updateXpackSetting(fromData: FormData) { export async function updateXpackSettingByKey(key: string, value: string) {
const searchXSettingGlob = import.meta.glob('xpack/api/modules/setting.ts'); const searchXSettingGlob = import.meta.glob('xpack/api/modules/setting.ts');
const module = await searchXSettingGlob?.['../xpack/api/modules/setting.ts']?.(); const module = await searchXSettingGlob?.['../xpack/api/modules/setting.ts']?.();
return module?.updateXSetting(fromData); return module?.updateXSettingByKey(key, value);
} }

@ -184,7 +184,7 @@ import Proxy from '@/views/setting/panel/proxy/index.vue';
import Network from '@/views/setting/panel/default-network/index.vue'; import Network from '@/views/setting/panel/default-network/index.vue';
import HideMenu from '@/views/setting/panel/hidemenu/index.vue'; import HideMenu from '@/views/setting/panel/hidemenu/index.vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { getXpackSetting, updateXpackSetting } from '@/utils/xpack'; import { getXpackSetting, updateXpackSettingByKey } from '@/utils/xpack';
const loading = ref(false); const loading = ref(false);
const i18n = useI18n(); const i18n = useI18n();
@ -357,18 +357,11 @@ const onSave = async (key: string, val: any) => {
globalStore.themeConfig.theme = val; globalStore.themeConfig.theme = val;
} }
switchTheme(); switchTheme();
if (isProductPro.value) { updateXpackSettingByKey('Theme', val === 'dark-gold' ? 'dark-gold' : '');
let formData = new FormData(); if (val === 'dark-gold') {
formData.append('theme', val); MsgSuccess(i18n.t('commons.msg.operationSuccess'));
await updateXpackSetting(formData) loading.value = false;
.then(async () => { search();
loading.value = false;
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
await search();
})
.catch(() => {
loading.value = false;
});
return; return;
} }
} }

Loading…
Cancel
Save