Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions frontend/src/views/setting/panel/theme-color/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,53 +164,63 @@ const changeDarkColor = (color: string) => {

const onSave = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
await formEl.validate(async (valid) => {
if (!valid) return;
form.themeColor = { light: form.light, dark: form.dark };
ElMessageBox.confirm(i18n.global.t('xpack.theme.setHelper'), i18n.global.t('commons.button.save'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
}).then(async () => {
await formEl.validate(async (valid) => {
if (!valid) return;
form.themeColor = { light: form.light, dark: form.dark };
if (globalStore.isProductPro) {
await updateXpackSettingByKey('ThemeColor', JSON.stringify(form.themeColor));
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
globalStore.themeConfig.themeColor = JSON.stringify(form.themeColor);
loading.value = false;
let color: string;
if (form.theme === 'auto') {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
color = prefersDark.matches ? form.dark : form.light;
} else {
color = form.theme === 'dark' ? form.dark : form.light;
}
globalStore.themeConfig.primary = color;
setPrimaryColor(color);
initFavicon();
drawerVisible.value = false;
emit('search');
}
});
});
};

const onReSet = async () => {
ElMessageBox.confirm(i18n.global.t('xpack.theme.setDefaultHelper'), i18n.global.t('xpack.theme.setDefault'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
}).then(async () => {
form.themeColor = { light: '#005eeb', dark: '#F0BE96' };
if (globalStore.isProductPro) {
await updateXpackSettingByKey('ThemeColor', JSON.stringify(form.themeColor));
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
globalStore.themeConfig.themeColor = JSON.stringify(form.themeColor);
loading.value = false;
globalStore.themeConfig.themeColor = JSON.stringify(form.themeColor);
let color: string;
if (form.theme === 'auto') {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
color = prefersDark.matches ? form.dark : form.light;
color = prefersDark.matches ? '#F0BE96' : '#005eeb';
} else {
color = form.theme === 'dark' ? form.dark : form.light;
color = form.theme === 'dark' ? '#F0BE96' : '#005eeb';
}
globalStore.themeConfig.primary = color;
setPrimaryColor(color);
initFavicon();
drawerVisible.value = false;
emit('search');
return;
}
});
};

const onReSet = async () => {
form.themeColor = { light: '#005eeb', dark: '#F0BE96' };
if (globalStore.isProductPro) {
await updateXpackSettingByKey('ThemeColor', JSON.stringify(form.themeColor));
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
loading.value = false;
globalStore.themeConfig.themeColor = JSON.stringify(form.themeColor);
let color: string;
if (form.theme === 'auto') {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
color = prefersDark.matches ? '#F0BE96' : '#005eeb';
} else {
color = form.theme === 'dark' ? '#F0BE96' : '#005eeb';
}
globalStore.themeConfig.primary = color;
setPrimaryColor(color);
initFavicon();
drawerVisible.value = false;
return;
}
};

const handleClose = () => {
drawerVisible.value = false;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前版本中的代码差异较小,没有明显的不规范之处或潜在问题。
然而,在优化方面可以考虑:

  • 使用ES6正则表达式来简化条件语句(const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;);
  • 检查和修改不必要的DOM操作以提高性能。

如果需要进一步的帮助,请提出具体的需求和场景。

Expand Down