DB-GPT/web/pages/construct/flow/libro/index.tsx
明天 0bc478b7b5
Feat/note book (#2134)
Co-authored-by: sunshinesmilelk <41573506+sunshinesmilelk@users.noreply.github.com>
Co-authored-by: csunny <cfqsunny@163.com>
2024-11-21 20:33:54 +08:00

52 lines
1.4 KiB
TypeScript

import { ChatContext } from '@/app/chat-context';
import { useSearchParams } from 'next/navigation';
import { useContext, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
const Libro: React.FC = () => {
const searchParams = useSearchParams();
const { i18n } = useTranslation();
const { mode } = useContext(ChatContext);
const iframeRef = useRef<HTMLIFrameElement | null>(null);
const id = searchParams?.get('id') || '';
useEffect(() => {
console.log(window.location);
// 监听语言切换事件
const handleLanguageChange = (lng: string) => {
iframeRef.current?.contentWindow?.postMessage(
`lang:${lng}`,
`${window.location.protocol}//${window.location.hostname}:5671`,
);
};
// 注册监听器
i18n.on('languageChanged', handleLanguageChange);
// 清理监听器
return () => {
i18n.off('languageChanged', handleLanguageChange);
};
}, []);
useEffect(() => {
iframeRef.current?.contentWindow?.postMessage(
`theme:${mode}`,
`${window.location.protocol}//${window.location.hostname}:5671`,
);
}, [mode]);
return (
<>
<iframe
src={`${window.location.protocol}//${window.location.hostname}:5671/dbgpt?flow_uid=${id}`}
className='h-full'
ref={iframeRef}
></iframe>
</>
);
};
export default Libro;