content.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <script setup lang="ts">
  2. import { type Component, computed } from 'vue';
  3. import { $t } from '@vben/locales';
  4. import { ContentCompact, ContentWide } from '../../icons';
  5. defineOptions({
  6. name: 'PreferenceLayoutContent',
  7. });
  8. const modelValue = defineModel<string>({ default: 'wide' });
  9. const components: Record<string, Component> = {
  10. compact: ContentCompact,
  11. wide: ContentWide,
  12. };
  13. const PRESET = computed(() => [
  14. {
  15. name: $t('preferences.wide'),
  16. type: 'wide',
  17. },
  18. {
  19. name: $t('preferences.compact'),
  20. type: 'compact',
  21. },
  22. ]);
  23. function activeClass(theme: string): string[] {
  24. return theme === modelValue.value ? ['outline-box-active'] : [];
  25. }
  26. </script>
  27. <template>
  28. <div class="flex w-full gap-5">
  29. <template v-for="theme in PRESET" :key="theme.name">
  30. <div
  31. class="flex w-[100px] cursor-pointer flex-col"
  32. @click="modelValue = theme.type"
  33. >
  34. <div :class="activeClass(theme.type)" class="outline-box flex-center">
  35. <component :is="components[theme.type]" />
  36. </div>
  37. <div class="text-muted-foreground mt-2 text-center text-xs">
  38. {{ theme.name }}
  39. </div>
  40. </div>
  41. </template>
  42. </div>
  43. </template>