From 9c1764edbd1d5adee9785f329200269ef6884e0d Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Wed, 29 Oct 2025 11:35:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=85=A5=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ImportFile/index.d.ts | 29 +++++++++++ components/ImportFile/index.js | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 components/ImportFile/index.d.ts create mode 100644 components/ImportFile/index.js diff --git a/components/ImportFile/index.d.ts b/components/ImportFile/index.d.ts new file mode 100644 index 0000000..67fbb9f --- /dev/null +++ b/components/ImportFile/index.d.ts @@ -0,0 +1,29 @@ +import type { FormInstance, FormProps } from "antd/es/form"; +import type { FC, ReactNode } from "react"; + +/** + * 表单值类型 + */ +export type FormValues = Record; + +export interface ImportFileProps extends Omit { + /** 弹窗是否显示 */ + visible: boolean; + /** 弹窗标题 */ + title?: string; + /** 模板文件地址 */ + templateUrl: string; + /** 子组件 */ + children?: ReactNode | ((props: { form: FormInstance }) => ReactNode); + /** 确认回调 */ + onConfirm: (values: FormValues) => void; + /** 取消回调 */ + onCancel: () => void; +} + +/** + * 导入文件组件 + */ +declare const ImportFile: FC; + +export default ImportFile; diff --git a/components/ImportFile/index.js b/components/ImportFile/index.js new file mode 100644 index 0000000..c20f774 --- /dev/null +++ b/components/ImportFile/index.js @@ -0,0 +1,87 @@ +import { Button, Form, Modal } from "antd"; +import { getFileUrl } from "../../utils"; +import Upload from "../Upload"; + +/** + * 导入文件组件 + */ +const ImportFile = (props) => { + const { + visible, + onCancel, + onConfirm, + title = "导入", + templateUrl, + labelCol = { span: 4 }, + children, + ...restProps + } = props; + + const [form] = Form.useForm(); + + // 关闭弹窗 + const handleClose = () => { + form.resetFields(); + onCancel(); + }; + + // 提交表单 + const handleSubmit = (values) => { + onConfirm(values); + handleClose(); + }; + + // 导出模板 + const handleExportTemplate = () => { + Modal.confirm({ + title: "提示", + content: "确定要下载excel模板吗?", + okText: "确定", + cancelText: "取消", + onOk: () => { + const fileUrl = getFileUrl(); + window.open(fileUrl + templateUrl); + }, + }); + }; + + return ( + + 导出模板 + + ), + , + , + ]} + > +
+ {children && typeof children === "function" ? children({ form }) : children} + + + +
+
+ ); +}; + +ImportFile.displayName = "ImportFile"; + +export default ImportFile;