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