home.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { useState, useEffect } from 'react';
  2. export function HomeLogic() {
  3. const [showDevices, setShowDevices] = useState(true);
  4. const [showScreenShot, setShowScreenShot] = useState(true);
  5. const [showChat, setShowChat] = useState(true);
  6. const [showBlueprint, setShowBlueprint] = useState(false);
  7. const [blueprintWorkflowName, setBlueprintWorkflowName] = useState(null);
  8. // 监听打开蓝图编辑器事件
  9. useEffect(() => {
  10. const handleOpenBlueprint = (e) => {
  11. const workflowName = e.detail?.workflowName;
  12. if (workflowName) {
  13. setBlueprintWorkflowName(workflowName);
  14. setShowBlueprint(true);
  15. // 隐藏其他组件
  16. setShowDevices(false);
  17. setShowScreenShot(false);
  18. setShowChat(false);
  19. }
  20. };
  21. const handleBlueprintBack = () => {
  22. setShowBlueprint(false);
  23. setBlueprintWorkflowName(null);
  24. // 恢复其他组件
  25. setShowDevices(true);
  26. setShowScreenShot(true);
  27. setShowChat(true);
  28. };
  29. window.addEventListener('open-blueprint', handleOpenBlueprint);
  30. window.addEventListener('blueprint-back', handleBlueprintBack);
  31. return () => {
  32. window.removeEventListener('open-blueprint', handleOpenBlueprint);
  33. window.removeEventListener('blueprint-back', handleBlueprintBack);
  34. };
  35. }, []);
  36. return {
  37. showDevices,
  38. setShowDevices,
  39. showScreenShot,
  40. setShowScreenShot,
  41. showChat,
  42. setShowChat,
  43. showBlueprint,
  44. setShowBlueprint,
  45. blueprintWorkflowName,
  46. setBlueprintWorkflowName,
  47. // expose data or methods here
  48. };
  49. }