cwg-page-wrapper.vue 5.1 KB

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