消毒机设备
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

74 lines
1.9 KiB

import { broadcast } from '../utils/websocket.js'
export const debugRoutes = (app) => {
const statusList = ['info', 'warn', 'success', 'error', 'finish']
app.post('/api/debug/cmd', (req, res) => {
const { commandId, command, params } = req.body
console.log('收到命令:', command, '参数:', params)
// 模拟返回数据
const mockResponse = {
code: '0',
msg: '成功',
data: null,
}
let messageNum = 0
// 异步广播消息
setTimeout(() => {
res.json(mockResponse)
const poll = setInterval(() => {
if (messageNum === 10) {
clearInterval(poll)
}
broadcast({
type: 'cmd_debug',
data: {
commandId,
command,
status: statusList[Math.floor(Math.random() * statusList.length)],
title: `步骤${messageNum}执行完成`,
content: `具体信息${messageNum}`,
},
})
messageNum++
}, Math.floor(Math.random() * (1000 - 500 + 1)) + 500)
}, 1000)
})
app.post('/api/cmd', (req, res) => {
const { commandId, command, params } = req.body
console.log('收到命令:', command, '参数:', params)
// 模拟返回数据
const mockResponse = {
code: '0',
msg: '成功',
data: null,
}
let messageNum = 0
// 异步广播消息
setTimeout(() => {
res.json(mockResponse)
const poll = setInterval(() => {
if (messageNum === 10) {
clearInterval(poll)
}
broadcast({
type: 'cmd_debug',
data: {
commandId,
command,
status: statusList[Math.floor(Math.random() * statusList.length)],
title: `步骤${messageNum}执行完成`,
content: `具体信息${messageNum}`,
},
})
messageNum++
}, Math.floor(Math.random() * (1000 - 500 + 1)) + 500)
}, 1000)
})
}