| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- <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="sidebar-mask mask-visible" v-if="sidebarVisible" @click="openLeftDrawer">
- </view>
- <view class="fixed"></view>
- <cwg-header v-if=pageTitle class="custom-header" :title="pageTitle" />
- </cwg-match-media>
- <cwg-language 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 @handle-click="openLeftDrawer" />
- </view>
- <view class="sidebar-mask" v-if="sidebarVisible" @click="openLeftDrawer" :style="{
- opacity: maskVisible ? 1 : 0,
- transition: 'opacity 0.3s 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 /> -->
- <transition name="fade" mode="out-in">
- <view>
- <slot />
- </view>
- </transition>
- <cwg-custom-footer />
- </view>
- </view>
- <cwg-match-media :max-width="991">
- <view class="chat-icon"
- :class="{ 'chat-icon-expanded': isChatIconExpanded, 'chat-icon-hidden': type == 'chat' }"
- @click="handleChatIconClick">
- <cwg-icon name="chat" color="#fff" />
- </view>
- </cwg-match-media>
- <view :style="{ height: isTabBarPage ? '60px' : '0px' }" />
- </view>
- </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 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: '',
- },
- type: {
- 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 isChatIconExpanded = ref(false)
- // 事件处理函数
- const handleOpenIb = () => {
- if (ibRef.value) ibRef.value?.getInfo()
- }
- const handleOpenNoticeDrawer = () => {
- noticeDrawerRef.value?.open()
- }
- // 处理聊天图标点击
- const handleChatIconClick = () => {
- // 如果还没显示 → 先滑出来
- if (!isChatIconExpanded.value) {
- isChatIconExpanded.value = true
- return
- }
- router.push('/pages/common/chat')
- setTimeout(() => {
- isChatIconExpanded.value = false
- }, 300)
- }
- const handleOpenRightDrawer = () => {
- openRightDrawer()
- }
- onMounted(() => {
- // 只在组件挂载时注册事件监听器
- uni.$once('open-ib', handleOpenIb)
- uni.$on('open-right-drawer', handleOpenRightDrawer)
- })
- onUnmounted(() => {
- // 在组件销毁时移除事件监听器
- uni.$off('open-ib', handleOpenIb)
- uni.$off('open-right-drawer', handleOpenRightDrawer)
- })
- function openRightDrawer() {
- rightDrawerRef.value?.open()
- }
- const sidebarVisible = ref(false)
- const maskVisible = ref(false)
- function openLeftDrawer() {
- if (sidebarVisible.value) {
- // 关闭时先隐藏遮罩层
- maskVisible.value = false
- // 等待遮罩层动画结束后再隐藏侧边栏
- setTimeout(() => {
- sidebarVisible.value = false
- }, 200)
- } else {
- // 打开时先显示侧边栏
- sidebarVisible.value = true
- // 等待侧边栏动画结束后再显示遮罩层
- setTimeout(() => {
- maskVisible.value = true
- }, 200)
- }
- }
- 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 81ms 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: 101;
- }
- .mask-visible {
- background-color: rgba(0, 0, 0, 0);
- width: 100vw;
- height: 56px;
- }
- .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);
- }
- .chat-icon {
- width: px2rpx(50);
- height: px2rpx(50);
- border-radius: 50%;
- background-color: #cf1322;
- display: flex;
- align-items: center;
- justify-content: center;
- position: fixed;
- bottom: px2rpx(25);
- right: px2rpx(-25);
- z-index: 999;
- cursor: pointer;
- transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
- box-shadow: 0 px2rpx(8) px2rpx(20) rgba(0, 0, 0, 0.15);
- will-change: transform;
- }
- .chat-icon:hover {
- transform: scale(1.1);
- }
- .chat-icon-expanded {
- bottom: px2rpx(20);
- right: px2rpx(20);
- transform: scale(1.1);
- box-shadow: 0 px2rpx(12) px2rpx(30) rgba(0, 0, 0, 0.2);
- }
- .chat-icon-hidden {
- display: none;
- }
- .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;
- }
- /* 页面切换动画 */
- .fade-enter-active,
- .fade-leave-active {
- transition: opacity 0.2s ease;
- }
- .fade-enter-from,
- .fade-leave-to {
- opacity: 0;
- }
- /* 侧边栏动画优化 */
- .left-sidebar {
- transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
- }
- .sidebar-mask {
- transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
- }
- /* 内容区域动画 */
- .content-wrapper {
- animation: slideIn 0.2s ease-out;
- }
- @keyframes slideIn {
- from {
- transform: translateY(20px);
- opacity: 0;
- }
- to {
- transform: translateY(0);
- opacity: 1;
- }
- }
- </style>
|