;
+
+export default Signature;
diff --git a/components/Signature/index.js b/components/Signature/index.js
new file mode 100644
index 0000000..4d2e7e2
--- /dev/null
+++ b/components/Signature/index.js
@@ -0,0 +1,87 @@
+import { Button, Image, message, Modal } from "antd";
+import dayjs from "dayjs";
+import { useRef, useState } from "react";
+import SignatureCanvas from "react-signature-canvas";
+import { base642File } from "../../utils";
+
+/**
+ * 签字组件
+ */
+function Signature(props) {
+ const {
+ onConfirm,
+ width = 752,
+ height = 300,
+ ...restProps
+ } = props;
+
+ const [signatureModalOpen, setSignatureModalOpen] = useState(false);
+ const signatureCanvas = useRef(null);
+ const [base64, setBase64] = useState("");
+
+ const onOk = () => {
+ if (signatureCanvas.current.isEmpty()) {
+ message.warning("请签名");
+ return;
+ }
+ const base64 = signatureCanvas.current.toDataURL();
+ setBase64(base64);
+ onConfirm({
+ time: dayjs().format("YYYY-MM-DD HH:mm:ss"),
+ base64,
+ file: base642File(base64),
+ });
+ signatureCanvas.current.clear();
+ setSignatureModalOpen(false);
+ };
+
+ return (
+ <>
+
+
+
+ {base64 && (
+
+
+
+ )}
+ setSignatureModalOpen(false)}
+ footer={[
+ ,
+ ,
+ ,
+ ]}
+ >
+
+
+
+
+ >
+ );
+}
+
+export default Signature;
diff --git a/package.json b/package.json
index e4d5ab8..1734989 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,7 @@
"dayjs": "^1.11.18",
"lodash-es": "^4.17.21",
"react": "^18.3.1",
- "react-pdf": "^10.2.0"
+ "react-pdf": "^10.2.0",
+ "react-signature-canvas": "^1.1.0-alpha.2"
}
}
diff --git a/utils/index.d.ts b/utils/index.d.ts
index 16abcf4..d2fbfe6 100644
--- a/utils/index.d.ts
+++ b/utils/index.d.ts
@@ -261,6 +261,11 @@ export function getIndexColumn(pagination: false | BasePaginationConfig): {
*/
export function getFileUrl(): string;
+/**
+ * base64转File对象
+ */
+export function base642File(base64: string, filename?: string): File;
+
/**
* 获取树形节点路径
*/
diff --git a/utils/index.js b/utils/index.js
index 3b3eb11..bfc6421 100644
--- a/utils/index.js
+++ b/utils/index.js
@@ -61,6 +61,23 @@ export function image2Base642(file) {
});
}
+/**
+ base64转File对象
+ */
+export function base642File(base64, filename = "file") {
+ const arr = base64.split(",");
+ const mime = arr[0].match(/:(.*?);/)[1];
+ const bstr = atob(arr[1]);
+ let n = bstr.length;
+ const u8arr = new Uint8Array(n);
+
+ while (n--) {
+ u8arr[n] = bstr.charCodeAt(n);
+ }
+
+ return new File([u8arr], filename, { type: mime });
+}
+
/**
* 判断图片是否可访问成功
*/