-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXmlViewer.tsx
More file actions
60 lines (52 loc) · 1.59 KB
/
XmlViewer.tsx
File metadata and controls
60 lines (52 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// src/components/XmlViewer.tsx
// XML 内容查看器
import { useState } from 'react';
import Toast from './Toast';
interface XmlViewerProps {
xmlContent: string;
filename: string;
}
export default function XmlViewer({ xmlContent, filename }: XmlViewerProps) {
const [toast, setToast] = useState<{ message: string; type: 'success' | 'error' } | null>(null);
const handleCopy = () => {
navigator.clipboard.writeText(xmlContent).then(() => {
setToast({ message: 'XML 内容已复制到剪贴板!', type: 'success' });
}).catch(err => {
console.error('复制失败:', err);
setToast({ message: '复制失败,请手动复制', type: 'error' });
});
};
const handleDownload = () => {
const blob = new Blob([xmlContent], { type: 'text/xml' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `${filename}_AndroidManifest.xml`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
return (
<div>
{toast && (
<Toast
message={toast.message}
type={toast.type}
onClose={() => setToast(null)}
/>
)}
<div className="xml-actions">
<button className="button" onClick={handleCopy}>
📋 复制
</button>
<button className="button button-secondary" onClick={handleDownload}>
⬇️ 下载
</button>
</div>
<div className="xml-viewer">
<pre>{xmlContent}</pre>
</div>
</div>
);
}