import { useStore } from '@nanostores/react'; import * as Dialog from '@radix-ui/react-dialog'; import { motion } from 'framer-motion'; import { useEffect, useState } from 'react'; import _1PanelConnection from '~/components/header/connections/_1PanelConnection'; import { useChatDeployment } from '~/lib/hooks/useChatDeployment'; import { _1PanelConnectionStore } from '~/lib/stores/1panel'; import { DeploymentPlatformEnum } from '~/types/deployment'; interface DeployTo1PanelDialogProps { isOpen: boolean; deploying: boolean; onClose: () => void; onDeploy: (options?: { customDomain?: string; siteId?: number; protocol?: string }) => Promise; } export function DeployTo1PanelDialog({ deploying, isOpen, onClose, onDeploy }: DeployTo1PanelDialogProps) { const { getDeploymentByPlatform } = useChatDeployment(); const connection = useStore(_1PanelConnectionStore); const [is1PanelConnected, setIs1PanelConnected] = useState(false); const [showConnectionForm, setShowConnectionForm] = useState(false); const [customDomain, setCustomDomain] = useState(''); const [proxyProtocol, setProxyProtocol] = useState('http'); useEffect(() => { if (connection.isConnect) { setIs1PanelConnected(true); if (isOpen && !is1PanelConnected && !showConnectionForm) { setShowConnectionForm(false); } return; } setIs1PanelConnected(false); if (isOpen && !showConnectionForm) { setShowConnectionForm(true); } }, [connection.isConnect, isOpen, is1PanelConnected]); const check1PanelConnection = () => { if (connection.isConnect) { setIs1PanelConnected(true); } }; const handleDeploy = async (options?: { customDomain?: string; siteId?: number; protocol?: string }) => { if (!connection.isConnect) { return; } await onDeploy({ ...options, customDomain: customDomain || undefined, protocol: proxyProtocol, }); }; const toggleProtocol = () => { setProxyProtocol(proxyProtocol === 'http' ? 'https' : 'http'); }; const handleClose = () => { if (!deploying) { onClose(); setShowConnectionForm(false); } }; const deploymentInfo = getDeploymentByPlatform(DeploymentPlatformEnum._1PANEL); return ( !open && handleClose()}>
部署到 1Panel
1Panel

{is1PanelConnected ? '部署到 1Panel' : '连接 1Panel 服务器'}

{is1PanelConnected ? '您的项目将被部署到 1Panel。点击"部署"按钮开始部署。' : '需要连接 1Panel 服务器才能部署项目。请在此页面完成连接。'}

{!is1PanelConnected && (

仅适用于 1Panel V2 版本

)} {is1PanelConnected && !deploymentInfo?.id && (
:// setCustomDomain(e.target.value)} placeholder="example.upage.ai" className="flex-1 px-3 py-2 rounded-lg text-sm bg-[#F8F8F8] dark:bg-[#1A1A1A] border border-[#E5E5E5] dark:border-[#333333] text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-1 focus:ring-upage-elements-borderColorActive" />

留空将使用自动生成的域名

)}
<_1PanelConnection isDeploying={deploying} onDeploy={(siteId) => handleDeploy({ siteId })} />
{!is1PanelConnected ? ( { check1PanelConnection(); setTimeout(check1PanelConnection, 500); }} className="px-4 py-2 rounded-lg bg-upage-elements-item-backgroundAccent text-upage-elements-item-contentAccent text-sm hover:bg-upage-elements-item-backgroundAccent/90 inline-flex items-center gap-2" whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.98 }} >
刷新连接状态 ) : ( handleDeploy()} disabled={deploying} className="px-4 py-2 rounded-lg bg-[#2b5fe3] text-white text-sm hover:bg-[#2b5fe3]/90 inline-flex items-center gap-2" whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.98 }} > {deploying ? ( <>
部署中... ) : ( <>
{!!deploymentInfo?.id ? '覆盖已有网站' : '部署到 1Panel'} )} )}
); }