Initial commit: 上传完整代码
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
*.json
|
||||
*.ts
|
||||
*.tsbuildinfo
|
||||
@@ -0,0 +1,33 @@
|
||||
# .
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
|
||||
|
||||
## Type Support for `.vue` Imports in TS
|
||||
|
||||
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
|
||||
|
||||
## Customize configuration
|
||||
|
||||
See [Vite Configuration Reference](https://vite.dev/config/).
|
||||
|
||||
## Project Setup
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compile and Hot-Reload for Development
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Type-Check, Compile and Minify for Production
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>测偏仪管理后台</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1,244 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { useRoute } from 'vue-router'
|
||||
import {
|
||||
Monitor,
|
||||
Connection,
|
||||
List,
|
||||
Setting,
|
||||
ArrowLeft,
|
||||
ArrowRight
|
||||
} from '@element-plus/icons-vue'
|
||||
|
||||
const systemInfo = ref(null)
|
||||
const networkInfo = ref(null)
|
||||
const isSidebarCollapsed = ref(false)
|
||||
const route = useRoute()
|
||||
|
||||
const currentRoute = computed(() => route.path)
|
||||
const activeMenu = computed(() => route.path)
|
||||
|
||||
const fetchSystemInfo = async () => {
|
||||
try {
|
||||
const response = await axios.get('/system/info')
|
||||
systemInfo.value = response.data
|
||||
} catch (error) {
|
||||
console.error('获取系统信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const fetchNetworkInfo = async () => {
|
||||
try {
|
||||
const response = await axios.get('/system/network')
|
||||
networkInfo.value = response.data.interfaces
|
||||
} catch (error) {
|
||||
console.error('获取网络信息失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const getProgressClass = (value: number) => {
|
||||
if (value >= 90) return 'danger'
|
||||
if (value >= 70) return 'warning'
|
||||
return 'normal'
|
||||
}
|
||||
|
||||
const toggleSidebar = () => {
|
||||
isSidebarCollapsed.value = !isSidebarCollapsed.value
|
||||
}
|
||||
|
||||
// 页面加载时获取信息
|
||||
onMounted(() => {
|
||||
fetchSystemInfo()
|
||||
fetchNetworkInfo()
|
||||
// 每30秒更新一次系统信息
|
||||
setInterval(fetchSystemInfo, 30000)
|
||||
// 每60秒更新一次网络信息
|
||||
setInterval(fetchNetworkInfo, 60000)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-container>
|
||||
<el-aside :width="isSidebarCollapsed ? '64px' : '200px'">
|
||||
<div class="logo">
|
||||
<span v-if="!isSidebarCollapsed">树莓派设备管理系统</span>
|
||||
</div>
|
||||
<el-menu
|
||||
:default-active="activeMenu"
|
||||
class="el-menu-vertical"
|
||||
:collapse="isSidebarCollapsed"
|
||||
router
|
||||
>
|
||||
<el-menu-item index="/">
|
||||
<el-icon><Monitor /></el-icon>
|
||||
<template #title>仪表盘</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/devices">
|
||||
<el-icon><Connection /></el-icon>
|
||||
<template #title>设备管理</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/device-types">
|
||||
<el-icon><List /></el-icon>
|
||||
<template #title>设备类型</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/interfaces">
|
||||
<el-icon><List /></el-icon>
|
||||
<template #title>接口管理</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/services">
|
||||
<el-icon><Setting /></el-icon>
|
||||
<template #title>服务管理</template>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</el-aside>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<div class="main-container" :class="{ 'sidebar-collapsed': isSidebarCollapsed }">
|
||||
<header class="header">
|
||||
<h1>测偏仪管理后台</h1>
|
||||
</header>
|
||||
<main class="main-content">
|
||||
<div class="content-wrapper">
|
||||
<router-view></router-view>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</el-container>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.app-container {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
background-color: #f5f5f5;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.el-container {
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.el-aside {
|
||||
background-color: #304156;
|
||||
height: 100vh;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 1000;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
flex: 1;
|
||||
margin-left: 200px;
|
||||
transition: margin-left 0.3s;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.main-container.sidebar-collapsed {
|
||||
margin-left: 64px;
|
||||
}
|
||||
|
||||
.header {
|
||||
background-color: white;
|
||||
padding: 1rem 2rem;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
left: 200px;
|
||||
z-index: 900;
|
||||
transition: left 0.3s;
|
||||
}
|
||||
|
||||
.sidebar-collapsed + .header {
|
||||
left: 64px;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: 2rem;
|
||||
margin-top: 60px;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
max-width: 1200px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
background-color: transparent;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 60px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 20px;
|
||||
background-color: #2b2f3a;
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.el-menu {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 1400px) {
|
||||
.content-wrapper {
|
||||
max-width: 1000px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.content-wrapper {
|
||||
max-width: 800px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.el-aside {
|
||||
position: fixed;
|
||||
height: 100vh;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.main-container.sidebar-collapsed {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.sidebar-collapsed + .header {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
max-width: 100%;
|
||||
padding: 0 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,86 @@
|
||||
/* color palette from <https://github.com/vuejs/theme> */
|
||||
:root {
|
||||
--vt-c-white: #ffffff;
|
||||
--vt-c-white-soft: #f8f8f8;
|
||||
--vt-c-white-mute: #f2f2f2;
|
||||
|
||||
--vt-c-black: #181818;
|
||||
--vt-c-black-soft: #222222;
|
||||
--vt-c-black-mute: #282828;
|
||||
|
||||
--vt-c-indigo: #2c3e50;
|
||||
|
||||
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
|
||||
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
|
||||
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
|
||||
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
|
||||
|
||||
--vt-c-text-light-1: var(--vt-c-indigo);
|
||||
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
|
||||
--vt-c-text-dark-1: var(--vt-c-white);
|
||||
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
|
||||
}
|
||||
|
||||
/* semantic color variables for this project */
|
||||
:root {
|
||||
--color-background: var(--vt-c-white);
|
||||
--color-background-soft: var(--vt-c-white-soft);
|
||||
--color-background-mute: var(--vt-c-white-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-light-2);
|
||||
--color-border-hover: var(--vt-c-divider-light-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-light-1);
|
||||
--color-text: var(--vt-c-text-light-1);
|
||||
|
||||
--section-gap: 160px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color-background: var(--vt-c-black);
|
||||
--color-background-soft: var(--vt-c-black-soft);
|
||||
--color-background-mute: var(--vt-c-black-mute);
|
||||
|
||||
--color-border: var(--vt-c-divider-dark-2);
|
||||
--color-border-hover: var(--vt-c-divider-dark-1);
|
||||
|
||||
--color-heading: var(--vt-c-text-dark-1);
|
||||
--color-text: var(--vt-c-text-dark-2);
|
||||
}
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
color: var(--color-text);
|
||||
background: var(--color-background);
|
||||
transition:
|
||||
color 0.5s,
|
||||
background-color 0.5s;
|
||||
line-height: 1.6;
|
||||
font-family:
|
||||
Inter,
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
'Segoe UI',
|
||||
Roboto,
|
||||
Oxygen,
|
||||
Ubuntu,
|
||||
Cantarell,
|
||||
'Fira Sans',
|
||||
'Droid Sans',
|
||||
'Helvetica Neue',
|
||||
sans-serif;
|
||||
font-size: 15px;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>
|
||||
|
After Width: | Height: | Size: 276 B |
@@ -0,0 +1,35 @@
|
||||
@import './base.css';
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
a,
|
||||
.green {
|
||||
text-decoration: none;
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
transition: 0.4s;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
a:hover {
|
||||
background-color: hsla(160, 100%, 37%, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
body {
|
||||
display: flex;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
#app {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
msg: string
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="greetings">
|
||||
<h1 class="green">{{ msg }}</h1>
|
||||
<h3>
|
||||
You’ve successfully created a project with
|
||||
<a href="https://vite.dev/" target="_blank" rel="noopener">Vite</a> +
|
||||
<a href="https://vuejs.org/" target="_blank" rel="noopener">Vue 3</a>.
|
||||
</h3>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
h1 {
|
||||
font-weight: 500;
|
||||
font-size: 2.6rem;
|
||||
position: relative;
|
||||
top: -10px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.greetings h1,
|
||||
.greetings h3 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.greetings h1,
|
||||
.greetings h3 {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
import WelcomeItem from './WelcomeItem.vue'
|
||||
import DocumentationIcon from './icons/IconDocumentation.vue'
|
||||
import ToolingIcon from './icons/IconTooling.vue'
|
||||
import EcosystemIcon from './icons/IconEcosystem.vue'
|
||||
import CommunityIcon from './icons/IconCommunity.vue'
|
||||
import SupportIcon from './icons/IconSupport.vue'
|
||||
|
||||
const openReadmeInEditor = () => fetch('/__open-in-editor?file=README.md')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<DocumentationIcon />
|
||||
</template>
|
||||
<template #heading>Documentation</template>
|
||||
|
||||
Vue’s
|
||||
<a href="https://vuejs.org/" target="_blank" rel="noopener">official documentation</a>
|
||||
provides you with all information you need to get started.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<ToolingIcon />
|
||||
</template>
|
||||
<template #heading>Tooling</template>
|
||||
|
||||
This project is served and bundled with
|
||||
<a href="https://vite.dev/guide/features.html" target="_blank" rel="noopener">Vite</a>. The
|
||||
recommended IDE setup is
|
||||
<a href="https://code.visualstudio.com/" target="_blank" rel="noopener">VSCode</a>
|
||||
+
|
||||
<a href="https://github.com/johnsoncodehk/volar" target="_blank" rel="noopener">Volar</a>. If
|
||||
you need to test your components and web pages, check out
|
||||
<a href="https://vitest.dev/" target="_blank" rel="noopener">Vitest</a>
|
||||
and
|
||||
<a href="https://www.cypress.io/" target="_blank" rel="noopener">Cypress</a>
|
||||
/
|
||||
<a href="https://playwright.dev/" target="_blank" rel="noopener">Playwright</a>.
|
||||
|
||||
<br />
|
||||
|
||||
More instructions are available in
|
||||
<a href="javascript:void(0)" @click="openReadmeInEditor"><code>README.md</code></a
|
||||
>.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<EcosystemIcon />
|
||||
</template>
|
||||
<template #heading>Ecosystem</template>
|
||||
|
||||
Get official tools and libraries for your project:
|
||||
<a href="https://pinia.vuejs.org/" target="_blank" rel="noopener">Pinia</a>,
|
||||
<a href="https://router.vuejs.org/" target="_blank" rel="noopener">Vue Router</a>,
|
||||
<a href="https://test-utils.vuejs.org/" target="_blank" rel="noopener">Vue Test Utils</a>, and
|
||||
<a href="https://github.com/vuejs/devtools" target="_blank" rel="noopener">Vue Dev Tools</a>. If
|
||||
you need more resources, we suggest paying
|
||||
<a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">Awesome Vue</a>
|
||||
a visit.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<CommunityIcon />
|
||||
</template>
|
||||
<template #heading>Community</template>
|
||||
|
||||
Got stuck? Ask your question on
|
||||
<a href="https://chat.vuejs.org" target="_blank" rel="noopener">Vue Land</a>
|
||||
(our official Discord server), or
|
||||
<a href="https://stackoverflow.com/questions/tagged/vue.js" target="_blank" rel="noopener"
|
||||
>StackOverflow</a
|
||||
>. You should also follow the official
|
||||
<a href="https://bsky.app/profile/vuejs.org" target="_blank" rel="noopener">@vuejs.org</a>
|
||||
Bluesky account or the
|
||||
<a href="https://x.com/vuejs" target="_blank" rel="noopener">@vuejs</a>
|
||||
X account for latest news in the Vue world.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<SupportIcon />
|
||||
</template>
|
||||
<template #heading>Support Vue</template>
|
||||
|
||||
As an independent project, Vue relies on community backing for its sustainability. You can help
|
||||
us by
|
||||
<a href="https://vuejs.org/sponsor/" target="_blank" rel="noopener">becoming a sponsor</a>.
|
||||
</WelcomeItem>
|
||||
</template>
|
||||
@@ -0,0 +1,87 @@
|
||||
<template>
|
||||
<div class="item">
|
||||
<i>
|
||||
<slot name="icon"></slot>
|
||||
</i>
|
||||
<div class="details">
|
||||
<h3>
|
||||
<slot name="heading"></slot>
|
||||
</h3>
|
||||
<slot></slot>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.item {
|
||||
margin-top: 2rem;
|
||||
display: flex;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.details {
|
||||
flex: 1;
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
i {
|
||||
display: flex;
|
||||
place-items: center;
|
||||
place-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.4rem;
|
||||
color: var(--color-heading);
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.item {
|
||||
margin-top: 0;
|
||||
padding: 0.4rem 0 1rem calc(var(--section-gap) / 2);
|
||||
}
|
||||
|
||||
i {
|
||||
top: calc(50% - 25px);
|
||||
left: -26px;
|
||||
position: absolute;
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-background);
|
||||
border-radius: 8px;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.item:before {
|
||||
content: ' ';
|
||||
border-left: 1px solid var(--color-border);
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: calc(50% + 25px);
|
||||
height: calc(50% - 25px);
|
||||
}
|
||||
|
||||
.item:after {
|
||||
content: ' ';
|
||||
border-left: 1px solid var(--color-border);
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: calc(50% + 25px);
|
||||
height: calc(50% - 25px);
|
||||
}
|
||||
|
||||
.item:first-of-type:before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.item:last-of-type:after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
|
||||
<path
|
||||
d="M15 4a1 1 0 1 0 0 2V4zm0 11v-1a1 1 0 0 0-1 1h1zm0 4l-.707.707A1 1 0 0 0 16 19h-1zm-4-4l.707-.707A1 1 0 0 0 11 14v1zm-4.707-1.293a1 1 0 0 0-1.414 1.414l1.414-1.414zm-.707.707l-.707-.707.707.707zM9 11v-1a1 1 0 0 0-.707.293L9 11zm-4 0h1a1 1 0 0 0-1-1v1zm0 4H4a1 1 0 0 0 1.707.707L5 15zm10-9h2V4h-2v2zm2 0a1 1 0 0 1 1 1h2a3 3 0 0 0-3-3v2zm1 1v6h2V7h-2zm0 6a1 1 0 0 1-1 1v2a3 3 0 0 0 3-3h-2zm-1 1h-2v2h2v-2zm-3 1v4h2v-4h-2zm1.707 3.293l-4-4-1.414 1.414 4 4 1.414-1.414zM11 14H7v2h4v-2zm-4 0c-.276 0-.525-.111-.707-.293l-1.414 1.414C5.42 15.663 6.172 16 7 16v-2zm-.707 1.121l3.414-3.414-1.414-1.414-3.414 3.414 1.414 1.414zM9 12h4v-2H9v2zm4 0a3 3 0 0 0 3-3h-2a1 1 0 0 1-1 1v2zm3-3V3h-2v6h2zm0-6a3 3 0 0 0-3-3v2a1 1 0 0 1 1 1h2zm-3-3H3v2h10V0zM3 0a3 3 0 0 0-3 3h2a1 1 0 0 1 1-1V0zM0 3v6h2V3H0zm0 6a3 3 0 0 0 3 3v-2a1 1 0 0 1-1-1H0zm3 3h2v-2H3v2zm1-1v4h2v-4H4zm1.707 4.707l.586-.586-1.414-1.414-.586.586 1.414 1.414z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" fill="currentColor">
|
||||
<path
|
||||
d="M11 2.253a1 1 0 1 0-2 0h2zm-2 13a1 1 0 1 0 2 0H9zm.447-12.167a1 1 0 1 0 1.107-1.666L9.447 3.086zM1 2.253L.447 1.42A1 1 0 0 0 0 2.253h1zm0 13H0a1 1 0 0 0 1.553.833L1 15.253zm8.447.833a1 1 0 1 0 1.107-1.666l-1.107 1.666zm0-14.666a1 1 0 1 0 1.107 1.666L9.447 1.42zM19 2.253h1a1 1 0 0 0-.447-.833L19 2.253zm0 13l-.553.833A1 1 0 0 0 20 15.253h-1zm-9.553-.833a1 1 0 1 0 1.107 1.666L9.447 14.42zM9 2.253v13h2v-13H9zm1.553-.833C9.203.523 7.42 0 5.5 0v2c1.572 0 2.961.431 3.947 1.086l1.107-1.666zM5.5 0C3.58 0 1.797.523.447 1.42l1.107 1.666C2.539 2.431 3.928 2 5.5 2V0zM0 2.253v13h2v-13H0zm1.553 13.833C2.539 15.431 3.928 15 5.5 15v-2c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM5.5 15c1.572 0 2.961.431 3.947 1.086l1.107-1.666C9.203 13.523 7.42 13 5.5 13v2zm5.053-11.914C11.539 2.431 12.928 2 14.5 2V0c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM14.5 2c1.573 0 2.961.431 3.947 1.086l1.107-1.666C18.203.523 16.421 0 14.5 0v2zm3.5.253v13h2v-13h-2zm1.553 12.167C18.203 13.523 16.421 13 14.5 13v2c1.573 0 2.961.431 3.947 1.086l1.107-1.666zM14.5 13c-1.92 0-3.703.523-5.053 1.42l1.107 1.666C11.539 15.431 12.928 15 14.5 15v-2z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" fill="currentColor">
|
||||
<path
|
||||
d="M11.447 8.894a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm0 1.789a1 1 0 1 0 .894-1.789l-.894 1.789zM7.447 7.106a1 1 0 1 0-.894 1.789l.894-1.789zM10 9a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0H8zm9.447-5.606a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm2 .789a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zM18 5a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0h-2zm-5.447-4.606a1 1 0 1 0 .894-1.789l-.894 1.789zM9 1l.447-.894a1 1 0 0 0-.894 0L9 1zm-2.447.106a1 1 0 1 0 .894 1.789l-.894-1.789zm-6 3a1 1 0 1 0 .894 1.789L.553 4.106zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zm-2-.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 2.789a1 1 0 1 0 .894-1.789l-.894 1.789zM2 5a1 1 0 1 0-2 0h2zM0 7.5a1 1 0 1 0 2 0H0zm8.553 12.394a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 1a1 1 0 1 0 .894 1.789l-.894-1.789zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zM8 19a1 1 0 1 0 2 0H8zm2-2.5a1 1 0 1 0-2 0h2zm-7.447.394a1 1 0 1 0 .894-1.789l-.894 1.789zM1 15H0a1 1 0 0 0 .553.894L1 15zm1-2.5a1 1 0 1 0-2 0h2zm12.553 2.606a1 1 0 1 0 .894 1.789l-.894-1.789zM17 15l.447.894A1 1 0 0 0 18 15h-1zm1-2.5a1 1 0 1 0-2 0h2zm-7.447-5.394l-2 1 .894 1.789 2-1-.894-1.789zm-1.106 1l-2-1-.894 1.789 2 1 .894-1.789zM8 9v2.5h2V9H8zm8.553-4.894l-2 1 .894 1.789 2-1-.894-1.789zm.894 0l-2-1-.894 1.789 2 1 .894-1.789zM16 5v2.5h2V5h-2zm-4.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zm-2.894-1l-2 1 .894 1.789 2-1L8.553.106zM1.447 5.894l2-1-.894-1.789-2 1 .894 1.789zm-.894 0l2 1 .894-1.789-2-1-.894 1.789zM0 5v2.5h2V5H0zm9.447 13.106l-2-1-.894 1.789 2 1 .894-1.789zm0 1.789l2-1-.894-1.789-2 1 .894 1.789zM10 19v-2.5H8V19h2zm-6.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zM2 15v-2.5H0V15h2zm13.447 1.894l2-1-.894-1.789-2 1 .894 1.789zM18 15v-2.5h-2V15h2z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
|
||||
<path
|
||||
d="M10 3.22l-.61-.6a5.5 5.5 0 0 0-7.666.105 5.5 5.5 0 0 0-.114 7.665L10 18.78l8.39-8.4a5.5 5.5 0 0 0-.114-7.665 5.5 5.5 0 0 0-7.666-.105l-.61.61z"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -0,0 +1,19 @@
|
||||
<!-- This icon is from <https://github.com/Templarian/MaterialDesign>, distributed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0) license-->
|
||||
<template>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
aria-hidden="true"
|
||||
role="img"
|
||||
class="iconify iconify--mdi"
|
||||
width="24"
|
||||
height="24"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
d="M20 18v-4h-3v1h-2v-1H9v1H7v-1H4v4h16M6.33 8l-1.74 4H7v-1h2v1h6v-1h2v1h2.41l-1.74-4H6.33M9 5v1h6V5H9m12.84 7.61c.1.22.16.48.16.8V18c0 .53-.21 1-.6 1.41c-.4.4-.85.59-1.4.59H4c-.55 0-1-.19-1.4-.59C2.21 19 2 18.53 2 18v-4.59c0-.32.06-.58.16-.8L4.5 7.22C4.84 6.41 5.45 6 6.33 6H7V5c0-.55.18-1 .57-1.41C7.96 3.2 8.44 3 9 3h6c.56 0 1.04.2 1.43.59c.39.41.57.86.57 1.41v1h.67c.88 0 1.49.41 1.83 1.22l2.34 5.39z"
|
||||
fill="currentColor"
|
||||
></path>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -0,0 +1,906 @@
|
||||
<template>
|
||||
<div class="device-management">
|
||||
<div class="toolbar">
|
||||
<button class="btn-primary" @click="showAddDeviceDialog = true">
|
||||
<i class="fas fa-plus"></i> 添加设备
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 设备列表 -->
|
||||
<div class="device-list">
|
||||
<div v-for="device in devices" :key="device.id" class="device-card">
|
||||
<div class="device-header">
|
||||
<h3>{{ device.name }}</h3>
|
||||
<div class="device-status-container">
|
||||
<div class="device-enabled" :class="device.enabled ? 'enabled' : 'disabled'">
|
||||
{{ device.enabled ? '已启用' : '已禁用' }}
|
||||
</div>
|
||||
<div class="device-status" :class="typeof device.status === 'object' && device.status.online ? 'online' : 'offline'">
|
||||
{{ typeof device.status === 'object' && device.status.online ? '在线' : '离线' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="device-info">
|
||||
<div class="info-item">
|
||||
<span class="label">代号:</span>
|
||||
<span>{{ device.code }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">设备类型:</span>
|
||||
<span>{{ device.device_type?.name || '未设置' }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">接口:</span>
|
||||
<span>{{ device.interface?.name || '未设置' }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">设备地址:</span>
|
||||
<span>0x{{ device.device_address.toString(16).padStart(2, '0').toUpperCase() }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">状态:</span>
|
||||
<span>
|
||||
<template v-if="typeof device.status === 'object'">
|
||||
<template v-if="device.device_type?.code === 'MTO'">
|
||||
电机状态: {{ device.status.state == 0 ? '正常': (device.status.state == 1 ?'上限位' : '下限位') }}
|
||||
电机位置: {{ device.status.location == 0 ? '未就绪': (device.status.location == 1 ? '上过渡段': (device.status.location == 2 ?'扫描段':'下过渡段') ) }}
|
||||
电机量程: {{ device.status.duration}}
|
||||
电机位置: {{ device.status.position.toFixed(2) }} mm
|
||||
电机速度: {{ device.status.velocity.toFixed(2) }} mm/s
|
||||
电机方向: {{ device.status.velocity < 0 ? '正向': '反向' }} <!-- 设备列表 device.status.direction == 1? '正向': '反向' -->
|
||||
</template>
|
||||
<template v-else-if="device.device_type?.code === 'HVS'">
|
||||
电压: {{ device.status.voltage }} V
|
||||
电流: {{ device.status.current }} A
|
||||
灯丝电流: {{ device.status.current_filament }} A
|
||||
内部温度: {{ device.status.internal_temperature }} ℃
|
||||
故障状态: {{ device.status.fault_status }}
|
||||
开关状态: {{ device.status.switch_status ? '开启' : '关闭' }}
|
||||
</template>
|
||||
<template v-if="device.device_type?.code === 'ALU'">
|
||||
灯光: {{ device.status.light ? '开启' : '关闭' }}
|
||||
</template>
|
||||
<template v-if="device.device_type?.code === 'WSU'">
|
||||
流量: {{ device.status.flow_rate }} L/min
|
||||
水温: {{ device.status.water_temp }} ℃
|
||||
</template>
|
||||
<template v-if="device.device_type?.code === 'OSU'">
|
||||
油温: {{ device.status.oil_temp }} ℃
|
||||
液位: <span :class="getOilLevelClass(device.status.oil_level)">{{ typeof device.status.oil_level === 'number' ? getOilLevelText(device.status.oil_level) : '未知' }}</span>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ device.status }}
|
||||
</template>
|
||||
</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">最后更新:</span>
|
||||
<span>{{ new Date(device.last_update).toLocaleString() }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="device-actions">
|
||||
<template v-if="device.device_type?.code === 'ALU' || device.device_type?.code === 'HVS'">
|
||||
<el-button
|
||||
type="success"
|
||||
@click="controlDevice(device, true)"
|
||||
>关闭</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
@click="controlDevice(device, false)"
|
||||
>打开</el-button>
|
||||
</template>
|
||||
<template v-if="device.device_type?.code === 'MTO'">
|
||||
<el-button
|
||||
type="success"
|
||||
@click="controlDevice2(device, 'switch', 1)"
|
||||
>启动</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
@click="controlDevice2(device, 'switch', 0)"
|
||||
>停止</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
@click="controlDevice2(device, 'emergency_stop', 0)"
|
||||
>急停</el-button>
|
||||
</template>
|
||||
<el-button type="primary" @click="editDevice(device)">编辑</el-button>
|
||||
<el-button type="danger" @click="deleteDevice(device)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加设备对话框 -->
|
||||
<el-dialog
|
||||
v-model="showAddDeviceDialog"
|
||||
:title="editingDevice ? '编辑设备' : '添加设备'"
|
||||
width="500px"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="deviceForm"
|
||||
:rules="rules"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="deviceForm.name" placeholder="请输入设备名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="代号" prop="code">
|
||||
<el-input v-model="deviceForm.code" placeholder="请输入设备代号" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设备类型">
|
||||
<el-select v-model="deviceForm.device_type_id" placeholder="请选择设备类型">
|
||||
<el-option
|
||||
v-for="type in deviceTypes"
|
||||
:key="type.id"
|
||||
:label="type.name"
|
||||
:value="type.id"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="接口" prop="interface_id">
|
||||
<el-select v-model="deviceForm.interface_id" placeholder="请选择接口">
|
||||
<el-option
|
||||
v-for="interfaceItem in interfaces"
|
||||
:key="interfaceItem.id"
|
||||
:label="interfaceItem.name"
|
||||
:value="interfaceItem.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备地址" prop="device_address">
|
||||
<el-input
|
||||
v-model="deviceForm.device_address"
|
||||
placeholder="0x00"
|
||||
@input="handleAddressInput($event)"
|
||||
@blur="handleAddressBlur($event)"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-switch
|
||||
v-model="deviceForm.enabled"
|
||||
:active-text="'启用'"
|
||||
:inactive-text="'禁用'"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="showAddDeviceDialog = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveDevice">确定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 寄存器表对话框 -->
|
||||
<el-dialog
|
||||
v-model="showRegistersDialog"
|
||||
title="寄存器管理"
|
||||
width="900px"
|
||||
>
|
||||
<div class="dialog-content">
|
||||
<!-- 寄存器表单 -->
|
||||
<div class="register-form" v-if="editingRegisterId !== null || registerForm.address !== undefined">
|
||||
<el-form :model="registerForm" label-width="100px">
|
||||
<el-form-item label="地址">
|
||||
<el-input-number
|
||||
v-model="registerForm.address"
|
||||
:min="0"
|
||||
:max="65535"
|
||||
placeholder="请输入寄存器地址"
|
||||
></el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item label="功能码">
|
||||
<el-select v-model="registerForm.functionCode" placeholder="请选择功能码">
|
||||
<el-option
|
||||
v-for="code in functionCodes"
|
||||
:key="code.value"
|
||||
:label="code.label"
|
||||
:value="code.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="名称">
|
||||
<el-input v-model="registerForm.name" placeholder="请输入寄存器名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input
|
||||
v-model="registerForm.description"
|
||||
type="textarea"
|
||||
placeholder="请输入备注说明"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="saveRegister">保存</el-button>
|
||||
<el-button @click="editingRegisterId = null; registerForm.address = ''">取消</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<!-- 寄存器列表 -->
|
||||
<div class="register-list">
|
||||
<div class="toolbar">
|
||||
<el-button type="primary" @click="addRegister" v-if="editingRegisterId === null && registerForm.address === ''">
|
||||
添加寄存器
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-table :data="currentDeviceRegisters" style="width: 100%">
|
||||
<el-table-column prop="address" label="地址" width="100">
|
||||
<template #default="{ row }">
|
||||
{{ row.address.toString(16).toUpperCase().padStart(4, '0') }}h
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="functionCode" label="功能码" width="150">
|
||||
<template #default="{ row }">
|
||||
{{ functionCodes.find(code => code.value === row.functionCode)?.label || row.functionCode }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="name" label="名称"></el-table-column>
|
||||
<el-table-column prop="description" label="备注"></el-table-column>
|
||||
<el-table-column prop="code" label="代号" width="120" />
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="editRegister(row)"
|
||||
:disabled="editingRegisterId !== null || registerForm.address !== ''"
|
||||
>编辑</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
size="small"
|
||||
@click="deleteRegister(row)"
|
||||
:disabled="editingRegisterId !== null || registerForm.address !== ''"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import type { DeviceTypeItem, InterfaceItem } from '../types'
|
||||
|
||||
// 修改设备类型定义
|
||||
interface DeviceItem {
|
||||
id: number;
|
||||
name: string;
|
||||
code: string;
|
||||
device_address: number;
|
||||
device_type_id: number | null;
|
||||
interface_id: number;
|
||||
enabled: boolean;
|
||||
status: string | {
|
||||
online?: boolean;
|
||||
light?: boolean;
|
||||
flow_rate?: number;
|
||||
water_temp?: number;
|
||||
oil_temp?: number; // 油温,单位:℃
|
||||
oil_level?: number; // 油位,范围:0-3
|
||||
[key: string]: any;
|
||||
};
|
||||
last_update: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
device_type?: {
|
||||
id: number;
|
||||
name: string;
|
||||
code: string;
|
||||
};
|
||||
interface?: {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
// 设备列表
|
||||
const devices = ref<DeviceItem[]>([])
|
||||
// 设备类型列表
|
||||
const deviceTypes = ref<DeviceTypeItem[]>([])
|
||||
// 接口列表
|
||||
const interfaces = ref<InterfaceItem[]>([])
|
||||
|
||||
// 对话框控制
|
||||
const showAddDeviceDialog = ref(false)
|
||||
const showRegistersDialog = ref(false)
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
// 表单数据
|
||||
const deviceForm = ref<Partial<DeviceItem>>({
|
||||
name: '',
|
||||
code: '',
|
||||
device_address: 1,
|
||||
device_type_id: undefined,
|
||||
interface_id: undefined,
|
||||
enabled: true // 默认启用
|
||||
})
|
||||
|
||||
// 当前编辑的设备
|
||||
const editingDevice = ref<DeviceItem | null>(null)
|
||||
// 当前设备的寄存器列表
|
||||
const currentDeviceRegisters = ref([])
|
||||
|
||||
// 寄存器相关
|
||||
const currentDeviceId = ref(null)
|
||||
const registerForm = ref({
|
||||
address: '',
|
||||
functionCode: '3', // 默认使用03功能码(读保持寄存器)
|
||||
name: '',
|
||||
description: ''
|
||||
})
|
||||
const editingRegisterId = ref(null)
|
||||
|
||||
// 功能码选项
|
||||
const functionCodes = [
|
||||
{ value: '1', label: '01 - 读线圈' },
|
||||
{ value: '2', label: '02 - 读离散输入' },
|
||||
{ value: '3', label: '03 - 读保持寄存器' },
|
||||
{ value: '4', label: '04 - 读输入寄存器' }
|
||||
]
|
||||
|
||||
// 在 data 中添加表单验证规则
|
||||
const rules = {
|
||||
name: [{ required: true, message: "请输入设备名称", trigger: "blur" }],
|
||||
code: [{ required: true, message: "请输入设备代号", trigger: "blur" }],
|
||||
device_address: [{ required: true, message: "请输入设备地址", trigger: "blur" }],
|
||||
interface_id: [{ required: true, message: "请选择接口", trigger: "change" }],
|
||||
};
|
||||
|
||||
// 获取设备类型列表
|
||||
const fetchDeviceTypes = async () => {
|
||||
try {
|
||||
const response = await axios.get('/device-types')
|
||||
deviceTypes.value = response.data
|
||||
} catch (error) {
|
||||
ElMessage.error('获取设备类型列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 获取设备列表
|
||||
const fetchDevices = async () => {
|
||||
try {
|
||||
const response = await axios.get<DeviceItem[]>('/devices')
|
||||
devices.value = response.data
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message)
|
||||
} else {
|
||||
ElMessage.error('获取设备列表失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取接口列表
|
||||
const fetchInterfaces = async () => {
|
||||
try {
|
||||
const response = await axios.get('/interfaces')
|
||||
interfaces.value = response.data
|
||||
} catch (error) {
|
||||
ElMessage.error('获取接口列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 保存设备
|
||||
const saveDevice = async () => {
|
||||
if (!formRef.value) return;
|
||||
|
||||
await formRef.value.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
try {
|
||||
const data = {
|
||||
name: deviceForm.value.name,
|
||||
code: deviceForm.value.code,
|
||||
device_address: Number(deviceForm.value.device_address),
|
||||
device_type_id: deviceForm.value.device_type_id || null,
|
||||
interface_id: deviceForm.value.interface_id,
|
||||
enabled: deviceForm.value.enabled
|
||||
};
|
||||
|
||||
if (editingDevice.value) {
|
||||
await axios.put(`/devices/${editingDevice.value.id}`, data);
|
||||
} else {
|
||||
await axios.post("/devices", data);
|
||||
}
|
||||
|
||||
ElMessage.success("保存成功");
|
||||
showAddDeviceDialog.value = false;
|
||||
fetchDevices();
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message);
|
||||
} else {
|
||||
ElMessage.error("保存失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 编辑设备
|
||||
const editDevice = (device: DeviceItem) => {
|
||||
editingDevice.value = device
|
||||
deviceForm.value = {
|
||||
name: device.name,
|
||||
code: device.code,
|
||||
device_address: device.device_address,
|
||||
device_type_id: device.device_type_id,
|
||||
interface_id: device.interface_id,
|
||||
enabled: device.enabled
|
||||
}
|
||||
showAddDeviceDialog.value = true
|
||||
}
|
||||
|
||||
// 删除设备
|
||||
const deleteDevice = (device: DeviceItem) => {
|
||||
ElMessageBox.confirm(
|
||||
'确定要删除这个设备吗?',
|
||||
'警告',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
).then(async () => {
|
||||
try {
|
||||
await axios.delete(`/devices/${device.id}`)
|
||||
ElMessage.success('设备删除成功')
|
||||
fetchDevices()
|
||||
} catch (error) {
|
||||
ElMessage.error('删除设备失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 查看寄存器
|
||||
const viewRegisters = async (device) => {
|
||||
currentDeviceId.value = device.id
|
||||
try {
|
||||
const response = await axios.get(`/devices/${device.id}/registers`)
|
||||
currentDeviceRegisters.value = response.data
|
||||
showRegistersDialog.value = true
|
||||
} catch (error) {
|
||||
ElMessage.error('获取寄存器列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 添加寄存器
|
||||
const addRegister = () => {
|
||||
editingRegisterId.value = null
|
||||
registerForm.value = {
|
||||
address: 0, // 设置默认值
|
||||
functionCode: '3',
|
||||
name: '',
|
||||
description: ''
|
||||
}
|
||||
// 确保表单显示
|
||||
showRegistersDialog.value = true
|
||||
}
|
||||
|
||||
// 编辑寄存器
|
||||
const editRegister = (register) => {
|
||||
editingRegisterId.value = register.id
|
||||
registerForm.value = { ...register }
|
||||
}
|
||||
|
||||
// 保存寄存器
|
||||
const saveRegister = async () => {
|
||||
try {
|
||||
if (editingRegisterId.value === null) {
|
||||
// 创建新寄存器
|
||||
await axios.post(
|
||||
`/devices/${currentDeviceId.value}/registers`,
|
||||
registerForm.value
|
||||
)
|
||||
ElMessage.success('寄存器添加成功')
|
||||
} else {
|
||||
// 更新现有寄存器
|
||||
await axios.put(
|
||||
`/devices/${currentDeviceId.value}/registers/${editingRegisterId.value}`,
|
||||
registerForm.value
|
||||
)
|
||||
ElMessage.success('寄存器更新成功')
|
||||
}
|
||||
// 重新加载寄存器列表
|
||||
const response = await axios.get(`/devices/${currentDeviceId.value}/registers`)
|
||||
currentDeviceRegisters.value = response.data
|
||||
editingRegisterId.value = null
|
||||
registerForm.value = {
|
||||
address: '',
|
||||
functionCode: '3',
|
||||
name: '',
|
||||
description: ''
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.response?.status === 400) {
|
||||
ElMessage.error(error.response.data.detail || '保存失败')
|
||||
} else {
|
||||
ElMessage.error('保存寄存器失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除寄存器
|
||||
const deleteRegister = async (register) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'确定要删除该寄存器吗?',
|
||||
'警告',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
)
|
||||
|
||||
await axios.delete(
|
||||
`/devices/${currentDeviceId.value}/registers/${register.id}`
|
||||
)
|
||||
ElMessage.success('寄存器删除成功')
|
||||
|
||||
// 重新加载寄存器列表
|
||||
const response = await axios.get(`/devices/${currentDeviceId.value}/registers`)
|
||||
currentDeviceRegisters.value = response.data
|
||||
} catch (error) {
|
||||
if (error !== 'cancel') {
|
||||
ElMessage.error('删除寄存器失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理地址输入
|
||||
const handleAddressInput = (event: Event) => {
|
||||
const value = (event.target as HTMLInputElement).value
|
||||
// 移除所有空格
|
||||
const cleanValue = value.replace(/\s/g, '')
|
||||
|
||||
// 如果输入为空,设置为0
|
||||
if (!cleanValue) {
|
||||
deviceForm.value.device_address = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 如果输入的是十六进制格式(以0x开头)
|
||||
if (cleanValue.toLowerCase().startsWith('0x')) {
|
||||
const hexValue = parseInt(cleanValue.slice(2), 16)
|
||||
if (!isNaN(hexValue) && hexValue >= 0 && hexValue <= 255) {
|
||||
deviceForm.value.device_address = hexValue
|
||||
}
|
||||
} else {
|
||||
// 如果输入的是十进制
|
||||
const decValue = parseInt(cleanValue, 10)
|
||||
if (!isNaN(decValue) && decValue >= 0 && decValue <= 255) {
|
||||
deviceForm.value.device_address = decValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理地址输入框失去焦点
|
||||
const handleAddressBlur = (event: FocusEvent) => {
|
||||
const value = (event.target as HTMLInputElement).value
|
||||
// 移除所有空格
|
||||
const cleanValue = value.replace(/\s/g, '')
|
||||
|
||||
// 如果输入为空,设置为0
|
||||
if (!cleanValue) {
|
||||
deviceForm.value.device_address = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 如果输入的是十六进制格式(以0x开头)
|
||||
if (cleanValue.toLowerCase().startsWith('0x')) {
|
||||
const hexValue = parseInt(cleanValue.slice(2), 16)
|
||||
if (!isNaN(hexValue) && hexValue >= 0 && hexValue <= 255) {
|
||||
deviceForm.value.device_address = hexValue
|
||||
}
|
||||
} else {
|
||||
// 如果输入的是十进制
|
||||
const decValue = parseInt(cleanValue, 10)
|
||||
if (!isNaN(decValue) && decValue >= 0 && decValue <= 255) {
|
||||
deviceForm.value.device_address = decValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改控制设备的方法2
|
||||
const controlDevice2 = async (device: DeviceItem, command: string, value: number) => {
|
||||
try {
|
||||
await axios.post('/devices/control2', {
|
||||
device_id: device.id,
|
||||
command: command,
|
||||
value: value
|
||||
})
|
||||
ElMessage.success( '设备控制成功' )
|
||||
|
||||
// 等待一小段时间后重新获取设备状态
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const response = await axios.get<DeviceItem>(`/devices/${device.id}`)
|
||||
// 更新设备状态
|
||||
const updatedDevice = response.data
|
||||
const index = devices.value.findIndex(d => d.id === device.id)
|
||||
if (index !== -1) {
|
||||
devices.value[index] = updatedDevice
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备状态失败:', error)
|
||||
}
|
||||
}, 1000) // 等待1秒后获取最新状态
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message)
|
||||
} else {
|
||||
ElMessage.error('控制设备失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改控制设备的方法
|
||||
const controlDevice = async (device: DeviceItem, status: boolean) => {
|
||||
try {
|
||||
await axios.post('/devices/control', {
|
||||
device_id: device.id,
|
||||
command: 'set_status',
|
||||
status: !status // 反转状态值
|
||||
})
|
||||
ElMessage.success(!status ? '设备已打开' : '设备已关闭')
|
||||
|
||||
// 等待一小段时间后重新获取设备状态
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const response = await axios.get<DeviceItem>(`/devices/${device.id}`)
|
||||
// 更新设备状态
|
||||
const updatedDevice = response.data
|
||||
const index = devices.value.findIndex(d => d.id === device.id)
|
||||
if (index !== -1) {
|
||||
devices.value[index] = updatedDevice
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备状态失败:', error)
|
||||
}
|
||||
}, 1000) // 等待1秒后获取最新状态
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message)
|
||||
} else {
|
||||
ElMessage.error('控制设备失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加油位状态转换函数
|
||||
const getOilLevelText = (level: number) => {
|
||||
switch (level) {
|
||||
case 0:
|
||||
return '空'
|
||||
case 1:
|
||||
return '低'
|
||||
case 2:
|
||||
return '中'
|
||||
case 3:
|
||||
return '满'
|
||||
default:
|
||||
return '未知'
|
||||
}
|
||||
}
|
||||
|
||||
// 添加油位状态样式类获取函数
|
||||
const getOilLevelClass = (level: number) => {
|
||||
if (typeof level !== 'number') return '';
|
||||
if (level >= 2) return 'oil-level-high';
|
||||
if (level === 1) return 'oil-level-medium';
|
||||
if (level === 0) return 'oil-level-low';
|
||||
return '';
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchDevices()
|
||||
fetchDeviceTypes()
|
||||
fetchInterfaces()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.device-management {
|
||||
padding: 20px;
|
||||
max-width: 1600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.device-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
|
||||
gap: 16px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.device-card {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
height: fit-content;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
min-width: 360px;
|
||||
}
|
||||
|
||||
.device-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.device-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.device-status-container {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.device-enabled {
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.device-enabled.enabled {
|
||||
background-color: #67C23A;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.device-enabled.disabled {
|
||||
background-color: #909399;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.device-status {
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.device-status.online {
|
||||
background-color: #67C23A;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.device-status.offline {
|
||||
background-color: #F56C6C;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.device-info {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.info-item .label {
|
||||
color: #666;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.device-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #1976d2;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 16px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 4px 8px;
|
||||
cursor: pointer;
|
||||
color: #1976d2;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.btn-text.danger {
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
.dialog-content {
|
||||
max-height: 70vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.register-form {
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Element Plus 样式覆盖 */
|
||||
:deep(.el-dialog__body) {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
:deep(.el-form-item:last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* 响应式布局调整 */
|
||||
@media (min-width: 1600px) {
|
||||
.device-list {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1599px) and (min-width: 1200px) {
|
||||
.device-list {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1199px) {
|
||||
.device-list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.device-card {
|
||||
min-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.status-online {
|
||||
color: #67C23A;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.status-offline {
|
||||
color: #F56C6C;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.oil-level-high {
|
||||
color: #67C23A;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.oil-level-medium {
|
||||
color: #E6A23C;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.oil-level-low {
|
||||
color: #F56C6C;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<div class="device-type-management">
|
||||
<div class="toolbar">
|
||||
<el-button type="primary" @click="showAddDialog = true">
|
||||
<i class="fas fa-plus"></i> 添加设备类型
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 设备类型列表 -->
|
||||
<el-table :data="deviceTypes" style="width: 100%">
|
||||
<el-table-column prop="name" label="名称" width="150"></el-table-column>
|
||||
<el-table-column prop="code" label="代号" width="120"></el-table-column>
|
||||
<el-table-column label="地址范围" width="150">
|
||||
<template #default="{ row }">
|
||||
0x{{ row.address_range_start.toString(16).padStart(2, '0').toUpperCase() }} - 0x{{ row.address_range_end.toString(16).padStart(2, '0').toUpperCase() }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="chip_model" label="芯片型号" width="150"></el-table-column>
|
||||
<el-table-column prop="description" label="备注" min-width="250">
|
||||
<template #default="{ row }">
|
||||
<el-tooltip
|
||||
v-if="row.description"
|
||||
:content="row.description"
|
||||
placement="top"
|
||||
:show-after="500"
|
||||
>
|
||||
<div class="description-cell">{{ row.description }}</div>
|
||||
</el-tooltip>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ new Date(row.created_at).toLocaleString() }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="editDeviceType(row)"
|
||||
>编辑</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
size="small"
|
||||
@click="confirmDelete(row)"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 添加/编辑对话框 -->
|
||||
<el-dialog
|
||||
v-model="showAddDialog"
|
||||
:title="editingType ? '编辑设备类型' : '添加设备类型'"
|
||||
width="500px"
|
||||
>
|
||||
<el-form :model="typeForm" label-width="100px">
|
||||
<el-form-item label="名称">
|
||||
<el-input v-model="typeForm.name" placeholder="请输入设备类型名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="代号">
|
||||
<el-input v-model="typeForm.code" placeholder="请输入设备类型代号"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="地址范围">
|
||||
<div class="address-range">
|
||||
<el-input
|
||||
v-model="typeForm.address_range_start"
|
||||
:min="0"
|
||||
:max="255"
|
||||
placeholder="0x00"
|
||||
@input="handleAddressInput('start', $event)"
|
||||
@blur="handleAddressBlur('start', $event)"
|
||||
></el-input>
|
||||
<span class="separator">-</span>
|
||||
<el-input
|
||||
v-model="typeForm.address_range_end"
|
||||
:min="0"
|
||||
:max="255"
|
||||
placeholder="0xFF"
|
||||
@input="handleAddressInput('end', $event)"
|
||||
@blur="handleAddressBlur('end', $event)"
|
||||
></el-input>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="芯片型号">
|
||||
<el-input v-model="typeForm.chip_model" placeholder="请输入芯片型号"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input
|
||||
v-model="typeForm.description"
|
||||
type="textarea"
|
||||
placeholder="请输入备注说明"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="showAddDialog = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveDeviceType">确定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
// 设备类型列表
|
||||
const deviceTypes = ref([])
|
||||
|
||||
// 对话框控制
|
||||
const showAddDialog = ref(false)
|
||||
const editingType = ref(null)
|
||||
|
||||
// 表单数据
|
||||
const typeForm = ref({
|
||||
name: '',
|
||||
code: '',
|
||||
address_range_start: 0,
|
||||
address_range_end: 0,
|
||||
chip_model: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
// 获取设备类型列表
|
||||
const fetchDeviceTypes = async () => {
|
||||
try {
|
||||
const response = await axios.get('/device-types')
|
||||
deviceTypes.value = response.data
|
||||
} catch (error) {
|
||||
ElMessage.error('获取设备类型列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑设备类型
|
||||
const editDeviceType = (type) => {
|
||||
editingType.value = type
|
||||
typeForm.value = {
|
||||
...type,
|
||||
address_range_start: `0x${type.address_range_start.toString(16).padStart(2, '0').toUpperCase()}`,
|
||||
address_range_end: `0x${type.address_range_end.toString(16).padStart(2, '0').toUpperCase()}`
|
||||
}
|
||||
showAddDialog.value = true
|
||||
}
|
||||
|
||||
// 保存设备类型
|
||||
const saveDeviceType = async () => {
|
||||
try {
|
||||
// 确保地址范围为数字类型
|
||||
const formData = {
|
||||
...typeForm.value,
|
||||
address_range_start: Number(typeForm.value.address_range_start),
|
||||
address_range_end: Number(typeForm.value.address_range_end)
|
||||
}
|
||||
|
||||
if (editingType.value) {
|
||||
await axios.put(
|
||||
`/device-types/${editingType.value.id}`,
|
||||
formData
|
||||
)
|
||||
ElMessage.success('设备类型更新成功')
|
||||
} else {
|
||||
await axios.post('/device-types', formData)
|
||||
ElMessage.success('设备类型添加成功')
|
||||
}
|
||||
showAddDialog.value = false
|
||||
fetchDeviceTypes()
|
||||
} catch (error) {
|
||||
if (error.response?.status === 400) {
|
||||
ElMessage.error(error.response.data.detail || '保存失败')
|
||||
} else {
|
||||
ElMessage.error('保存设备类型失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除设备类型
|
||||
const confirmDelete = (type) => {
|
||||
ElMessageBox.confirm(
|
||||
'确定要删除该设备类型吗?',
|
||||
'警告',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
).then(async () => {
|
||||
try {
|
||||
await axios.delete(`/device-types/${type.id}`)
|
||||
ElMessage.success('设备类型删除成功')
|
||||
fetchDeviceTypes()
|
||||
} catch (error) {
|
||||
ElMessage.error('删除设备类型失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 处理地址输入
|
||||
const handleAddressInput = (type: 'start' | 'end', value: string) => {
|
||||
// 移除所有空格
|
||||
value = value.replace(/\s/g, '')
|
||||
|
||||
// 如果输入为空,设置为0
|
||||
if (!value) {
|
||||
typeForm.value[`address_range_${type}`] = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 如果输入的是十六进制格式(以0x开头)
|
||||
if (value.toLowerCase().startsWith('0x')) {
|
||||
// 只更新显示值,不立即转换
|
||||
typeForm.value[`address_range_${type}`] = value
|
||||
} else {
|
||||
// 如果输入的是十进制
|
||||
const decValue = parseInt(value, 10)
|
||||
if (!isNaN(decValue) && decValue >= 0 && decValue <= 255) {
|
||||
typeForm.value[`address_range_${type}`] = decValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理地址输入框失去焦点
|
||||
const handleAddressBlur = (type: 'start' | 'end', value: string) => {
|
||||
// 移除所有空格
|
||||
value = value.replace(/\s/g, '')
|
||||
|
||||
// 如果输入为空,设置为0
|
||||
if (!value) {
|
||||
typeForm.value[`address_range_${type}`] = 0
|
||||
return
|
||||
}
|
||||
|
||||
// 如果输入的是十六进制格式(以0x开头)
|
||||
if (value.toLowerCase().startsWith('0x')) {
|
||||
const hexValue = parseInt(value.slice(2), 16)
|
||||
if (!isNaN(hexValue) && hexValue >= 0 && hexValue <= 255) {
|
||||
typeForm.value[`address_range_${type}`] = hexValue
|
||||
}
|
||||
} else {
|
||||
// 如果输入的是十进制
|
||||
const decValue = parseInt(value, 10)
|
||||
if (!isNaN(decValue) && decValue >= 0 && decValue <= 255) {
|
||||
typeForm.value[`address_range_${type}`] = decValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化地址显示
|
||||
const formatAddress = (value: number) => {
|
||||
return `0x${value.toString(16).padStart(2, '0').toUpperCase()}`
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchDeviceTypes()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.device-type-management {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.address-range {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.separator {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
:deep(.el-form-item:last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.description-cell {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
:deep(.el-table) {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
:deep(.el-table .cell) {
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,201 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<div class="dashboard-grid">
|
||||
<!-- 系统状态卡片 -->
|
||||
<div class="card">
|
||||
<h2>系统状态</h2>
|
||||
<div class="status-grid">
|
||||
<div class="status-item">
|
||||
<div class="status-label">CPU 使用率</div>
|
||||
<div class="status-value">{{ cpu_usage || 0 }}%</div>
|
||||
<div class="progress-bar">
|
||||
<div :style="{ width: `${cpu_usage || 0}%` }" :class="getProgressClass(cpu_usage || 0)"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<div class="status-label">内存使用率</div>
|
||||
<div class="status-value">{{ memory_usage || 0 }}%</div>
|
||||
<div class="progress-bar">
|
||||
<div :style="{ width: `${memory_usage || 0}%` }" :class="getProgressClass(memory_usage || 0)"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<div class="status-label">磁盘使用率</div>
|
||||
<div class="status-value">{{ disk_usage || 0 }}%</div>
|
||||
<div class="progress-bar">
|
||||
<div :style="{ width: `${disk_usage || 0}%` }" :class="getProgressClass(disk_usage || 0)"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<div class="status-label">CPU 温度</div>
|
||||
<div class="status-value">{{ temperature || 0 }}°C</div>
|
||||
<div class="progress-bar">
|
||||
<div :style="{ width: `${(temperature || 0) * 2}%` }" :class="getTemperatureClass(temperature || 0)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网络信息卡片 -->
|
||||
<div class="card">
|
||||
<h2>网络信息</h2>
|
||||
<div class="network-list">
|
||||
<div v-for="(addresses, interfaceName) in network_info" :key="interfaceName" class="network-item">
|
||||
<div class="interface-name">{{ interfaceName }}</div>
|
||||
<div class="interface-addresses">
|
||||
<div v-for="address in addresses" :key="address">{{ address }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const cpu_usage = ref(0)
|
||||
const memory_usage = ref(0)
|
||||
const disk_usage = ref(0)
|
||||
const network_info = ref<Record<string, string[]>>({})
|
||||
const temperature = ref(0)
|
||||
|
||||
const fetchSystemInfo = async () => {
|
||||
try {
|
||||
const response = await axios.get('/system/info')
|
||||
cpu_usage.value = response.data.cpu_usage
|
||||
memory_usage.value = response.data.memory_usage
|
||||
disk_usage.value = response.data.disk_usage
|
||||
network_info.value = response.data.network_info
|
||||
temperature.value = response.data.temperature
|
||||
} catch (error) {
|
||||
console.error('获取系统信息失败:', error)
|
||||
ElMessage.error('获取系统信息失败')
|
||||
}
|
||||
}
|
||||
|
||||
const getProgressClass = (value: number) => {
|
||||
if (value >= 90) return 'danger'
|
||||
if (value >= 70) return 'warning'
|
||||
return 'normal'
|
||||
}
|
||||
|
||||
const getTemperatureClass = (value: number) => {
|
||||
if (value >= 80) return 'danger'
|
||||
if (value >= 60) return 'warning'
|
||||
return 'normal'
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchSystemInfo()
|
||||
setInterval(fetchSystemInfo, 30000) // 每30秒更新一次系统信息
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dashboard {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.status-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.status-item {
|
||||
padding: 15px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.status-label {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.status-value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 6px;
|
||||
background: #e4e7ed;
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-bar > div {
|
||||
height: 100%;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.normal {
|
||||
background: #67c23a;
|
||||
}
|
||||
|
||||
.warning {
|
||||
background: #e6a23c;
|
||||
}
|
||||
|
||||
.danger {
|
||||
background: #f56c6c;
|
||||
}
|
||||
|
||||
.network-list {
|
||||
display: grid;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.network-item {
|
||||
padding: 15px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.interface-name {
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.interface-addresses {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.status-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,532 @@
|
||||
<template>
|
||||
<div class="interface-management">
|
||||
<div class="toolbar">
|
||||
<el-button type="primary" @click="showAddInterfaceDialog = true">
|
||||
<i class="fas fa-plus"></i> 添加接口
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 接口列表 -->
|
||||
<div class="interface-list">
|
||||
<div v-for="item in interfaces" :key="item.id" class="interface-card">
|
||||
<div class="interface-header">
|
||||
<h3>{{ item.name }}</h3>
|
||||
<el-tag :type="item.type === 'CAN' ? 'primary' : 'success'">
|
||||
{{ item.type }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="interface-info">
|
||||
<div class="info-item">
|
||||
<span class="label">描述:</span>
|
||||
<span>{{ item.description || '无' }}</span>
|
||||
</div>
|
||||
<template v-if="item.type === 'CAN'">
|
||||
<div class="info-item">
|
||||
<span class="label">通道号:</span>
|
||||
<span>{{ item.can_channel }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">波特率:</span>
|
||||
<span>{{ item.can_baud_rate }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'Powerbus'">
|
||||
<div class="info-item">
|
||||
<span class="label">串口:</span>
|
||||
<span>{{ item.port }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'Modbus'">
|
||||
<div class="info-item">
|
||||
<span class="label">Modbus类型:</span>
|
||||
<span>{{ item.modbus_type === 'TCP' ? 'Modbus-TCP' : 'Modbus-RTU' }}</span>
|
||||
</div>
|
||||
<template v-if="item.modbus_type === 'TCP'">
|
||||
<div class="info-item">
|
||||
<span class="label">IP地址:</span>
|
||||
<span>{{ item.ip_address }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">端口号:</span>
|
||||
<span>{{ item.port }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="item.modbus_type === 'RTU'">
|
||||
<div class="info-item">
|
||||
<span class="label">串口:</span>
|
||||
<span>{{ item.port }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">波特率:</span>
|
||||
<span>{{ item.baud_rate }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">数据位:</span>
|
||||
<span>{{ item.data_bits }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">停止位:</span>
|
||||
<span>{{ item.stop_bits }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">校验位:</span>
|
||||
<span>{{ item.parity === 'N' ? '无' : item.parity === 'O' ? '奇校验' : '偶校验' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else-if="item.type === 'Mqtt'">
|
||||
<div class="info-item">
|
||||
<span class="label">Broker地址:</span>
|
||||
<span>{{ item.broker_url }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Broker端口:</span>
|
||||
<span>{{ item.broker_port }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">Topic:</span>
|
||||
<span>{{ item.topic }}</span>
|
||||
</div>
|
||||
<div v-if="item.username" class="info-item">
|
||||
<span class="label">用户名:</span>
|
||||
<span>{{ item.username }}</span>
|
||||
</div>
|
||||
<div v-if="item.client_id" class="info-item">
|
||||
<span class="label">Client ID:</span>
|
||||
<span>{{ item.client_id }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="interface-actions">
|
||||
<button class="btn-text" @click="editInterface(item)">
|
||||
<i class="fas fa-edit"></i> 编辑
|
||||
</button>
|
||||
<button class="btn-text danger" @click="confirmDelete(item)">
|
||||
<i class="fas fa-trash"></i> 删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加/编辑接口对话框 -->
|
||||
<el-dialog
|
||||
:title="editingInterface ? '编辑接口' : '添加接口'"
|
||||
v-model="showAddInterfaceDialog"
|
||||
width="500px"
|
||||
>
|
||||
<el-form :model="interfaceForm" label-width="100px">
|
||||
<el-form-item label="名称" required>
|
||||
<el-input v-model="interfaceForm.name" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型" required>
|
||||
<el-select v-model="interfaceForm.type" placeholder="请选择接口类型">
|
||||
<el-option label="CAN" value="CAN" />
|
||||
<el-option label="Powerbus" value="Powerbus" />
|
||||
<el-option label="Modbus" value="Modbus" />
|
||||
<el-option label="Mqtt" value="Mqtt" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="interfaceForm.description" type="textarea" />
|
||||
</el-form-item>
|
||||
<template v-if="interfaceForm.type === 'CAN'">
|
||||
<el-form-item label="通道号" required>
|
||||
<el-input-number v-model="interfaceForm.can_channel" :min="0" :max="3" />
|
||||
</el-form-item>
|
||||
<el-form-item label="波特率" required>
|
||||
<el-select v-model="interfaceForm.can_baud_rate" placeholder="请选择波特率">
|
||||
<el-option label="125000" :value="125000" />
|
||||
<el-option label="250000" :value="250000" />
|
||||
<el-option label="500000" :value="500000" />
|
||||
<el-option label="1000000" :value="1000000" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<template v-else-if="interfaceForm.type === 'Powerbus'">
|
||||
<el-form-item label="串口" required>
|
||||
<el-select v-model="interfaceForm.port" placeholder="请选择串口">
|
||||
<el-option
|
||||
v-for="port in serialPorts"
|
||||
:key="port.value"
|
||||
:label="port.label"
|
||||
:value="port.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="波特率" required>
|
||||
<el-select v-model="interfaceForm.baud_rate" placeholder="请选择波特率">
|
||||
<el-option label="4800" :value="4800" />
|
||||
<el-option label="9600" :value="9600" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<template v-else-if="interfaceForm.type === 'Modbus'">
|
||||
<el-form-item label="Modbus类型" required>
|
||||
<el-select v-model="interfaceForm.modbus_type" placeholder="请选择Modbus类型">
|
||||
<el-option label="Modbus-TCP" value="TCP" />
|
||||
<el-option label="Modbus-RTU" value="RTU" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="interfaceForm.modbus_type === 'TCP'">
|
||||
<el-form-item label="IP地址" required>
|
||||
<el-input v-model="interfaceForm.ip_address" placeholder="请输入IP地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="端口号" required>
|
||||
<el-input-number v-model="interfaceForm.port" :min="1" :max="65535" placeholder="默认502" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<template v-else-if="interfaceForm.modbus_type === 'RTU'">
|
||||
<el-form-item label="串口" required>
|
||||
<el-select v-model="interfaceForm.port" placeholder="请选择串口">
|
||||
<el-option
|
||||
v-for="port in serialPorts"
|
||||
:key="port.value"
|
||||
:label="port.label"
|
||||
:value="port.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="波特率" required>
|
||||
<el-select v-model="interfaceForm.baud_rate" placeholder="请选择波特率">
|
||||
<el-option label="9600" :value="9600" />
|
||||
<el-option label="19200" :value="19200" />
|
||||
<el-option label="38400" :value="38400" />
|
||||
<el-option label="57600" :value="57600" />
|
||||
<el-option label="115200" :value="115200" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="数据位" required>
|
||||
<el-select v-model="interfaceForm.data_bits" placeholder="请选择数据位">
|
||||
<el-option label="7" :value="7" />
|
||||
<el-option label="8" :value="8" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="停止位" required>
|
||||
<el-select v-model="interfaceForm.stop_bits" placeholder="请选择停止位">
|
||||
<el-option label="1" :value="1" />
|
||||
<el-option label="2" :value="2" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="校验位" required>
|
||||
<el-select v-model="interfaceForm.parity" placeholder="请选择校验位">
|
||||
<el-option label="无" value="N" />
|
||||
<el-option label="奇校验" value="O" />
|
||||
<el-option label="偶校验" value="E" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else-if="interfaceForm.type === 'Mqtt'">
|
||||
<el-form-item label="Broker地址" required>
|
||||
<el-input v-model="interfaceForm.broker_url" />
|
||||
</el-form-item>
|
||||
<el-form-item label="Broker端口" required>
|
||||
<el-input-number v-model="interfaceForm.broker_port" :min="1" :max="65535" />
|
||||
</el-form-item>
|
||||
<el-form-item label="Topic" required>
|
||||
<el-input v-model="interfaceForm.topic" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名">
|
||||
<el-input v-model="interfaceForm.username" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码">
|
||||
<el-input v-model="interfaceForm.password" type="password" show-password />
|
||||
</el-form-item>
|
||||
<el-form-item label="Client ID">
|
||||
<el-input v-model="interfaceForm.client_id" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="showAddInterfaceDialog = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveInterface">确定</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, watch } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
interface InterfaceItem {
|
||||
id: number
|
||||
name: string
|
||||
type: 'CAN' | 'Powerbus' | 'Mqtt' | 'Modbus'
|
||||
description?: string
|
||||
modbus_type?: 'TCP' | 'RTU'
|
||||
ip_address?: string
|
||||
port?: number
|
||||
baud_rate?: number
|
||||
can_channel?: number
|
||||
can_baud_rate?: number
|
||||
broker_url?: string
|
||||
topic?: string
|
||||
broker_port?: number
|
||||
username?: string
|
||||
password?: string
|
||||
client_id?: string
|
||||
data_bits?: number
|
||||
stop_bits?: number
|
||||
parity?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
interface SerialPort {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
// 接口列表
|
||||
const interfaces = ref<InterfaceItem[]>([])
|
||||
const serialPorts = ref<SerialPort[]>([])
|
||||
|
||||
// 对话框控制
|
||||
const showAddInterfaceDialog = ref(false)
|
||||
const editingInterface = ref<InterfaceItem | null>(null)
|
||||
|
||||
// 表单数据
|
||||
const interfaceForm = ref<Partial<InterfaceItem>>({
|
||||
name: '',
|
||||
type: 'CAN',
|
||||
description: '',
|
||||
modbus_type: 'TCP',
|
||||
ip_address: undefined,
|
||||
port: undefined,
|
||||
baud_rate: undefined,
|
||||
can_channel: undefined,
|
||||
can_baud_rate: undefined,
|
||||
broker_url: undefined,
|
||||
topic: undefined,
|
||||
broker_port: undefined,
|
||||
username: undefined,
|
||||
password: undefined,
|
||||
client_id: undefined,
|
||||
data_bits: undefined,
|
||||
stop_bits: undefined,
|
||||
parity: undefined
|
||||
})
|
||||
|
||||
// 获取接口列表
|
||||
const fetchInterfaces = async () => {
|
||||
try {
|
||||
const response = await axios.get<InterfaceItem[]>('/interfaces')
|
||||
interfaces.value = response.data
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message)
|
||||
} else {
|
||||
ElMessage.error('获取接口列表失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取串口列表
|
||||
const fetchSerialPorts = async () => {
|
||||
try {
|
||||
const response = await axios.get<SerialPort[]>('/serial/ports')
|
||||
serialPorts.value = response.data
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message)
|
||||
} else {
|
||||
ElMessage.error('获取串口列表失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存接口
|
||||
const saveInterface = async () => {
|
||||
try {
|
||||
if (editingInterface.value) {
|
||||
await axios.put(
|
||||
`/interfaces/${editingInterface.value.id}`,
|
||||
interfaceForm.value
|
||||
)
|
||||
ElMessage.success('接口更新成功')
|
||||
} else {
|
||||
await axios.post('/interfaces', interfaceForm.value)
|
||||
ElMessage.success('接口添加成功')
|
||||
}
|
||||
showAddInterfaceDialog.value = false
|
||||
fetchInterfaces()
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message)
|
||||
} else if (typeof error === 'object' && error !== null && 'response' in error) {
|
||||
const axiosError = error as { response?: { data?: { detail?: string } } }
|
||||
ElMessage.error(axiosError.response?.data?.detail || '保存失败')
|
||||
} else {
|
||||
ElMessage.error('保存接口失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑接口
|
||||
const editInterface = (interfaceItem: InterfaceItem) => {
|
||||
editingInterface.value = interfaceItem
|
||||
interfaceForm.value = { ...interfaceItem }
|
||||
showAddInterfaceDialog.value = true
|
||||
}
|
||||
|
||||
// 删除接口
|
||||
const confirmDelete = (interfaceItem: InterfaceItem) => {
|
||||
ElMessageBox.confirm(
|
||||
'确定要删除该接口吗?',
|
||||
'警告',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
).then(async () => {
|
||||
try {
|
||||
await axios.delete(`/interfaces/${interfaceItem.id}`)
|
||||
ElMessage.success('接口删除成功')
|
||||
fetchInterfaces()
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
ElMessage.error(error.message)
|
||||
} else if (typeof error === 'object' && error !== null && 'response' in error) {
|
||||
const axiosError = error as { response?: { data?: { detail?: string } } }
|
||||
ElMessage.error(axiosError.response?.data?.detail || '删除失败')
|
||||
} else {
|
||||
ElMessage.error('删除接口失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 监听接口类型变化,重置相关字段
|
||||
watch(() => interfaceForm.value.type, (newType) => {
|
||||
if (!newType) return
|
||||
|
||||
// 重置所有相关字段
|
||||
interfaceForm.value.port = undefined
|
||||
interfaceForm.value.can_channel = undefined
|
||||
interfaceForm.value.can_baud_rate = undefined
|
||||
interfaceForm.value.ip_address = undefined
|
||||
interfaceForm.value.baud_rate = undefined
|
||||
interfaceForm.value.data_bits = undefined
|
||||
interfaceForm.value.stop_bits = undefined
|
||||
interfaceForm.value.parity = undefined
|
||||
|
||||
// 如果是Modbus类型,设置默认的modbus_type
|
||||
if (newType === 'Modbus') {
|
||||
interfaceForm.value.modbus_type = 'TCP'
|
||||
} else {
|
||||
interfaceForm.value.modbus_type = undefined
|
||||
}
|
||||
})
|
||||
|
||||
// 监听Modbus类型变化,重置相关字段
|
||||
watch(() => interfaceForm.value.modbus_type, (newModbusType) => {
|
||||
if (!newModbusType) return
|
||||
|
||||
// 重置Modbus相关字段
|
||||
interfaceForm.value.port = undefined
|
||||
interfaceForm.value.ip_address = undefined
|
||||
interfaceForm.value.baud_rate = undefined
|
||||
interfaceForm.value.data_bits = undefined
|
||||
interfaceForm.value.stop_bits = undefined
|
||||
interfaceForm.value.parity = undefined
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
fetchInterfaces()
|
||||
fetchSerialPorts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.interface-management {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.interface-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.interface-card {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.interface-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.interface-header h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.interface-info {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
margin-bottom: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-item .label {
|
||||
color: #909399;
|
||||
margin-right: 8px;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.interface-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #409EFF;
|
||||
cursor: pointer;
|
||||
padding: 5px 10px;
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.btn-text:hover {
|
||||
color: #66b1ff;
|
||||
}
|
||||
|
||||
.btn-text.danger {
|
||||
color: #F56C6C;
|
||||
}
|
||||
|
||||
.btn-text.danger:hover {
|
||||
color: #f78989;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,442 @@
|
||||
<template>
|
||||
<div class="service-management">
|
||||
<h2>服务管理</h2>
|
||||
|
||||
<!-- EMQX服务管理 -->
|
||||
<el-card class="service-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>EMQX服务</span>
|
||||
<el-tag :type="emqxStatus.toLowerCase() === 'running' ? 'success' : 'danger'">
|
||||
{{ emqxStatus.toLowerCase() === 'running' ? '运行中' : '已停止' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="service-info">
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="版本">{{ emqxInfo.version }}</el-descriptions-item>
|
||||
<el-descriptions-item label="节点">{{ emqxInfo.node }}</el-descriptions-item>
|
||||
<el-descriptions-item label="运行时间">{{ formatUptime(emqxInfo.uptime) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="当前连接数">{{ emqxInfo.connections }}</el-descriptions-item>
|
||||
<el-descriptions-item label="内存使用">{{ emqxInfo.memory_used }} / {{ emqxInfo.memory_total }}</el-descriptions-item>
|
||||
<el-descriptions-item label="CPU负载">
|
||||
1分钟: {{ emqxInfo.load1 }} | 5分钟: {{ emqxInfo.load5 }} | 15分钟: {{ emqxInfo.load15 }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- Powerbus设备通讯服务 -->
|
||||
<el-card class="service-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>Powerbus设备通讯服务</span>
|
||||
<el-tag :type="powerbusServiceStatus.available ? 'success' : 'danger'">
|
||||
{{ powerbusServiceStatus.available ? '运行中' : '已停止' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="service-info">
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="服务状态">{{ powerbusServiceStatus.available ? '可用' : '不可用' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="运行时间">{{ formatRunningTime(powerbusServiceStatus.running_time) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div class="service-actions">
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="controlLoading"
|
||||
@click="controlPowerbusService('start')"
|
||||
>
|
||||
启动
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
:loading="controlLoading"
|
||||
@click="controlPowerbusService('stop')"
|
||||
>
|
||||
停止
|
||||
</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
:loading="controlLoading"
|
||||
@click="controlPowerbusService('restart')"
|
||||
>
|
||||
重启
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
<!-- Modbus设备通讯服务 -->
|
||||
<el-card class="service-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>Modbus设备通讯服务</span>
|
||||
<el-tag :type="modbusServiceStatus.available ? 'success' : 'danger'">
|
||||
{{ modbusServiceStatus.available ? '运行中' : '已停止' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="service-info">
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="服务状态">{{ powerbusServiceStatus.available ? '可用' : '不可用' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="运行时间">{{ formatRunningTime(powerbusServiceStatus.running_time) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div class="service-actions">
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="controlLoading"
|
||||
@click="controlModbusService('start')"
|
||||
>
|
||||
启动
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
:loading="controlLoading"
|
||||
@click="controlModbusService('stop')"
|
||||
>
|
||||
停止
|
||||
</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
:loading="controlLoading"
|
||||
@click="controlModbusService('restart')"
|
||||
>
|
||||
重启
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
<!-- Motor设备通讯服务 -->
|
||||
<el-card class="service-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>Motor设备通讯服务</span>
|
||||
<el-tag :type="motorServiceStatus.available ? 'success' : 'danger'">
|
||||
{{ motorServiceStatus.available ? '运行中' : '已停止' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="service-info">
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="服务状态">{{ motorServiceStatus.available ? '可用' : '不可用' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="运行时间">{{ formatRunningTime(motorServiceStatus.running_time) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div class="service-actions">
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="controlLoading2"
|
||||
@click="controlMotorService('start')"
|
||||
>
|
||||
启动
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
:loading="controlLoading2"
|
||||
@click="controlMotorService('stop')"
|
||||
>
|
||||
停止
|
||||
</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
:loading="controlLoading2"
|
||||
@click="controlMotorService('restart')"
|
||||
>
|
||||
重启
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onActivated, onDeactivated } from 'vue'
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const emqxStatus = ref('unknown')
|
||||
const emqxInfo = ref({
|
||||
version: '',
|
||||
node: '',
|
||||
uptime: 0,
|
||||
connections: 0,
|
||||
memory_used: '',
|
||||
memory_total: '',
|
||||
load1: 0,
|
||||
load5: 0,
|
||||
load15: 0
|
||||
})
|
||||
|
||||
// Powerbus服务状态
|
||||
const powerbusServiceStatus = ref({
|
||||
available: false,
|
||||
running_time: 0
|
||||
})
|
||||
|
||||
const modbusServiceStatus = ref({
|
||||
available: false,
|
||||
running_time: 0
|
||||
})
|
||||
|
||||
// Motor服务状态
|
||||
const motorServiceStatus = ref({
|
||||
available: false,
|
||||
running_time: 0
|
||||
})
|
||||
|
||||
// 控制按钮加载状态
|
||||
const controlLoading = ref(false)
|
||||
const controlLoading2 = ref(false)
|
||||
|
||||
let refreshTimer: number | null = null
|
||||
|
||||
// 格式化运行时间
|
||||
const formatUptime = (ms: number) => {
|
||||
const seconds = Math.floor(ms / 1000)
|
||||
const days = Math.floor(seconds / 86400)
|
||||
const hours = Math.floor((seconds % 86400) / 3600)
|
||||
const minutes = Math.floor((seconds % 3600) / 60)
|
||||
|
||||
return `${days}天${hours}小时${minutes}分钟`
|
||||
}
|
||||
|
||||
// 格式化Powerbus服务运行时间(秒)
|
||||
const formatRunningTime = (seconds: number) => {
|
||||
if (!seconds) return '0秒'
|
||||
|
||||
const days = Math.floor(seconds / 86400)
|
||||
const hours = Math.floor((seconds % 86400) / 3600)
|
||||
const minutes = Math.floor((seconds % 3600) / 60)
|
||||
const secs = Math.floor(seconds % 60)
|
||||
|
||||
return `${days > 0 ? days + '天' : ''}${hours > 0 ? hours + '小时' : ''}${minutes > 0 ? minutes + '分钟' : ''}${secs}秒`
|
||||
}
|
||||
|
||||
const controlService = async (command: string, serviceName: string) => {
|
||||
controlLoading.value = true
|
||||
try {
|
||||
const response = await axios.post(`/services/control`, {
|
||||
service_name: serviceName,
|
||||
command: command
|
||||
})
|
||||
|
||||
if (response.data.status === 'success') {
|
||||
ElMessage.success(response.data.message)
|
||||
// 控制成功后立即刷新状态
|
||||
setTimeout(fetchServiceStatus, 1000)
|
||||
} else {
|
||||
ElMessage.error(response.data.message || '操作失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`控制${serviceName}服务失败:`, error)
|
||||
ElMessage.error(`控制${serviceName}服务失败`)
|
||||
} finally {
|
||||
controlLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 控制Modbus服务
|
||||
const controlModbusService = async (command: string) => {
|
||||
controlService(command, 'modbus_service')
|
||||
}
|
||||
|
||||
// 控制Powerbus服务
|
||||
const controlPowerbusService = async (command: string) => {
|
||||
controlService(command, 'powerbus_service')
|
||||
}
|
||||
|
||||
// 控制Motor服务
|
||||
const controlMotorService = async (command: string) => {
|
||||
controlService(command, 'motor_service')
|
||||
}
|
||||
|
||||
// 获取EMQX状态
|
||||
const fetchEmqxStatus = async () => {
|
||||
try {
|
||||
const response = await axios.get('/services/emqx/status')
|
||||
if (response.data.nodes && response.data.nodes.length > 0) {
|
||||
const node = response.data.nodes[0]
|
||||
emqxStatus.value = node.node_status
|
||||
emqxInfo.value = {
|
||||
version: node.version,
|
||||
node: node.node,
|
||||
uptime: node.uptime,
|
||||
connections: node.connections,
|
||||
memory_used: node.memory_used,
|
||||
memory_total: node.memory_total,
|
||||
load1: node.load1,
|
||||
load5: node.load5,
|
||||
load15: node.load15
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取EMQX状态失败:', error)
|
||||
ElMessage.error('获取EMQX状态失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 获取Powerbus服务状态
|
||||
const fetchPowerbusServiceStatus = async () => {
|
||||
try {
|
||||
const response = await axios.get('/services/status?service_name=powerbus_service')
|
||||
powerbusServiceStatus.value = response.data
|
||||
} catch (error) {
|
||||
console.error('获取Powerbus设备通讯服务状态失败:', error)
|
||||
ElMessage.error('获取Powerbus设备通讯服务状态失败')
|
||||
powerbusServiceStatus.value = {
|
||||
available: false,
|
||||
running_time: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchModbusServiceStatus = async () => {
|
||||
try {
|
||||
const response = await axios.get('/services/status?service_name=modbus_service')
|
||||
modbusServiceStatus.value = response.data
|
||||
} catch (error) {
|
||||
console.error('获取Modbus设备通讯服务状态失败:', error)
|
||||
ElMessage.error('获取Modbus设备通讯服务状态失败')
|
||||
modbusServiceStatus.value = {
|
||||
available: false,
|
||||
running_time: 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 获取Motor服务状态
|
||||
const fetchMotorServiceStatus = async () => {
|
||||
try {
|
||||
const response = await axios.get('/services/status?service_name=motor_service')
|
||||
motorServiceStatus.value = response.data
|
||||
} catch (error) {
|
||||
console.error('获取Motor设备通讯服务状态失败:', error)
|
||||
ElMessage.error('获取Motor设备通讯服务状态失败')
|
||||
motorServiceStatus.value = {
|
||||
available: false,
|
||||
running_time: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 启动定时刷新
|
||||
const startRefresh = () => {
|
||||
// 先立即获取一次数据
|
||||
fetchEmqxStatus()
|
||||
fetchPowerbusServiceStatus()
|
||||
fetchModbusServiceStatus()
|
||||
fetchMotorServiceStatus()
|
||||
|
||||
// 每30秒更新一次状态
|
||||
refreshTimer = window.setInterval(() => {
|
||||
fetchEmqxStatus()
|
||||
fetchModbusServiceStatus()
|
||||
fetchPowerbusServiceStatus()
|
||||
fetchMotorServiceStatus()
|
||||
}, 30000)
|
||||
}
|
||||
|
||||
// 停止定时刷新
|
||||
const stopRefresh = () => {
|
||||
if (refreshTimer) {
|
||||
clearInterval(refreshTimer)
|
||||
refreshTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时获取状态
|
||||
onMounted(() => {
|
||||
startRefresh()
|
||||
})
|
||||
|
||||
// 页面激活时获取状态
|
||||
onActivated(() => {
|
||||
startRefresh()
|
||||
})
|
||||
|
||||
// 页面失活时停止刷新
|
||||
onDeactivated(() => {
|
||||
stopRefresh()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.service-management {
|
||||
padding: 20px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
min-height: calc(100vh - 84px); /* 减去头部导航的高度 */
|
||||
background-color: #f5f7fa;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-bottom: 24px;
|
||||
color: #1f2f3d;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.service-card {
|
||||
margin-bottom: 20px;
|
||||
width: 100%;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
transition: box-shadow 0.3s;
|
||||
}
|
||||
|
||||
.service-card:hover {
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
}
|
||||
|
||||
.service-info {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* 新增服务操作按钮样式 */
|
||||
.service-actions {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
:deep(.el-descriptions) {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.el-descriptions__label) {
|
||||
width: 120px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
:deep(.el-descriptions__content) {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
:deep(.el-card__header) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:deep(.el-card__body) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tag) {
|
||||
font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user