1 | import React from "react";
|
2 | import { DownloadOutlined } from "@ant-design/icons";
|
3 |
|
4 | export default function Download({ src, children = "文件下载" }) {
|
5 | if (!src) return <div>--</div>;
|
6 | return (
|
7 | <a
|
8 | href={src}
|
9 | download={getFileName(src)}
|
10 | style={{
|
11 | color: "blue",
|
12 | cursor: "pointer",
|
13 | "&:hover": { color: "red" },
|
14 | }}
|
15 | >
|
16 | <DownloadOutlined style={{ fontSize: "16px" }} /> {children}
|
17 | </a>
|
18 | );
|
19 | }
|
20 |
|
21 | const getFileName = src => {
|
22 |
|
23 | const match = src.match(/[^\/]+$/);
|
24 | return match ? match[0] : src;
|
25 | };
|