Files
Lydc_frontend/src/components/Home.vue
2025-12-05 11:12:10 +08:00

186 lines
4.9 KiB
Vue

<template>
<el-container>
<el-header>
<el-row class="container">
<el-col class="topbar-wrap">
<div class="topbar-logo topbar-btn">
<a href>
<img
src="../assets/icon/logo.png"
style="padding: 10px 23px 0px 20px; height: 25px; width: 20px"
/>
</a>
</div>
<div class="topbar-logos">
<a
href
style="
font-family: 'Microsoft YaHei', 'SimHei', 'STHeiti', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
font-size: 20px;
line-height: 70px;
color: #2E7D32;
margin-left: 10px;
font-weight: 600;
letter-spacing: 1px;
"
>{{ myname }}</a
>
</div>
<div class="topbar-title">
<el-menu
:default-active="$route.path"
class="el-menu"
mode="horizontal"
background-color="#E8F5E9"
text-color="#2E7D32"
active-text-color="#1B5E20"
@select="handleMenuSelect"
>
<template v-for="item in menu">
<el-submenu
v-if="item.children"
:index="item.index"
:key="item.index"
>
<template slot="title">{{ item.name }}</template>
<el-menu-item
v-for="submenu in item.children"
:index="submenu.index"
:key="submenu.index"
style="width: 100%"
>{{ submenu.name }}</el-menu-item
>
</el-submenu>
<el-menu-item v-else :index="item.index" :key="item.index">{{
item.name
}}</el-menu-item>
</template>
</el-menu>
</div>
</el-col>
</el-row>
</el-header>
<el-main>
<div class="content">
<router-view />
</div>
</el-main>
</el-container>
</template>
<script>
import "element-ui/lib/theme-chalk/display.css";
import "../assets/css/main.css";
export default {
name: "Home",
data() {
return {
menu: [],
myname: myname,
};
},
methods: {
// 处理菜单选择,避免重复导航
handleMenuSelect(index) {
// 如果点击的是当前路径,阻止导航
if (this.$route.path === index) {
return false;
}
// 否则正常导航
this.$router.push({ path: index }).catch(err => {
// 忽略 NavigationDuplicated 错误
if (err.name !== 'NavigationDuplicated') {
console.error('路由导航错误:', err);
}
});
}
},
mounted() {
if (sessionStorage.getItem("access-user") == "Leader") {
this.menu = [
{ index: "/view", name: "工作监管" },
{ index: "/statistic", name: "汇总统计" },
{ index: "/analysis", name: "分析决策" },
{ index: "/data", name: "数据管理" },
{ index: "/login", name: "退出" },
];
} else if (
sessionStorage.getItem("access-user") == "Admin" ||
sessionStorage.getItem("access-user") == "SuperAdmin"
) {
this.menu = [
{ index: "/view", name: "工作监管" },
{ index: "/statistic", name: "汇总统计" },
{ index: "/analysis", name: "分析决策" },
{ index: "/data", name: "数据管理" },
{ index: "/main", name: "任务管理" },
{ index: "/login", name: "退出" },
];
} else if (sessionStorage.getItem("access-user") == "Operator") {
this.menu = [
{ index: "/main", name: "任务管理" },
{ index: "/login", name: "退出" },
];
}
},
};
</script>
<style scoped>
.header ul {
z-index: 1;
list-style-type: none;
overflow: hidden;
background-color: #333;
}
.header ul li {
float: right;
}
.el-header {
padding: 0;
z-index: 99;
}
.topbar-title .el-menu--horizontal > .el-menu-item {
font-weight: bold !important;
height: 50px;
line-height: 70px;
width: 114px;
text-align: center;
font-family: PingFangSC-Regular;
font-size: 16px;
color: #2E7D32;
letter-spacing: 0;
transition: all 0.3s ease;
border-bottom: 3px solid transparent;
}
.el-menu--horizontal > .el-menu-item.is-active {
color: #1B5E20 !important;
font-family: PingFangSC-Semibold;
font-size: 16px;
letter-spacing: 0;
border-bottom: 3px solid #4CAF50 !important;
background: rgba(76, 175, 80, 0.1) !important;
}
.el-menu--horizontal .el-menu-item:not(.is-disabled):focus,
.el-menu--horizontal .el-menu-item:not(.is-disabled):hover {
outline: 0;
background: rgba(76, 175, 80, 0.15) !important;
color: #1B5E20 !important;
}
.el-main {
padding: 0;
height: 100%;
background: #F1F8F4;
}
.content {
height: 100%;
background: #F1F8F4;
}
</style>