layout-toggle.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <script setup lang="ts">
  2. import type { AuthPageLayoutType } from '@vben/types';
  3. import type { VbenDropdownMenuItem } from '@vben-core/shadcn-ui';
  4. import { computed } from 'vue';
  5. import { InspectionPanel, PanelLeft, PanelRight } from '@vben/icons';
  6. import { $t } from '@vben/locales';
  7. import {
  8. preferences,
  9. updatePreferences,
  10. usePreferences,
  11. } from '@vben/preferences';
  12. import { VbenDropdownRadioMenu, VbenIconButton } from '@vben-core/shadcn-ui';
  13. defineOptions({
  14. name: 'AuthenticationLayoutToggle',
  15. });
  16. const menus = computed((): VbenDropdownMenuItem[] => [
  17. {
  18. icon: PanelLeft,
  19. label: $t('authentication.layout.alignLeft'),
  20. value: 'panel-left',
  21. },
  22. {
  23. icon: InspectionPanel,
  24. label: $t('authentication.layout.center'),
  25. value: 'panel-center',
  26. },
  27. {
  28. icon: PanelRight,
  29. label: $t('authentication.layout.alignRight'),
  30. value: 'panel-right',
  31. },
  32. ]);
  33. const { authPanelCenter, authPanelLeft, authPanelRight } = usePreferences();
  34. function handleUpdate(value: string) {
  35. updatePreferences({
  36. app: {
  37. authPageLayout: value as AuthPageLayoutType,
  38. },
  39. });
  40. }
  41. </script>
  42. <template>
  43. <VbenDropdownRadioMenu
  44. :menus="menus"
  45. :model-value="preferences.app.authPageLayout"
  46. @update:model-value="handleUpdate"
  47. >
  48. <VbenIconButton>
  49. <PanelRight v-if="authPanelRight" class="size-4" />
  50. <PanelLeft v-if="authPanelLeft" class="size-4" />
  51. <InspectionPanel v-if="authPanelCenter" class="size-4" />
  52. </VbenIconButton>
  53. </VbenDropdownRadioMenu>
  54. </template>