App.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <a-config-provider :locale="locale">
  3. <a-layout class="app-layout">
  4. <!-- 头部 -->
  5. <a-layout-header class="app-header">
  6. <div class="header-content">
  7. <a-row align="middle" justify="space-between">
  8. <a-col>
  9. <a-space align="center">
  10. <!-- <a-icon type="gateway" size="large" /> -->
  11. <div class="logo"></div>
  12. </a-space>
  13. </a-col>
  14. <a-col>
  15. <a-space size="middle">
  16. <span class="header-status-item">
  17. <span :class="['status-badge', dataStore.serialConnected ? 'on' : 'off']" />
  18. <span>串口 {{ dataStore.serialConnected ? '已连接' : '未连接' }}</span>
  19. </span>
  20. <span class="header-status-item">
  21. <span :class="['status-badge', dataStore.mqttConnected ? 'on' : 'off']" />
  22. <span>MQTT {{ dataStore.mqttConnected ? '已连接' : '未连接' }}</span>
  23. </span>
  24. </a-space>
  25. </a-col>
  26. </a-row>
  27. </div>
  28. </a-layout-header>
  29. <a-layout>
  30. <!-- 左侧菜单 -->
  31. <a-layout-sider
  32. class="app-sider"
  33. width="256"
  34. :collapsible="true"
  35. v-model:collapsed="collapsed"
  36. :trigger="null"
  37. breakpoint="lg"
  38. collapsed-width="80"
  39. >
  40. <div class="app-title">配线架配置系统</div>
  41. <a-menu
  42. mode="inline"
  43. :selected-keys="[selectedKey]"
  44. :collapsed="collapsed"
  45. @click="handleMenuClick"
  46. theme="dark"
  47. class="side-menu"
  48. >
  49. <a-menu-item key="/real-time-status" icon="<area-chart />">
  50. <router-link to="/real-time-status">实时状态</router-link>
  51. </a-menu-item>
  52. <a-menu-item key="/system-config" icon="<setting />">
  53. <router-link to="/system-config">系统配置</router-link>
  54. </a-menu-item>
  55. <a-menu-item key="/led-debug" icon="<idcard />">
  56. <router-link to="/led-debug">卡号设置测试</router-link>
  57. </a-menu-item>
  58. <a-menu-item key="/port-status" icon="<api />">
  59. <router-link to="/port-status">端口状态</router-link>
  60. </a-menu-item>
  61. <a-menu-item key="/panel-status" icon="<appstore />">
  62. <router-link to="/panel-status">面板状态</router-link>
  63. </a-menu-item>
  64. <a-menu-item key="/panel-manage" icon="<cluster />">
  65. <router-link to="/panel-manage">线架管理</router-link>
  66. </a-menu-item>
  67. <a-menu-item key="/port-mapping" icon="<switcher />">
  68. <router-link to="/port-mapping">端口映射</router-link>
  69. </a-menu-item>
  70. <a-menu-item key="/alarm-status" icon="<alert />">
  71. <router-link to="/alarm-status">告警显示</router-link>
  72. </a-menu-item>
  73. <a-menu-item key="/env-sensor" icon="<dashboard />">
  74. <router-link to="/env-sensor">环境传感器</router-link>
  75. </a-menu-item>
  76. <a-menu-item key="/jumper-status" icon="<link-outlined />">
  77. <router-link to="/jumper-status">跳线器状态</router-link>
  78. </a-menu-item>
  79. <a-menu-item key="/ota-upgrade" icon="<cloud-upload-outlined />">
  80. <router-link to="/ota-upgrade">OTA升级</router-link>
  81. </a-menu-item>
  82. <a-menu-item key="/network-config" icon="<wifi />">
  83. <router-link to="/network-config">网络配置</router-link>
  84. </a-menu-item>
  85. <a-menu-item key="/backup-restore" icon="<database />">
  86. <router-link to="/backup-restore">数据备份</router-link>
  87. </a-menu-item>
  88. <a-menu-item key="/about" icon="<info-circle />">
  89. <router-link to="/about">关于</router-link>
  90. </a-menu-item>
  91. </a-menu>
  92. </a-layout-sider>
  93. <!-- 主要内容区域 -->
  94. <a-layout-content class="app-content">
  95. <div class="content-container">
  96. <router-view />
  97. </div>
  98. </a-layout-content>
  99. </a-layout>
  100. <!-- 页脚 -->
  101. <a-layout-footer class="app-footer">
  102. <p class="footer-text">&copy; {{ new Date().getFullYear() }} 配线架配置系统 v1.0.0 | 实时数据通信平台</p>
  103. </a-layout-footer>
  104. </a-layout>
  105. </a-config-provider>
  106. </template>
  107. <script setup>
  108. import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
  109. import { useRoute } from 'vue-router'
  110. import { useDataStore } from './stores/dataStore'
  111. import { initWebSocket } from './utils/websocket'
  112. import apiService from './api/apiService'
  113. import zhCN from 'ant-design-vue/es/locale/zh_CN'
  114. // 初始化数据存储
  115. const dataStore = useDataStore()
  116. const route = useRoute()
  117. const locale = zhCN
  118. const collapsed = ref(false)
  119. // 主动拉取 MQTT / 串口状态(SocketIO 事件仅在状态变化时触发,页面加载时若已连接收不到事件)
  120. let statusTimer = null
  121. async function refreshConnStatus() {
  122. try {
  123. const [mqttRes, serialRes] = await Promise.all([
  124. apiService.mqtt.getStatus(),
  125. apiService.serial.getStatus()
  126. ])
  127. if (mqttRes.data) dataStore.setMQTTConnected(!!mqttRes.data.connected)
  128. if (serialRes.data) dataStore.setSerialConnected(!!serialRes.data.connected)
  129. } catch (e) { /* ignore */ }
  130. }
  131. // 计算当前选中的菜单项
  132. const selectedKey = computed(() => {
  133. return route.path
  134. })
  135. // 处理菜单点击
  136. const handleMenuClick = (e) => {
  137. console.log('菜单点击:', e.key)
  138. }
  139. // 监听路由变化
  140. watch(() => route.path, (newPath) => {
  141. console.log('路由变化:', newPath)
  142. })
  143. // 组件挂载时初始化WebSocket连接 + 主动拉取连接状态
  144. onMounted(() => {
  145. initWebSocket(dataStore)
  146. refreshConnStatus()
  147. statusTimer = setInterval(refreshConnStatus, 5000)
  148. })
  149. onUnmounted(() => {
  150. if (statusTimer) clearInterval(statusTimer)
  151. })
  152. </script>
  153. <style scoped>
  154. /* 应用布局 */
  155. .app-layout {
  156. min-height: 100vh;
  157. }
  158. /* 头部样式 */
  159. .app-header {
  160. background-color: #001529;
  161. padding: 0;
  162. height: 64px;
  163. line-height: 64px;
  164. position: fixed;
  165. width: 100%;
  166. z-index: 10;
  167. }
  168. .header-content {
  169. max-width: 100%;
  170. margin: 0 auto;
  171. padding: 0 24px;
  172. height: 100%;
  173. }
  174. .app-title {
  175. margin: 0;
  176. font-size: 20px;
  177. font-weight: 600;
  178. color: #fff;
  179. margin: 10px;
  180. font-size: 15px;
  181. margin-bottom: 0;;
  182. }
  183. /* 侧边栏样式 */
  184. .app-sider {
  185. background-color: #001529;
  186. position: fixed;
  187. left: 0;
  188. top: 64px;
  189. height: calc(100vh - 64px);
  190. z-index: 9;
  191. transition: all 0.3s;
  192. }
  193. .logo {
  194. height: 60px;
  195. width: 94px;
  196. position: absolute;
  197. top: 0px;
  198. background: url('/vite.svg') center no-repeat;
  199. background-size: contain;
  200. }
  201. .side-menu {
  202. height: calc(100% - 64px);
  203. padding: 20px 0;
  204. padding-top: 0px;
  205. }
  206. .side-menu .ant-menu-item {
  207. margin: 0;
  208. padding: 0 20px;
  209. height: 50px;
  210. line-height: 50px;
  211. }
  212. .side-menu .ant-menu-item:hover {
  213. background-color: rgba(255, 255, 255, 0.1);
  214. }
  215. .side-menu .ant-menu-item-selected {
  216. background-color: #1890ff;
  217. }
  218. /* 主要内容区域 */
  219. .app-content {
  220. padding: 24px;
  221. background-color: #f0f2f5;
  222. min-height: calc(100vh - 64px);
  223. margin-left: 256px;
  224. margin-top: 64px;
  225. transition: all 0.3s;
  226. }
  227. .app-sider.collapsed + .app-content {
  228. margin-left: 80px;
  229. }
  230. .content-container {
  231. max-width: 100%;
  232. margin: 0 auto;
  233. }
  234. /* 页脚样式 */
  235. .app-footer {
  236. text-align: center;
  237. background-color: #001529;
  238. color: rgba(255, 255, 255, 0.65);
  239. font-size: 14px;
  240. padding: 16px 0;
  241. margin-left: 256px;
  242. transition: all 0.3s;
  243. }
  244. .app-sider.collapsed + .app-content + .app-footer {
  245. margin-left: 80px;
  246. }
  247. .footer-text {
  248. margin: 0;
  249. }
  250. /* 响应式调整 */
  251. @media (max-width: 1024px) {
  252. .app-sider {
  253. transform: translateX(-100%);
  254. }
  255. .app-sider.collapsed {
  256. transform: translateX(0);
  257. }
  258. .app-content {
  259. margin-left: 0;
  260. }
  261. .app-footer {
  262. margin-left: 0;
  263. }
  264. }
  265. @media (max-width: 768px) {
  266. .app-content {
  267. padding: 16px;
  268. }
  269. .header-content {
  270. padding: 0 16px;
  271. }
  272. .app-title {
  273. font-size: 18px;
  274. }
  275. }
  276. /* 路由链接样式 */
  277. :deep(.ant-menu-item a) {
  278. color: rgba(255, 255, 255, 0.65);
  279. width: 100%;
  280. display: flex;
  281. align-items: center;
  282. }
  283. :deep(.ant-menu-item a:hover) {
  284. color: #fff;
  285. }
  286. :deep(.ant-menu-item-selected a) {
  287. color: #fff;
  288. }
  289. /* 修复侧边栏滚动问题 */
  290. :deep(.ant-layout-sider-children) {
  291. overflow-y: auto;
  292. height: 100%;
  293. }
  294. .status-badge {
  295. display: inline-block;
  296. width: 8px;
  297. height: 8px;
  298. border-radius: 50%;
  299. }
  300. .status-badge.on {
  301. background-color: #52c41a;
  302. }
  303. .status-badge.off {
  304. background-color: #ff4d4f;
  305. }
  306. .header-status-item {
  307. color: #fff;
  308. font-size: 12px;
  309. }
  310. .header-status-item span {
  311. vertical-align: middle;
  312. }
  313. .header-status-item .status-badge {
  314. margin-right: 4px;
  315. }
  316. </style>