Skip to content

Commit

Permalink
Merge pull request #1477 from jumpserver/pr@dev@perf_theme_preview
Browse files Browse the repository at this point in the history
perf: Added theme preview functionality
  • Loading branch information
ZhaoJiSen authored Sep 11, 2024
2 parents 6675f2c + 82e87b2 commit 22a4e35
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion ui/src/components/ThemeConfig/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
<n-grid :cols="24">
<n-grid-item :span="20">
<n-select
class="pr-[20px]"
v-model:value="theme"
:placeholder="t('SelectTheme')"
:options="themes"
@update:value="setTheme"
class="pr-[20px]"
@keydown="handlePreviewTheme"
/>
</n-grid-item>
<n-grid-item :span="4">
Expand Down Expand Up @@ -160,11 +161,47 @@ const colors = computed(() => {
}
});
/**
* 设置主题
*
* @param value
*/
const setTheme = (value: string) => {
theme.value = value;
props.preview(theme.value);
mittBus.emit('set-theme', { themeName: value });
};
/**
* 处理当使用键盘上下键时的主题预览功能
*
* @param event
*/
const handlePreviewTheme = (event: KeyboardEvent) => {
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
const currentIndex = themes.value.findIndex(option => option.value === theme.value);
let nextIndex = currentIndex;
if (event.key === 'ArrowUp') {
// 如果当前索引为 0,则跳转到最后一个选项,否则向上移动
nextIndex = currentIndex === 0 ? themes.value.length - 1 : currentIndex - 1;
} else if (event.key === 'ArrowDown') {
// 如果当前索引为最后一个,则跳转到第一个选项,否则向下移动
nextIndex = currentIndex === themes.value.length - 1 ? 0 : currentIndex + 1;
}
const nextValue = themes.value[nextIndex]?.value;
if (nextValue) {
setTheme(nextValue);
}
}
};
/**
* 点击同步按钮的回调
*/
const syncTheme = () => {
loading.value = true;
Expand All @@ -191,6 +228,7 @@ onMounted(() => {
showThemeConfig.value = !showThemeConfig.value;
});
});
onUnmounted(() => {
mittBus.off('show-theme-config');
});
Expand Down

0 comments on commit 22a4e35

Please sign in to comment.