foreign-admin-ui/src/components/layout/Layout.vue

109 lines
2.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<section class="layout">
<!-- 顶部导航栏固定在顶部 -->
<Header @toggle-sidebar="handleToggleSidebar" />
<!-- 主体内容区域 -->
<section class="main-container" :class="{ 'is-collapsed': sidebarCollapsed }">
<!-- 左侧侧边菜单固定在左侧 -->
<Sidebar :collapsed="sidebarCollapsed" />
<!-- 右侧内容区页签 + 主体内容 -->
<section class="content-container">
<!-- 页签标签栏 -->
<!-- <Tabs /> -->
<!-- 主体内容区 -->
<main class="main-content">
<transition
name="fade-transform"
mode="out-in"
style="height: 100%; display: flex; flex-direction: column"
>
<router-view v-slot="{ Component }">
<KeepAlive v-if="route.meta.keepAlive">
<component :is="Component" :key="route.path" />
</KeepAlive>
<component v-else :is="Component" :key="route.path" />
</router-view>
</transition>
</main>
</section>
</section>
</section>
</template>
<script setup lang="ts">
defineOptions({
name: 'Layout',
})
import Header from './Header.vue'
import Sidebar from './Sidebar.vue'
import Tabs from './Tabs.vue'
const route = useRoute()
// 侧边栏收缩状态
const sidebarCollapsed = ref(false)
// 切换侧边栏
const handleToggleSidebar = (collapsed: boolean) => {
sidebarCollapsed.value = collapsed
}
</script>
<style scoped lang="scss">
.layout {
width: 100%;
height: 100vh;
overflow: hidden;
background: var(--el-bg-color-page);
.main-container {
display: flex;
height: calc(100vh - 50px);
margin-top: 50px;
transition: margin-left 0.3s ease;
&.is-collapsed {
.content-container {
margin-left: 64px;
}
}
.content-container {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
margin-left: 200px;
transition: margin-left 0.3s ease;
.main-content {
flex: 1;
padding: 16px;
overflow-y: auto;
overflow-x: hidden;
background: var(--el-bg-color-page);
}
}
}
}
// 页面切换动画
.fade-transform-enter-active,
.fade-transform-leave-active {
transition: all 0.3s;
}
.fade-transform-enter-from {
opacity: 0;
transform: translateX(30px);
}
.fade-transform-leave-to {
opacity: 0;
transform: translateX(-30px);
}
</style>