| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <template>
- <view :class="['page-wrapper', { dark: isDark }]">
- <cwg-match-media :max-width="991" v-if="!isLoginPage">
- <cwg-pc-header @open-right-drawer="openRightDrawer" @open-left-drawer="openLeftDrawer" class="header-box"
- :sidebarVisible="sidebarVisible" />
- <!-- 占位-->
- <view class="fixed"></view>
- <cwg-header class="custom-header" :title="pageTitle" />
- </cwg-match-media>
- <LanguageDropdown style="width: 0;display: none;" />
- <cwg-progress />
- <cwg-confirm-popup />
- <view class="page-content" :style="{ backgroundColor: bgColor }">
-
- <cwg-match-media :max-width="991" v-if="!isLoginPage">
- <view class="left-sidebar" :class="{ 'sidebar-visible': sidebarVisible }">
- <cwg-sidebar />
- </view>
- <view class="sidebar-mask" v-if="sidebarVisible" @click="openLeftDrawer" :style="{
- opacity: sidebarVisible ? 1 : 0,
- transition: 'opacity 281ms cubic-bezier(0.4, 0, 0.2, 1)'
- }">
- </view>
- </cwg-match-media>
- <view class="content-info">
- <!-- 完善信息提示,-->
- <PrefectInfo v-if="!isLoginPage" />
- <!-- 申请成为ib,-->
- <IbInfo ref="ibRef" v-if="!isLoginPage" />
- <view class="content-wrapper" :class="{ 'content-wrapper-padding': isContentPadding }">
- <!-- <cwg-header /> -->
- <view>
- <slot />
- </view>
- <cwg-custom-footer />
- </view>
- </view>
- <view :style="{ height: isTabBarPage ? '60px' : '0px' }" />
- </view>
- <cwg-right-drawer v-if="!isLoginPage" ref="rightDrawerRef" @navigate="handleDrawerNavigate"
- @logout="handleDrawerLogout" />
- <cwg-notice-drawer v-if="!isLoginPage" ref="noticeDrawerRef" @navigate="handleDrawerNavigate"
- @logout="handleDrawerLogout" />
- </view>
- </template>
- <script setup lang="ts">
- import { ref, computed, onMounted, onUnmounted } from 'vue'
- import { onLoad, onShow } from '@dcloudio/uni-app'
- import useRoute, { updateRoute } from '@/hooks/useRoute'
- import useRouter from '@/hooks/useRouter'
- import useUserStore from '@/stores/use-user-store'
- import { userApi } from '@/api/user'
- import useGlobalStore from '@/stores/use-global-store'
- import LanguageDropdown from './LanguageDropdown.vue'
- import PrefectInfo from '@/components/PrefectInfo.vue'
- import IbInfo from '@/components/IbInfo.vue'
- const globalStore = useGlobalStore()
- const router = useRouter()
- const userStore = useUserStore()
- const props = defineProps({
- // 是否固定顶部导航栏
- isHeaderFixed: {
- type: Boolean,
- default: false,
- },
- // 是否登录页,登录页不显示侧边栏和顶部导航,注册忘记密码等页面
- isLoginPage: {
- type: Boolean,
- default: false,
- },
- // 是否含有padding 默认有
- isContentPadding: {
- type: Boolean,
- default: true,
- },
- // 主内容背景颜色
- bgColor: {
- type: String,
- default: '',
- },
- // 顶部导航栏标题
- pageTitle: {
- type: String,
- default: '',
- },
- })
- const isDark = computed(() => globalStore.theme === 'dark')
- const isTabBarPage = ref(false)
- const rightDrawerRef = ref<any>(null)
- const noticeDrawerRef = ref<any>(null)
- const ibRef = ref<any>(null)
- // 事件处理函数
- const handleOpenIb = () => {
- if (ibRef.value) ibRef.value?.getInfo()
- }
- const handleOpenNoticeDrawer = () => {
- noticeDrawerRef.value?.open()
- }
- const handleOpenRightDrawer = () => {
- openRightDrawer()
- }
- onMounted(() => {
- // 只在组件挂载时注册事件监听器
- uni.$once('open-ib', handleOpenIb)
- uni.$on('open-notice-drawer', handleOpenNoticeDrawer)
- uni.$on('open-right-drawer', handleOpenRightDrawer)
- })
- onUnmounted(() => {
- // 在组件销毁时移除事件监听器
- uni.$off('open-ib', handleOpenIb)
- uni.$off('open-notice-drawer', handleOpenNoticeDrawer)
- uni.$off('open-right-drawer', handleOpenRightDrawer)
- })
- function openRightDrawer() {
- rightDrawerRef.value?.open()
- }
- const sidebarVisible = ref(false)
- function openLeftDrawer() {
- sidebarVisible.value = !sidebarVisible.value
- }
- function handleDrawerNavigate(path: string) {
- router.push(path)
- }
- async function handleDrawerLogout() {
- try {
- const res = await userApi.logout()
- if (res.code === 200) {
- userStore.clearUserInfo()
- router.push('/pages/login/index')
- }
- } catch (error) {
- userStore.clearUserInfo()
- router.push('/pages/login/index')
- }
- }
- onLoad(() => {
- updateRoute()
- })
- onShow(() => {
- updateRoute()
- })
- </script>
- <style lang="scss" scoped>
- @import "@/uni.scss";
- .page-wrapper {
- height: calc(100vh - 56px);
- }
- .header-box {
- width: 100%;
- height: 56px;
- }
- .page-content {
- width: 100%;
- height: calc(100vh - 56px);
- overflow: hidden;
- display: flex;
- flex-direction: column;
- position: relative;
- box-sizing: border-box;
- .content-info {
- height: calc(100vh - 56px);
- overflow: auto;
- }
- }
- .left-sidebar {
- width: 0;
- overflow: hidden;
- position: absolute;
- left: 0;
- top: 0;
- z-index: 1000;
- background-color: #fff;
- transition: width 281ms cubic-bezier(0.4, 0, 0.2, 1);
- }
- .sidebar-mask {
- position: absolute;
- left: 0;
- top: 0;
- width: 100vw;
- height: calc(100vh - 56px);
- background-color: rgba(0, 0, 0, 0.2);
- z-index: 999;
- }
- .sidebar-visible {
- width: px2rpx(280);
- }
- .content-wrapper {
- max-width: px2rpx(1224);
- width: 100%;
- margin: 0 auto;
- padding-top: px2rpx(20);
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- min-height: calc(100vh - 56px);
- }
- .fixed {
- // position: fixed;
- // top: 0;
- // left: 0;
- width: 100%;
- height: 56px;
- background-color: var(--color-white);
- z-index: 9;
- }
- .custom-header {
- background-color: var(--color-white);
- padding: 0 px2rpx(15);
- position: fixed;
- top: 56px;
- left: 0;
- }
- @media screen and (max-width: 1504px) {
- .content-wrapper-padding {
- padding: px2rpx(16) px2rpx(16) 0 px2rpx(16);
- }
- }
- @media screen and (max-width: 991px) {
- .content-wrapper-padding {
- padding: px2rpx(16) px2rpx(16) 0 px2rpx(16);
- }
- .page-wrapper {
- height: 100vh;
- }
- }
- .mobile-menu-btn {
- width: px2rpx(64);
- height: px2rpx(64);
- display: flex;
- align-items: center;
- justify-content: center;
- }
- </style>
|