index.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-02-15 16:48:56
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-09-26 10:49:17
  6. * @FilePath: /BudgetManaSystem/src/components/BMSUpload/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import React, { useState } from 'react';
  10. import { InboxOutlined } from '@ant-design/icons';
  11. import { Alert, UploadFile, UploadProps } from 'antd';
  12. import { Upload } from 'antd';
  13. import './style.less';
  14. const { Dragger } = Upload;
  15. type KCIMUploadPropsType = {
  16. onChange?: () => void;
  17. ifShowTip?: boolean; //是否展示黄底提示
  18. ifShowTemplateDownload?: boolean; //是否展示模板下载
  19. downloadTemplateFile?: () => void; //模板下载回调
  20. } & UploadProps;
  21. const KCIMUpload = (props: KCIMUploadPropsType) => {
  22. const [fileList, setFileList] = useState<UploadFile[]>([]);
  23. const {
  24. onChange,
  25. downloadTemplateFile,
  26. ifShowTip = true,
  27. ifShowTemplateDownload = true,
  28. } = props;
  29. const config: UploadProps = {
  30. action: () => Promise.resolve(''),
  31. name: 'file',
  32. multiple: false,
  33. beforeUpload: (file) => {
  34. setFileList([...fileList, file]);
  35. return false;
  36. },
  37. //onChange:onChange?onChange:()=>{},
  38. onChange: (fileInfo) => {
  39. onChange && onChange(fileInfo);
  40. },
  41. onDrop(e) {
  42. console.log('Dropped files', e.dataTransfer.files);
  43. },
  44. };
  45. const download = () => {
  46. downloadTemplateFile && downloadTemplateFile();
  47. };
  48. return (
  49. <div className="KCIMUpload" style={{ paddingBottom: 16 }}>
  50. {ifShowTemplateDownload && (
  51. <div className="toolBar">
  52. <span>文件下载</span>
  53. <span onClick={() => download()}>模板下载</span>
  54. </div>
  55. )}
  56. {ifShowTip && (
  57. <Alert
  58. message="注意,导入的数据将会覆盖当前数据"
  59. type="warning"
  60. style={{ height: 24, fontSize: 12, marginBottom: 16, marginTop: 16 }}
  61. showIcon
  62. closable
  63. banner
  64. />
  65. )}
  66. <Dragger {...config} height={140}>
  67. <p className="ant-upload-drag-icon" style={{ marginBottom: 5 }}>
  68. <InboxOutlined style={{ fontSize: 50, color: '#3376FE' }} />
  69. </p>
  70. <p className="ant-upload-text">点击或将文件拖拽到这里上传</p>
  71. </Dragger>
  72. </div>
  73. );
  74. };
  75. export default KCIMUpload;