DashboardLayout.vue 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <script setup>
  2. import { ref, computed } from 'vue'
  3. import { Head } from '@inertiajs/inertia-vue3'
  4. import menu from './menu'
  5. import AppMessage from '@/components/AppMessage.vue'
  6. import TopBar from './Components/TopBar.vue'
  7. import Sidebar from './Components/Sidebar.vue'
  8. import Footer from './Components/Footer.vue'
  9. defineProps({
  10. title: String,
  11. })
  12. const mobileMenuActive = ref(false)
  13. const staticMenuInactive = ref(false)
  14. const menuClick = ref(false)
  15. const isDesktop = () => window.innerWidth >= 992
  16. const containerClass = computed(() => {
  17. return [
  18. 'layout-wrapper',
  19. 'layout-static',
  20. {
  21. 'layout-static-sidebar-inactive': staticMenuInactive.value,
  22. 'layout-mobile-sidebar-active': mobileMenuActive.value,
  23. },
  24. ]
  25. })
  26. const onWrapperClick = () => {
  27. if (!menuClick.value) {
  28. mobileMenuActive.value = false
  29. }
  30. menuClick.value = false
  31. }
  32. const onMenuToggle = () => {
  33. menuClick.value = true
  34. if (isDesktop()) {
  35. staticMenuInactive.value = !staticMenuInactive.value
  36. } else {
  37. mobileMenuActive.value = !mobileMenuActive.value
  38. }
  39. }
  40. </script>
  41. <template>
  42. <Head :title="title" />
  43. <ConfirmDialog />
  44. <div :class="containerClass" @click="onWrapperClick">
  45. <TopBar @menu-toggle="onMenuToggle" />
  46. <nav class="layout-sidebar">
  47. <Sidebar :menu="menu[$page.props.auth.user.role_id]" />
  48. </nav>
  49. <div class="layout-main-container">
  50. <main class="layout-main">
  51. <AppMessage />
  52. <slot />
  53. </main>
  54. <Footer />
  55. </div>
  56. <Transition name="layout-mask">
  57. <div
  58. class="layout-mask p-component-overlay"
  59. v-if="mobileMenuActive"
  60. ></div>
  61. </Transition>
  62. </div>
  63. </template>