zy-react-library 1.0.96 → 1.0.98

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>
@@ -22,6 +22,8 @@ export interface MapSelectorProps {
22
22
  area?: string;
23
23
  /** 是否显示所属区域 */
24
24
  showArea?: boolean;
25
+ /** 是否只查看 */
26
+ disable?: boolean;
25
27
  /** 确认选择回调 */
26
28
  onConfirm?: (longitude: number | string, latitude: number | string, extra: { area: string }) => void;
27
29
  }
@@ -13,6 +13,7 @@ const MapSelector = (props) => {
13
13
  onConfirm,
14
14
  area = "",
15
15
  showArea = false,
16
+ disable = false,
16
17
  } = props;
17
18
 
18
19
  const mapContainerRef = useRef(null);
@@ -66,14 +67,16 @@ const MapSelector = (props) => {
66
67
  }
67
68
 
68
69
  // 添加点击事件
69
- map.addEventListener("click", (event) => {
70
- map.clearOverlays();
71
- const point = new window.BMapGL.Point(event.latlng.lng, event.latlng.lat);
72
- const marker = new window.BMapGL.Marker(point);
73
- map.addOverlay(marker);
74
- setCurrentLatitude(event.latlng.lat);
75
- setCurrentLongitude(event.latlng.lng);
76
- });
70
+ if (!disable) {
71
+ map.addEventListener("click", (event) => {
72
+ map.clearOverlays();
73
+ const point = new window.BMapGL.Point(event.latlng.lng, event.latlng.lat);
74
+ const marker = new window.BMapGL.Marker(point);
75
+ map.addOverlay(marker);
76
+ setCurrentLatitude(event.latlng.lat);
77
+ setCurrentLongitude(event.latlng.lng);
78
+ });
79
+ }
77
80
  }
78
81
 
79
82
  setLoading(false);
@@ -149,10 +152,19 @@ const MapSelector = (props) => {
149
152
  open={visible}
150
153
  title="坐标"
151
154
  onCancel={handleClose}
152
- onOk={handleConfirm}
153
155
  width={1000}
154
156
  destroyOnHidden={false}
155
157
  afterClose={handleAfterClose}
158
+ footer={[
159
+ <Button key="back" onClick={handleClose}>
160
+ 取消
161
+ </Button>,
162
+ !disable && (
163
+ <Button key="submit" type="primary" onClick={handleConfirm}>
164
+ 确定
165
+ </Button>
166
+ ),
167
+ ]}
156
168
  >
157
169
  <Form labelAlign="right" labelCol={{ span: 6 }} wrapperCol={{ span: 18 }}>
158
170
  {
@@ -169,20 +181,24 @@ const MapSelector = (props) => {
169
181
  </Row>
170
182
  )
171
183
  }
172
- <Row gutter={24}>
173
- <Col span={12}>
174
- <Form.Item label="关键字搜索">
175
- <Input value={localSearch} onChange={e => setLocalSearch(e.target.value)} allowClear />
176
- </Form.Item>
177
- </Col>
178
- <Col span={12}>
179
- <Form.Item label=" " colon={false}>
180
- <Button type="primary" onClick={handleLocalSearch}>
181
- 搜索
182
- </Button>
183
- </Form.Item>
184
- </Col>
185
- </Row>
184
+ {
185
+ !disable && (
186
+ <Row gutter={24}>
187
+ <Col span={12}>
188
+ <Form.Item label="关键字搜索">
189
+ <Input value={localSearch} onChange={e => setLocalSearch(e.target.value)} allowClear />
190
+ </Form.Item>
191
+ </Col>
192
+ <Col span={12}>
193
+ <Form.Item label=" " colon={false}>
194
+ <Button type="primary" onClick={handleLocalSearch}>
195
+ 搜索
196
+ </Button>
197
+ </Form.Item>
198
+ </Col>
199
+ </Row>
200
+ )
201
+ }
186
202
  <Row gutter={24}>
187
203
  <Col span={12}>
188
204
  <Form.Item label="经度">
@@ -0,0 +1,24 @@
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
+ }
9
+
10
+ export interface SignatureProps {
11
+ /** 确认签字回调 */
12
+ onConfirm: (value: SignatureValue) => void;
13
+ /** 签字区域宽度,默认为 752 */
14
+ width?: number;
15
+ /** 签字区域高度,默认为 300 */
16
+ height?: number;
17
+ }
18
+
19
+ /**
20
+ * 签字组件
21
+ */
22
+ declare const Signature: FC<SignatureProps>;
23
+
24
+ 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.96",
4
+ "version": "1.0.98",
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
  */