256 lines
6.9 KiB
Vue
Raw Normal View History

2022-08-02 10:16:07 +08:00
<template>
2022-09-01 18:49:41 +08:00
<div>
<el-container>
<el-container>
2024-03-14 14:29:23 +08:00
<el-aside :class="show ? 'aside-show' : 'aside-hide'">
<el-menu router background-color="#282c34" :unique-opened="true" text-color="#fff" :default-active="$route.path"
2022-09-01 18:49:41 +08:00
:default-openeds="openeds">
<div v-for="item in menu" :key="item.id">
<el-menu-item :index="'/' + item.code" v-if="!item.children">
2022-09-01 18:49:41 +08:00
<span>{{ item.name }}</span>
</el-menu-item>
<el-submenu v-else :index="'/' + item.code">
2022-09-01 18:49:41 +08:00
<template slot="title">
<span>{{ item.name }}</span>
</template>
<el-menu-item :index="'/' + children.code" :key="children.id" v-for="children in item.children">{{
2023-07-15 18:18:22 +08:00
children.name }}
2022-09-01 18:49:41 +08:00
</el-menu-item>
</el-submenu>
</div>
</el-menu>
</el-aside>
<el-main>
<div class="head">
<ul>
<li>
<div @click="add" class="add">
<i class="el-icon-s-unfold" v-if="show"></i>
<i class="el-icon-s-fold" v-else></i>
</div>
<div class="right">
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item v-for="(item, index) in titie" :key="index">{{ item.name }}
</el-breadcrumb-item>
</el-breadcrumb>
</div>
</li>
<li>
2023-07-15 18:18:22 +08:00
<div style="margin-right: 10px;">{{ usernmae }}</div>
<div class="token" @click="hanleLogout">登出</div>
2022-09-01 18:49:41 +08:00
</li>
</ul>
</div>
<div class="box-card">
<router-view></router-view>
</div>
</el-main>
</el-container>
</el-container>
</div>
2022-08-02 10:16:07 +08:00
</template>
<script>
2022-09-01 18:49:41 +08:00
import { removeToken } from "@/util/auth";
import { getMenu } from "../api/menu.js";
export default {
2022-08-25 11:21:14 +08:00
mounted() {
2022-09-01 18:49:41 +08:00
getMenu().then((res) => {
this.menu = res.data.data;
console.log(this.menu)
2022-09-01 18:49:41 +08:00
});
2023-07-15 18:18:22 +08:00
this.usernmae = localStorage.getItem('userName');
2022-08-25 11:21:14 +08:00
},
data() {
2022-09-01 18:49:41 +08:00
return {
menu: [], // 侧边栏
show: false, // 导航栏折叠
2022-09-01 18:49:41 +08:00
levelData: [], // table导航栏
2024-03-14 14:29:23 +08:00
titie: [], // 面包屑
2022-09-01 18:49:41 +08:00
head: "", // 路由name
onindex: 0, // 索引
openeds: ["GOODS_MANAGE"],
2023-07-15 18:18:22 +08:00
usernmae: ''
2022-09-01 18:49:41 +08:00
};
2022-08-25 11:21:14 +08:00
},
watch: {
2022-09-01 18:49:41 +08:00
// table构造
$route: {
handler: function (val) {
this.titie = val.matched;
this.head = val.name;
this.levelData.push({ name: val.name, path: val.path });
const newArr = [];
const obj = {};
for (var i = 0; i < this.levelData.length; i++) {
if (!obj[this.levelData[i].name]) {
newArr.push(this.levelData[i]);
obj[this.levelData[i].name] = true;
}
}
this.levelData = newArr;
},
deep: true,
immediate: true,
2022-08-25 11:21:14 +08:00
},
2022-08-02 10:16:07 +08:00
},
2022-08-25 11:21:14 +08:00
methods: {
2022-09-01 18:49:41 +08:00
next() {
this.hanletop();
},
hanletop() {
document.getElementById("bottom").scrollIntoView({ behavior: "smooth" });
},
hanlebottom() {
document.getElementById("top").scrollIntoView({ behavior: "smooth" });
},
hanleLogout() {
removeToken();
this.$router.push({ path: "/Login" });
},
handlerclick(e) {
if (this.$route.path !== e) {
this.$router.push({ path: e });
2022-08-25 11:21:14 +08:00
}
2022-09-01 18:49:41 +08:00
},
add() {
this.show = !this.show;
},
hanblDelete(index, titie) {
var list = this.levelData[index].name;
this.onindex = index;
this.levelData.splice(this.onindex, 1);
if (titie === this.head) {
var item;
var name;
for (let i = 0; i < this.levelData.length; i++) {
item = this.levelData[i].path;
name = this.levelData[i].name;
}
if (this.levelData.length) {
if (name !== list) {
this.$router.push({ path: item });
}
}
}
},
2022-08-02 10:16:07 +08:00
},
2022-09-01 18:49:41 +08:00
};
2022-08-02 10:16:07 +08:00
</script>
<style scoped lang="scss">
2024-03-14 14:29:23 +08:00
.aside-show {
2022-08-25 11:21:14 +08:00
transition: all 0.3s;
opacity: 0;
width: 0px !important;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2024-03-14 14:29:23 +08:00
.aside-hide {
2022-08-25 11:21:14 +08:00
transition: all 0.3s;
opacity: 1;
width: 200px !important;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-container {
2022-08-25 11:21:14 +08:00
height: 100vh;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-aside {
2022-08-25 11:21:14 +08:00
background-color: #d3dce6;
color: #333;
overflow-x: hidden;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-aside::-webkit-scrollbar {
2022-08-25 11:21:14 +08:00
width: 8px;
/*对垂直流动条有效*/
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-aside::-webkit-scrollbar-thumb {
2022-08-25 11:21:14 +08:00
background-color: rgba(144, 147, 153, 0.3);
border-radius: 20px;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-main {
2022-08-25 11:21:14 +08:00
background-color: #f0f2f5;
color: #333;
padding: 0 0 !important;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-main::-webkit-scrollbar {
2022-08-25 11:21:14 +08:00
width: 10px;
/*对垂直流动条有效*/
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-main::-webkit-scrollbar-thumb {
2022-08-25 11:21:14 +08:00
background-color: rgba(144, 147, 153, 0.3);
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.box-card {
min-height: calc(100vh - 120px);
2022-08-25 11:21:14 +08:00
margin: 10px;
2022-09-01 18:49:41 +08:00
}
.conent {
width: 100%;
min-height: calc(100vh - 200px);
position: relative;
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.add {
2022-08-25 11:21:14 +08:00
cursor: pointer;
font-size: 25px;
color: #606266;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.head {
2022-08-25 11:21:14 +08:00
padding: 10px;
background-color: #fff;
border-bottom: 1px solid #f6f6f6;
box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
ul {
display: flex;
2022-09-01 18:49:41 +08:00
justify-content: space-between;
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
li {
display: flex;
align-items: center;
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.right {
margin-left: 20px;
}
.token {
cursor: pointer;
}
2022-08-25 11:21:14 +08:00
}
2022-08-02 10:16:07 +08:00
}
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-aside {
2022-08-25 11:21:14 +08:00
background: #282c34;
box-shadow: 2px 0 6px rgb(0 21 41 / 35%);
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
::v-deep .el-menu {
2022-08-25 11:21:14 +08:00
border: none;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-menu-item:hover {
2022-08-25 11:21:14 +08:00
outline: 0 !important;
background: #5470c6 !important;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-menu-item.is-active {
2022-08-25 11:21:14 +08:00
color: #fff !important;
background: #5470c6 !important;
2022-09-01 18:49:41 +08:00
}
2022-08-25 11:21:14 +08:00
2022-09-01 18:49:41 +08:00
.el-menu-item-group__title {
2022-08-25 11:21:14 +08:00
padding: 0 0 !important;
2022-09-01 18:49:41 +08:00
}
</style>