feat(frontend): support external downloads

This commit is contained in:
2026-03-13 17:19:01 +08:00
parent 46afd3149f
commit 19d647c9e1

View File

@@ -84,6 +84,29 @@ const Button = styled.button`
}
`;
const SmallButton = styled.button`
background: ${props => {
if (props.variant === 'danger') return '#f44336';
if (props.variant === 'secondary') return '#757575';
return '#81c784';
}};
color: white;
border: none;
padding: 6px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 12px;
transition: background 0.3s ease;
&:hover {
background: ${props => {
if (props.variant === 'danger') return '#d32f2f';
if (props.variant === 'secondary') return '#616161';
return '#66bb6a';
}};
}
`;
const FormSection = styled.div`
background: white;
border-radius: 15px;
@@ -445,6 +468,7 @@ const WorkEditor = ({ work, onClose }) => {
const [uploadItems, setUploadItems] = useState({});
const [uploading, setUploading] = useState(false);
const [showUploadModal, setShowUploadModal] = useState(false);
const [newExternalLinks, setNewExternalLinks] = useState({});
const platforms = ['Windows', 'Android', 'Linux', 'iOS', 'macOS'];
const categories = ['游戏', '工具', '应用', '网站', '其他'];
@@ -495,9 +519,53 @@ const WorkEditor = ({ work, onClose }) => {
const newFileNames = { ...formData.文件名称 };
delete newFileNames[platform];
handleInputChange('文件名称', newFileNames);
// 移除该平台的外部下载
const newExternal = { ...(formData.外部下载 || {}) };
delete newExternal[platform];
handleInputChange('外部下载', newExternal);
}
};
const updateNewExternal = (platform, field, value) => {
setNewExternalLinks(prev => ({
...prev,
[platform]: {
...(prev[platform] || { 别名: '', 链接: '' }),
[field]: value,
}
}));
};
const handleAddExternalLink = (platform) => {
const draft = newExternalLinks[platform] || {};
const alias = (draft.别名 || '').trim();
const url = (draft.链接 || '').trim();
if (!url) {
setError('外部下载链接不能为空');
return;
}
const list = Array.isArray(formData.外部下载?.[platform]) ? formData.外部下载[platform] : [];
const next = { ...(formData.外部下载 || {}) };
next[platform] = [...list, { 别名: alias || '外部下载', 链接: url }];
handleInputChange('外部下载', next);
setNewExternalLinks(prev => ({
...prev,
[platform]: { 别名: '', 链接: '' }
}));
setSuccess(`已添加 ${platform} 外部下载链接`);
};
const handleDeleteExternalLink = (platform, index) => {
const list = Array.isArray(formData.外部下载?.[platform]) ? formData.外部下载[platform] : [];
const next = { ...(formData.外部下载 || {}) };
next[platform] = list.filter((_, i) => i !== index);
handleInputChange('外部下载', next);
setSuccess(`已删除 ${platform} 外部下载链接`);
};
const handleFileUpload = async (files, fileType, platform = null) => {
if (!formData.作品ID) {
setError('请先保存作品基本信息后再上传文件');
@@ -1030,6 +1098,59 @@ const WorkEditor = ({ work, onClose }) => {
))}
</FileList>
)}
{/* 外部下载链接(带别名) */}
<ExternalLinksContainer>
<h4 style={{ marginTop: '18px', marginBottom: '8px', color: '#2e7d32' }}>
其他地址下载外部链接
</h4>
<p style={{ fontSize: '0.85rem', color: '#666', marginBottom: '8px' }}>
可为 {platform} 配置多个外部下载地址网盘/商店/直链等并设置显示别名
</p>
<ExternalLinkRow>
<Input
type="text"
value={(newExternalLinks[platform]?.别名) || ''}
onChange={(e) => updateNewExternal(platform, '别名', e.target.value)}
placeholder="别名(例如:夸克网盘 / GitHub Releases"
/>
<Input
type="url"
value={(newExternalLinks[platform]?.链接) || ''}
onChange={(e) => updateNewExternal(platform, '链接', e.target.value)}
placeholder="外部下载链接https://..."
/>
<Button
onClick={() => handleAddExternalLink(platform)}
disabled={loading || uploading}
style={{ whiteSpace: 'nowrap' }}
>
+ 添加
</Button>
</ExternalLinkRow>
{Array.isArray(formData.外部下载?.[platform]) && formData.外部下载[platform].length > 0 && (
<ExternalLinksList>
{formData.外部下载[platform].map((item, idx) => (
<ExternalLinkItem key={idx}>
<ExternalLinkText>
<ExternalAlias>{item.别名 || '外部下载'}</ExternalAlias>
<ExternalUrl href={item.链接} target="_blank" rel="noreferrer">
{item.链接}
</ExternalUrl>
</ExternalLinkText>
<SmallButton
variant="danger"
onClick={() => handleDeleteExternalLink(platform, idx)}
>
删除
</SmallButton>
</ExternalLinkItem>
))}
</ExternalLinksList>
)}
</ExternalLinksContainer>
</FormSection>
))}
</>