侧边栏

This commit is contained in:
龚皓 2024-09-30 15:51:44 +08:00
parent 677804fbf6
commit 31ece3ea1f
1 changed files with 61 additions and 22 deletions

View File

@ -11,22 +11,30 @@
<el-menu :default-active="activeIndex" class="el-menu-part" router :collapse="isCollapse"> <el-menu :default-active="activeIndex" class="el-menu-part" router :collapse="isCollapse">
<el-menu-item index="/"> <el-menu-item index="/">
<el-icon> <el-icon>
<WarnTriangleFilled /> <House />
</el-icon> </el-icon>
<template #title><span>告警展示</span></template> <template #title><span>首页</span></template>
</el-menu-item> </el-menu-item>
<el-menu-item index="/test"> <el-menu-item index="/alertManagement">
<el-icon> <el-icon>
<document /> <Management />
</el-icon> </el-icon>
<template #title><span>测试</span></template> <template #title><span>告警列表</span></template>
</el-menu-item>
<el-menu-item index="/dataStatistics">
<el-icon><TrendCharts /></el-icon>
<template #title><span>数据统计</span></template>
</el-menu-item>
<el-menu-item index="/userList">
<el-icon><Avatar /></el-icon>
<template #title><span>用户管理</span></template>
</el-menu-item> </el-menu-item>
<el-sub-menu index="1"> <el-sub-menu index="1">
<template #title> <template #title>
<el-icon> <el-icon>
<location /> <location />
</el-icon> </el-icon>
<span>功能面板</span> <span>面板测试</span>
</template> </template>
<el-menu-item index="/alertChart"> <el-menu-item index="/alertChart">
<el-icon> <el-icon>
@ -46,13 +54,13 @@
<div class="content-layout"> <div class="content-layout">
<!-- 头部区域 --> <!-- 头部区域 -->
<el-header class="nav-header"> <el-header class="nav-header">
<div class="header-right"> <div class="header-right">
<!-- 用户头像下拉菜单 --> <!-- 用户头像下拉菜单 -->
<el-dropdown trigger="click"> <el-dropdown trigger="click">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
<el-avatar shape="square"> 用户 </el-avatar> <el-avatar shape="square"> 用户 </el-avatar>
<span class="username">Soybean</span> <span class="username">{{ username }}</span>
</span> </span>
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
@ -61,7 +69,7 @@
<User /> <User />
</el-icon> </el-icon>
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <el-dropdown-item @click="onLogout">
<el-icon> <el-icon>
<SwitchButton /> <SwitchButton />
</el-icon> 退 </el-icon> 退
@ -86,8 +94,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch } from 'vue'; import { ref, watch, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { import {
Document, Document,
WarningFilled, WarningFilled,
@ -96,26 +104,58 @@ import {
SwitchButton, SwitchButton,
WarnTriangleFilled, WarnTriangleFilled,
Setting, Setting,
} from '@element-plus/icons-vue' House,
import { el } from 'element-plus/es/locale/index.mjs'; Grid,
Management,
TrendCharts,
Avatar
} from '@element-plus/icons-vue';
import { BoxApi } from '@/utils/boxApi';
import { ElMessage } from 'element-plus';
const route = useRoute(); const route = useRoute();
const router = useRouter();
const activeIndex = ref(route.path); const activeIndex = ref(route.path);
const isCollapse = ref(false);
const isCollapse = ref(false) // username
// const handleOpen = (key: string, keyPath: string[]) => { const username = ref(''); //
// console.log(key, keyPath)
// }
// const handleClose = (key: string, keyPath: string[]) => {
// console.log(key, keyPath)
// }
// localStorage
onMounted(() => {
const storedUsername = localStorage.getItem('username');
if (storedUsername) {
username.value = storedUsername;
} else {
username.value = '用户'; // localStorage ""
}
});
const apiInstance = new BoxApi();
// active
watch( watch(
() => route.path, () => route.path,
(newPath) => { (newPath) => {
activeIndex.value = newPath; activeIndex.value = newPath;
} }
); );
// const onLogout = () => {
// localStorage.removeItem('alertToken');
// router.push('/login');
// };
const onLogout = async () => {
try {
localStorage.removeItem('alertToken');
ElMessage.success('退出登录成功');
router.push('/login');
await apiInstance.logout();
} catch (error: any) {
ElMessage.error(`后台接口调用失败: ${error.message}`);
}
};
</script> </script>
<style scoped> <style scoped>
@ -241,5 +281,4 @@ watch(
justify-content: center; justify-content: center;
text-align: center; text-align: center;
/* flex-shrink: 0; */ /* flex-shrink: 0; */
} }</style>
</style>