cwg-page-wrapper.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view :class="['page-wrapper', { dark: isDark }]">
  3. <cwg-match-media :max-width="991" v-if="!isLoginPage" class="header-box">
  4. <cwg-pc-header @open-right-drawer="openRightDrawer" @open-left-drawer="openLeftDrawer" />
  5. </cwg-match-media>
  6. <cwg-progress />
  7. <view class="page-content">
  8. <cwg-match-media :max-width="991" v-if="!isLoginPage">
  9. <view class="left-sidebar" :class="{ 'sidebar-visible': sidebarVisible }">
  10. <cwg-sidebar />
  11. </view>
  12. <view class="sidebar-mask" v-if="sidebarVisible" @click="openLeftDrawer" :style="{
  13. opacity: sidebarVisible ? 1 : 0,
  14. transition: 'opacity 281ms cubic-bezier(0.4, 0, 0.2, 1)'
  15. }"></view>
  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. <cwg-right-drawer v-if="!isLoginPage" ref="rightDrawerRef" @navigate="handleDrawerNavigate"
  26. @logout="handleDrawerLogout" />
  27. </view>
  28. </template>
  29. <script setup lang="ts">
  30. import { ref, computed } from "vue";
  31. import { onLoad, onShow } from '@dcloudio/uni-app'
  32. import { updateRoute } from '@/hooks/useRoute'
  33. import useRouter from '@/hooks/useRouter'
  34. import useUserStore from '@/stores/use-user-store'
  35. import { userApi } from '@/api/user'
  36. import useGlobalStore from '@/stores/use-global-store'
  37. const globalStore = useGlobalStore()
  38. const router = useRouter()
  39. const userStore = useUserStore()
  40. const props = defineProps({
  41. // 是否固定顶部导航栏
  42. isHeaderFixed: {
  43. type: Boolean,
  44. default: false
  45. },
  46. // 是否登录页,登录页不显示侧边栏和顶部导航,注册忘记密码等页面
  47. isLoginPage: {
  48. type: Boolean,
  49. default: false
  50. },
  51. // 是否含有padding 默认有
  52. isContentPadding: {
  53. type: Boolean,
  54. default: true
  55. }
  56. })
  57. const isDark = computed(() => globalStore.theme === 'dark')
  58. const isTabBarPage = ref(false)
  59. const rightDrawerRef = ref<any>(null)
  60. function openRightDrawer() {
  61. rightDrawerRef.value?.open()
  62. }
  63. const sidebarVisible = ref(false)
  64. function openLeftDrawer() {
  65. sidebarVisible.value = !sidebarVisible.value;
  66. }
  67. function handleDrawerNavigate(path: string) {
  68. router.push(path)
  69. }
  70. async function handleDrawerLogout() {
  71. try {
  72. const res = await userApi.logout()
  73. if (res.code === 200) {
  74. userStore.clearUserInfo()
  75. router.push('/pages/login/index')
  76. }
  77. } catch (error) {
  78. userStore.clearUserInfo()
  79. router.push('/pages/login/index')
  80. }
  81. }
  82. onLoad(() => {
  83. updateRoute()
  84. })
  85. onShow(() => {
  86. updateRoute()
  87. })
  88. </script>
  89. <style lang="scss" scoped>
  90. @import "@/uni.scss";
  91. .page-wrapper {
  92. height: calc(100vh - 56px);
  93. }
  94. .header-box {
  95. width: 100%;
  96. height: 56px;
  97. }
  98. .page-content {
  99. width: 100%;
  100. display: flex;
  101. position: relative;
  102. box-sizing: border-box;
  103. }
  104. .left-sidebar {
  105. width: 0;
  106. overflow: hidden;
  107. position: absolute;
  108. left: 0;
  109. top: 0;
  110. z-index: 1000;
  111. background-color: #fff;
  112. transition: width 281ms cubic-bezier(0.4, 0, 0.2, 1);
  113. }
  114. .sidebar-mask {
  115. position: absolute;
  116. left: 0;
  117. top: 0;
  118. width: 100vw;
  119. height: calc(100vh - 56px);
  120. background-color: rgba(0, 0, 0, 0.2);
  121. z-index: 999;
  122. }
  123. .sidebar-visible {
  124. width: px2rpx(280);
  125. }
  126. .content-wrapper {
  127. max-width: px2rpx(1224);
  128. width: 100%;
  129. margin: 0 auto;
  130. // border: 1px solid rgba(108, 133, 149, 0.12);
  131. }
  132. @media screen and (max-width: 1504px) {
  133. .content-wrapper-padding {
  134. padding: px2rpx(20);
  135. }
  136. }
  137. @media screen and (max-width: 991px) {
  138. .page-wrapper {
  139. height: 100vh;
  140. }
  141. }
  142. .mobile-menu-btn {
  143. width: px2rpx(64);
  144. height: px2rpx(64);
  145. display: flex;
  146. align-items: center;
  147. justify-content: center;
  148. }
  149. // 针对不同屏幕尺寸的响应式调整
  150. @media screen and (max-width: 767px) {
  151. .content-wrapper-padding {
  152. padding: px2rpx(0) !important;
  153. }
  154. }
  155. </style>