mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-13 04:36:37 +08:00
修复ws连接问题
This commit is contained in:
@@ -66,6 +66,11 @@ export default function NodePage() {
|
|||||||
});
|
});
|
||||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
|
// 安装命令相关状态
|
||||||
|
const [installCommandModal, setInstallCommandModal] = useState(false);
|
||||||
|
const [installCommand, setInstallCommand] = useState('');
|
||||||
|
const [currentNodeName, setCurrentNodeName] = useState('');
|
||||||
|
|
||||||
const websocketRef = useRef<WebSocket | null>(null);
|
const websocketRef = useRef<WebSocket | null>(null);
|
||||||
const reconnectTimerRef = useRef<NodeJS.Timeout | null>(null);
|
const reconnectTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
const reconnectAttemptsRef = useRef(0);
|
const reconnectAttemptsRef = useRef(0);
|
||||||
@@ -409,13 +414,20 @@ export default function NodePage() {
|
|||||||
try {
|
try {
|
||||||
const res = await getNodeInstallCommand(node.id);
|
const res = await getNodeInstallCommand(node.id);
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
await navigator.clipboard.writeText(res.data);
|
try {
|
||||||
toast.success('安装命令已复制到剪贴板');
|
await navigator.clipboard.writeText(res.data);
|
||||||
|
toast.success('安装命令已复制到剪贴板');
|
||||||
|
} catch (copyError) {
|
||||||
|
// 复制失败,显示安装命令模态框
|
||||||
|
setInstallCommand(res.data);
|
||||||
|
setCurrentNodeName(node.name);
|
||||||
|
setInstallCommandModal(true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.error(res.msg || '获取安装命令失败');
|
toast.error(res.msg || '获取安装命令失败');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('复制失败,请手动复制');
|
toast.error('获取安装命令失败');
|
||||||
} finally {
|
} finally {
|
||||||
setNodeList(prev => prev.map(n =>
|
setNodeList(prev => prev.map(n =>
|
||||||
n.id === node.id ? { ...n, copyLoading: false } : n
|
n.id === node.id ? { ...n, copyLoading: false } : n
|
||||||
@@ -423,6 +435,17 @@ export default function NodePage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 手动复制安装命令
|
||||||
|
const handleManualCopy = async () => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(installCommand);
|
||||||
|
toast.success('安装命令已复制到剪贴板');
|
||||||
|
setInstallCommandModal(false);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('复制失败,请手动选择文本复制');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!validateForm()) return;
|
if (!validateForm()) return;
|
||||||
@@ -785,6 +808,58 @@ export default function NodePage() {
|
|||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
{/* 安装命令模态框 */}
|
||||||
|
<Modal
|
||||||
|
isOpen={installCommandModal}
|
||||||
|
onClose={() => setInstallCommandModal(false)}
|
||||||
|
size="2xl"
|
||||||
|
scrollBehavior="inside"
|
||||||
|
>
|
||||||
|
<ModalContent>
|
||||||
|
<ModalHeader>安装命令 - {currentNodeName}</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<p className="text-sm text-default-600">
|
||||||
|
请复制以下安装命令到服务器上执行:
|
||||||
|
</p>
|
||||||
|
<div className="relative">
|
||||||
|
<Textarea
|
||||||
|
value={installCommand}
|
||||||
|
readOnly
|
||||||
|
variant="bordered"
|
||||||
|
minRows={6}
|
||||||
|
maxRows={10}
|
||||||
|
className="font-mono text-sm"
|
||||||
|
classNames={{
|
||||||
|
input: "font-mono text-sm"
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
variant="flat"
|
||||||
|
className="absolute top-2 right-2"
|
||||||
|
onPress={handleManualCopy}
|
||||||
|
>
|
||||||
|
复制
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-default-500">
|
||||||
|
💡 提示:如果复制按钮失效,请手动选择上方文本进行复制
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
variant="flat"
|
||||||
|
onPress={() => setInstallCommandModal(false)}
|
||||||
|
>
|
||||||
|
关闭
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
</AdminLayout>
|
</AdminLayout>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user