<template>
<el-container class="haaa">
<!-- 头部 -->
<el-header>
<div><span></span><span>后台管理系统</span></div>
<el-button type="info" @click="logout" :loading="loading">退出</el-button>
</el-header>
<!-- 主体 -->
<el-container>
<!-- 侧边 -->
<el-aside width="200px">
<!-- 侧边菜单栏 -->
<el-menu
background-color="#333744"
text-color="#fff"
active-text-color="#409eff"
>
<!-- 一级菜单 -->
<el-submenu
:index="item.id + ''"
v-for="item in menulist"
:key="item.id"
>
<template slot="title">
<i :class="iconsObj[item.id]"></i>
<span>{{ item.authName }}</span>
</template>
<!-- 二级菜单 -->
<el-menu-item
:index="subItem.id + ''"
v-for="subItem in item.children"
:key="subItem.id"
>
<template slot="title">
<i class="el-icon-menu"></i>
<span>{{ subItem.authName }}</span>
</template></el-menu-item
>
</el-submenu>
</el-menu>
</el-aside>
<el-container>
<!-- 左边主体 -->
<el-main>Main</el-main>
</el-container>
</el-container>
</el-container>
</template>
<script>
export default {
components: {},
created() {
this.getMenuList();
},
data() {
return {
loading: false,
menulist: [],
iconsObj: {
125: "iconfont icon-user",
103: "iconfont icon-tijikongjian",
101: "iconfont icon-shangpin",
102: "iconfont icon-danju",
145: "iconfont icon-baobiao",
},
};
},
methods: {
logout() {
window.sessionStorage.clear();
this.loading = true;
setTimeout(() => {
this.$router.push("/Login").catch(() => {
});
}, 2000);
},
async getMenuList() {
const { data: res } = await this.$http.get("menus");
console.log(res);
if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
this.menulist = res.data;
},
},
};
</script>
<style lang="less" scoped>
.haaa {
height: 100%;
}
.el-header {
background-color: #373d41;
color: #ffffff;
font-size: 20px;
display: flex;
justify-content: space-between;
align-items: center;
padding-left: 0;
div {
display: flex;
justify-content: space-between;
align-items: center;
span {
margin-left: 15px;
}
}
}
.el-aside {
background-color: #333744;
color: #333;
text-align: center;
line-height: 200px;
}
.el-main {
background-color: #eaedf1;
color: #333;
text-align: center;
line-height: 160px;
}
/deep/.el-submenu__title {
padding-left: 0px !important;
padding-right: 60px !important;
}
/deep/.el-menu-item {
padding-left: 60px !important;
padding-right: 40px !important;
}
body > .el-container {
margin-bottom: 40px;
}
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
line-height: 260px;
}
.el-container:nth-child(7) .el-aside {
line-height: 320px;
}
</style>