From fb16b8544f536495ea558e9882ac2478202900f3 Mon Sep 17 00:00:00 2001 From: Team Date: Tue, 10 Mar 2026 07:37:06 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E7=BB=84=E4=BB=B6=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/renderer/components/ShareModal.jsx | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 frontend/src/renderer/components/ShareModal.jsx diff --git a/frontend/src/renderer/components/ShareModal.jsx b/frontend/src/renderer/components/ShareModal.jsx new file mode 100644 index 0000000..7c4a470 --- /dev/null +++ b/frontend/src/renderer/components/ShareModal.jsx @@ -0,0 +1,108 @@ +import React, { useState } from 'react'; +import { Modal, Input, Button, Switch, message } from 'antd'; + +function ShareModal({ file, visible, onClose }) { + const [shareLink, setShareLink] = useState(''); + const [password, setPassword] = useState(''); + const [enablePassword, setEnablePassword] = useState(false); + const [expireHours, setExpireHours] = useState(24); + const [loading, setLoading] = useState(false); + + const handleShare = async () => { + if (!file) return; + + setLoading(true); + try { + const token = localStorage.getItem('token'); + const response = await fetch('/api/share', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + }, + body: JSON.stringify({ + fileId: file.id, + password: enablePassword ? password : null, + expiresIn: expireHours * 3600 + }) + }); + + const data = await response.json(); + if (data.success) { + const link = `${window.location.origin}/share/${data.shareToken}`; + setShareLink(link); + message.success('分享链接已生成'); + } + } catch (error) { + message.error('创建分享失败'); + } finally { + setLoading(false); + } + }; + + const handleCopy = () => { + navigator.clipboard.writeText(shareLink); + message.success('链接已复制'); + }; + + return ( + 关闭 + ]} + > +
+

分享: {file?.name}

+
+ +
+
+ + 设置密码保护 +
+ {enablePassword && ( + setPassword(e.target.value)} + /> + )} +
+ +
+ 有效期: + +
+ + {!shareLink && ( + + )} + + {shareLink && ( +
+ + +
+ )} +
+ ); +} + +export default ShareModal;