cwg-page-wrapper.vue 4.8 KB

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