hongjli
2025-04-16 91ee71ab6443c774f8f721e826d9fc0811939fb7
优化
已修改1个文件
34 ■■■■ 文件已修改
src/app/ai-scene/chat/page.tsx 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/app/ai-scene/chat/page.tsx
@@ -4,6 +4,7 @@
import { motion, AnimatePresence } from 'framer-motion';
import { useSearchParams } from 'next/navigation';
import { useRouter } from 'next/navigation';
import Image from 'next/image';
import DataPreviewDialog from '@/components/DataPreviewDialog';
// 导入场景数据
@@ -220,6 +221,13 @@
  const [services] = useState([defaultServices.find(s => s.chatbotId === sceneId) || defaultServices[0]]);
  const [selectedScene, setSelectedScene] = useState(initialScene);
  const [iframeKey, setIframeKey] = useState(0);
  const [token, setToken] = useState<string | null>(null);
  useEffect(() => {
    // Get token from localStorage
    const storedToken = localStorage.getItem('token');
    setToken(storedToken);
  }, []);
  // 切换场景时重新加载iframe
  const handleSceneChange = (scene: typeof services[0]) => {
@@ -423,24 +431,14 @@
        </div>
        {/* 聊天窗口 */}
        <div className="flex-1 relative [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-[#E5E6EB] [&::-webkit-scrollbar-thumb]:rounded-full hover:[&::-webkit-scrollbar-thumb]:bg-[#C9CDD4]">
          <AnimatePresence mode="wait">
            <motion.div
              key={iframeKey}
              className="absolute inset-0"
              initial={{ opacity: 0, scale: 0.98 }}
              animate={{ opacity: 1, scale: 1 }}
              exit={{ opacity: 0, scale: 1.02 }}
              transition={{ duration: 0.3 }}
            >
              <iframe
                src={`http://121.43.139.99/chatbot/${selectedScene.chatbotId}`}
                className="w-full h-full"
                style={{ border: 'none' }}
                allow="microphone"
              />
            </motion.div>
          </AnimatePresence>
        <div className="flex-1 relative">
          <iframe
            key={iframeKey}
            className="w-full h-full rounded-lg"
            src={`http://121.43.139.99:7000/chatbot/${selectedScene.chatbotId}${token ? `?token=${token}` : ''}`}
            frameBorder="0"
            allow="microphone"
          ></iframe>
        </div>
      </div>
    </div>