2025-09-19 14:38:47 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<el-container class="layout-container">
|
|
|
|
|
|
<!-- 侧边栏菜单 -->
|
2025-09-19 15:15:20 +08:00
|
|
|
|
<el-aside :width="isCollapse ? '64px' : '200px'" class="sidebar">
|
|
|
|
|
|
<div class="logo" @click="toggleCollapse">
|
|
|
|
|
|
<h2 v-if="!isCollapse" class="logo-text">猪场管理系统</h2>
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon v-else class="logo-icon">
|
|
|
|
|
|
<Menu/>
|
|
|
|
|
|
</el-icon>
|
2025-09-19 14:38:47 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<el-menu
|
2025-11-16 15:36:26 +08:00
|
|
|
|
:default-active="activeMenu"
|
|
|
|
|
|
class="sidebar-menu"
|
|
|
|
|
|
background-color="#545c64"
|
|
|
|
|
|
text-color="#fff"
|
|
|
|
|
|
active-text-color="#ffd04b"
|
|
|
|
|
|
:collapse="isCollapse"
|
|
|
|
|
|
:collapse-transition="false"
|
|
|
|
|
|
router
|
2025-11-21 16:57:50 +08:00
|
|
|
|
:default-openeds="['/device-management', '/monitor', '/pms', '/alarm', '/feed']"
|
2025-09-19 14:38:47 +08:00
|
|
|
|
>
|
|
|
|
|
|
<el-menu-item index="/">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<House/>
|
|
|
|
|
|
</el-icon>
|
2025-09-19 15:15:20 +08:00
|
|
|
|
<template #title>首页</template>
|
2025-09-19 14:38:47 +08:00
|
|
|
|
</el-menu-item>
|
2025-09-30 23:05:27 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 设备管理二级菜单 -->
|
|
|
|
|
|
<el-sub-menu index="/device-management">
|
|
|
|
|
|
<template #title>
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Setting/>
|
|
|
|
|
|
</el-icon>
|
2025-09-30 23:05:27 +08:00
|
|
|
|
<span>设备</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-menu-item index="/devices">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Monitor/>
|
|
|
|
|
|
</el-icon>
|
2025-09-30 23:05:27 +08:00
|
|
|
|
<template #title>设备管理</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/device-templates">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Tickets/>
|
|
|
|
|
|
</el-icon>
|
2025-09-30 23:05:27 +08:00
|
|
|
|
<template #title>设备模板管理</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
</el-sub-menu>
|
|
|
|
|
|
|
2025-10-22 18:55:51 +08:00
|
|
|
|
<!-- 猪场管理二级菜单 -->
|
|
|
|
|
|
<el-sub-menu index="/pms">
|
|
|
|
|
|
<template #title>
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<OfficeBuilding/>
|
|
|
|
|
|
</el-icon>
|
2025-10-22 18:55:51 +08:00
|
|
|
|
<span>猪场管理</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-menu-item index="/pms/farm-management">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Tickets/>
|
|
|
|
|
|
</el-icon>
|
2025-10-22 18:55:51 +08:00
|
|
|
|
<template #title>栏舍管理</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-10-23 11:51:19 +08:00
|
|
|
|
<el-menu-item index="/pms/batch-management">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Management/>
|
|
|
|
|
|
</el-icon>
|
2025-10-23 11:51:19 +08:00
|
|
|
|
<template #title>猪群管理</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-10-22 18:55:51 +08:00
|
|
|
|
</el-sub-menu>
|
|
|
|
|
|
|
2025-11-21 16:57:50 +08:00
|
|
|
|
<!-- 饲料管理二级菜单 -->
|
|
|
|
|
|
<el-sub-menu index="/feed">
|
|
|
|
|
|
<template #title>
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<TakeawayBox />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<span>饲料管理</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-menu-item index="/feed/raw-materials">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Tickets/>
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<template #title>原料管理</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-11-21 17:55:20 +08:00
|
|
|
|
<el-menu-item index="/feed/nutrients">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Tickets/>
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<template #title>营养管理</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-11-21 18:18:22 +08:00
|
|
|
|
<el-menu-item index="/feed/pig-age-stages">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Tickets/>
|
|
|
|
|
|
</el-icon>
|
2025-11-22 14:19:42 +08:00
|
|
|
|
<template #title>年龄阶段管理</template>
|
2025-11-21 18:18:22 +08:00
|
|
|
|
</el-menu-item>
|
2025-11-21 18:45:38 +08:00
|
|
|
|
<el-menu-item index="/feed/pig-breeds">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Tickets/>
|
|
|
|
|
|
</el-icon>
|
2025-11-22 14:06:46 +08:00
|
|
|
|
<template #title>品种管理</template>
|
2025-11-21 18:45:38 +08:00
|
|
|
|
</el-menu-item>
|
2025-11-21 17:55:20 +08:00
|
|
|
|
|
2025-11-21 16:57:50 +08:00
|
|
|
|
</el-sub-menu>
|
|
|
|
|
|
|
2025-09-19 14:38:47 +08:00
|
|
|
|
<el-menu-item index="/plans">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Calendar/>
|
|
|
|
|
|
</el-icon>
|
2025-09-19 15:15:20 +08:00
|
|
|
|
<template #title>计划管理</template>
|
2025-09-19 14:38:47 +08:00
|
|
|
|
</el-menu-item>
|
2025-10-20 15:48:08 +08:00
|
|
|
|
|
2025-11-16 20:03:35 +08:00
|
|
|
|
<!-- 告警中心二级菜单 -->
|
|
|
|
|
|
<el-sub-menu index="/alarm">
|
|
|
|
|
|
<template #title>
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Bell/>
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<span>告警中心</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-menu-item index="/alarms">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Warning />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<template #title>告警管理</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/alarms/thresholds">
|
|
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Setting />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<template #title>阈值告警配置</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
</el-sub-menu>
|
|
|
|
|
|
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<!-- 数据中心二级菜单 -->
|
2025-10-20 15:48:08 +08:00
|
|
|
|
<el-sub-menu index="/monitor">
|
|
|
|
|
|
<template #title>
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<DataAnalysis/>
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<span>数据中心</span>
|
2025-10-20 15:48:08 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<el-menu-item index="/monitor/device-command-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Document/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 15:48:08 +08:00
|
|
|
|
<template #title>设备命令日志</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<el-menu-item index="/monitor/medication-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<FirstAidKit/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>用药记录</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-10-25 15:34:28 +08:00
|
|
|
|
<el-menu-item index="/monitor/notifications">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Bell/>
|
|
|
|
|
|
</el-icon>
|
2025-10-25 15:34:28 +08:00
|
|
|
|
<template #title>通知记录</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<el-menu-item index="/monitor/pending-collections">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Clock/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>待采集请求</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/pig-batch-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Files/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>猪批次日志</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/pig-purchases">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<ShoppingCart/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>猪只采购记录</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/pig-sales">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<SoldOut/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>猪只售卖记录</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/pig-sick-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Warning/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>病猪日志</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/pig-transfer-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Switch/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>猪只迁移日志</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/sensor-data">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<DataLine/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>传感器数据</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-11-01 14:38:05 +08:00
|
|
|
|
<el-menu-item index="/monitor/plan-execution-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<List/>
|
|
|
|
|
|
</el-icon>
|
2025-11-01 14:38:05 +08:00
|
|
|
|
<template #title>计划执行日志</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<el-menu-item index="/monitor/task-execution-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Finished/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>任务执行日志</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/user-action-logs">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<User/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>用户操作日志</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/weighing-batches">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<ScaleToOriginal/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>批次称重记录</template>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
<el-menu-item index="/monitor/weighing-records">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<ScaleToOriginal/>
|
|
|
|
|
|
</el-icon>
|
2025-10-20 16:31:16 +08:00
|
|
|
|
<template #title>单次称重记录</template>
|
|
|
|
|
|
</el-menu-item>
|
2025-10-20 15:48:08 +08:00
|
|
|
|
</el-sub-menu>
|
|
|
|
|
|
|
2025-09-19 14:38:47 +08:00
|
|
|
|
</el-menu>
|
|
|
|
|
|
</el-aside>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 主区域 -->
|
|
|
|
|
|
<el-container>
|
|
|
|
|
|
<!-- 头部 -->
|
|
|
|
|
|
<el-header class="header">
|
|
|
|
|
|
<div class="header-content">
|
2025-09-19 15:15:20 +08:00
|
|
|
|
<div class="header-left">
|
|
|
|
|
|
<el-button link @click="toggleCollapse">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<el-icon>
|
|
|
|
|
|
<Expand v-if="isCollapse"/>
|
|
|
|
|
|
<Fold v-else/>
|
|
|
|
|
|
</el-icon>
|
2025-09-19 15:15:20 +08:00
|
|
|
|
</el-button>
|
|
|
|
|
|
<h3 class="page-title">{{ currentPageTitle }}</h3>
|
|
|
|
|
|
</div>
|
2025-09-19 14:38:47 +08:00
|
|
|
|
<div class="user-info">
|
2025-11-16 20:03:35 +08:00
|
|
|
|
<!-- 告警铃铛图标和角标 -->
|
|
|
|
|
|
<el-badge :value="unresolvedAlarmCount" :max="99" class="alarm-badge" @click="goToAlarmList" v-if="unresolvedAlarmCount > 0">
|
|
|
|
|
|
<el-icon :size="20"><Bell /></el-icon>
|
|
|
|
|
|
</el-badge>
|
|
|
|
|
|
<el-icon :size="20" class="alarm-icon" @click="goToAlarmList" v-else><Bell /></el-icon>
|
|
|
|
|
|
|
2025-09-19 14:38:47 +08:00
|
|
|
|
<el-dropdown>
|
|
|
|
|
|
<span class="el-dropdown-link">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
{{ username }} <el-icon><ArrowDown/></el-icon>
|
2025-09-19 14:38:47 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
<template #dropdown>
|
|
|
|
|
|
<el-dropdown-menu>
|
|
|
|
|
|
<el-dropdown-item>个人信息</el-dropdown-item>
|
2025-09-30 22:35:36 +08:00
|
|
|
|
<el-dropdown-item @click="logout">退出登录</el-dropdown-item>
|
2025-09-19 14:38:47 +08:00
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-header>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 主内容区 -->
|
|
|
|
|
|
<el-main class="main-content">
|
2025-11-16 15:36:26 +08:00
|
|
|
|
<router-view/>
|
2025-09-19 14:38:47 +08:00
|
|
|
|
</el-main>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 底部 -->
|
|
|
|
|
|
<el-footer class="footer">
|
|
|
|
|
|
<p>© 2025 猪场管理系统. All rights reserved.</p>
|
|
|
|
|
|
</el-footer>
|
|
|
|
|
|
</el-container>
|
|
|
|
|
|
</el-container>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-11-16 15:36:26 +08:00
|
|
|
|
import {ref, computed, onMounted, onUnmounted} from 'vue';
|
|
|
|
|
|
import {useRoute, useRouter} from 'vue-router';
|
|
|
|
|
|
import {
|
|
|
|
|
|
House,
|
|
|
|
|
|
Monitor,
|
|
|
|
|
|
Calendar,
|
|
|
|
|
|
ArrowDown,
|
|
|
|
|
|
Menu,
|
|
|
|
|
|
Fold,
|
|
|
|
|
|
Expand,
|
|
|
|
|
|
Setting,
|
|
|
|
|
|
Tickets,
|
|
|
|
|
|
DataAnalysis,
|
|
|
|
|
|
Document,
|
|
|
|
|
|
FirstAidKit,
|
|
|
|
|
|
Clock,
|
|
|
|
|
|
Files,
|
|
|
|
|
|
ShoppingCart,
|
|
|
|
|
|
SoldOut,
|
|
|
|
|
|
Warning,
|
|
|
|
|
|
Switch,
|
|
|
|
|
|
List,
|
|
|
|
|
|
DataLine,
|
|
|
|
|
|
Finished,
|
|
|
|
|
|
User,
|
|
|
|
|
|
ScaleToOriginal,
|
|
|
|
|
|
OfficeBuilding,
|
|
|
|
|
|
Management,
|
2025-11-21 16:57:50 +08:00
|
|
|
|
Bell,
|
|
|
|
|
|
TakeawayBox
|
2025-10-20 16:31:16 +08:00
|
|
|
|
} from '@element-plus/icons-vue';
|
2025-11-16 20:03:35 +08:00
|
|
|
|
import { getActiveAlarms } from '../api/alarm'; // 导入告警API
|
2025-09-19 14:38:47 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'MainLayout',
|
|
|
|
|
|
components: {
|
2025-11-16 15:36:26 +08:00
|
|
|
|
House,
|
|
|
|
|
|
Monitor,
|
|
|
|
|
|
Calendar,
|
|
|
|
|
|
ArrowDown,
|
|
|
|
|
|
Menu,
|
|
|
|
|
|
Fold,
|
|
|
|
|
|
Expand,
|
|
|
|
|
|
Setting,
|
|
|
|
|
|
Tickets,
|
|
|
|
|
|
DataAnalysis,
|
|
|
|
|
|
Document,
|
|
|
|
|
|
FirstAidKit,
|
|
|
|
|
|
Clock,
|
|
|
|
|
|
Files,
|
|
|
|
|
|
ShoppingCart,
|
|
|
|
|
|
SoldOut,
|
|
|
|
|
|
Warning,
|
|
|
|
|
|
Switch,
|
|
|
|
|
|
List,
|
|
|
|
|
|
DataLine,
|
|
|
|
|
|
Finished,
|
|
|
|
|
|
User,
|
|
|
|
|
|
ScaleToOriginal,
|
|
|
|
|
|
OfficeBuilding,
|
|
|
|
|
|
Management,
|
2025-11-21 16:57:50 +08:00
|
|
|
|
Bell,
|
|
|
|
|
|
TakeawayBox
|
2025-09-19 14:38:47 +08:00
|
|
|
|
},
|
|
|
|
|
|
setup() {
|
|
|
|
|
|
const route = useRoute();
|
2025-09-30 22:35:36 +08:00
|
|
|
|
const router = useRouter();
|
2025-09-19 15:15:20 +08:00
|
|
|
|
const isCollapse = ref(false);
|
2025-09-30 22:35:36 +08:00
|
|
|
|
const username = ref(localStorage.getItem('username') || '管理员');
|
2025-11-16 20:03:35 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 未解决告警数量
|
|
|
|
|
|
* @type {import('vue').Ref<number>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
const unresolvedAlarmCount = ref(0);
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 告警刷新定时器
|
|
|
|
|
|
* @type {number | null}
|
|
|
|
|
|
*/
|
|
|
|
|
|
let alarmFetchInterval = null;
|
2025-09-30 22:35:36 +08:00
|
|
|
|
|
|
|
|
|
|
const handleStorageChange = () => {
|
|
|
|
|
|
username.value = localStorage.getItem('username') || '管理员';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-16 20:03:35 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取未解决告警数量
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
const fetchUnresolvedAlarmCount = async () => {
|
2025-11-16 23:24:06 +08:00
|
|
|
|
// 检查用户是否已登录
|
|
|
|
|
|
const token = localStorage.getItem('jwt_token');
|
|
|
|
|
|
if (!token) {
|
|
|
|
|
|
// 如果未登录,则不执行告警接口调用
|
|
|
|
|
|
unresolvedAlarmCount.value = 0;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-16 20:03:35 +08:00
|
|
|
|
try {
|
|
|
|
|
|
// 调用API获取活跃且未忽略的告警数量
|
|
|
|
|
|
const response = await getActiveAlarms({
|
|
|
|
|
|
is_ignored: false,
|
2025-11-16 20:24:28 +08:00
|
|
|
|
page: 1, // 确保分页参数完整
|
2025-11-16 20:03:35 +08:00
|
|
|
|
page_size: 1 // 只需获取总数,所以page_size设为1
|
|
|
|
|
|
});
|
2025-11-18 13:34:36 +08:00
|
|
|
|
if (response && response.data && response.data.pagination) {
|
|
|
|
|
|
unresolvedAlarmCount.value = response.data.pagination.total || 0;
|
2025-11-16 20:03:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('获取未解决告警数量失败:', error);
|
|
|
|
|
|
unresolvedAlarmCount.value = 0; // 发生错误时重置为0
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 跳转到告警列表页面
|
|
|
|
|
|
* @returns {void}
|
|
|
|
|
|
*/
|
|
|
|
|
|
const goToAlarmList = () => {
|
|
|
|
|
|
router.push('/alarms');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-30 22:35:36 +08:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
window.addEventListener('storage', handleStorageChange);
|
2025-11-18 13:44:01 +08:00
|
|
|
|
window.addEventListener('alarm-updated', fetchUnresolvedAlarmCount);
|
2025-11-16 20:03:35 +08:00
|
|
|
|
// 首次加载时获取告警数量
|
|
|
|
|
|
fetchUnresolvedAlarmCount();
|
2025-11-16 23:24:06 +08:00
|
|
|
|
// 每60秒刷新一次告警数量
|
|
|
|
|
|
alarmFetchInterval = setInterval(fetchUnresolvedAlarmCount, 60000);
|
2025-09-30 22:35:36 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
window.removeEventListener('storage', handleStorageChange);
|
2025-11-18 13:44:01 +08:00
|
|
|
|
window.removeEventListener('alarm-updated', fetchUnresolvedAlarmCount);
|
2025-11-16 20:03:35 +08:00
|
|
|
|
// 清除定时器
|
|
|
|
|
|
if (alarmFetchInterval) {
|
|
|
|
|
|
clearInterval(alarmFetchInterval);
|
|
|
|
|
|
alarmFetchInterval = null;
|
|
|
|
|
|
}
|
2025-09-30 22:35:36 +08:00
|
|
|
|
});
|
2025-11-16 15:36:26 +08:00
|
|
|
|
|
2025-09-19 15:15:20 +08:00
|
|
|
|
const toggleCollapse = () => {
|
|
|
|
|
|
isCollapse.value = !isCollapse.value;
|
|
|
|
|
|
};
|
2025-11-16 15:36:26 +08:00
|
|
|
|
|
2025-09-19 14:38:47 +08:00
|
|
|
|
const activeMenu = computed(() => {
|
2025-10-22 18:55:51 +08:00
|
|
|
|
const path = route.path;
|
2025-11-21 16:57:50 +08:00
|
|
|
|
if (path.startsWith('/monitor') || path.startsWith('/pms') || path.startsWith('/devices') || path.startsWith('/device-templates') || path.startsWith('/alarms') || path.startsWith('/feed')) {
|
2025-10-22 18:55:51 +08:00
|
|
|
|
return path;
|
2025-09-30 23:05:27 +08:00
|
|
|
|
}
|
2025-09-19 14:38:47 +08:00
|
|
|
|
return route.path;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const currentPageTitle = computed(() => {
|
2025-11-16 15:36:26 +08:00
|
|
|
|
return route.meta.title || '猪场管理系统';
|
2025-09-19 14:38:47 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-30 22:35:36 +08:00
|
|
|
|
const logout = () => {
|
|
|
|
|
|
localStorage.removeItem('jwt_token');
|
2025-10-20 16:31:16 +08:00
|
|
|
|
localStorage.removeItem('username');
|
|
|
|
|
|
username.value = '管理员';
|
2025-09-30 22:35:36 +08:00
|
|
|
|
router.push('/login');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-19 14:38:47 +08:00
|
|
|
|
return {
|
2025-09-19 15:15:20 +08:00
|
|
|
|
isCollapse,
|
2025-09-19 14:38:47 +08:00
|
|
|
|
activeMenu,
|
2025-09-19 15:15:20 +08:00
|
|
|
|
currentPageTitle,
|
2025-09-30 22:35:36 +08:00
|
|
|
|
toggleCollapse,
|
|
|
|
|
|
logout,
|
2025-11-16 20:03:35 +08:00
|
|
|
|
username,
|
|
|
|
|
|
unresolvedAlarmCount, // 暴露给模板
|
|
|
|
|
|
goToAlarmList // 暴露给模板
|
2025-09-19 14:38:47 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.layout-container {
|
|
|
|
|
|
min-height: 100vh;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.sidebar {
|
|
|
|
|
|
background-color: #545c64;
|
|
|
|
|
|
box-shadow: 2px 0 6px rgba(0, 21, 18, 0.1);
|
2025-09-19 15:15:20 +08:00
|
|
|
|
transition: width 0.3s ease;
|
|
|
|
|
|
overflow: hidden;
|
2025-09-19 14:38:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.logo {
|
|
|
|
|
|
height: 60px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
background-color: #454d54;
|
2025-09-19 15:15:20 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.logo-text {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.logo-icon {
|
|
|
|
|
|
font-size: 24px;
|
2025-09-19 14:38:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.sidebar-menu {
|
|
|
|
|
|
border-right: none;
|
|
|
|
|
|
height: calc(100% - 60px);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-19 15:15:20 +08:00
|
|
|
|
.sidebar-menu:not(.el-menu--collapse) {
|
|
|
|
|
|
width: 200px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-19 14:38:47 +08:00
|
|
|
|
.header {
|
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
|
box-shadow: 0 1px 4px rgba(0, 21, 18, 0.1);
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.header-content {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
height: 100%;
|
2025-09-19 15:15:20 +08:00
|
|
|
|
padding: 0 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.header-left {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 15px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-title {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
|
font-weight: 500;
|
2025-09-19 14:38:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.user-info {
|
2025-09-19 15:15:20 +08:00
|
|
|
|
margin-right: 10px;
|
2025-11-16 20:03:35 +08:00
|
|
|
|
display: flex; /* 使内部元素水平排列 */
|
|
|
|
|
|
align-items: center; /* 垂直居中 */
|
|
|
|
|
|
gap: 20px; /* 元素间距 */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.alarm-badge {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.alarm-icon {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
color: #606266; /* 默认图标颜色 */
|
2025-09-19 14:38:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.main-content {
|
|
|
|
|
|
background-color: #f5f5f5;
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
|
color: #666;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
border-top: 1px solid #eee;
|
|
|
|
|
|
}
|
2025-11-21 18:45:38 +08:00
|
|
|
|
</style>
|