cwg-page-wrapper.vue 5.8 KB

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