消毒机设备
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

  1. import { broadcast } from '../utils/websocket.js'
  2. export const debugRoutes = (app) => {
  3. const statusList = ['info', 'warn', 'success', 'error', 'finish']
  4. app.post('/api/debug/cmd', (req, res) => {
  5. const { commandId, command, params } = req.body
  6. console.log('收到命令:', command, '参数:', params)
  7. // 模拟返回数据
  8. const mockResponse = {
  9. code: '0',
  10. msg: '成功',
  11. data: null,
  12. }
  13. let messageNum = 0
  14. // 异步广播消息
  15. setTimeout(() => {
  16. res.json(mockResponse)
  17. const poll = setInterval(() => {
  18. if (messageNum === 10) {
  19. clearInterval(poll)
  20. }
  21. broadcast({
  22. type: 'cmd_debug',
  23. data: {
  24. commandId,
  25. command,
  26. status: statusList[Math.floor(Math.random() * statusList.length)],
  27. title: `步骤${messageNum}执行完成`,
  28. content: `具体信息${messageNum}`,
  29. },
  30. })
  31. messageNum++
  32. }, Math.floor(Math.random() * (1000 - 500 + 1)) + 500)
  33. }, 1000)
  34. })
  35. app.post('/api/cmd', (req, res) => {
  36. const { commandId, command, params } = req.body
  37. console.log('收到命令:', command, '参数:', params)
  38. // 模拟返回数据
  39. const mockResponse = {
  40. code: '0',
  41. msg: '成功',
  42. data: null,
  43. }
  44. let messageNum = 0
  45. // 异步广播消息
  46. setTimeout(() => {
  47. res.json(mockResponse)
  48. const poll = setInterval(() => {
  49. if (messageNum === 10) {
  50. clearInterval(poll)
  51. }
  52. broadcast({
  53. type: 'cmd_debug',
  54. data: {
  55. commandId,
  56. command,
  57. status: statusList[Math.floor(Math.random() * statusList.length)],
  58. title: `步骤${messageNum}执行完成`,
  59. content: `具体信息${messageNum}`,
  60. },
  61. })
  62. messageNum++
  63. }, Math.floor(Math.random() * (1000 - 500 + 1)) + 500)
  64. }, 1000)
  65. })
  66. }