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