增加前端侧边栏收起功能

This commit is contained in:
2026-06-20 15:26:17 +08:00
parent a3e2222388
commit 1e7b462c2c
+28 -6
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { ref, onMounted, onUnmounted, computed } from 'vue'
import axios from 'axios'
import { useRoute } from 'vue-router'
import {
@@ -15,8 +15,18 @@ import {
const systemInfo = ref(null)
const networkInfo = ref(null)
const isSidebarCollapsed = ref(false)
const isMobile = ref(false)
const route = useRoute()
// 检测是否为移动设备
const checkMobile = () => {
isMobile.value = window.innerWidth <= 768
// 移动设备上默认折叠侧边栏
if (isMobile.value) {
isSidebarCollapsed.value = true
}
}
const currentRoute = computed(() => route.path)
const activeMenu = computed(() => route.path)
@@ -50,6 +60,8 @@ const toggleSidebar = () => {
// 页面加载时获取信息
onMounted(() => {
checkMobile()
window.addEventListener('resize', checkMobile)
fetchSystemInfo()
fetchNetworkInfo()
// 每30秒更新一次系统信息
@@ -57,6 +69,10 @@ onMounted(() => {
// 每60秒更新一次网络信息
setInterval(fetchNetworkInfo, 60000)
})
onUnmounted(() => {
window.removeEventListener('resize', checkMobile)
})
</script>
<template>
@@ -220,27 +236,33 @@ onMounted(() => {
position: fixed;
height: 100vh;
z-index: 1000;
width: 64px !important;
}
.main-container {
margin-left: 0;
margin-left: 64px !important;
}
.main-container.sidebar-collapsed {
margin-left: 0;
margin-left: 64px !important;
}
.header {
left: 0;
left: 64px !important;
}
.sidebar-collapsed + .header {
left: 0;
left: 64px !important;
}
.content-wrapper {
max-width: 100%;
padding: 0 1rem;
padding: 0 0.5rem;
}
.logo {
padding: 0;
justify-content: center;
}
}
</style>