| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <view :class="['page-wrapper', { dark: isDark }]">
- <cwg-match-media :min-width="991" v-if="!isLoginPage">
- <view class="left-sidebar">
- <cwg-sidebar />
- <cwg-submenu v-if="sidebarVisible" @submenu-click="onSubmenuClick" />
- </view>
- </cwg-match-media>
- <cwg-progress />
- <view class="page-content">
- <cwg-match-media :min-width="991" v-if="!isLoginPage">
- <cwg-pc-header @toggle-sidebar="toggleSidebar" :sidebarVisible="sidebarVisible"
- @open-right-drawer="openRightDrawer" />
- </cwg-match-media>
- <cwg-match-media :max-width="991">
- <cwg-header v-if="!isHeaderFixed">
- <view class="mobile-menu-btn" @click="openRightDrawer">
- <cwg-icon name="crm-bars-staggered" :size="20" color="#0f172b" />
- </view>
- </cwg-header>
- </cwg-match-media>
- <view class="content-wrapper" :class="{ 'content-wrapper-padding': isContentPadding }">
- <slot />
- </view>
- <view :style="{ height: isTabBarPage ? '60px' : '0px' }" />
- </view>
- <cwg-match-media :max-width="991">
- <cwg-tab-bar v-model:isTabBarPage="isTabBarPage" />
- </cwg-match-media>
- <cwg-right-drawer v-if="!isLoginPage" ref="rightDrawerRef" @navigate="handleDrawerNavigate"
- @logout="handleDrawerLogout" />
- </view>
- </template>
- <script setup lang="ts">
- import { ref, computed } from "vue";
- import { onLoad, onShow } from '@dcloudio/uni-app'
- import { 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'
- 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
- }
- })
- const isDark = computed(() => globalStore.theme === 'dark')
- const isTabBarPage = ref(false)
- const sidebarVisible = ref(true)
- const rightDrawerRef = ref<any>(null)
- function toggleSidebar() {
- sidebarVisible.value = !sidebarVisible.value;
- }
- function openRightDrawer() {
- console.log(32423423);
- rightDrawerRef.value?.open()
- }
- 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 {
- display: flex;
- flex-direction: row;
- height: 100vh;
- overflow: hidden;
- }
- .left-sidebar {
- display: flex;
- flex-direction: row;
- }
- .page-content {
- flex: 1;
- display: flex;
- flex-direction: column;
- }
- .content-wrapper {
- flex: 1;
- // padding: 0 px2rpx(24) px2rpx(0) px2rpx(24);
- box-sizing: border-box;
- overflow-y: auto;
- }
- .content-wrapper-padding {
- padding: px2rpx(30);
- }
- .mobile-menu-btn {
- width: px2rpx(64);
- height: px2rpx(64);
- display: flex;
- align-items: center;
- justify-content: center;
- }
- </style>
|