cwg-page-wrapper.vue 4.7 KB

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