| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- <template>
- <a-config-provider :locale="locale">
- <a-layout class="app-layout">
- <!-- 头部 -->
- <a-layout-header class="app-header">
- <div class="header-content">
- <a-row align="middle" justify="space-between">
- <a-col>
- <a-space align="center">
- <!-- <a-icon type="gateway" size="large" /> -->
- <div class="logo"></div>
- </a-space>
- </a-col>
- <a-col>
- <a-space size="middle">
- <span class="header-status-item">
- <span :class="['status-badge', dataStore.serialConnected ? 'on' : 'off']" />
- <span>串口 {{ dataStore.serialConnected ? '已连接' : '未连接' }}</span>
- </span>
- <span class="header-status-item">
- <span :class="['status-badge', dataStore.mqttConnected ? 'on' : 'off']" />
- <span>MQTT {{ dataStore.mqttConnected ? '已连接' : '未连接' }}</span>
- </span>
- </a-space>
- </a-col>
- </a-row>
- </div>
- </a-layout-header>
- <a-layout>
- <!-- 左侧菜单 -->
- <a-layout-sider
- class="app-sider"
- width="256"
- :collapsible="true"
- v-model:collapsed="collapsed"
- :trigger="null"
- breakpoint="lg"
- collapsed-width="80"
- >
- <div class="app-title">配线架配置系统</div>
- <a-menu
- mode="inline"
- :selected-keys="[selectedKey]"
- :collapsed="collapsed"
- @click="handleMenuClick"
- theme="dark"
- class="side-menu"
- >
- <a-menu-item key="/real-time-status" icon="<area-chart />">
- <router-link to="/real-time-status">实时状态</router-link>
- </a-menu-item>
- <a-menu-item key="/system-config" icon="<setting />">
- <router-link to="/system-config">系统配置</router-link>
- </a-menu-item>
- <a-menu-item key="/led-debug" icon="<idcard />">
- <router-link to="/led-debug">卡号设置测试</router-link>
- </a-menu-item>
- <a-menu-item key="/port-status" icon="<api />">
- <router-link to="/port-status">端口状态</router-link>
- </a-menu-item>
- <a-menu-item key="/panel-status" icon="<appstore />">
- <router-link to="/panel-status">面板状态</router-link>
- </a-menu-item>
- <a-menu-item key="/panel-manage" icon="<cluster />">
- <router-link to="/panel-manage">线架管理</router-link>
- </a-menu-item>
- <a-menu-item key="/port-mapping" icon="<switcher />">
- <router-link to="/port-mapping">端口映射</router-link>
- </a-menu-item>
- <a-menu-item key="/alarm-status" icon="<alert />">
- <router-link to="/alarm-status">告警显示</router-link>
- </a-menu-item>
- <a-menu-item key="/env-sensor" icon="<dashboard />">
- <router-link to="/env-sensor">环境传感器</router-link>
- </a-menu-item>
- <a-menu-item key="/jumper-status" icon="<link-outlined />">
- <router-link to="/jumper-status">跳线器状态</router-link>
- </a-menu-item>
- <a-menu-item key="/ota-upgrade" icon="<cloud-upload-outlined />">
- <router-link to="/ota-upgrade">OTA升级</router-link>
- </a-menu-item>
- <a-menu-item key="/network-config" icon="<wifi />">
- <router-link to="/network-config">网络配置</router-link>
- </a-menu-item>
- <a-menu-item key="/backup-restore" icon="<database />">
- <router-link to="/backup-restore">数据备份</router-link>
- </a-menu-item>
- <a-menu-item key="/about" icon="<info-circle />">
- <router-link to="/about">关于</router-link>
- </a-menu-item>
- </a-menu>
- </a-layout-sider>
- <!-- 主要内容区域 -->
- <a-layout-content class="app-content">
- <div class="content-container">
- <router-view />
- </div>
- </a-layout-content>
- </a-layout>
- <!-- 页脚 -->
- <a-layout-footer class="app-footer">
- <p class="footer-text">© {{ new Date().getFullYear() }} 配线架配置系统 v1.0.0 | 实时数据通信平台</p>
- </a-layout-footer>
- </a-layout>
- </a-config-provider>
- </template>
- <script setup>
- import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
- import { useRoute } from 'vue-router'
- import { useDataStore } from './stores/dataStore'
- import { initWebSocket } from './utils/websocket'
- import apiService from './api/apiService'
- import zhCN from 'ant-design-vue/es/locale/zh_CN'
- // 初始化数据存储
- const dataStore = useDataStore()
- const route = useRoute()
- const locale = zhCN
- const collapsed = ref(false)
- // 主动拉取 MQTT / 串口状态(SocketIO 事件仅在状态变化时触发,页面加载时若已连接收不到事件)
- let statusTimer = null
- async function refreshConnStatus() {
- try {
- const [mqttRes, serialRes] = await Promise.all([
- apiService.mqtt.getStatus(),
- apiService.serial.getStatus()
- ])
- if (mqttRes.data) dataStore.setMQTTConnected(!!mqttRes.data.connected)
- if (serialRes.data) dataStore.setSerialConnected(!!serialRes.data.connected)
- } catch (e) { /* ignore */ }
- }
- // 计算当前选中的菜单项
- const selectedKey = computed(() => {
- return route.path
- })
- // 处理菜单点击
- const handleMenuClick = (e) => {
- console.log('菜单点击:', e.key)
- }
- // 监听路由变化
- watch(() => route.path, (newPath) => {
- console.log('路由变化:', newPath)
- })
- // 组件挂载时初始化WebSocket连接 + 主动拉取连接状态
- onMounted(() => {
- initWebSocket(dataStore)
- refreshConnStatus()
- statusTimer = setInterval(refreshConnStatus, 5000)
- })
- onUnmounted(() => {
- if (statusTimer) clearInterval(statusTimer)
- })
- </script>
- <style scoped>
- /* 应用布局 */
- .app-layout {
- min-height: 100vh;
- }
- /* 头部样式 */
- .app-header {
- background-color: #001529;
- padding: 0;
- height: 64px;
- line-height: 64px;
- position: fixed;
- width: 100%;
- z-index: 10;
- }
- .header-content {
- max-width: 100%;
- margin: 0 auto;
- padding: 0 24px;
- height: 100%;
- }
- .app-title {
- margin: 0;
- font-size: 20px;
- font-weight: 600;
- color: #fff;
- margin: 10px;
- font-size: 15px;
- margin-bottom: 0;;
- }
- /* 侧边栏样式 */
- .app-sider {
- background-color: #001529;
- position: fixed;
- left: 0;
- top: 64px;
- height: calc(100vh - 64px);
- z-index: 9;
- transition: all 0.3s;
- }
- .logo {
- height: 60px;
- width: 94px;
- position: absolute;
- top: 0px;
- background: url('/vite.svg') center no-repeat;
- background-size: contain;
- }
- .side-menu {
- height: calc(100% - 64px);
- padding: 20px 0;
- padding-top: 0px;
- }
- .side-menu .ant-menu-item {
- margin: 0;
- padding: 0 20px;
- height: 50px;
- line-height: 50px;
- }
- .side-menu .ant-menu-item:hover {
- background-color: rgba(255, 255, 255, 0.1);
- }
- .side-menu .ant-menu-item-selected {
- background-color: #1890ff;
- }
- /* 主要内容区域 */
- .app-content {
- padding: 24px;
- background-color: #f0f2f5;
- min-height: calc(100vh - 64px);
- margin-left: 256px;
- margin-top: 64px;
- transition: all 0.3s;
- }
- .app-sider.collapsed + .app-content {
- margin-left: 80px;
- }
- .content-container {
- max-width: 100%;
- margin: 0 auto;
- }
- /* 页脚样式 */
- .app-footer {
- text-align: center;
- background-color: #001529;
- color: rgba(255, 255, 255, 0.65);
- font-size: 14px;
- padding: 16px 0;
- margin-left: 256px;
- transition: all 0.3s;
- }
- .app-sider.collapsed + .app-content + .app-footer {
- margin-left: 80px;
- }
- .footer-text {
- margin: 0;
- }
- /* 响应式调整 */
- @media (max-width: 1024px) {
- .app-sider {
- transform: translateX(-100%);
- }
-
- .app-sider.collapsed {
- transform: translateX(0);
- }
-
- .app-content {
- margin-left: 0;
- }
-
- .app-footer {
- margin-left: 0;
- }
- }
- @media (max-width: 768px) {
- .app-content {
- padding: 16px;
- }
-
- .header-content {
- padding: 0 16px;
- }
-
- .app-title {
- font-size: 18px;
- }
- }
- /* 路由链接样式 */
- :deep(.ant-menu-item a) {
- color: rgba(255, 255, 255, 0.65);
- width: 100%;
- display: flex;
- align-items: center;
- }
- :deep(.ant-menu-item a:hover) {
- color: #fff;
- }
- :deep(.ant-menu-item-selected a) {
- color: #fff;
- }
- /* 修复侧边栏滚动问题 */
- :deep(.ant-layout-sider-children) {
- overflow-y: auto;
- height: 100%;
- }
- .status-badge {
- display: inline-block;
- width: 8px;
- height: 8px;
- border-radius: 50%;
- }
- .status-badge.on {
- background-color: #52c41a;
- }
- .status-badge.off {
- background-color: #ff4d4f;
- }
- .header-status-item {
- color: #fff;
- font-size: 12px;
- }
- .header-status-item span {
- vertical-align: middle;
- }
- .header-status-item .status-badge {
- margin-right: 4px;
- }
- </style>
|