cwg-page-wrapper.vue 4.1 KB

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