cwg-page-wrapper.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view :class="['page-wrapper', { dark: isDark }]">
  3. <cwg-match-media :min-width="991" v-if="!isLoginPage">
  4. <view class="left-sidebar">
  5. <cwg-sidebar />
  6. <cwg-submenu v-if="sidebarVisible" @submenu-click="onSubmenuClick" />
  7. </view>
  8. </cwg-match-media>
  9. <cwg-progress />
  10. <view class="page-content">
  11. <cwg-match-media :min-width="991" v-if="!isLoginPage">
  12. <cwg-pc-header @toggle-sidebar="toggleSidebar" />
  13. </cwg-match-media>
  14. <cwg-match-media :max-width="991">
  15. <cwg-header v-if="!isHeaderFixed" />
  16. </cwg-match-media>
  17. <view class="content-wrapper" :class="{ 'content-wrapper-padding': isContentPadding}">
  18. <slot />
  19. </view>
  20. <view :style="{ height: isTabBarPage ? '60px' : '0px' }" />
  21. </view>
  22. <cwg-match-media :max-width="991">
  23. <cwg-tab-bar v-model:isTabBarPage="isTabBarPage" />
  24. </cwg-match-media>
  25. </view>
  26. </template>
  27. <script setup lang="ts">
  28. import { ref, watch, computed } from "vue";
  29. import { onLoad, onShow } from '@dcloudio/uni-app'
  30. import { updateRoute } from '@/hooks/useRoute'
  31. import useGlobalStore from '@/stores/use-global-store'
  32. const globalStore = useGlobalStore()
  33. interface MenuItem {
  34. key: string;
  35. label: string;
  36. icon?: string;
  37. children?: MenuItem[];
  38. }
  39. const props = defineProps({
  40. // 是否固定顶部导航栏
  41. isHeaderFixed: {
  42. type: Boolean,
  43. default: false
  44. },
  45. // 是否登录页,登录页不显示侧边栏和顶部导航,注册忘记密码等页面
  46. isLoginPage: {
  47. type: Boolean,
  48. default: false
  49. },
  50. // 是否含有padding 默认有
  51. isContentPadding: {
  52. type: Boolean,
  53. default: true
  54. }
  55. })
  56. const isDark = computed(() => globalStore.theme === 'dark')
  57. const isTabBarPage = ref(false)
  58. const sidebarVisible = ref(true)
  59. function toggleSidebar() {
  60. sidebarVisible.value = !sidebarVisible.value;
  61. }
  62. onLoad(() => {
  63. updateRoute()
  64. })
  65. onShow(() => {
  66. updateRoute()
  67. })
  68. </script>
  69. <style lang="scss" scoped>
  70. @import "@/uni.scss";
  71. .page-wrapper {
  72. display: flex;
  73. flex-direction: row;
  74. height: 100vh;
  75. overflow: hidden;
  76. }
  77. .left-sidebar {
  78. display: flex;
  79. flex-direction: row;
  80. }
  81. .page-content {
  82. flex: 1;
  83. display: flex;
  84. flex-direction: column;
  85. }
  86. .content-wrapper {
  87. flex: 1;
  88. // padding: 0 px2rpx(24) px2rpx(0) px2rpx(24);
  89. box-sizing: border-box;
  90. overflow-y: auto;
  91. }
  92. .content-wrapper-padding{
  93. padding: px2rpx(30);
  94. }
  95. </style>