cwg-page-wrapper.vue 6.1 KB

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