From 128e0eb8e1cf7a52e3ba2f5fb5dd0106b09369c2 Mon Sep 17 00:00:00 2001 From: guoapeng Date: Wed, 30 Apr 2025 14:59:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=B1=BB=E5=9E=8B=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/system.ts | 8 +-- src/components/common/FTStream/index.vue | 2 +- src/libs/utils.ts | 18 ------ src/stores/debugStore.ts | 17 ++++++ src/types/System.d.ts | 5 ++ src/views/debug/index.vue | 94 +++++++++++++++++++++----------- 6 files changed, 86 insertions(+), 58 deletions(-) diff --git a/src/apis/system.ts b/src/apis/system.ts index 8d9ff45..99fa143 100644 --- a/src/apis/system.ts +++ b/src/apis/system.ts @@ -1,9 +1,3 @@ import http from 'libs/http' -export interface Params { - commandId: string - command: string - params: T -} -export const debugControl = (params: Params): Promise => http.post('/debug/cmd', params) -export const control = (params: Params): Promise => http.post('/cmd', params) +export const debugControl = (params: System.CmdControlParams): Promise => http.post('/debug/cmd', params) diff --git a/src/components/common/FTStream/index.vue b/src/components/common/FTStream/index.vue index ad94392..88c3067 100644 --- a/src/components/common/FTStream/index.vue +++ b/src/components/common/FTStream/index.vue @@ -20,7 +20,7 @@ const maskRef = ref(null) const maskHeaderRef = ref(null) const statusMap = { - info: 'default', + info: 'info', error: 'danger', warn: 'warning', success: 'success', diff --git a/src/libs/utils.ts b/src/libs/utils.ts index f49304f..7eead40 100644 --- a/src/libs/utils.ts +++ b/src/libs/utils.ts @@ -1,21 +1,3 @@ -import { control, debugControl } from 'apis/system' -import { FtMessage } from 'libs/message' -import { useSystemStore } from 'stores/systemStore' - -export const sendControl = async (params: any, type: 'debug' | 'control' = 'control') => { - if (!params.commandId) { - params.commandId = Date.now().toString() - } - const systemStore = useSystemStore() - - systemStore.systemList = [] - const cmdName = cmdNameMap[params.command as keyof typeof cmdNameMap] || params.command - - await (type === 'debug' ? debugControl(params) : control(params)) - systemStore.updateStreamVisible(true) - FtMessage.success(`[${cmdName}]已发送`) -} - export const cmdNameMap = { debug_door_open: '开门', debug_door_close: '关门', diff --git a/src/stores/debugStore.ts b/src/stores/debugStore.ts index 0f12ff3..23aec00 100644 --- a/src/stores/debugStore.ts +++ b/src/stores/debugStore.ts @@ -1,4 +1,8 @@ +import { debugControl } from 'apis/system' +import { FtMessage } from 'libs/message' +import { cmdNameMap } from 'libs/utils' import { defineStore } from 'pinia' +import { useSystemStore } from 'stores/systemStore' export const useDebugStore = defineStore('debug', { state: (): Debug.DebugStore => ({ @@ -60,6 +64,19 @@ export const useDebugStore = defineStore('debug', { }, }), actions: { + async sendControl(params: System.CmdControlParams<{ [key: string]: any }>) { + if (!params.commandId) { + params.commandId = Date.now().toString() + } + const systemStore = useSystemStore() + + systemStore.systemList = [] + const cmdName = cmdNameMap[params.command as keyof typeof cmdNameMap] || params.command + + await debugControl(params) + systemStore.updateStreamVisible(true) + FtMessage.success(`[${cmdName}]已发送`) + }, }, persist: true, }) diff --git a/src/types/System.d.ts b/src/types/System.d.ts index cea7769..9aea243 100644 --- a/src/types/System.d.ts +++ b/src/types/System.d.ts @@ -7,6 +7,11 @@ declare namespace System { menuExpand: boolean systemUser: SystemUser } + interface CmdControlParams { + commandId: string + command: string + params: T + } interface SystemUser { username: string } diff --git a/src/views/debug/index.vue b/src/views/debug/index.vue index 6a11020..c5f5c51 100644 --- a/src/views/debug/index.vue +++ b/src/views/debug/index.vue @@ -1,6 +1,5 @@