ruoyi-plus-vben5/packages/business/common-ui/src/preferences/blocks/theme/theme.vue

82 lines
1.7 KiB
Vue
Raw Normal View History

2024-05-19 21:20:42 +08:00
<script setup lang="ts">
2024-06-08 19:49:06 +08:00
import { $t } from '@vben/locales';
2024-05-19 21:20:42 +08:00
import {
IcRoundMotionPhotosAuto,
IcRoundWbSunny,
MdiMoonAndStars,
} from '@vben-core/iconify';
import SwitchItem from '../switch-item.vue';
defineOptions({
name: 'PreferenceTheme',
});
const modelValue = defineModel<string>({ default: 'auto' });
2024-06-09 12:53:38 +08:00
const appSemiDarkMenu = defineModel<boolean>('appSemiDarkMenu', {
2024-05-19 21:20:42 +08:00
default: true,
});
const THEME_PRESET = [
{
icon: IcRoundWbSunny,
name: 'light',
},
{
icon: MdiMoonAndStars,
name: 'dark',
},
{
icon: IcRoundMotionPhotosAuto,
name: 'auto',
},
];
function activeClass(theme: string): string[] {
return theme === modelValue.value ? ['outline-box-active'] : [];
}
function nameView(name: string) {
switch (name) {
case 'light': {
2024-06-16 13:43:33 +08:00
return $t('preferences.light');
2024-05-19 21:20:42 +08:00
}
case 'dark': {
2024-06-16 13:43:33 +08:00
return $t('preferences.dark');
2024-05-19 21:20:42 +08:00
}
case 'auto': {
2024-06-16 13:43:33 +08:00
return $t('preferences.follow-system');
2024-05-19 21:20:42 +08:00
}
}
}
</script>
<template>
<div class="flex w-full flex-wrap justify-between">
<template v-for="theme in THEME_PRESET" :key="theme.name">
<div
class="flex cursor-pointer flex-col"
@click="modelValue = theme.name"
>
<div
:class="activeClass(theme.name)"
class="outline-box flex-center py-4"
>
<component :is="theme.icon" class="mx-9 size-5" />
</div>
<div class="text-muted-foreground mt-2 text-center text-xs">
{{ nameView(theme.name) }}
</div>
</div>
</template>
<SwitchItem
2024-06-09 12:53:38 +08:00
v-model="appSemiDarkMenu"
2024-05-19 21:20:42 +08:00
:disabled="modelValue !== 'light'"
class="mt-6"
>
2024-06-16 13:43:33 +08:00
{{ $t('preferences.dark-menu') }}
2024-05-19 21:20:42 +08:00
</SwitchItem>
</div>
</template>