Browse Source

fix:硬件状态

master
guoapeng 2 months ago
parent
commit
2ab5641fac
  1. 56
      src/layouts/default.vue
  2. 2
      src/libs/utils.ts
  3. 10
      src/stores/systemStore.ts
  4. 10
      src/types/system.d.ts
  5. 6
      src/views/home/index.vue

56
src/layouts/default.vue

@ -57,7 +57,7 @@ const menuList = computed(() => {
if (item.meta?.isDefault) {
return true
}
return !!(item.path === '/debug' && systemStore.isDebug)
return (item.path === '/debug' && systemStore.isDebug)
})
})
@ -75,6 +75,21 @@ const getSolution = async () => {
const res = await getContainerList()
containerList.value = res.filter(item => item.type === 0)
}
const statusMap = {
start: {
type: 'primary',
name: '指令开始执行',
},
success: {
type: 'success',
name: '指令执行成功',
},
fail: {
type: 'error',
name: '指令执行异常',
},
}
</script>
<template>
@ -152,7 +167,27 @@ const getSolution = async () => {
<el-col :span="16">
<div class="footer-left">
<img src="../assets/images/run.svg" alt="">
<span class="text">机器运行状态</span>
<span v-if="!systemStore.systemLogList.length" class="text">设备运行状态</span>
<el-popover v-else width="auto" trigger="click" placement="top">
<template #reference>
<el-tag style="width: 100%" :type="statusMap[systemStore.systemLogList[0]?.status as keyof typeof statusMap].type">
{{ systemStore.systemLogList[0]?.cmdName }}: {{ statusMap[systemStore.systemLogList[0]?.status as keyof typeof statusMap].name }}
{{ systemStore.systemLogList[0]?.time }}
</el-tag>
</template>
<template #default>
<div class="log-box">
<el-tag
v-for="(item, key) in systemStore.systemLogList"
:key
:type="statusMap[item?.status as keyof typeof statusMap].type"
>
{{ item.cmdName }}: {{ statusMap[item.status as keyof typeof statusMap].name }}
{{ item.time }}
</el-tag>
</div>
</template>
</el-popover>
</div>
</el-col>
@ -351,12 +386,17 @@ const getSolution = async () => {
}
.footer-left {
border-right: 5px solid #F6F6F6;
display: flex;
align-items: center;
justify-content: space-between;
img {
height: 60%;
margin-right: 20px;
}
.text {
color: #1C1C1C ;
margin-left: 10px;
font-size: 14px;
}
}
@ -396,6 +436,16 @@ const getSolution = async () => {
grid-gap: 10px;
}
.log-box {
width: 500px;
height: 400px;
overflow: auto;
.el-tag {
margin: 5px 0;
width: 100%;
}
}
@keyframes swing {
0% {
transform: rotate(0deg);

2
src/libs/utils.ts

@ -99,7 +99,7 @@ export function isNumber(value: any) {
return typeof value === 'number' && !Number.isNaN(value)
}
export function formatDateTime(template: string = 'YYYY/MM/DD HH:mm:ss'): string {
export function formatDateTime(template: string = 'YYYY-MM-DD HH:mm:ss'): string {
const now = new Date()
const tokens: Record<string, string> = {
YYYY: String(now.getFullYear()),

10
src/stores/systemStore.ts

@ -219,9 +219,6 @@ export const useSystemStore = defineStore('system', {
},
],
},
systemUser: {
username: '',
},
loginForm: {
username: import.meta.env.FT_NODE_ENV !== 'prod' ? 'admin' : '',
password: import.meta.env.FT_NODE_ENV !== 'prod' ? '123456' : '',
@ -230,8 +227,12 @@ export const useSystemStore = defineStore('system', {
isDebug: import.meta.env.FT_NODE_ENV !== 'prod',
streamVisible: false,
systemList: [],
systemLogList: [],
}),
actions: {
insertLog(log: System.SystemLog) {
this.systemLogList.unshift(log)
},
updateDebug() {
this.isDebug = !this.isDebug
},
@ -244,9 +245,6 @@ export const useSystemStore = defineStore('system', {
updateMenuExpand() {
this.menuExpand = !this.menuExpand
},
updateSystemUser(data: System.SystemUser) {
this.systemUser = data
},
pushSystemList(text: any) {
this.systemList.push(text)
},

10
src/types/system.d.ts

@ -7,8 +7,13 @@ declare namespace System {
streamVisible: boolean
isDebug: boolean
menuExpand: boolean
systemUser: SystemUser
loginForm: LoginForm
systemLogList: SystemLog[]
}
interface SystemLog {
cmdName: string
status: 'start' | 'success' | 'fail'
time: string
}
interface SystemStatus {
virtual: boolean
@ -71,9 +76,6 @@ declare namespace System {
command: string
params: T
}
interface SystemUser {
username: string
}
interface LoginForm {
username: string
password: string

6
src/views/home/index.vue

@ -10,6 +10,7 @@ import Tube from 'components/home/Tube/index.vue'
import { ElMessageBox } from 'element-plus'
import { FtMessage } from 'libs/message'
import { socket } from 'libs/socket'
import { cmdNameMap, formatDateTime } from 'libs/utils'
import { useHomeStore } from 'stores/homeStore'
import { useSystemStore } from 'stores/systemStore'
import { onMounted, onUnmounted, provide, ref } from 'vue'
@ -28,8 +29,13 @@ onUnmounted(() => {
})
let currentCommandId = ''
const receiveMessage = (data: Socket.cmdData) => {
data.commandId === currentCommandId && systemStore.pushSystemList(data)
if (['start', 'success', 'fail'].includes(data.status)) {
const cmdName = cmdNameMap[data.command as keyof typeof cmdNameMap] || data.command
systemStore.insertLog({ cmdName, status: data.status as System.SystemLog['status'], time: formatDateTime() })
}
}
const startVisible = ref(false)

Loading…
Cancel
Save