<template>
<!-- 这个Home组件会重定向到Welcome组件 -->
<el-container class="home-container">
<!-- A头部区域 -->
<el-header>
<div>
<div class="taobao"><img src="../assets/pic3.png" alt=""></div>
<span class="ziti">淘宝电商后台管理系统</span>
</div>
<el-button type="warning" @click="logout">退出</el-button>
</el-header>
<!-- B页面主体区域 -->
<el-container>
<!-- a左侧边栏 菜单区域 -->
<el-aside :width="isCollapse?'64px':'200px'">
<div class="toggle-button" @click="isCollapse=!isCollapse">
<el-button type="danger" round>|||</el-button>
</div>
<!-- 侧边栏菜单区 router:true开启路由模式-->
<el-menu
background-color="#333744"
text-color="#fff"
active-text-color="#409EFF"
:unique-opened="true"
:collapse="isCollapse"
:collapse-transition="false"
:default-active="activePath"
:router="true"
>
<!-- 一级菜单 -->
<el-submenu :index="item.id+''" v-for="item in menulist"
:key="item.id">
<!-- {{item}} -->
<!-- 一级菜单的模板区域 -->
<template slot="title">
<i :class="iconsObj[item.id]"></i> <!-- item.id是iconsObj的
属性 -->
<span>{{item.authName}}</span>
</template>
<!-- 二级菜单 index:唯一标志,字符串类型-->
<el-menu-item :index="'/'+subItem.path" v-for="subItem in
item.children"
:key="subItem.id" @click="saveNavState('/'+subItem.path)">
<template slot="title">
<i class="el-icon-menu"></i>
<span>{{subItem.authName}}</span>
</template>
</el-menu-item>
</el-submenu>
</el-menu>
</el-aside>
<!-- b右侧内容主体 -->
<el-main>
<!-- 路由占位符 -->
<router-view></router-view>
</el-main>
</el-container>
</el-container>
</template>
<script>
export default {
data(){
return{
//左侧菜单数据
menulist:[],
iconsObj:{ //创建一个图标对象
"125":"iconfont icon-icon_user", //右边这个value是类名 左边key是item.id
"103":"iconfont icon-icon_shangpinguanli_01",
"101":"iconfont icon-icon-shangpin",
"102":"iconfont icon-icon-danju-tianchong",
"145":"iconfont icon-icon-baobiao-shengchantongji"
},
// 是否折叠
isCollapse:false,
// 被激活的链接地址
activePath:''
}
},
created(){
this.getMenuList()
this.activePath=window.sessionStorage.getItem("activePath")
},
name: "Home",
methods: {
logout() {
window.sessionStorage.clear();
this.$router.push("/login");
},
// 获取所有的菜单
async getMenuList(){
const {data:res}= await this.$http.get("menus")
if(res.meta.status!==200) return this.$message.error(res.meta.msg)
this.menulist=res.data
console.log(res,"=========");
},
// 保存链接的激活状态
saveNavState(activePath){
window.sessionStorage.setItem("activePath",activePath)
this.activePath=activePath
}
},
};
</script>
<style lang="less" scoped>
.el-header {
background-color: #373d41;
display: flex;
justify-content: space-between;
padding-left: 0;
align-items: center;
color: #fff;
font-size: 20px;
> div {
display: flex;
align-items: center;
span {
margin-left: 15px;
}
}
}
.el-aside {
background-color: #333744;
.el-menu{
border-right: none;
}
}
.el-main {
background-color: #eaedf1;
}
.home-container {
height: 100%;
}
.iconfont{
margin-right: 10px;
}
.toggle-button{
background-color: #4A5064;
font-size: 9px;
line-height: 24px;
color: #fff;
text-align: center;
letter-spacing: 0.2em;
cursor: pointer;
}
.taobao img{
border-radius: 35%;
}
.ziti{
font-size: 30px;
font-weight: bold;
background:linear-gradient(to right,yellow,skyblue);
background-clip:text;
color: transparent;
}
// body{
// background-color: yellow;
// color: yellow;
// }
</style>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/126778.html