250 lines
5.0 KiB
Vue
250 lines
5.0 KiB
Vue
<script setup lang="ts">
|
|
import { ref, onMounted, computed } from 'vue'
|
|
import axios from 'axios'
|
|
import { useRoute } from 'vue-router'
|
|
import {
|
|
Monitor,
|
|
Connection,
|
|
List,
|
|
Setting,
|
|
Zap,
|
|
ArrowLeft,
|
|
ArrowRight
|
|
} from '@element-plus/icons-vue'
|
|
|
|
const systemInfo = ref(null)
|
|
const networkInfo = ref(null)
|
|
const isSidebarCollapsed = ref(false)
|
|
const route = useRoute()
|
|
|
|
const currentRoute = computed(() => route.path)
|
|
const activeMenu = computed(() => route.path)
|
|
|
|
const fetchSystemInfo = async () => {
|
|
try {
|
|
const response = await axios.get('/system/info')
|
|
systemInfo.value = response.data
|
|
} catch (error) {
|
|
console.error('获取系统信息失败:', error)
|
|
}
|
|
}
|
|
|
|
const fetchNetworkInfo = async () => {
|
|
try {
|
|
const response = await axios.get('/system/network')
|
|
networkInfo.value = response.data.interfaces
|
|
} catch (error) {
|
|
console.error('获取网络信息失败:', error)
|
|
}
|
|
}
|
|
|
|
const getProgressClass = (value: number) => {
|
|
if (value >= 90) return 'danger'
|
|
if (value >= 70) return 'warning'
|
|
return 'normal'
|
|
}
|
|
|
|
const toggleSidebar = () => {
|
|
isSidebarCollapsed.value = !isSidebarCollapsed.value
|
|
}
|
|
|
|
// 页面加载时获取信息
|
|
onMounted(() => {
|
|
fetchSystemInfo()
|
|
fetchNetworkInfo()
|
|
// 每30秒更新一次系统信息
|
|
setInterval(fetchSystemInfo, 30000)
|
|
// 每60秒更新一次网络信息
|
|
setInterval(fetchNetworkInfo, 60000)
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="app-container">
|
|
<el-container>
|
|
<el-aside :width="isSidebarCollapsed ? '64px' : '200px'">
|
|
<div class="logo">
|
|
<span v-if="!isSidebarCollapsed">树莓派设备管理系统</span>
|
|
</div>
|
|
<el-menu
|
|
:default-active="activeMenu"
|
|
class="el-menu-vertical"
|
|
:collapse="isSidebarCollapsed"
|
|
router
|
|
>
|
|
<el-menu-item index="/">
|
|
<el-icon><Monitor /></el-icon>
|
|
<template #title>仪表盘</template>
|
|
</el-menu-item>
|
|
<el-menu-item index="/devices">
|
|
<el-icon><Connection /></el-icon>
|
|
<template #title>设备管理</template>
|
|
</el-menu-item>
|
|
<el-menu-item index="/device-types">
|
|
<el-icon><List /></el-icon>
|
|
<template #title>设备类型</template>
|
|
</el-menu-item>
|
|
<el-menu-item index="/interfaces">
|
|
<el-icon><List /></el-icon>
|
|
<template #title>接口管理</template>
|
|
</el-menu-item>
|
|
<el-menu-item index="/services">
|
|
<el-icon><Setting /></el-icon>
|
|
<template #title>服务管理</template>
|
|
</el-menu-item>
|
|
<el-menu-item index="/power-control">
|
|
<el-icon><Zap /></el-icon>
|
|
<template #title>电源控制</template>
|
|
</el-menu-item>
|
|
</el-menu>
|
|
</el-aside>
|
|
|
|
<!-- 主内容区 -->
|
|
<div class="main-container" :class="{ 'sidebar-collapsed': isSidebarCollapsed }">
|
|
<header class="header">
|
|
<h1>测偏仪管理后台</h1>
|
|
</header>
|
|
<main class="main-content">
|
|
<div class="content-wrapper">
|
|
<router-view></router-view>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</el-container>
|
|
</div>
|
|
</template>
|
|
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.app-container {
|
|
min-height: 100vh;
|
|
display: flex;
|
|
background-color: #f5f5f5;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
|
|
.el-container {
|
|
width: 100%;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.el-aside {
|
|
background-color: #304156;
|
|
height: 100vh;
|
|
position: fixed;
|
|
left: 0;
|
|
top: 0;
|
|
z-index: 1000;
|
|
transition: width 0.3s;
|
|
}
|
|
|
|
.main-container {
|
|
flex: 1;
|
|
margin-left: 200px;
|
|
transition: margin-left 0.3s;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.main-container.sidebar-collapsed {
|
|
margin-left: 64px;
|
|
}
|
|
|
|
.header {
|
|
background-color: white;
|
|
padding: 1rem 2rem;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
position: fixed;
|
|
top: 0;
|
|
right: 0;
|
|
left: 200px;
|
|
z-index: 900;
|
|
transition: left 0.3s;
|
|
}
|
|
|
|
.sidebar-collapsed + .header {
|
|
left: 64px;
|
|
}
|
|
|
|
.main-content {
|
|
padding: 2rem;
|
|
margin-top: 60px;
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.content-wrapper {
|
|
max-width: 1200px;
|
|
width: 100%;
|
|
margin: 0 auto;
|
|
background-color: transparent;
|
|
flex: 1;
|
|
}
|
|
|
|
.logo {
|
|
height: 60px;
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 0 20px;
|
|
background-color: #2b2f3a;
|
|
color: #fff;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.el-menu {
|
|
border-right: none;
|
|
}
|
|
|
|
/* 响应式设计 */
|
|
@media (max-width: 1400px) {
|
|
.content-wrapper {
|
|
max-width: 1000px;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 1200px) {
|
|
.content-wrapper {
|
|
max-width: 800px;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.el-aside {
|
|
position: fixed;
|
|
height: 100vh;
|
|
z-index: 1000;
|
|
}
|
|
|
|
.main-container {
|
|
margin-left: 0;
|
|
}
|
|
|
|
.main-container.sidebar-collapsed {
|
|
margin-left: 0;
|
|
}
|
|
|
|
.header {
|
|
left: 0;
|
|
}
|
|
|
|
.sidebar-collapsed + .header {
|
|
left: 0;
|
|
}
|
|
|
|
.content-wrapper {
|
|
max-width: 100%;
|
|
padding: 0 1rem;
|
|
}
|
|
}
|
|
</style>
|