cwg-page-wrapper.vue 4.3 KB

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