|
@@ -1,6 +1,4 @@
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
-import { Button, Upload, message } from 'antd';
|
|
|
|
|
-import { UploadOutlined, DownloadOutlined } from '@ant-design/icons';
|
|
|
|
|
import * as XLSX from 'xlsx';
|
|
import * as XLSX from 'xlsx';
|
|
|
|
|
|
|
|
const ExcelImportExport = ({ members, onImport }) => {
|
|
const ExcelImportExport = ({ members, onImport }) => {
|
|
@@ -11,7 +9,8 @@ const ExcelImportExport = ({ members, onImport }) => {
|
|
|
XLSX.writeFile(workbook, "members.xlsx");
|
|
XLSX.writeFile(workbook, "members.xlsx");
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const handleImport = (file) => {
|
|
|
|
|
|
|
+ const handleImport = (e) => {
|
|
|
|
|
+ const file = e.target.files[0];
|
|
|
const reader = new FileReader();
|
|
const reader = new FileReader();
|
|
|
reader.onload = (event) => {
|
|
reader.onload = (event) => {
|
|
|
const bstr = event.target.result;
|
|
const bstr = event.target.result;
|
|
@@ -24,29 +23,10 @@ const ExcelImportExport = ({ members, onImport }) => {
|
|
|
reader.readAsBinaryString(file);
|
|
reader.readAsBinaryString(file);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const props = {
|
|
|
|
|
- beforeUpload: (file) => {
|
|
|
|
|
- const isXlsx = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
|
|
|
- if (!isXlsx) {
|
|
|
|
|
- message.error('只能上传 XLSX 文件!');
|
|
|
|
|
- }
|
|
|
|
|
- return isXlsx || Upload.LIST_IGNORE;
|
|
|
|
|
- },
|
|
|
|
|
- onChange: (info) => {
|
|
|
|
|
- if (info.file.status !== 'uploading') {
|
|
|
|
|
- handleImport(info.file.originFileObj);
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div style={{ marginBottom: 16 }}>
|
|
|
|
|
- <Button onClick={handleExport} icon={<DownloadOutlined />} style={{ marginRight: 8 }}>
|
|
|
|
|
- 导出 Excel
|
|
|
|
|
- </Button>
|
|
|
|
|
- <Upload {...props} showUploadList={false}>
|
|
|
|
|
- <Button icon={<UploadOutlined />}>导入 Excel</Button>
|
|
|
|
|
- </Upload>
|
|
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <button onClick={handleExport}>导出 Excel</button>
|
|
|
|
|
+ <input type="file" onChange={handleImport} accept=".xlsx, .xls" />
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|