cwg-page-wrapper.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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" :sidebarVisible="sidebarVisible"
  13. @open-right-drawer="openRightDrawer" />
  14. </cwg-match-media>
  15. <cwg-match-media :max-width="991">
  16. <cwg-header v-if="!isHeaderFixed">
  17. <view class="mobile-menu-btn" @click="openRightDrawer">
  18. <cwg-icon name="crm-bars-staggered" :size="20" color="#0f172b" />
  19. </view>
  20. </cwg-header>
  21. </cwg-match-media>
  22. <view class="content-wrapper" :class="{ 'content-wrapper-padding': isContentPadding }">
  23. <slot />
  24. </view>
  25. <view :style="{ height: isTabBarPage ? '60px' : '0px' }" />
  26. </view>
  27. <cwg-match-media :max-width="991">
  28. <cwg-tab-bar v-model:isTabBarPage="isTabBarPage" />
  29. </cwg-match-media>
  30. <cwg-right-drawer v-if="!isLoginPage" ref="rightDrawerRef" @navigate="handleDrawerNavigate"
  31. @logout="handleDrawerLogout" />
  32. </view>
  33. </template>
  34. <script setup lang="ts">
  35. import { ref, computed } from "vue";
  36. import { onLoad, onShow } from '@dcloudio/uni-app'
  37. import { updateRoute } from '@/hooks/useRoute'
  38. import useRouter from '@/hooks/useRouter'
  39. import useUserStore from '@/stores/use-user-store'
  40. import { userApi } from '@/api/user'
  41. import useGlobalStore from '@/stores/use-global-store'
  42. const globalStore = useGlobalStore()
  43. const router = useRouter()
  44. const userStore = useUserStore()
  45. const props = defineProps({
  46. // 是否固定顶部导航栏
  47. isHeaderFixed: {
  48. type: Boolean,
  49. default: false
  50. },
  51. // 是否登录页,登录页不显示侧边栏和顶部导航,注册忘记密码等页面
  52. isLoginPage: {
  53. type: Boolean,
  54. default: false
  55. },
  56. // 是否含有padding 默认有
  57. isContentPadding: {
  58. type: Boolean,
  59. default: true
  60. }
  61. })
  62. const isDark = computed(() => globalStore.theme === 'dark')
  63. const isTabBarPage = ref(false)
  64. const sidebarVisible = ref(true)
  65. const rightDrawerRef = ref<any>(null)
  66. function toggleSidebar() {
  67. sidebarVisible.value = !sidebarVisible.value;
  68. }
  69. function openRightDrawer() {
  70. console.log(32423423);
  71. rightDrawerRef.value?.open()
  72. }
  73. function handleDrawerNavigate(path: string) {
  74. router.push(path)
  75. }
  76. async function handleDrawerLogout() {
  77. try {
  78. const res = await userApi.logout()
  79. if (res.code === 200) {
  80. userStore.clearUserInfo()
  81. router.push('/pages/login/index')
  82. }
  83. } catch (error) {
  84. userStore.clearUserInfo()
  85. router.push('/pages/login/index')
  86. }
  87. }
  88. onLoad(() => {
  89. updateRoute()
  90. })
  91. onShow(() => {
  92. updateRoute()
  93. })
  94. </script>
  95. <style lang="scss" scoped>
  96. @import "@/uni.scss";
  97. .page-wrapper {
  98. display: flex;
  99. flex-direction: row;
  100. height: 100vh;
  101. overflow: hidden;
  102. }
  103. .left-sidebar {
  104. display: flex;
  105. flex-direction: row;
  106. }
  107. .page-content {
  108. flex: 1;
  109. display: flex;
  110. flex-direction: column;
  111. }
  112. .content-wrapper {
  113. flex: 1;
  114. // padding: 0 px2rpx(24) px2rpx(0) px2rpx(24);
  115. box-sizing: border-box;
  116. overflow-y: auto;
  117. }
  118. .content-wrapper-padding {
  119. padding: px2rpx(30);
  120. }
  121. .mobile-menu-btn {
  122. width: px2rpx(64);
  123. height: px2rpx(64);
  124. display: flex;
  125. align-items: center;
  126. justify-content: center;
  127. }
  128. </style>