zy-react-library 1.0.97 → 1.0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,12 +59,12 @@ const FormBuilder = (props) => {
59
59
  {submitButtonText}
60
60
  </Button>
61
61
  )}
62
+ {extraActionButtons}
62
63
  {showCancelButton && (
63
64
  <Button onClick={handleCancel}>
64
65
  {cancelButtonText}
65
66
  </Button>
66
67
  )}
67
- {extraActionButtons}
68
68
  </Space>
69
69
  )}
70
70
  </Col>
@@ -0,0 +1,26 @@
1
+ import type { FC } from "react";
2
+
3
+ export interface SignatureValue {
4
+ /** 签字时间,YYYY-MM-DD HH:mm:ss */
5
+ time: string;
6
+ /** 签字图片的 base64 编码 */
7
+ base64: string;
8
+ /** 签字图片的 file 对象 */
9
+ file: File;
10
+ }
11
+
12
+ export interface SignatureProps {
13
+ /** 确认签字回调 */
14
+ onConfirm: (value: SignatureValue) => void;
15
+ /** 签字区域宽度,默认为 752 */
16
+ width?: number;
17
+ /** 签字区域高度,默认为 300 */
18
+ height?: number;
19
+ }
20
+
21
+ /**
22
+ * 签字组件
23
+ */
24
+ declare const Signature: FC<SignatureProps>;
25
+
26
+ export default Signature;
@@ -0,0 +1,87 @@
1
+ import { Button, Image, message, Modal } from "antd";
2
+ import dayjs from "dayjs";
3
+ import { useRef, useState } from "react";
4
+ import SignatureCanvas from "react-signature-canvas";
5
+ import { base642File } from "../../utils";
6
+
7
+ /**
8
+ * 签字组件
9
+ */
10
+ function Signature(props) {
11
+ const {
12
+ onConfirm,
13
+ width = 752,
14
+ height = 300,
15
+ ...restProps
16
+ } = props;
17
+
18
+ const [signatureModalOpen, setSignatureModalOpen] = useState(false);
19
+ const signatureCanvas = useRef(null);
20
+ const [base64, setBase64] = useState("");
21
+
22
+ const onOk = () => {
23
+ if (signatureCanvas.current.isEmpty()) {
24
+ message.warning("请签名");
25
+ return;
26
+ }
27
+ const base64 = signatureCanvas.current.toDataURL();
28
+ setBase64(base64);
29
+ onConfirm({
30
+ time: dayjs().format("YYYY-MM-DD HH:mm:ss"),
31
+ base64,
32
+ file: base642File(base64),
33
+ });
34
+ signatureCanvas.current.clear();
35
+ setSignatureModalOpen(false);
36
+ };
37
+
38
+ return (
39
+ <>
40
+ <div>
41
+ <Button
42
+ type="primary"
43
+ onClick={() => {
44
+ setSignatureModalOpen(true);
45
+ }}
46
+ >
47
+ {base64 ? "重新签字" : "手写签字"}
48
+ </Button>
49
+ </div>
50
+ {base64 && (
51
+ <div style={{ border: "1px dashed #d9d9d9", width, height, marginTop: 16 }}>
52
+ <Image src={base64} />
53
+ </div>
54
+ )}
55
+ <Modal
56
+ title="签字"
57
+ width={800}
58
+ open={signatureModalOpen}
59
+ onCancel={() => setSignatureModalOpen(false)}
60
+ footer={[
61
+ <Button key="clear" onClick={() => signatureCanvas.current.clear()}>重签</Button>,
62
+ <Button
63
+ key="cancel"
64
+ onClick={() => {
65
+ setSignatureModalOpen(false);
66
+ signatureCanvas.current.clear();
67
+ }}
68
+ >
69
+ 取消
70
+ </Button>,
71
+ <Button key="ok" type="primary" onClick={onOk}>确定</Button>,
72
+ ]}
73
+ >
74
+ <div style={{ border: "1px dashed #d9d9d9" }}>
75
+ <SignatureCanvas
76
+ ref={signatureCanvas}
77
+ penColor="black"
78
+ canvasProps={{ width, height }}
79
+ {...restProps}
80
+ />
81
+ </div>
82
+ </Modal>
83
+ </>
84
+ );
85
+ }
86
+
87
+ export default Signature;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "1.0.97",
4
+ "version": "1.0.99",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",
@@ -31,6 +31,7 @@
31
31
  "dayjs": "^1.11.18",
32
32
  "lodash-es": "^4.17.21",
33
33
  "react": "^18.3.1",
34
- "react-pdf": "^10.2.0"
34
+ "react-pdf": "^10.2.0",
35
+ "react-signature-canvas": "^1.1.0-alpha.2"
35
36
  }
36
37
  }
package/utils/index.d.ts CHANGED
@@ -261,6 +261,11 @@ export function getIndexColumn(pagination: false | BasePaginationConfig): {
261
261
  */
262
262
  export function getFileUrl(): string;
263
263
 
264
+ /**
265
+ * base64转File对象
266
+ */
267
+ export function base642File(base64: string, filename?: string): File;
268
+
264
269
  /**
265
270
  * 获取树形节点路径
266
271
  */
package/utils/index.js CHANGED
@@ -61,6 +61,23 @@ export function image2Base642(file) {
61
61
  });
62
62
  }
63
63
 
64
+ /**
65
+ base64转File对象
66
+ */
67
+ export function base642File(base64, filename = "file") {
68
+ const arr = base64.split(",");
69
+ const mime = arr[0].match(/:(.*?);/)[1];
70
+ const bstr = atob(arr[1]);
71
+ let n = bstr.length;
72
+ const u8arr = new Uint8Array(n);
73
+
74
+ while (n--) {
75
+ u8arr[n] = bstr.charCodeAt(n);
76
+ }
77
+
78
+ return new File([u8arr], filename, { type: mime });
79
+ }
80
+
64
81
  /**
65
82
  * 判断图片是否可访问成功
66
83
  */