@hzab/form-render 0.3.1 → 0.4.0

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.
Files changed (34) hide show
  1. package/lib/index.js +1 -1
  2. package/lib/static/imgs/marker-icon_ab8bbcc8cb.svg +4 -0
  3. package/lib/static/imgs/picker-icon_24d725ef02.svg +5 -0
  4. package/lib/static/imgs/position-icon_5bcb8a742e.svg +6 -0
  5. package/lib/static/imgs/reset-icon_9edad62306.svg +5 -0
  6. package/package.json +4 -3
  7. package/src/common/location-utils.ts +21 -0
  8. package/src/components/DatePicker/index.tsx +89 -0
  9. package/src/components/LocationPicker/Map/AMap/common/loader.ts +59 -0
  10. package/src/components/LocationPicker/Map/AMap/common/utils.ts +137 -0
  11. package/src/components/LocationPicker/Map/AMap/index.jsx +44 -0
  12. package/src/components/LocationPicker/Map/AMap/index.less +4 -0
  13. package/src/components/LocationPicker/README.md +35 -0
  14. package/src/components/LocationPicker/assets/marker-icon.svg +4 -0
  15. package/src/components/LocationPicker/assets/picker-icon.svg +5 -0
  16. package/src/components/LocationPicker/assets/position-icon.svg +6 -0
  17. package/src/components/LocationPicker/assets/reset-icon.svg +5 -0
  18. package/src/components/LocationPicker/common/utils.ts +45 -0
  19. package/src/components/LocationPicker/components/MapSearch/index.jsx +61 -0
  20. package/src/components/LocationPicker/components/MapSearch/index.less +10 -0
  21. package/src/components/LocationPicker/components/ModalContent/index.less +81 -0
  22. package/src/components/LocationPicker/components/ModalContent/index.tsx +258 -0
  23. package/src/components/LocationPicker/components/Notice/index.tsx +14 -0
  24. package/src/components/LocationPicker/components/PickerInfo/index.less +21 -0
  25. package/src/components/LocationPicker/components/PickerInfo/index.tsx +100 -0
  26. package/src/components/LocationPicker/components/ResInfo/index.less +25 -0
  27. package/src/components/LocationPicker/components/ResInfo/index.tsx +58 -0
  28. package/src/components/LocationPicker/components/ResInfo/picker-icon.svg +5 -0
  29. package/src/components/LocationPicker/index.less +17 -0
  30. package/src/components/LocationPicker/index.tsx +199 -0
  31. package/src/components/LocationPicker/marker-icon.png +0 -0
  32. package/src/components/LocationPicker/servers/index.ts +121 -0
  33. package/src/components/UserSelect/index.tsx +1 -1
  34. package/src/components/index.tsx +3 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * 根据经纬度获取定义的地址
3
+ * @param lon
4
+ * @param lat
5
+ * @returns
6
+ */
7
+ export function getAddress(lon, lat) {
8
+ return new Promise((resolve, reject) => {
9
+ if (!window.AMap) {
10
+ reject(Error("Error getAddress window.AMap is not defined."));
11
+ return;
12
+ }
13
+ const geocoder = new window.AMap.Geocoder({});
14
+ geocoder.getAddress([lon, lat], function (status, result) {
15
+ if (status === "complete" && result.info === "OK") {
16
+ const formattedAddress = result?.regeocode?.formattedAddress;
17
+ resolve(formattedAddress);
18
+ return formattedAddress;
19
+ } else if (result === "USER_DAILY_QUERY_OVER_LIMIT") {
20
+ // 超出限制,使用 webServer 进行请求
21
+ if (!window._AMapLoaderTemp.serverKey) {
22
+ reject(new Error("超出使用限制,请联系管理员"));
23
+ return;
24
+ }
25
+ fetch(
26
+ `https://restapi.amap.com/v3/geocode/regeo?location=${lon?.toFixed(6)},${lat?.toFixed(6)}&key=${
27
+ window._AMapLoaderTemp.serverKey
28
+ }`,
29
+ {
30
+ mode: "cors",
31
+ },
32
+ )
33
+ .then((res) => res.json())
34
+ .then((res) => {
35
+ if (res.status === "1") {
36
+ resolve(res.regeocode?.formatted_address);
37
+ } else {
38
+ console.warn("Warn getAddress fetch: ", res);
39
+ reject(new Error(res.info));
40
+ }
41
+ })
42
+ .catch(reject);
43
+ } else {
44
+ reject(result);
45
+ }
46
+ });
47
+ });
48
+ }
49
+
50
+ /**
51
+ * 获取搜索提示
52
+ * @param search
53
+ * @param cityCode
54
+ * @returns
55
+ */
56
+ export function getSearchTips(search, cityCode = "0571") {
57
+ return new Promise((resolve, reject) => {
58
+ if (!window.AMap) {
59
+ reject(Error("Error getAddress window.AMap is not defined."));
60
+ return;
61
+ }
62
+ const autoComplete = new window.AMap.Autocomplete({
63
+ // city 限定城市,默认全国
64
+ city: cityCode,
65
+ });
66
+ autoComplete.search(search, function (status, result) {
67
+ if (status === "complete" && result.info === "OK") {
68
+ resolve(
69
+ result.tips?.map((it) => {
70
+ const { lng, lat } = it?.location || {};
71
+ return {
72
+ ...it,
73
+ label: it.name,
74
+ value: it.id,
75
+ lon: +lng,
76
+ lng: +lng,
77
+ lat: +lat,
78
+ };
79
+ }),
80
+ );
81
+ } else if (result === "USER_DAILY_QUERY_OVER_LIMIT") {
82
+ // 超出限制,使用 webServer 进行请求
83
+ if (!window._AMapLoaderTemp.serverKey) {
84
+ reject(new Error("超出使用限制,请联系管理员"));
85
+ return;
86
+ }
87
+ fetch(
88
+ `https://restapi.amap.com/v3/assistant/inputtips?key=${window._AMapLoaderTemp.serverKey}&keywords=${search}&city=${cityCode}`,
89
+ {
90
+ mode: "cors",
91
+ },
92
+ )
93
+ .then((res) => res.json())
94
+ .then((res) => {
95
+ if (res.status === "1") {
96
+ resolve(
97
+ res.tips?.map((it) => {
98
+ const [lng, lat] = it.location?.split(",");
99
+
100
+ return {
101
+ ...it,
102
+ label: it.name,
103
+ value: it.id,
104
+ lng: +lng,
105
+ lon: +lng,
106
+ lat: +lat,
107
+ };
108
+ }),
109
+ );
110
+ } else {
111
+ console.warn("Warn getSearchTips fetch: ", res);
112
+ reject(new Error(res.info));
113
+ }
114
+ })
115
+ .catch(reject);
116
+ } else {
117
+ reject(result);
118
+ }
119
+ });
120
+ });
121
+ }
@@ -65,7 +65,7 @@ export const UserSelect: React.FC<UserSelectProps> = observer((props) => {
65
65
 
66
66
  return (
67
67
  <AntdSelect
68
- defaultOpen
68
+ // defaultOpen
69
69
  className={styles["user-select"]}
70
70
  {...resetProps}
71
71
  value={field.value}
@@ -5,5 +5,8 @@ export * from "./Upload";
5
5
  export * from "./UserSelect";
6
6
 
7
7
  export * from "./TreeCheckbox";
8
+ export * from "./DatePicker";
9
+
10
+ export * from "./LocationPicker";
8
11
 
9
12
  export { Text };