mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
fix: 解决主题颜色切换失败的问题 (#5218)
This commit is contained in:
parent
9df8f13fa7
commit
c133f39b5e
@ -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…
x
Reference in New Issue
Block a user