cwg-page-wrapper.vue 5.7 KB

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