master
tanyp 2023-05-05 10:37:00 +08:00
parent 13a54ef206
commit 5c891a8b6f
2 changed files with 37 additions and 8 deletions

View File

@ -10,6 +10,7 @@
headerHeight: '52px', headerHeight: '52px',
asideWidth: '260px', asideWidth: '260px',
defaultHeight: null, defaultHeight: null,
isCollapse: false,
routers: [], routers: [],
}) })
@ -40,6 +41,16 @@
state.defaultHeight = window.innerHeight state.defaultHeight = window.innerHeight
} }
function onCollapse(val:Boolean){
if(val){
state.isCollapse = false
state.asideWidth = "260px"
} else {
state.isCollapse = true
state.asideWidth = "110px"
}
}
</script> </script>
<template> <template>
<div class="layout-container"> <div class="layout-container">
@ -49,11 +60,13 @@
:logo="logo" :logo="logo"
:shadow="proxy.$global.cardShadow" :shadow="proxy.$global.cardShadow"
:title="proxy.$global.title" :title="proxy.$global.title"
:height="state.defaultHeight-105"/> :height="state.defaultHeight-105"
:isCollapse="state.isCollapse"
@onCollapse="onCollapse"/>
</el-aside> </el-aside>
<el-container> <el-container>
<el-header :height="state.headerHeight"> <el-header :height="state.headerHeight">
<TbHeader :height="state.headerHeight"/> <TbHeader :height="state.headerHeight" :isCollapse="state.isCollapse"/>
</el-header> </el-header>
<el-main> <el-main>
<el-card :shadow="proxy.$global.cardShadow"> <el-card :shadow="proxy.$global.cardShadow">
@ -75,6 +88,7 @@
padding: 0.4rem; padding: 0.4rem;
overflow-x: auto; overflow-x: auto;
overflow-y: hidden; overflow-y: hidden;
transition: all .5s;
} }
.el-header{ .el-header{
padding: 0 0.6rem 0 0; padding: 0 0.6rem 0 0;

View File

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import {defineProps} from 'vue' import {defineProps} from 'vue'
import {useRouter} from 'vue-router'
import TbSubmenu from "./TbSubmenu.vue" import TbSubmenu from "./TbSubmenu.vue"
const props = defineProps({ const props = defineProps({
@ -7,18 +8,26 @@
height: Number, height: Number,
logo: Object, logo: Object,
shadow: String, shadow: String,
title: String title: String,
isCollapse: Boolean
}) })
const emit = defineEmits(['onCollapse'])
const router = useRouter()
function toHome(){
router.push({path: '/index'});
}
</script> </script>
<template> <template>
<el-card :shadow="shadow" :body-style="{padding: '1rem'}"> <el-card :shadow="shadow" :body-style="{padding: '1rem 0.8rem', position: 'relative'}">
<div class="logo"> <div @click="toHome" class="logo">
<el-image :src="logo" fit="fit" style="width: 20%; height:00%"></el-image> <el-image :src="logo" fit="fit" :style="{width: isCollapse?'60%':'20%', height: '100%'}"></el-image>
<span class="title">{{title}}</span> <span v-show="!isCollapse" class="title">{{title}}</span>
</div> </div>
<el-scrollbar :height="height"> <el-scrollbar :height="height">
<el-menu router :default-active="$route.path"> <el-menu router :default-active="$route.path" :collapse="isCollapse">
<template v-for="item in routers" :key="item"> <template v-for="item in routers" :key="item">
<el-menu-item v-if="!item.children || item.children.length <= 1" :index="item.path"> <el-menu-item v-if="!item.children || item.children.length <= 1" :index="item.path">
<el-icon v-if="item.icon" style="vertical-align: middle;"> <el-icon v-if="item.icon" style="vertical-align: middle;">
@ -30,6 +39,7 @@
</template> </template>
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
<el-button @click="$emit('onCollapse', isCollapse)" :icon="isCollapse ? 'ArrowRightBold':'ArrowLeftBold'" circle size="small" class="collapse"></el-button>
</el-card> </el-card>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -62,4 +72,9 @@
background: transparent; background: transparent;
} }
} }
.collapse{
position: absolute;
right: -10px;
top: 25%;
}
</style> </style>