Browse Source

fix: 类型结构优化

feature/three
guoapeng 3 months ago
parent
commit
128e0eb8e1
  1. 8
      src/apis/system.ts
  2. 2
      src/components/common/FTStream/index.vue
  3. 18
      src/libs/utils.ts
  4. 17
      src/stores/debugStore.ts
  5. 5
      src/types/System.d.ts
  6. 94
      src/views/debug/index.vue

8
src/apis/system.ts

@ -1,9 +1,3 @@
import http from 'libs/http' import http from 'libs/http'
export interface Params<T> {
commandId: string
command: string
params: T
}
export const debugControl = <T>(params: Params<T>): Promise<any> => http.post('/debug/cmd', params)
export const control = <T>(params: Params<T>): Promise<any> => http.post('/cmd', params)
export const debugControl = <T>(params: System.CmdControlParams<T>): Promise<any> => http.post('/debug/cmd', params)

2
src/components/common/FTStream/index.vue

@ -20,7 +20,7 @@ const maskRef = ref<HTMLElement | null>(null)
const maskHeaderRef = ref<HTMLElement | null>(null) const maskHeaderRef = ref<HTMLElement | null>(null)
const statusMap = { const statusMap = {
info: 'default',
info: 'info',
error: 'danger', error: 'danger',
warn: 'warning', warn: 'warning',
success: 'success', success: 'success',

18
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<any>(params) : control(params))
systemStore.updateStreamVisible(true)
FtMessage.success(`[${cmdName}]已发送`)
}
export const cmdNameMap = { export const cmdNameMap = {
debug_door_open: '开门', debug_door_open: '开门',
debug_door_close: '关门', debug_door_close: '关门',

17
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 { defineStore } from 'pinia'
import { useSystemStore } from 'stores/systemStore'
export const useDebugStore = defineStore('debug', { export const useDebugStore = defineStore('debug', {
state: (): Debug.DebugStore => ({ state: (): Debug.DebugStore => ({
@ -60,6 +64,19 @@ export const useDebugStore = defineStore('debug', {
}, },
}), }),
actions: { 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, persist: true,
}) })

5
src/types/System.d.ts

@ -7,6 +7,11 @@ declare namespace System {
menuExpand: boolean menuExpand: boolean
systemUser: SystemUser systemUser: SystemUser
} }
interface CmdControlParams<T> {
commandId: string
command: string
params: T
}
interface SystemUser { interface SystemUser {
username: string username: string
} }

94
src/views/debug/index.vue

@ -1,6 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { socket } from 'libs/socket' import { socket } from 'libs/socket'
import { sendControl } from 'libs/utils'
import { useDebugStore } from 'stores/debugStore' import { useDebugStore } from 'stores/debugStore'
import { useSystemStore } from 'stores/systemStore' import { useSystemStore } from 'stores/systemStore'
import { onMounted, onUnmounted } from 'vue' import { onMounted, onUnmounted } from 'vue'
@ -23,301 +22,332 @@ const receiveMessage = (data: Socket.NotificationData) => {
const pallet_elevator_lift_up = async () => { const pallet_elevator_lift_up = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_pallet_elevator_lift_up', command: 'debug_pallet_elevator_lift_up',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
...debugStore.formData.heatArea.heatMotorData, ...debugStore.formData.heatArea.heatMotorData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const pallet_elevator_lift_down = async () => { const pallet_elevator_lift_down = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_pallet_elevator_lift_down', command: 'debug_pallet_elevator_lift_down',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
...debugStore.formData.heatArea.heatMotorData, ...debugStore.formData.heatArea.heatMotorData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const pallet_elevator_stop = async () => { const pallet_elevator_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_pallet_elevator_stop', command: 'debug_pallet_elevator_stop',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const heater_start = async () => { const heater_start = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_heater_start', command: 'debug_heater_start',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
...debugStore.formData.heatArea.heatTemperature, ...debugStore.formData.heatArea.heatTemperature,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const heater_stop = async () => { const heater_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_heater_stop', command: 'debug_heater_stop',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_heater_start_heat_maintaining = async () => { const debug_heater_start_heat_maintaining = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_heater_start_heat_maintaining', command: 'debug_heater_start_heat_maintaining',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
...debugStore.formData.heatArea.heatTemperature, ...debugStore.formData.heatArea.heatTemperature,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_heater_stop_heat_maintaining = async () => { const debug_heater_stop_heat_maintaining = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_heater_stop_heat_maintaining', command: 'debug_heater_stop_heat_maintaining',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_fan_start = async () => { const debug_fan_start = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_fan_start', command: 'debug_fan_start',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_fan_stop = async () => { const debug_fan_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_fan_stop', command: 'debug_fan_stop',
params: { params: {
index: debugStore.formData.heatArea.index, index: debugStore.formData.heatArea.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_cover_elvator_lift_up = async () => { const debug_cover_elvator_lift_up = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_cover_elvator_lift_up', command: 'debug_cover_elvator_lift_up',
params: { params: {
...debugStore.formData.lidData, ...debugStore.formData.lidData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_cover_elvator_lift_down = async () => { const debug_cover_elvator_lift_down = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_cover_elvator_lift_down', command: 'debug_cover_elvator_lift_down',
params: { params: {
...debugStore.formData.lidData, ...debugStore.formData.lidData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_cover_elvator_reset = async () => { const debug_cover_elvator_reset = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_cover_elvator_reset', command: 'debug_cover_elvator_reset',
params: {}, params: {},
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_cover_elvator_stop = async () => { const debug_cover_elvator_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_cover_elvator_stop', command: 'debug_cover_elvator_stop',
params: {}, params: {},
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const liquid_arm_reset = async () => { const liquid_arm_reset = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_liquid_arm_reset', command: 'debug_liquid_arm_reset',
params: { params: {
target: ['largeArm', 'smallArm'], target: ['largeArm', 'smallArm'],
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const liquid_arm_rotation = async () => { const liquid_arm_rotation = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_liquid_arm_rotation', command: 'debug_liquid_arm_rotation',
params: { params: {
...debugStore.formData.liquidArmData, ...debugStore.formData.liquidArmData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const liquid_arm_stop = async () => { const liquid_arm_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_liquid_arm_stop', command: 'debug_liquid_arm_stop',
params: { params: {
target: ['largeArm', 'smallArm'], target: ['largeArm', 'smallArm'],
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const liquid_pump_pre_filling = async () => { const liquid_pump_pre_filling = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_liquid_pump_pre_filling', command: 'debug_liquid_pump_pre_filling',
params: { params: {
index: debugStore.formData.liquidPumpData.index, index: debugStore.formData.liquidPumpData.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const liquid_pump_pre_evacuation = async () => { const liquid_pump_pre_evacuation = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_liquid_pump_pre_evacuation', command: 'debug_liquid_pump_pre_evacuation',
params: { params: {
index: debugStore.formData.liquidPumpData.index, index: debugStore.formData.liquidPumpData.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const liquid_pump_start = async () => { const liquid_pump_start = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_liquid_pump_start', command: 'debug_liquid_pump_start',
params: { params: {
...debugStore.formData.liquidPumpData, ...debugStore.formData.liquidPumpData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const liquid_pump_stop = async () => { const liquid_pump_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_liquid_pump_stop', command: 'debug_liquid_pump_stop',
params: { params: {
index: debugStore.formData.liquidPumpData.index, index: debugStore.formData.liquidPumpData.index,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const shaker_start = async () => { const shaker_start = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_shaker_start', command: 'debug_shaker_start',
params: { params: {
...debugStore.formData.shakeSpeed, ...debugStore.formData.shakeSpeed,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const shaker_stop = async () => { const shaker_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_shaker_stop', command: 'debug_shaker_stop',
params: {}, params: {},
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_transportation_arm_reset = async (motor: 'x' | 'y' | 'z') => { const debug_transportation_arm_reset = async (motor: 'x' | 'y' | 'z') => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_transportation_arm_reset', command: 'debug_transportation_arm_reset',
params: { params: {
dim: [motor], dim: [motor],
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_transportation_arm_move = async (motor: 'x' | 'y' | 'z') => { const debug_transportation_arm_move = async (motor: 'x' | 'y' | 'z') => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_transportation_arm_move', command: 'debug_transportation_arm_move',
params: { params: {
...debugStore.formData.transferModule[`${motor}MotorData`], ...debugStore.formData.transferModule[`${motor}MotorData`],
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_transportation_arm_stop = async (motor: 'x' | 'y' | 'z') => { const debug_transportation_arm_stop = async (motor: 'x' | 'y' | 'z') => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_transportation_arm_stop', command: 'debug_transportation_arm_stop',
params: { params: {
dim: [motor], dim: [motor],
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_holding_jaw_open = async () => { const debug_holding_jaw_open = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_holding_jaw_open', command: 'debug_holding_jaw_open',
params: { params: {
...debugStore.formData.transferModule.JawData, ...debugStore.formData.transferModule.JawData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_holding_jaw_close = async () => { const debug_holding_jaw_close = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_holding_jaw_close', command: 'debug_holding_jaw_close',
params: { params: {
...debugStore.formData.transferModule.JawData, ...debugStore.formData.transferModule.JawData,
}, },
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const debug_holding_jaw_pause = async () => { const debug_holding_jaw_pause = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_holding_jaw_pause', command: 'debug_holding_jaw_pause',
params: {}, params: {},
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const door_open = async () => { const door_open = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_door_open', command: 'debug_door_open',
params: {}, params: {},
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const door_close = async () => { const door_close = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_door_close', command: 'debug_door_close',
params: {}, params: {},
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
const door_stop = async () => { const door_stop = async () => {
const params = { const params = {
commandId: Date.now().toString(),
command: 'debug_door_stop', command: 'debug_door_stop',
params: {}, params: {},
} }
await sendControl(params, 'debug')
await debugStore.sendControl(params)
} }
</script> </script>

Loading…
Cancel
Save