hongjli
2025-04-09 d67b1bfa110b3d36bd06de14f6b09554b6d5f452
src/components/SceneIntroDialog.tsx
@@ -1,8 +1,9 @@
"use client";
import { Dialog, Transition } from '@headlessui/react';
import { Fragment } from 'react';
import { motion } from 'framer-motion';
import { Fragment, useEffect, useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import DataPreviewDialog from './DataPreviewDialog';
interface SceneIntroDialogProps {
  isOpen: boolean;
@@ -14,6 +15,8 @@
    imageUrl: string;
    background?: string;
    instructions?: string;
    dataDescription?: string;
    exampleData?: string;
  };
}
@@ -23,155 +26,284 @@
  onStartChat,
  scene
}: SceneIntroDialogProps) {
  return (
    <Transition appear show={isOpen} as={Fragment}>
      <Dialog as="div" className="relative z-50" onClose={onClose}>
        <Transition.Child
          as={Fragment}
          enter="ease-out duration-500"
          enterFrom="opacity-0"
          enterTo="opacity-100"
          leave="ease-in duration-300"
          leaveFrom="opacity-100"
          leaveTo="opacity-0"
        >
          <div className="fixed inset-0 bg-black/80 backdrop-blur-sm" />
        </Transition.Child>
  const [showDataPreview, setShowDataPreview] = useState(false);
        <div className="fixed inset-0">
          <div className="absolute top-0 right-0 h-full">
  // 确保动画状态在每次打开时都被重置
  useEffect(() => {
    if (isOpen) {
      // 重置所有动画元素的状态
      const animatedElements = document.querySelectorAll('.dialog-animated');
      animatedElements.forEach(el => {
        if (el instanceof HTMLElement) {
          el.style.opacity = '0';
          el.style.transform = 'none';
          void el.offsetHeight; // 触发重排
        }
      });
    }
  }, [isOpen]);
  return (
    <AnimatePresence>
      {isOpen && (
        <Transition
          appear
          show={isOpen}
          as={Fragment}
          afterLeave={() => {
            // 清理动画资源
            document.body.style.removeProperty('pointer-events');
            window.requestAnimationFrame(() => {
              const elements = document.querySelectorAll('.animate-fade-out, .animate-slide-out, .dialog-animated');
              elements.forEach(el => {
                if (el instanceof HTMLElement) {
                  el.style.animation = 'none';
                  el.style.opacity = '';
                  el.style.transform = '';
                  void el.offsetHeight; // 触发重排以确保动画重置
                  el.style.removeProperty('animation');
                }
              });
            });
          }}
        >
          <Dialog as="div" className="relative z-50" onClose={onClose}>
            <Transition.Child
              as={Fragment}
              enter="transform transition ease-out duration-400"
              enterFrom="translate-x-full"
              enterTo="translate-x-0"
              leave="transform transition ease-in duration-300"
              leaveFrom="translate-x-0"
              leaveTo="translate-x-full"
              enter="ease-out duration-300"
              enterFrom="opacity-0"
              enterTo="opacity-100"
              leave="ease-in duration-200"
              leaveFrom="opacity-100"
              leaveTo="opacity-0"
            >
              <Dialog.Panel className="w-[75vw] h-full bg-gradient-to-br from-[#131C41] to-[#0A1033] shadow-[0_0_50px_rgba(106,219,255,0.2)]">
                <div className="h-full overflow-y-auto">
                  <div className="p-8">
                    <div className="max-w-[1200px] mx-auto">
                      <div className="flex justify-between items-center mb-6">
                        <Dialog.Title className="text-2xl font-bold text-white flex items-center">
                          <span className="text-transparent bg-clip-text bg-gradient-to-r from-[#6ADBFF] to-[#5E72EB]">
                            {scene.title}
                          </span>
                          <motion.span
                            className="ml-2 inline-block w-2 h-2 rounded-full bg-[#6ADBFF]"
                            animate={{
                              scale: [1, 1.5, 1],
                              opacity: [0.7, 1, 0.7]
                            }}
                            transition={{
                              duration: 2,
                              repeat: Infinity,
                              ease: "easeInOut"
                            }}
                          />
                        </Dialog.Title>
                        <button
                          onClick={onClose}
                          className="text-gray-300 hover:text-white transition-colors"
                        >
                          <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
                          </svg>
                        </button>
                      </div>
              <div className="fixed inset-0 bg-black/80 backdrop-blur-sm transition-opacity" />
            </Transition.Child>
                      <div className="space-y-6">
                        {/* 场景图片 */}
                        <motion.div
                          className="relative h-48 rounded-lg overflow-hidden bg-[#1A2547] p-4"
                          initial={{ opacity: 0, scale: 0.95 }}
                          animate={{ opacity: 1, scale: 1 }}
                          transition={{ duration: 0.5, delay: 0.3 }}
                        >
                          <div className="absolute inset-0 bg-gradient-to-t from-[#0A1033]/80 to-transparent z-10"></div>
                          <img
                            src={scene.imageUrl}
                            alt={scene.title}
                            className="w-full h-full object-cover rounded transform scale-100 hover:scale-105 transition-transform duration-700 ease-out"
                          />
                          {/* 装饰性科技感元素 */}
                          <div className="absolute top-3 right-3 w-8 h-8 border-t-2 border-r-2 border-[#6ADBFF]/70 opacity-70"></div>
                          <div className="absolute bottom-3 left-3 w-8 h-8 border-b-2 border-l-2 border-[#6ADBFF]/70 opacity-70"></div>
                        </motion.div>
                        {/* 场景背景 */}
                        <motion.div
                          className="bg-[#1A2547] rounded-lg p-6"
                          initial={{ opacity: 0, x: -20 }}
                          animate={{ opacity: 1, x: 0 }}
                          transition={{ duration: 0.5, delay: 0.4 }}
                        >
                          <h3 className="text-lg font-semibold text-[#6ADBFF] mb-4 flex items-center">
                            <div className="w-1 h-4 bg-[#6ADBFF] mr-2"></div>
                            场景背景
                          </h3>
                          <p className="text-gray-300 leading-relaxed">
                            {scene.background || scene.description}
                          </p>
                        </motion.div>
                        {/* 使用说明 */}
                        <motion.div
                          className="bg-[#1A2547] rounded-lg p-6"
                          initial={{ opacity: 0, x: -20 }}
                          animate={{ opacity: 1, x: 0 }}
                          transition={{ duration: 0.5, delay: 0.5 }}
                        >
                          <h3 className="text-lg font-semibold text-[#6ADBFF] mb-4 flex items-center">
                            <div className="w-1 h-4 bg-[#6ADBFF] mr-2"></div>
                            使用说明
                          </h3>
                          <p className="text-gray-300 leading-relaxed">
                            {scene.instructions || '通过自然语言对话的方式,描述您的具体需求,AI助手将为您提供专业的解决方案。'}
                          </p>
                        </motion.div>
                        {/* 按钮组 */}
                        <motion.div
                          className="sticky bottom-0 bg-gradient-to-br from-[#131C41] to-[#0A1033] pt-4"
                          initial={{ opacity: 0, y: 20 }}
                          animate={{ opacity: 1, y: 0 }}
                          transition={{ duration: 0.5, delay: 0.6 }}
                        >
                          <div className="flex justify-end gap-4">
            <div className="fixed inset-0">
              <div className="absolute inset-0 flex items-center justify-center">
                <Transition.Child
                  as={Fragment}
                  enter="transform transition ease-out duration-400"
                  enterFrom="translate-y-full opacity-0 scale-95"
                  enterTo="translate-y-0 opacity-100 scale-100"
                  leave="transform transition ease-in-out duration-300"
                  leaveFrom="translate-y-0 opacity-100 scale-100"
                  leaveTo="translate-y-full opacity-0 scale-95"
                  afterLeave={() => {
                    const panel = document.querySelector('.dialog-panel');
                    if (panel instanceof HTMLElement) {
                      panel.style.transform = '';
                      panel.style.transition = '';
                    }
                  }}
                >
                  <Dialog.Panel className="dialog-panel w-[80vw] max-h-[90vh] bg-gradient-to-br from-[#131C41] to-[#0A1033] shadow-[0_0_50px_rgba(106,219,255,0.2)] rounded-lg overflow-hidden flex flex-col">
                    <div className="flex-1 overflow-y-auto">
                      <div className="p-8">
                        <div className="max-w-[1200px] mx-auto">
                          <div className="flex justify-between items-center mb-6">
                            <Dialog.Title className="text-2xl font-bold text-white flex items-center">
                              <span className="text-transparent bg-clip-text bg-gradient-to-r from-[#6ADBFF] to-[#5E72EB]">
                                {scene.title}
                              </span>
                              <motion.span
                                className="ml-2 inline-block w-2 h-2 rounded-full bg-[#6ADBFF]"
                                animate={{
                                  scale: [1, 1.5, 1],
                                  opacity: [0.7, 1, 0.7]
                                }}
                                transition={{
                                  duration: 2,
                                  repeat: Infinity,
                                  ease: "easeInOut"
                                }}
                              />
                            </Dialog.Title>
                            <button
                              onClick={onClose}
                              className="px-4 py-2 text-sm font-medium text-gray-300 hover:text-white transition-colors relative overflow-hidden group"
                              className="group relative p-2 rounded-full hover:bg-white/5 transition-colors duration-300 cursor-pointer"
                            >
                              <span className="relative z-10">关闭</span>
                              <span className="absolute bottom-0 left-0 right-0 h-[1px] bg-gray-300/30 transform scale-x-0 group-hover:scale-x-100 transition-transform duration-300 origin-left"></span>
                              <svg
                                xmlns="http://www.w3.org/2000/svg"
                                className="h-6 w-6 text-gray-400 group-hover:text-[#6ADBFF] transition-colors duration-300"
                                fill="none"
                                viewBox="0 0 24 24"
                                stroke="currentColor"
                              >
                                <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
                              </svg>
                            </button>
                          </div>
                          <motion.div
                            className="mb-6 flex justify-center"
                            initial={{ opacity: 0, y: 20 }}
                            animate={{ opacity: 1, y: 0 }}
                            transition={{ duration: 0.5, delay: 0.3 }}
                          >
                            <button
                              onClick={onStartChat}
                              className="group relative"
                              className="group relative w-64 cursor-pointer"
                            >
                              <div className="absolute -inset-0.5 rounded-lg bg-gradient-to-r from-[#6ADBFF] to-[#5E72EB] opacity-60 blur group-hover:opacity-100 transition-all duration-300"></div>
                              <div className="relative px-6 py-2 rounded-lg bg-[#131C41] text-white group-hover:text-[#6ADBFF] transition-colors duration-300 flex items-center gap-2">
                                <span>开始使用</span>
                                <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 transform group-hover:translate-x-1 transition-transform duration-300" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                              <div className="relative px-6 py-3 rounded-lg bg-[#131C41] text-white group-hover:text-[#6ADBFF] transition-colors duration-300 flex items-center justify-center gap-2">
                                <span className="text-lg">开始使用</span>
                                <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5 transform group-hover:translate-x-1 transition-transform duration-300" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 7l5 5m0 0l-5 5m5-5H6" />
                                </svg>
                              </div>
                            </button>
                          </motion.div>
                          <div className="relative mb-8 flex items-center">
                            <div className="flex-grow h-[1px] bg-gradient-to-r from-transparent via-[#6ADBFF]/30 to-transparent"></div>
                            <span className="mx-4 text-sm text-gray-400">场景信息</span>
                            <div className="flex-grow h-[1px] bg-gradient-to-r from-[#6ADBFF]/30 via-[#6ADBFF]/30 to-transparent"></div>
                          </div>
                        </motion.div>
                          <div className="space-y-6">
                            {/* 场景图片 */}
                            <motion.div
                              className="relative h-48 rounded-lg overflow-hidden bg-[#1A2547] p-4"
                              initial={{ opacity: 0, scale: 0.95 }}
                              animate={{ opacity: 1, scale: 1 }}
                              transition={{ duration: 0.5, delay: 0.3 }}
                            >
                              <div className="absolute inset-0 bg-gradient-to-t from-[#0A1033]/80 to-transparent z-10"></div>
                              <img
                                src={scene.imageUrl}
                                alt={scene.title}
                                className="w-full h-full object-cover rounded transform scale-100 hover:scale-105 transition-transform duration-700 ease-out"
                              />
                              {/* 装饰性科技感元素 */}
                              <div className="absolute top-3 right-3 w-8 h-8 border-t-2 border-r-2 border-[#6ADBFF]/70 opacity-70"></div>
                              <div className="absolute bottom-3 left-3 w-8 h-8 border-b-2 border-l-2 border-[#6ADBFF]/70 opacity-70"></div>
                            </motion.div>
                            {/* 内容区域 */}
                            <div className="space-y-5">
                              {/* 场景背景 */}
                              <motion.div
                                initial={{ opacity: 0, y: 20 }}
                                animate={{ opacity: 1, y: 0 }}
                                transition={{
                                  duration: 0.4,
                                  delay: 0.2,
                                  ease: [0.21, 1.11, 0.81, 0.99]
                                }}
                                className="relative p-6 rounded-lg bg-gradient-to-r from-[#1A2547] to-[#1E2B63] group overflow-hidden"
                              >
                                {/* 装饰性光效 */}
                                <div className="absolute inset-0 bg-gradient-to-r from-[#6ADBFF]/0 via-[#6ADBFF]/5 to-[#6ADBFF]/0 translate-x-[-100%] group-hover:translate-x-[100%] transition-transform duration-1000 ease-out"></div>
                                <div className="relative">
                                  <h3 className="text-lg font-semibold mb-4 flex items-center text-white group-hover:text-[#6ADBFF] transition-colors duration-300">
                                    <div className="w-1 h-4 bg-[#6ADBFF] mr-2 opacity-70 group-hover:opacity-100 group-hover:h-5 transition-all duration-300"></div>
                                    背景说明
                                  </h3>
                                  <p className="text-gray-300 leading-relaxed group-hover:text-gray-200 transition-colors duration-300">{scene.background}</p>
                                </div>
                              </motion.div>
                              {/* 使用说明 */}
                              <motion.div
                                initial={{ opacity: 0, y: 20 }}
                                animate={{ opacity: 1, y: 0 }}
                                transition={{
                                  duration: 0.4,
                                  delay: 0.3,
                                  ease: [0.21, 1.11, 0.81, 0.99]
                                }}
                                className="relative p-6 rounded-lg bg-gradient-to-r from-[#1E2B63] to-[#1A2547] group overflow-hidden"
                              >
                                {/* 装饰性光效 */}
                                <div className="absolute inset-0 bg-gradient-to-r from-[#FF6A88]/0 via-[#FF6A88]/5 to-[#FF6A88]/0 translate-x-[-100%] group-hover:translate-x-[100%] transition-transform duration-1000 ease-out"></div>
                                <div className="relative">
                                  <h3 className="text-lg font-semibold mb-4 flex items-center text-white group-hover:text-[#FF6A88] transition-colors duration-300">
                                    <div className="w-1 h-4 bg-[#FF6A88] mr-2 opacity-70 group-hover:opacity-100 group-hover:h-5 transition-all duration-300"></div>
                                    使用说明
                                  </h3>
                                  <p className="text-gray-300 leading-relaxed group-hover:text-gray-200 transition-colors duration-300">{scene.instructions}</p>
                                </div>
                              </motion.div>
                              {/* 数据说明 */}
                              <motion.div
                                initial={{ opacity: 0, y: 20 }}
                                animate={{ opacity: 1, y: 0 }}
                                transition={{
                                  duration: 0.4,
                                  delay: 0.4,
                                  ease: [0.21, 1.11, 0.81, 0.99]
                                }}
                                className="relative p-6 rounded-lg bg-gradient-to-r from-[#1A2547] via-[#1E2B63] to-[#1A2547] group overflow-hidden"
                              >
                                {/* 装饰性光效 */}
                                <div className="absolute inset-0 bg-gradient-to-r from-[#6ADBFF]/0 via-[#6ADBFF]/5 to-[#6ADBFF]/0 translate-x-[-100%] group-hover:translate-x-[100%] transition-transform duration-1000 ease-out"></div>
                                <div className="relative">
                                  <div className="flex items-center justify-between mb-4">
                                    <h3 className="text-lg font-semibold flex items-center text-white group-hover:text-[#6ADBFF] transition-colors duration-300">
                                      <div className="w-1 h-4 bg-[#6ADBFF] mr-2 opacity-70 group-hover:opacity-100 group-hover:h-5 transition-all duration-300"></div>
                                      数据说明
                                    </h3>
                                    <button
                                      onClick={() => setShowDataPreview(true)}
                                      className="flex items-center px-3 py-1.5 text-sm text-[#6ADBFF] hover:text-white bg-[#1A2547]/50 hover:bg-[#6ADBFF]/10 rounded-full transition-all duration-300 group/btn cursor-pointer"
                                    >
                                      <svg
                                        xmlns="http://www.w3.org/2000/svg"
                                        className="h-4 w-4 mr-1.5 opacity-70 group-hover/btn:opacity-100 transition-opacity duration-300"
                                        fill="none"
                                        viewBox="0 0 24 24"
                                        stroke="currentColor"
                                      >
                                        <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 10h16M4 14h16M4 18h16" />
                                      </svg>
                                      演示数据
                                    </button>
                                  </div>
                                  <p className="text-gray-300 leading-relaxed group-hover:text-gray-200 transition-colors duration-300">
                                    {scene.dataDescription || '本场景所使用的数据均为模拟数据,仅用于演示目的。在实际应用中,将根据您的具体需求使用真实数据进行分析和处理。'}
                                  </p>
                                </div>
                              </motion.div>
                              {/* 示例数据预览对话框 */}
                              <DataPreviewDialog
                                isOpen={showDataPreview}
                                onClose={() => setShowDataPreview(false)}
                                markdownContent={scene.exampleData || `
### 演示数据
| 工位 | 原材料需求 | 原材料消耗速率 | 生产的产品 | 产线名 |
|------|------------|----------------|------------|--------|
| 1 | A1 | 2/小时 | P | 产线1 |
| 2 | A2 | 1/小时 | P | 产线1 |
| 3 | A3 | 2/小时 | P | 产线1 |
| 4 | A4 | 4/小时 | P | 产线1 |
| 5 | A5 | 5/小时 | P | 产线1 |
| 6 | - | - | P | 产线1 |
| 7 | A7 | 3/小时 | P | 产线1 |
| 8 | - | - | P | 产线1 |
| 9 | A9 | 3/小时 | P | 产线1 |
                                `}
                              />
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </Dialog.Panel>
            </Transition.Child>
          </div>
        </div>
      </Dialog>
    </Transition>
                  </Dialog.Panel>
                </Transition.Child>
              </div>
            </div>
          </Dialog>
        </Transition>
      )}
    </AnimatePresence>
  );