| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { useState, useEffect } from 'react';
- export function HomeLogic() {
- const [showDevices, setShowDevices] = useState(true);
- const [showScreenShot, setShowScreenShot] = useState(true);
- const [showChat, setShowChat] = useState(true);
- const [showBlueprint, setShowBlueprint] = useState(false);
- const [blueprintWorkflowName, setBlueprintWorkflowName] = useState(null);
- // 监听打开蓝图编辑器事件
- useEffect(() => {
- const handleOpenBlueprint = (e) => {
- const workflowName = e.detail?.workflowName;
- if (workflowName) {
- setBlueprintWorkflowName(workflowName);
- setShowBlueprint(true);
- // 隐藏其他组件
- setShowDevices(false);
- setShowScreenShot(false);
- setShowChat(false);
- }
- };
- const handleBlueprintBack = () => {
- setShowBlueprint(false);
- setBlueprintWorkflowName(null);
- // 恢复其他组件
- setShowDevices(true);
- setShowScreenShot(true);
- setShowChat(true);
- };
- window.addEventListener('open-blueprint', handleOpenBlueprint);
- window.addEventListener('blueprint-back', handleBlueprintBack);
- return () => {
- window.removeEventListener('open-blueprint', handleOpenBlueprint);
- window.removeEventListener('blueprint-back', handleBlueprintBack);
- };
- }, []);
- return {
- showDevices,
- setShowDevices,
- showScreenShot,
- setShowScreenShot,
- showChat,
- setShowChat,
- showBlueprint,
- setShowBlueprint,
- blueprintWorkflowName,
- setBlueprintWorkflowName,
- // expose data or methods here
- };
- }
|