UNPKG

723 BJavaScriptView Raw
1import React from "react";
2import { Button } from "antd";
3/**
4 * ----------------------------------------
5 * 文件上传按钮
6 * @param {Function} onChange - onChange(file:Base64)
7 * ----------------------------------------
8 */
9export default function InputFileBtn({ onChange }) {
10 const _onChange = e => {
11 const file = e.target.files[0];
12 const reader = new FileReader();
13 reader.readAsDataURL(file);
14 reader.onload = function() {
15 onChange(this.result);
16 };
17 };
18
19 return (
20 <label>
21 <input
22 type="file"
23 style={{ opacity: 0, width: "1px" }}
24 onChange={_onChange}
25 />
26 <span style={{ cursor: "pointer", color: "#1944bb" }}>上传</span>
27 </label>
28 );
29}