@hzab/form-render-mobile 0.0.2 → 0.0.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/form-render-mobile",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "formily-form-render-mobile",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -44,9 +44,7 @@
44
44
  "@formily/core": "^2.2.29",
45
45
  "@formily/react": "^2.2.29",
46
46
  "antd-mobile": "^5.32.0",
47
- "antd-mobile-icons": "^0.2.2",
48
- "leaflet": "^1.9.4",
49
- "react-leaflet": "^2.8.0"
47
+ "antd-mobile-icons": "^0.2.2"
50
48
  },
51
49
  "directories": {
52
50
  "lib": "lib"
@@ -5,7 +5,7 @@ import { Picker } from "antd-mobile";
5
5
  import "./index.less";
6
6
 
7
7
  function Select(props) {
8
- const { disabled, readOnly, placeholder = "请选择", field = {}, onChange } = props;
8
+ const { value, disabled, readOnly, placeholder = "请选择", field = {}, onChange } = props;
9
9
 
10
10
  const { dataSource } = field;
11
11
 
@@ -33,13 +33,15 @@ function Select(props) {
33
33
  }
34
34
 
35
35
  function onConfirm(value) {
36
- onChange && onChange(value);
36
+ // 去除数组?
37
+ onChange && onChange(value.length === 1 ? value[0] : value);
37
38
  }
38
39
 
39
40
  return (
40
41
  <div className="formily-select" onClick={onClick}>
41
42
  <Picker
42
43
  {...props}
44
+ value={Array.isArray(value) ? value : [value]}
43
45
  style={{ pointerEvents: readOnly || disabled ? "none" : undefined }}
44
46
  columns={_options}
45
47
  visible={visible}
@@ -0,0 +1,43 @@
1
+ .uploader-image-previewer {
2
+ display: flex;
3
+ justify-content: center;
4
+ align-items: center;
5
+ width: 100%;
6
+ height: 100%;
7
+ border: 1px solid #eee;
8
+ color: #fff;
9
+ background-color: #000;
10
+ border-radius: 4px;
11
+
12
+ .uploader-image-previewer-img {
13
+ max-width: 100%;
14
+ max-height: 100%;
15
+ }
16
+ }
17
+
18
+ .uploader-image-previewer-mask {
19
+ display: flex;
20
+ justify-content: center;
21
+ align-items: center;
22
+ max-width: 100vw;
23
+ max-height: 100vh;
24
+ background-color: #000 !important;
25
+ .image-previewer-mask-img {
26
+ max-width: 100vw;
27
+ max-height: 100vh;
28
+ width: 100vw;
29
+ }
30
+ .image-previewer-mask-close-btn {
31
+ position: absolute;
32
+ right: 2vw;
33
+ top: 1vh;
34
+ width: 5vw;
35
+ height: 5vw;
36
+ line-height: 5vw;
37
+ font-size: 3vw;
38
+ text-align: center;
39
+ color: #fff;
40
+ border-radius: 50%;
41
+ background-color: #333;
42
+ }
43
+ }
@@ -0,0 +1,32 @@
1
+ import { useState } from "react";
2
+ import { Mask } from "antd-mobile";
3
+
4
+ import "./index.less";
5
+
6
+ function ImagePreviewer(props) {
7
+ const [maskVisible, setMaskVisible] = useState(false);
8
+
9
+ function onPreview() {
10
+ setMaskVisible(true);
11
+ }
12
+
13
+ return (
14
+ <div className={`uploader-image-previewer ${props.className || ""}`}>
15
+ <img className="uploader-image-previewer-img" src={props.src} alt={props.alt} onClick={onPreview} />
16
+ <Mask
17
+ className="uploader-image-previewer-mask"
18
+ visible={maskVisible}
19
+ getContainer={document.body}
20
+ destroyOnClose
21
+ onMaskClick={() => setMaskVisible(false)}
22
+ >
23
+ <img className="image-previewer-mask-img" src={props.src} alt={props.alt} />
24
+ <div className="image-previewer-mask-close-btn" onClick={() => setMaskVisible(false)}>
25
+ X
26
+ </div>
27
+ </Mask>
28
+ </div>
29
+ );
30
+ }
31
+
32
+ export default ImagePreviewer;
@@ -23,6 +23,9 @@ export function getImage(_options = {}) {
23
23
  reader.onloadend = function (e) {
24
24
  imgBlob = new Blob([this.result], { type: "image/jpeg" });
25
25
  console.log("imgBlob", imgBlob);
26
+ if (!imgBlob?.uid) {
27
+ imgBlob.uid = Date.now();
28
+ }
26
29
  if (!imgBlob?.name) {
27
30
  imgBlob.name = `${Date.now()}.${imgBlob.type?.replace("image/", "")}`;
28
31
  }
@@ -86,6 +89,9 @@ export function getVideo(_options = {}) {
86
89
  reader.onloadend = function (e) {
87
90
  imgBlob = new Blob([this.result], { type: "video/mp4" });
88
91
  console.log("imgBlob", imgBlob);
92
+ if (!imgBlob?.uid) {
93
+ imgBlob.uid = Date.now();
94
+ }
89
95
  if (!imgBlob?.name) {
90
96
  imgBlob.name = `${Date.now()}.${imgBlob.type?.replace("video/", "")}`;
91
97
  }
@@ -146,6 +152,9 @@ export function getAudio(_options = {}) {
146
152
  reader.onloadend = function (e) {
147
153
  audioBlob = new Blob([this.result], { type: "audio/mp3" });
148
154
  console.log("audioBlob", audioBlob);
155
+ if (!audioBlob?.uid) {
156
+ audioBlob.uid = Date.now();
157
+ }
149
158
  if (!audioBlob?.name) {
150
159
  audioBlob.name = `${Date.now()}.${audioBlob.type?.replace("audio/", "")}`;
151
160
  }
@@ -5,18 +5,22 @@
5
5
  * blob:http://localhost:8000/c9950644-5118-4231-9be7-8183bde1fdc7
6
6
  */
7
7
  export function getFileURL(file) {
8
- let url = null;
8
+ let url = file.url || null;
9
9
 
10
- // 下面函数执行的效果是一样的,只是需要针对不同的浏览器执行不同的 js 函数而已
11
- if (window.createObjectURL != undefined) {
12
- // basic
13
- url = window.createObjectURL(file);
14
- } else if (window.URL != undefined) {
15
- // mozilla(firefox)
16
- url = window.URL.createObjectURL(file);
17
- } else if (window.webkitURL != undefined) {
18
- // webkit or chrome
19
- url = window.webkitURL.createObjectURL(file);
10
+ try {
11
+ // 下面函数执行的效果是一样的,只是需要针对不同的浏览器执行不同的 js 函数而已
12
+ if (window.createObjectURL != undefined) {
13
+ // basic
14
+ url = window.createObjectURL(file);
15
+ } else if (window.URL != undefined) {
16
+ // mozilla(firefox)
17
+ url = window.URL.createObjectURL(file);
18
+ } else if (window.webkitURL != undefined) {
19
+ // webkit or chrome
20
+ url = window.webkitURL.createObjectURL(file);
21
+ }
22
+ } catch (error) {
23
+ console.warn("getFileURL Error: ", error);
20
24
  }
21
25
 
22
26
  return url;
@@ -1,11 +1,10 @@
1
- import { Form } from "antd-mobile";
2
1
  import { connect, mapProps } from "@formily/react";
3
2
 
4
3
  import Uploader from "./uploader";
5
4
 
6
5
  function UploaderCom(props) {
7
- const { field = {}, form, onChange } = props;
8
- const { name, mode } = field;
6
+ const { field = {}, onChange } = props;
7
+ const { name, mode, componentProps = {} } = field;
9
8
 
10
9
  function onUploadChange(files) {
11
10
  if (field?.autoUpload && props.fieldsConf[name]?.onUpload) {
@@ -18,6 +17,7 @@ function UploaderCom(props) {
18
17
  const _props = {
19
18
  mode: mode,
20
19
  ...props,
20
+ ...componentProps,
21
21
  };
22
22
 
23
23
  return <Uploader {..._props} onChange={onUploadChange} />;
@@ -1,8 +1,9 @@
1
1
  import { useState, useRef, useEffect, useMemo } from "react";
2
- import { Image, Button, Dialog, ActionSheet } from "antd-mobile";
2
+ import { Button, Dialog, ActionSheet } from "antd-mobile";
3
3
  import { CloseCircleFill } from "antd-mobile-icons";
4
4
 
5
5
  import Video from "./video";
6
+ import Image from "./Image";
6
7
 
7
8
  import { getImage, getVideo, getAudio } from "./common/cordova-camera";
8
9
  import { getFileURL, checkImageUrl, checkVideoUrl, checkAudioUrl } from "./common/utils";
@@ -25,20 +26,26 @@ function Uploader(props) {
25
26
  accept,
26
27
  disabled,
27
28
  readOnly,
28
- data,
29
+ value,
30
+ baseUrl = "",
29
31
  } = props;
30
32
  const [curAccept, setCurAccept] = useState(accept);
31
- const [fileList, setFileList] = useState(data || []);
33
+ const [fileList, setFileList] = useState(value || []);
32
34
  const [actionSheetVisible, setActionSheetVisible] = useState(false);
33
35
 
34
36
  useEffect(() => {
35
- setFileList(data || []);
36
- }, [data]);
37
+ setFileList(value || []);
38
+ }, [value]);
37
39
 
38
40
  function onFileChange(e) {
39
41
  e.persist();
40
42
  const { files: rawFiles } = e.target;
41
- let files = [].slice.call(rawFiles);
43
+ let files = [].slice.call(rawFiles)?.map((it) => {
44
+ if (!it.uid) {
45
+ it.uid = Date.now();
46
+ }
47
+ return it;
48
+ });
42
49
  e.target.value = ""; // HACK: fix the same file doesn't trigger onChange
43
50
  handleChange(files);
44
51
  }
@@ -167,7 +174,8 @@ function Uploader(props) {
167
174
  src = url ? url : it;
168
175
  it = url ? url : it;
169
176
  // 图片
170
- if (it.startsWith("data:image/") || (/[ ,]?image\//.test(accept) && checkImageUrl(it))) {
177
+ const isImg = checkImageUrl(it);
178
+ if (it.startsWith("data:image/") || (/[ ,]?image\//.test(accept) && isImg) || isImg) {
171
179
  fileType = TYPE_IMG;
172
180
  }
173
181
  // 视频
@@ -200,6 +208,10 @@ function Uploader(props) {
200
208
  }
201
209
  }
202
210
 
211
+ if (baseUrl) {
212
+ src = baseUrl + src;
213
+ }
214
+
203
215
  if (fileType === TYPE_IMG) {
204
216
  return (
205
217
  <ItemRender index={idx} key={name + "_" + idx}>
@@ -4,7 +4,6 @@ import Cascader from "./Cascader";
4
4
  import NumberPicker from "./NumberPicker";
5
5
  import DatePicker from "./DatePicker";
6
6
  import Password from "./Password";
7
- import MapPicker from "./MapPicker";
8
7
  import Uploader from "./Uploader";
9
8
 
10
- export { NumberPicker, Password, Select, Cascader, DatePicker, Text, MapPicker, Uploader };
9
+ export { NumberPicker, Password, Select, Cascader, DatePicker, Text, Uploader };
package/src/index.tsx CHANGED
@@ -90,7 +90,7 @@ const FormRender = forwardRef((props: formPropsI, parentRef) => {
90
90
  props.onSubmit && props.onSubmit(values);
91
91
  }}
92
92
  >
93
- 提交
93
+ {props.submitText || "提交"}
94
94
  </Submit>
95
95
  </FormButtonGroup>
96
96
  ) : null}
package/src/type.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface formPropsI {
21
21
  formOptions?: Object;
22
22
  /** 是否有提交按钮 */
23
23
  hasSubmit?: boolean;
24
+ /** 提交按钮文案 */
25
+ submitText?: string;
24
26
  /** 提交事件 */
25
27
  onSubmit?(values): void;
26
28
  /** 组件初始化 */
@@ -1,27 +0,0 @@
1
- function getCurrentPosition(config) {
2
- return new Promise((resolve, reject) => {
3
- // if (window._isMock) {
4
- // // TODO: 去除 mock 数据
5
- // resolve({
6
- // coords: {
7
- // longitude: 120.19832490988816,
8
- // latitude: 30.229457352287543,
9
- // },
10
- // });
11
- // return;
12
- // }
13
- navigator.geolocation.getCurrentPosition(
14
- (position) => {
15
- resolve(position);
16
- },
17
- reject,
18
- {
19
- enableHighAccuracy: true,
20
- timeout: 5000,
21
- ...config,
22
- },
23
- );
24
- });
25
- }
26
-
27
- export default getCurrentPosition;
@@ -1,236 +0,0 @@
1
- /* eslint-disable*/
2
- /*
3
- * BD-09:百度坐标系(百度地图)
4
- * GCJ-02:火星坐标系(谷歌中国地图、高德地图)
5
- * WGS84:地球坐标系(国际通用坐标系,谷歌地图)
6
- */
7
-
8
- const x_PI = (3.14159265358979324 * 3000.0) / 180.0;
9
- const PI = 3.1415926535897932384626;
10
- const a = 6378245.0;
11
- const ee = 0.00669342162296594323;
12
-
13
- // 百度坐标系转火星坐标系
14
- function bd09togcj02(bd_lon, bd_lat) {
15
- const x = bd_lon - 0.0065;
16
- const y = bd_lat - 0.006;
17
- const z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
18
- const theta = Math.Atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
19
-
20
- const gcj_lon = z * Math.cos(theta);
21
- const gcj_lat = z * Math.sin(theta);
22
- const gcj = [gcj_lon, gcj_lat]; // 火星坐标系值
23
-
24
- // 火星坐标系转wgs84
25
- const wgs = [gcj02towgs84(gcj[0], gcj[1])];
26
- return wgs;
27
- }
28
-
29
- // 火星坐标系转wgs84
30
- export function gcj02towgs84(gcj_lon, gcj_lat) {
31
- gcj_lon = Number(gcj_lon);
32
- gcj_lat = Number(gcj_lat);
33
- if (out_of_china(gcj_lon, gcj_lat)) {
34
- // 不在国内,不进行纠偏
35
- const back = [gcj_lat, gcj_lon];
36
- return back;
37
- } else {
38
- let dlon = transformlon(gcj_lon - 105.0, gcj_lat - 35.0);
39
- let dlat = transformlat(gcj_lon - 105.0, gcj_lat - 35.0);
40
- const radlat = (gcj_lat / 180.0) * PI;
41
- let magic = Math.sin(radlat);
42
- magic = 1 - ee * magic * magic;
43
- const sqrtmagic = Math.sqrt(magic);
44
- dlon = (dlon * 180.0) / ((a / sqrtmagic) * Math.cos(radlat) * PI);
45
- dlat = (dlat * 180.0) / (((a * (1 - ee)) / (magic * sqrtmagic)) * PI);
46
- const mglon = gcj_lon + dlon;
47
- const mglat = gcj_lat + dlat;
48
- const wgs_lon = gcj_lon * 2 - mglon;
49
- const wgs_lat = gcj_lat * 2 - mglat;
50
- const wgs = [wgs_lat, wgs_lon]; // wgs84坐标系值
51
- return wgs;
52
- }
53
- }
54
-
55
- // 火星坐标系转百度坐标系
56
- function gcj02tobd09(gcj_lon, gcj_lat) {
57
- const z = Math.sqrt(gcj_lon * gcj_lon + gcj_lat * gcj_lat) + 0.00002 * Math.sin(gcj_lat * x_PI);
58
- const theta = Math.atan2(gcj_lat, gcj_lon) + 0.000003 * Math.cos(gcj_lon * x_PI);
59
- const bd_lon = z * Math.cos(theta) + 0.0065;
60
- const bd_lat = z * Math.sin(theta) + 0.006;
61
- const bd = [bd_lon, bd_lat];
62
- return bd;
63
- }
64
-
65
- // wgs84转火星坐标系
66
- export function wgs84togcj02(wgs_lon, wgs_lat, isWgs84 = false) {
67
- wgs_lon = Number(wgs_lon);
68
- wgs_lat = Number(wgs_lat);
69
- if (out_of_china(wgs_lon, wgs_lat)) {
70
- // 不在国内
71
- const back = [wgs_lon, wgs_lat];
72
- return back;
73
- } else {
74
- if (isWgs84) {
75
- return [wgs_lat, wgs_lon];
76
- } else {
77
- let dwgs_lon = transformlon(wgs_lon - 105.0, wgs_lat - 35.0);
78
- let dwgs_lat = transformlat(wgs_lon - 105.0, wgs_lat - 35.0);
79
- const radwgs_lat = (wgs_lat / 180.0) * PI;
80
- let magic = Math.sin(radwgs_lat);
81
- magic = 1 - ee * magic * magic;
82
- const sqrtmagic = Math.sqrt(magic);
83
- dwgs_lon = (dwgs_lon * 180.0) / ((a / sqrtmagic) * Math.cos(radwgs_lat) * PI);
84
- dwgs_lat = (dwgs_lat * 180.0) / (((a * (1 - ee)) / (magic * sqrtmagic)) * PI);
85
- const gcj_lon = wgs_lon + dwgs_lon;
86
- const gcj_lat = wgs_lat + dwgs_lat;
87
- const gcj = [gcj_lat, gcj_lon];
88
- return gcj;
89
- }
90
- }
91
- }
92
-
93
- function transformlon(lon, lat) {
94
- let ret = 300.0 + lon + 2.0 * lat + 0.1 * lon * lon + 0.1 * lon * lat + 0.1 * Math.sqrt(Math.abs(lon));
95
- ret += ((20.0 * Math.sin(6.0 * lon * PI) + 20.0 * Math.sin(2.0 * lon * PI)) * 2.0) / 3.0;
96
- ret += ((20.0 * Math.sin(lon * PI) + 40.0 * Math.sin((lon / 3.0) * PI)) * 2.0) / 3.0;
97
- ret += ((150.0 * Math.sin((lon / 12.0) * PI) + 300.0 * Math.sin((lon / 30.0) * PI)) * 2.0) / 3.0;
98
- return ret;
99
- }
100
-
101
- function transformlat(lon, lat) {
102
- let ret = -100.0 + 2.0 * lon + 3.0 * lat + 0.2 * lat * lat + 0.1 * lon * lat + 0.2 * Math.sqrt(Math.abs(lon));
103
- ret += ((20.0 * Math.sin(6.0 * lon * PI) + 20.0 * Math.sin(2.0 * lon * PI)) * 2.0) / 3.0;
104
- ret += ((20.0 * Math.sin(lat * PI) + 40.0 * Math.sin((lat / 3.0) * PI)) * 2.0) / 3.0;
105
- ret += ((160.0 * Math.sin((lat / 12.0) * PI) + 320 * Math.sin((lat * PI) / 30.0)) * 2.0) / 3.0;
106
- return ret;
107
- }
108
-
109
- // 判断是否在国内,不在国内则不做偏移
110
- function out_of_china(lon, lat) {
111
- return lon < 72.004 || lon > 137.8347 || lat < 0.8293 || lat > 55.8271 || false;
112
- }
113
-
114
- // 1.加密解密方法使用:
115
-
116
- // 1.加密
117
- // var str = '124中文内容';
118
- // var base = new Base64();
119
- // var result = base.encode(str);
120
- // document.write(result);
121
-
122
- // 2.解密
123
- // var result2 = base.decode(result);
124
- // document.write(result2);
125
- // 2.加密、解密算法封装:
126
-
127
- function Base64() {
128
- // private property
129
- _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
130
-
131
- // public method for encoding
132
- this.encode = function (input) {
133
- let output = "";
134
- let chr1;
135
- let chr2;
136
- let chr3;
137
- let enc1;
138
- let enc2;
139
- let enc3;
140
- let enc4;
141
- let i = 0;
142
- input = _utf8_encode(input);
143
- while (i < input.length) {
144
- chr1 = input.charCodeAt(i++);
145
- chr2 = input.charCodeAt(i++);
146
- chr3 = input.charCodeAt(i++);
147
- enc1 = chr1 >> 2;
148
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
149
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
150
- enc4 = chr3 & 63;
151
- if (isNaN(chr2)) {
152
- enc3 = enc4 = 64;
153
- } else if (isNaN(chr3)) {
154
- enc4 = 64;
155
- }
156
- output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
157
- }
158
- return output;
159
- };
160
-
161
- // public method for decoding
162
- this.decode = function (input) {
163
- let output = "";
164
- let chr1;
165
- let chr2;
166
- let chr3;
167
- let enc1;
168
- let enc2;
169
- let enc3;
170
- let enc4;
171
- let i = 0;
172
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
173
- while (i < input.length) {
174
- enc1 = _keyStr.indexOf(input.charAt(i++));
175
- enc2 = _keyStr.indexOf(input.charAt(i++));
176
- enc3 = _keyStr.indexOf(input.charAt(i++));
177
- enc4 = _keyStr.indexOf(input.charAt(i++));
178
- chr1 = (enc1 << 2) | (enc2 >> 4);
179
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
180
- chr3 = ((enc3 & 3) << 6) | enc4;
181
- output += String.fromCharCode(chr1);
182
- if (enc3 != 64) {
183
- output += String.fromCharCode(chr2);
184
- }
185
- if (enc4 != 64) {
186
- output += String.fromCharCode(chr3);
187
- }
188
- }
189
- output = _utf8_decode(output);
190
- return output;
191
- };
192
-
193
- // private method for UTF-8 encoding
194
- _utf8_encode = function (string) {
195
- string = string.replace(/\r\n/g, "\n");
196
- let utftext = "";
197
- for (let n = 0; n < string.length; n++) {
198
- const c = string.charCodeAt(n);
199
- if (c < 128) {
200
- utftext += String.fromCharCode(c);
201
- } else if (c > 127 && c < 2048) {
202
- utftext += String.fromCharCode((c >> 6) | 192);
203
- utftext += String.fromCharCode((c & 63) | 128);
204
- } else {
205
- utftext += String.fromCharCode((c >> 12) | 224);
206
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
207
- utftext += String.fromCharCode((c & 63) | 128);
208
- }
209
- }
210
- return utftext;
211
- };
212
-
213
- // private method for UTF-8 decoding
214
- _utf8_decode = function (utftext) {
215
- let string = "";
216
- let i = 0;
217
- let c = (c1 = c2 = 0);
218
- while (i < utftext.length) {
219
- c = utftext.charCodeAt(i);
220
- if (c < 128) {
221
- string += String.fromCharCode(c);
222
- i++;
223
- } else if (c > 191 && c < 224) {
224
- c2 = utftext.charCodeAt(i + 1);
225
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
226
- i += 2;
227
- } else {
228
- c2 = utftext.charCodeAt(i + 1);
229
- c3 = utftext.charCodeAt(i + 2);
230
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
231
- i += 3;
232
- }
233
- }
234
- return string;
235
- };
236
- }
@@ -1,7 +0,0 @@
1
- export const mapConfig = {
2
- center: [30.25027961206251, 120.16514401757941], // 默认地图展示位置
3
- minZoom: 3,
4
- maxZoom: 16,
5
- zoom: 14,
6
- attributionControl: false,
7
- };
@@ -1,82 +0,0 @@
1
- import { useState } from "react";
2
- import { connect, mapProps } from "@formily/react";
3
- import { Form, Button, Popup } from "antd-mobile";
4
-
5
- import LocationPicker from "./location-picker";
6
- import LinePicker from "./line-picker";
7
-
8
- function LocationPickerCom(props) {
9
- const { name, formInstance, onChange, data = {}, disabled, readOnly, fieldConf, mode } = props;
10
-
11
- const [visible, setVisible] = useState(false);
12
- const [_data, setData] = useState({});
13
-
14
- function onLocationChange(res) {
15
- formInstance?.setFieldValue(name, res);
16
-
17
- setData(res);
18
- onChange && onChange(res);
19
- onCancel();
20
- }
21
-
22
- function onCancel() {
23
- setVisible(false);
24
- }
25
-
26
- let _mode = mode;
27
- if (fieldConf && fieldConf.mode && !_mode) {
28
- _mode = fieldConf.mode;
29
- }
30
-
31
- return (
32
- <>
33
- {_mode === "line" ? (
34
- // TODO: 展示逻辑优化
35
- <div>
36
- <div>
37
- 起点:{_data?.start?.lng || data?.start?.lng}, {_data?.start?.lat || data?.start?.lat}
38
- </div>
39
- <div>
40
- 终点:{_data?.end?.lng || data?.end?.lng}, {_data?.end?.lat || data?.end?.lat}
41
- </div>
42
- {/* <div>
43
- 起点:{_data.start && _data.start.lng},{" "}
44
- {_data.start && _data.start.lat}
45
- </div>
46
- <div>
47
- 终点:{_data.end && _data.end.lng}, {_data.end && _data.end.lat}
48
- </div> */}
49
- </div>
50
- ) : (
51
- <span>
52
- 经度:{_data.lng || data.lng}
53
- &nbsp; 纬度:{_data.lat || data.lat}
54
- &nbsp;
55
- </span>
56
- )}
57
- {disabled || readOnly ? null : (
58
- <Button
59
- onClick={() => {
60
- setVisible(true);
61
- }}
62
- >
63
- 地图选点
64
- </Button>
65
- )}
66
- <Popup visible={visible} onMaskClick={onCancel} bodyStyle={{ height: "80vh" }}>
67
- {_mode === "line" ? (
68
- <LinePicker data={props.data} onConfirm={onLocationChange} onCancel={onCancel} />
69
- ) : (
70
- <LocationPicker data={props.data} onConfirm={onLocationChange} onCancel={onCancel} />
71
- )}
72
- </Popup>
73
- </>
74
- );
75
- }
76
-
77
- export default connect(
78
- LocationPickerCom,
79
- mapProps((props, field) => {
80
- return { ...props, form: field.form, field };
81
- }),
82
- );