@nocobase/plugin-map 0.9.1-alpha.1 → 0.9.2-alpha.1
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/docs/en-US/changelog.md +1 -0
- package/docs/en-US/index.md +1 -0
- package/docs/en-US/installation.md +1 -0
- package/docs/en-US/tabs.json +18 -0
- package/docs/en-US/usage.md +1 -0
- package/docs/zh-CN/changelog.md +1 -0
- package/docs/zh-CN/index.md +1 -0
- package/docs/zh-CN/installation.md +1 -0
- package/docs/zh-CN/tabs.json +18 -0
- package/docs/zh-CN/usage.md +1 -0
- package/lib/client/block/MapActionInitializers.d.ts +89 -0
- package/lib/client/block/MapActionInitializers.js +93 -0
- package/lib/client/block/MapBlock.d.ts +1 -0
- package/lib/client/block/MapBlock.js +358 -0
- package/lib/client/block/MapBlockDesigner.d.ts +1 -0
- package/lib/client/block/MapBlockDesigner.js +196 -0
- package/lib/client/block/MapBlockInitializer.d.ts +1 -0
- package/lib/client/block/MapBlockInitializer.js +122 -0
- package/lib/client/block/MapBlockProvider.d.ts +5 -0
- package/lib/client/block/MapBlockProvider.js +91 -0
- package/lib/client/block/index.d.ts +2 -0
- package/lib/client/block/index.js +58 -0
- package/lib/client/block/utils.d.ts +56 -0
- package/lib/client/block/utils.js +102 -0
- package/lib/client/components/AMap.d.ts +32 -6
- package/lib/client/components/AMap.js +152 -203
- package/lib/client/components/Configuration.js +11 -45
- package/lib/client/components/Designer.js +6 -40
- package/lib/client/components/Map.d.ts +4 -1
- package/lib/client/components/Map.js +4 -18
- package/lib/client/components/ReadPretty.js +12 -29
- package/lib/client/components/Search.js +31 -65
- package/lib/client/constants.js +0 -2
- package/lib/client/fields/circle.js +3 -8
- package/lib/client/fields/index.js +0 -5
- package/lib/client/fields/lineString.js +3 -8
- package/lib/client/fields/point.js +3 -8
- package/lib/client/fields/polygon.js +3 -8
- package/lib/client/fields/schema.d.ts +1 -2
- package/lib/client/fields/schema.js +3 -18
- package/lib/client/hooks/index.js +0 -2
- package/lib/client/hooks/useMapConfiguration.d.ts +1 -0
- package/lib/client/hooks/useMapConfiguration.js +28 -8
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +8 -26
- package/lib/client/initialize.d.ts +1 -1
- package/lib/client/initialize.js +4 -21
- package/lib/client/locale/index.js +6 -13
- package/lib/client/locale/pt-BR.d.ts +46 -0
- package/lib/client/locale/pt-BR.js +54 -0
- package/lib/client/locale/zh-CN.d.ts +5 -2
- package/lib/client/locale/zh-CN.js +21 -18
- package/lib/index.js +0 -2
- package/lib/server/actions/index.js +0 -11
- package/lib/server/collections/mapConfiguration.d.ts +1 -1
- package/lib/server/collections/mapConfiguration.js +1 -3
- package/lib/server/fields/circle.js +3 -22
- package/lib/server/fields/index.js +0 -8
- package/lib/server/fields/lineString.js +3 -22
- package/lib/server/fields/point.js +3 -23
- package/lib/server/fields/polygon.js +3 -21
- package/lib/server/helpers/index.js +0 -12
- package/lib/server/index.js +0 -2
- package/lib/server/plugin.js +0 -24
- package/lib/server/value-parsers/index.js +0 -21
- package/package.json +8 -5
- package/src/client/block/MapActionInitializers.tsx +97 -0
- package/src/client/block/MapBlock.tsx +308 -0
- package/src/client/block/MapBlockDesigner.tsx +161 -0
- package/src/client/block/MapBlockInitializer.tsx +76 -0
- package/src/client/block/MapBlockProvider.tsx +55 -0
- package/src/client/block/index.tsx +35 -0
- package/src/client/block/utils.ts +81 -0
- package/src/client/components/AMap.tsx +148 -71
- package/src/client/components/Configuration.tsx +2 -1
- package/src/client/components/Map.tsx +5 -2
- package/src/client/components/ReadPretty.tsx +6 -5
- package/src/client/fields/schema.ts +4 -7
- package/src/client/hooks/useMapConfiguration.ts +32 -9
- package/src/client/index.tsx +11 -7
- package/src/client/initialize.tsx +2 -2
- package/src/client/locale/index.ts +4 -3
- package/src/client/locale/pt-BR.ts +49 -0
- package/src/client/locale/zh-CN.ts +22 -19
- package/src/server/collections/mapConfiguration.ts +8 -8
|
@@ -6,20 +6,28 @@ import { useFieldSchema } from '@formily/react';
|
|
|
6
6
|
import { useCollection } from '@nocobase/client';
|
|
7
7
|
import { useMemoizedFn } from 'ahooks';
|
|
8
8
|
import { Alert, Button, Modal } from 'antd';
|
|
9
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
9
|
+
import React, { useEffect, useCallback, useRef, useState, useMemo, useImperativeHandle } from 'react';
|
|
10
10
|
import { useHistory } from 'react-router';
|
|
11
11
|
import { useMapConfiguration } from '../hooks';
|
|
12
12
|
import { useMapTranslation } from '../locale';
|
|
13
13
|
import Search from './Search';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
value
|
|
19
|
-
onChange
|
|
15
|
+
export type MapEditorType = 'point' | 'polygon' | 'lineString' | 'circle';
|
|
16
|
+
|
|
17
|
+
export interface AMapComponentProps {
|
|
18
|
+
value?: any;
|
|
19
|
+
onChange?: (value: number[]) => void;
|
|
20
20
|
disabled?: boolean;
|
|
21
21
|
mapType: string;
|
|
22
|
+
/**
|
|
23
|
+
* only ReadPretty
|
|
24
|
+
*/
|
|
25
|
+
readonly: string;
|
|
22
26
|
zoom: number;
|
|
27
|
+
type: MapEditorType;
|
|
28
|
+
style?: React.CSSProperties;
|
|
29
|
+
overlayCommonOptions?: AMap.PolylineOptions & AMap.PolygonOptions;
|
|
30
|
+
block?: boolean;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
const methodMapping = {
|
|
@@ -53,9 +61,30 @@ const methodMapping = {
|
|
|
53
61
|
},
|
|
54
62
|
};
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
export interface AMapForwardedRefProps {
|
|
65
|
+
setOverlay: (t: MapEditorType, v: any, o?: AMap.PolylineOptions & AMap.PolygonOptions & AMap.MarkerOptions) => any;
|
|
66
|
+
getOverlay: (t: MapEditorType, v: any, o?: AMap.PolylineOptions & AMap.PolygonOptions & AMap.MarkerOptions) => any;
|
|
67
|
+
createMouseTool: (type: MapEditorType) => void;
|
|
68
|
+
createEditor: (type: MapEditorType) => void;
|
|
69
|
+
executeMouseTool: (type: MapEditorType) => void;
|
|
70
|
+
|
|
71
|
+
aMap: any;
|
|
72
|
+
map: AMap.Map;
|
|
73
|
+
editor: () => {
|
|
74
|
+
getTarget: () => AMap.Polygon;
|
|
75
|
+
setTarget: (o: any) => void;
|
|
76
|
+
close: () => void;
|
|
77
|
+
on: (event: string, callback: (e: any) => void) => void;
|
|
78
|
+
};
|
|
79
|
+
mouseTool: () => {
|
|
80
|
+
close: (clear?: boolean) => void;
|
|
81
|
+
};
|
|
82
|
+
overlay: AMap.Polygon;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapComponentProps>((props, ref) => {
|
|
57
86
|
const { accessKey, securityJsCode } = useMapConfiguration(props.mapType) || {};
|
|
58
|
-
const { value, onChange, disabled, zoom = 13 } = props;
|
|
87
|
+
const { value, onChange, block = false, readonly, disabled = block, zoom = 13, overlayCommonOptions } = props;
|
|
59
88
|
const { t } = useMapTranslation();
|
|
60
89
|
const fieldSchema = useFieldSchema();
|
|
61
90
|
const aMap = useRef<any>();
|
|
@@ -64,9 +93,13 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
64
93
|
const [needUpdateFlag, forceUpdate] = useState([]);
|
|
65
94
|
const [errMessage, setErrMessage] = useState('');
|
|
66
95
|
const { getField } = useCollection();
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
96
|
+
const type = useMemo<MapEditorType>(() => {
|
|
97
|
+
if (props.type) return props.type;
|
|
98
|
+
const collectionField = getField(fieldSchema?.name);
|
|
99
|
+
return collectionField?.interface;
|
|
100
|
+
}, [props?.type, fieldSchema?.name]);
|
|
101
|
+
|
|
102
|
+
const overlay = useRef<AMap.Polygon>();
|
|
70
103
|
const editor = useRef(null);
|
|
71
104
|
const history = useHistory();
|
|
72
105
|
const id = useRef(`nocobase-map-${type}-${Date.now().toString(32)}`);
|
|
@@ -76,16 +109,17 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
76
109
|
strokeColor: '#4e9bff',
|
|
77
110
|
fillColor: '#4e9bff',
|
|
78
111
|
strokeOpacity: 1,
|
|
112
|
+
...overlayCommonOptions,
|
|
79
113
|
});
|
|
80
114
|
|
|
81
115
|
const toRemoveOverlay = useMemoizedFn(() => {
|
|
82
116
|
if (overlay.current) {
|
|
83
|
-
|
|
117
|
+
overlay.current.remove();
|
|
84
118
|
}
|
|
85
119
|
});
|
|
86
120
|
|
|
87
121
|
const setTarget = useMemoizedFn(() => {
|
|
88
|
-
if (!disabled && type !== 'point' && editor.current) {
|
|
122
|
+
if ((!disabled || block) && type !== 'point' && editor.current) {
|
|
89
123
|
editor.current.setTarget(overlay.current);
|
|
90
124
|
editor.current.open();
|
|
91
125
|
}
|
|
@@ -113,25 +147,38 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
113
147
|
overlay.current = target;
|
|
114
148
|
setTarget();
|
|
115
149
|
}
|
|
116
|
-
onChange(nextValue);
|
|
150
|
+
onChange?.(nextValue);
|
|
117
151
|
});
|
|
118
152
|
|
|
119
|
-
const createEditor = useMemoizedFn(() => {
|
|
120
|
-
const mapping = methodMapping[
|
|
153
|
+
const createEditor = useMemoizedFn((curType = type) => {
|
|
154
|
+
const mapping = methodMapping[curType];
|
|
121
155
|
if (mapping && 'editor' in mapping && !editor.current) {
|
|
122
|
-
editor.current = new aMap.current[mapping.editor](map.current
|
|
156
|
+
editor.current = new aMap.current[mapping.editor](map.current, null, {
|
|
157
|
+
createOptions: commonOptions,
|
|
158
|
+
editOptions: commonOptions,
|
|
159
|
+
controlPoint: {
|
|
160
|
+
...commonOptions,
|
|
161
|
+
strokeWeight: 3,
|
|
162
|
+
},
|
|
163
|
+
midControlPoint: {
|
|
164
|
+
...commonOptions,
|
|
165
|
+
strokeWeight: 2,
|
|
166
|
+
fillColor: '#fff',
|
|
167
|
+
},
|
|
168
|
+
});
|
|
123
169
|
editor.current.on('adjust', function ({ target }) {
|
|
124
170
|
onMapChange(target, true);
|
|
125
171
|
});
|
|
126
172
|
editor.current.on('move', function ({ target }) {
|
|
127
173
|
onMapChange(target, true);
|
|
128
174
|
});
|
|
175
|
+
return editor.current;
|
|
129
176
|
}
|
|
130
177
|
});
|
|
131
178
|
|
|
132
|
-
const executeMouseTool = useMemoizedFn(() => {
|
|
179
|
+
const executeMouseTool = useMemoizedFn((curType = type) => {
|
|
133
180
|
if (!mouseTool.current || editor.current?.getTarget()) return;
|
|
134
|
-
const mapping = methodMapping[
|
|
181
|
+
const mapping = methodMapping[curType];
|
|
135
182
|
if (!mapping) {
|
|
136
183
|
return;
|
|
137
184
|
}
|
|
@@ -140,15 +187,13 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
140
187
|
} as AMap.PolylineOptions);
|
|
141
188
|
});
|
|
142
189
|
|
|
143
|
-
const createMouseTool = useMemoizedFn(() => {
|
|
190
|
+
const createMouseTool = useMemoizedFn((curType: MapEditorType = type) => {
|
|
144
191
|
if (mouseTool.current) return;
|
|
145
|
-
|
|
146
192
|
mouseTool.current = new aMap.current.MouseTool(map.current);
|
|
147
193
|
mouseTool.current.on('draw', function ({ obj }) {
|
|
148
194
|
onMapChange(obj);
|
|
149
195
|
});
|
|
150
|
-
|
|
151
|
-
executeMouseTool();
|
|
196
|
+
executeMouseTool(curType);
|
|
152
197
|
});
|
|
153
198
|
|
|
154
199
|
const toCenter = (position, imm?: boolean) => {
|
|
@@ -164,7 +209,7 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
164
209
|
editor.current.setTarget();
|
|
165
210
|
editor.current.close();
|
|
166
211
|
}
|
|
167
|
-
onChange(null);
|
|
212
|
+
onChange?.(null);
|
|
168
213
|
};
|
|
169
214
|
Modal.confirm({
|
|
170
215
|
title: t('Clear the canvas'),
|
|
@@ -183,33 +228,47 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
183
228
|
}
|
|
184
229
|
};
|
|
185
230
|
|
|
231
|
+
const getOverlay = useCallback(
|
|
232
|
+
(t = type, v = value, o?: AMap.PolylineOptions & AMap.PolygonOptions) => {
|
|
233
|
+
const mapping = methodMapping[t];
|
|
234
|
+
if (!mapping) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const options = { ...commonOptions, ...o } as AMap.MarkerOptions;
|
|
238
|
+
if ('transformOptions' in mapping) {
|
|
239
|
+
Object.assign(options, mapping.transformOptions(v));
|
|
240
|
+
} else if ('propertyKey' in mapping) {
|
|
241
|
+
options[mapping.propertyKey] = v;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return new aMap.current[mapping.overlay](options);
|
|
245
|
+
},
|
|
246
|
+
[commonOptions],
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const setOverlay = (t = type, v = value, o?: AMap.PolylineOptions & AMap.PolygonOptions) => {
|
|
250
|
+
if (!aMap.current) return;
|
|
251
|
+
const nextOverlay = getOverlay(t, v, o);
|
|
252
|
+
nextOverlay.setMap(map.current);
|
|
253
|
+
return nextOverlay;
|
|
254
|
+
};
|
|
255
|
+
|
|
186
256
|
// 编辑时
|
|
187
257
|
useEffect(() => {
|
|
188
258
|
if (!aMap.current) return;
|
|
189
|
-
if (!value || overlay.current) {
|
|
259
|
+
if (!value || (!readonly && overlay.current)) {
|
|
190
260
|
return;
|
|
191
261
|
}
|
|
192
|
-
const mapping = methodMapping[type as keyof typeof methodMapping];
|
|
193
|
-
if (!mapping) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const options = { ...commonOptions };
|
|
197
|
-
if ('transformOptions' in mapping) {
|
|
198
|
-
Object.assign(options, mapping.transformOptions(value));
|
|
199
|
-
} else if ('propertyKey' in mapping) {
|
|
200
|
-
options[mapping.propertyKey] = value;
|
|
201
|
-
}
|
|
202
|
-
const nextOverlay = new aMap.current[mapping.overlay](options);
|
|
203
262
|
|
|
263
|
+
const nextOverlay = setOverlay();
|
|
204
264
|
// 聚焦在编辑的位置
|
|
205
265
|
map.current.setFitView([nextOverlay]);
|
|
206
|
-
|
|
207
|
-
nextOverlay.setMap(map.current);
|
|
208
266
|
overlay.current = nextOverlay;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
267
|
+
if (!disabled) {
|
|
268
|
+
createEditor();
|
|
269
|
+
setTarget();
|
|
270
|
+
}
|
|
271
|
+
}, [value, needUpdateFlag, type, commonOptions, disabled, readonly]);
|
|
213
272
|
|
|
214
273
|
// 当在编辑时,关闭 mouseTool
|
|
215
274
|
useEffect(() => {
|
|
@@ -231,6 +290,7 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
231
290
|
createEditor();
|
|
232
291
|
}, [disabled, needUpdateFlag, type]);
|
|
233
292
|
|
|
293
|
+
// 当值变更时,toggle mouseTool
|
|
234
294
|
useEffect(() => {
|
|
235
295
|
if (!mouseTool.current || !editor.current) return;
|
|
236
296
|
const target = editor.current.getTarget();
|
|
@@ -256,7 +316,7 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
256
316
|
plugins: ['AMap.MouseTool', 'AMap.PolygonEditor', 'AMap.PolylineEditor', 'AMap.CircleEditor'],
|
|
257
317
|
})
|
|
258
318
|
.then((amap) => {
|
|
259
|
-
|
|
319
|
+
requestIdleCallback(() => {
|
|
260
320
|
map.current = new amap.Map(id.current, {
|
|
261
321
|
resizeEnable: true,
|
|
262
322
|
zoom,
|
|
@@ -264,7 +324,7 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
264
324
|
aMap.current = amap;
|
|
265
325
|
setErrMessage('');
|
|
266
326
|
forceUpdate([]);
|
|
267
|
-
}
|
|
327
|
+
});
|
|
268
328
|
})
|
|
269
329
|
.catch((err) => {
|
|
270
330
|
if (err.includes('多个不一致的 key')) {
|
|
@@ -283,6 +343,19 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
283
343
|
};
|
|
284
344
|
}, [accessKey, type, securityJsCode]);
|
|
285
345
|
|
|
346
|
+
useImperativeHandle(ref, () => ({
|
|
347
|
+
setOverlay,
|
|
348
|
+
getOverlay,
|
|
349
|
+
createMouseTool,
|
|
350
|
+
createEditor,
|
|
351
|
+
executeMouseTool,
|
|
352
|
+
aMap: aMap.current,
|
|
353
|
+
map: map.current,
|
|
354
|
+
overlay: overlay.current,
|
|
355
|
+
mouseTool: () => mouseTool.current,
|
|
356
|
+
editor: () => editor.current,
|
|
357
|
+
}));
|
|
358
|
+
|
|
286
359
|
if (!accessKey || errMessage) {
|
|
287
360
|
return (
|
|
288
361
|
<Alert
|
|
@@ -301,44 +374,48 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
301
374
|
<div
|
|
302
375
|
className={css`
|
|
303
376
|
position: relative;
|
|
377
|
+
height: 500px;
|
|
304
378
|
`}
|
|
305
379
|
id={id.current}
|
|
306
|
-
style={
|
|
307
|
-
height: '500px',
|
|
308
|
-
}}
|
|
380
|
+
style={props?.style}
|
|
309
381
|
>
|
|
310
|
-
{/* bottom: 20px; right: 50%; transform: translateX(50%); z-index: 2; */}
|
|
311
|
-
<div
|
|
312
|
-
className={css`
|
|
313
|
-
position: absolute;
|
|
314
|
-
bottom: 80px;
|
|
315
|
-
right: 20px;
|
|
316
|
-
z-index: 10;
|
|
317
|
-
`}
|
|
318
|
-
>
|
|
319
|
-
<Button
|
|
320
|
-
onClick={onFocusOverlay}
|
|
321
|
-
disabled={!overlay.current}
|
|
322
|
-
type="primary"
|
|
323
|
-
shape="round"
|
|
324
|
-
size="large"
|
|
325
|
-
icon={<SyncOutlined />}
|
|
326
|
-
></Button>
|
|
327
|
-
</div>
|
|
328
382
|
{!disabled ? (
|
|
329
383
|
<>
|
|
330
384
|
<Search toCenter={toCenter} aMap={aMap.current} />
|
|
331
385
|
<div
|
|
332
386
|
className={css`
|
|
333
387
|
position: absolute;
|
|
334
|
-
bottom:
|
|
335
|
-
|
|
336
|
-
z-index:
|
|
337
|
-
pointer-events: none;
|
|
388
|
+
bottom: 80px;
|
|
389
|
+
right: 20px;
|
|
390
|
+
z-index: 10;
|
|
338
391
|
`}
|
|
339
392
|
>
|
|
340
|
-
<
|
|
393
|
+
<Button
|
|
394
|
+
onClick={onFocusOverlay}
|
|
395
|
+
disabled={!overlay.current}
|
|
396
|
+
type="primary"
|
|
397
|
+
shape="round"
|
|
398
|
+
size="large"
|
|
399
|
+
icon={<SyncOutlined />}
|
|
400
|
+
></Button>
|
|
341
401
|
</div>
|
|
402
|
+
{type !== 'point' ? (
|
|
403
|
+
<div
|
|
404
|
+
className={css`
|
|
405
|
+
position: absolute;
|
|
406
|
+
bottom: 20px;
|
|
407
|
+
left: 10px;
|
|
408
|
+
z-index: 2;
|
|
409
|
+
pointer-events: none;
|
|
410
|
+
`}
|
|
411
|
+
>
|
|
412
|
+
<Alert
|
|
413
|
+
message={t('Click to select the starting point and double-click to end the drawing')}
|
|
414
|
+
type="info"
|
|
415
|
+
/>
|
|
416
|
+
</div>
|
|
417
|
+
) : null}
|
|
418
|
+
|
|
342
419
|
<div
|
|
343
420
|
className={css`
|
|
344
421
|
position: absolute;
|
|
@@ -363,6 +440,6 @@ const AMapComponent: React.FC<AMapComponentProps> = (props) => {
|
|
|
363
440
|
) : null}
|
|
364
441
|
</div>
|
|
365
442
|
);
|
|
366
|
-
};
|
|
443
|
+
});
|
|
367
444
|
|
|
368
445
|
export default AMapComponent;
|
|
@@ -3,7 +3,7 @@ import { useBoolean } from 'ahooks';
|
|
|
3
3
|
import { Button, Card, Form, Input, message, Tabs } from 'antd';
|
|
4
4
|
import React, { useEffect, useMemo } from 'react';
|
|
5
5
|
import { MapTypes } from '../constants';
|
|
6
|
-
import { MapConfigurationResourceKey, useMapConfiguration } from '../hooks';
|
|
6
|
+
import { MapConfigurationResourceKey, getSSKey, useMapConfiguration } from '../hooks';
|
|
7
7
|
import { useMapTranslation } from '../locale';
|
|
8
8
|
|
|
9
9
|
const AMapConfiguration = ({ type }) => {
|
|
@@ -30,6 +30,7 @@ const AMapConfiguration = ({ type }) => {
|
|
|
30
30
|
type,
|
|
31
31
|
})
|
|
32
32
|
.then((res) => {
|
|
33
|
+
sessionStorage.removeItem(getSSKey(type));
|
|
33
34
|
message.success(t('Saved successfully'));
|
|
34
35
|
})
|
|
35
36
|
.catch((err) => {
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { connect, mapReadPretty } from '@formily/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import AMapComponent from './AMap';
|
|
3
|
+
import AMapComponent, { AMapComponentProps } from './AMap';
|
|
4
4
|
import ReadPretty from './ReadPretty';
|
|
5
5
|
import { css } from '@emotion/css';
|
|
6
6
|
import Designer from './Designer';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface MapProps extends AMapComponentProps {}
|
|
9
|
+
|
|
10
|
+
const InternalMap = connect((props: MapProps) => {
|
|
9
11
|
return (
|
|
10
12
|
<div
|
|
11
13
|
className={css`
|
|
14
|
+
height: 100%;
|
|
12
15
|
border: 1px solid transparent;
|
|
13
16
|
.ant-formily-item-error & {
|
|
14
17
|
border: 1px solid #ff4d4f;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { useField, useFieldSchema } from '@formily/react';
|
|
1
|
+
import { useField, useFieldSchema, useForm } from '@formily/react';
|
|
2
2
|
import { EllipsisWithTooltip, useCollection } from '@nocobase/client';
|
|
3
3
|
import React, { useEffect } from 'react';
|
|
4
4
|
import AMapComponent from './AMap';
|
|
5
5
|
|
|
6
6
|
const ReadPretty = (props) => {
|
|
7
|
-
const { value
|
|
7
|
+
const { value } = props;
|
|
8
8
|
const fieldSchema = useFieldSchema();
|
|
9
9
|
const { getField } = useCollection();
|
|
10
10
|
const collectionField = getField(fieldSchema.name);
|
|
11
11
|
const mapType = props.mapType || collectionField?.uiSchema['x-component-props']?.mapType;
|
|
12
12
|
const field = useField();
|
|
13
|
-
|
|
13
|
+
const form = useForm();
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
if (!field.title && collectionField?.uiSchema?.title) {
|
|
16
16
|
field.title = collectionField.uiSchema.title;
|
|
17
17
|
}
|
|
18
18
|
}, collectionField?.title);
|
|
19
19
|
|
|
20
|
-
if (!
|
|
20
|
+
if (!form.readPretty) {
|
|
21
21
|
return (
|
|
22
22
|
<div>
|
|
23
23
|
<EllipsisWithTooltip ellipsis={true}>
|
|
@@ -25,8 +25,9 @@ const ReadPretty = (props) => {
|
|
|
25
25
|
</EllipsisWithTooltip>
|
|
26
26
|
</div>
|
|
27
27
|
);
|
|
28
|
+
}
|
|
28
29
|
|
|
29
|
-
return mapType === 'amap' ? <AMapComponent mapType={mapType} {...props}></AMapComponent> : null;
|
|
30
|
+
return mapType === 'amap' ? <AMapComponent readonly mapType={mapType} {...props}></AMapComponent> : null;
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
export default ReadPretty;
|
|
@@ -41,17 +41,14 @@ export const commonSchema = {
|
|
|
41
41
|
},
|
|
42
42
|
'x-disabled': '{{ isOverride || !createOnly }}',
|
|
43
43
|
default: 'amap',
|
|
44
|
-
enum: MapTypes
|
|
45
|
-
}
|
|
44
|
+
enum: MapTypes,
|
|
45
|
+
},
|
|
46
46
|
},
|
|
47
|
-
schemaInitialize(schema: ISchema, {
|
|
47
|
+
schemaInitialize(schema: ISchema, { block }) {
|
|
48
48
|
if (block === 'Form') {
|
|
49
49
|
Object.assign(schema, {
|
|
50
|
-
'x-component-props': {
|
|
51
|
-
readOnly: readPretty ? true : false
|
|
52
|
-
},
|
|
53
50
|
'x-designer': 'Map.Designer',
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
53
|
},
|
|
57
|
-
}
|
|
54
|
+
};
|
|
@@ -1,15 +1,38 @@
|
|
|
1
|
-
import { useRequest } from
|
|
1
|
+
import { useRequest } from '@nocobase/client';
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
|
|
3
4
|
export const MapConfigurationResourceKey = 'map-configuration';
|
|
5
|
+
export const getSSKey = (type) => {
|
|
6
|
+
return `NOCOBASE_PLUGIN_MAP_CONFIGURATION_${type}`;
|
|
7
|
+
};
|
|
4
8
|
|
|
5
9
|
export const useMapConfiguration = (type: string) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
}
|
|
10
|
+
// cache
|
|
11
|
+
const config = useMemo(() => {
|
|
12
|
+
const d = sessionStorage.getItem(getSSKey(type));
|
|
13
|
+
if (d) {
|
|
14
|
+
return JSON.parse(d);
|
|
15
|
+
}
|
|
16
|
+
return d;
|
|
17
|
+
}, [type]);
|
|
14
18
|
|
|
19
|
+
if (config) return config;
|
|
15
20
|
|
|
21
|
+
return useRequest(
|
|
22
|
+
{
|
|
23
|
+
resource: MapConfigurationResourceKey,
|
|
24
|
+
action: 'get',
|
|
25
|
+
params: {
|
|
26
|
+
type,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
onSuccess(data) {
|
|
31
|
+
sessionStorage.setItem(getSSKey(type), JSON.stringify(data?.data));
|
|
32
|
+
},
|
|
33
|
+
refreshOnWindowFocus: false,
|
|
34
|
+
refreshDeps: [],
|
|
35
|
+
manual: config ? true : false,
|
|
36
|
+
},
|
|
37
|
+
).data?.data;
|
|
38
|
+
};
|
package/src/client/index.tsx
CHANGED
|
@@ -2,21 +2,23 @@ import {
|
|
|
2
2
|
CollectionManagerContext,
|
|
3
3
|
CurrentAppInfoProvider,
|
|
4
4
|
SchemaComponentOptions,
|
|
5
|
-
SettingsCenterProvider
|
|
5
|
+
SettingsCenterProvider,
|
|
6
6
|
} from '@nocobase/client';
|
|
7
7
|
import React, { useContext } from 'react';
|
|
8
|
+
import { MapBlockOptions } from './block';
|
|
8
9
|
import Configuration from './components/Configuration';
|
|
9
10
|
import Map from './components/Map';
|
|
10
11
|
import { interfaces } from './fields';
|
|
11
|
-
import {
|
|
12
|
+
import { MapInitializer } from './initialize';
|
|
12
13
|
import { useMapTranslation } from './locale';
|
|
14
|
+
import './locale';
|
|
13
15
|
|
|
14
16
|
export default React.memo((props) => {
|
|
15
17
|
const ctx = useContext(CollectionManagerContext);
|
|
16
18
|
const { t } = useMapTranslation();
|
|
17
19
|
return (
|
|
18
20
|
<CurrentAppInfoProvider>
|
|
19
|
-
<
|
|
21
|
+
<MapInitializer>
|
|
20
22
|
<SettingsCenterProvider
|
|
21
23
|
settings={{
|
|
22
24
|
map: {
|
|
@@ -32,12 +34,14 @@ export default React.memo((props) => {
|
|
|
32
34
|
}}
|
|
33
35
|
>
|
|
34
36
|
<SchemaComponentOptions components={{ Map }}>
|
|
35
|
-
<
|
|
36
|
-
{
|
|
37
|
-
|
|
37
|
+
<MapBlockOptions>
|
|
38
|
+
<CollectionManagerContext.Provider value={{ ...ctx, interfaces: { ...ctx.interfaces, ...interfaces } }}>
|
|
39
|
+
{props.children}
|
|
40
|
+
</CollectionManagerContext.Provider>
|
|
41
|
+
</MapBlockOptions>
|
|
38
42
|
</SchemaComponentOptions>
|
|
39
43
|
</SettingsCenterProvider>
|
|
40
|
-
</
|
|
44
|
+
</MapInitializer>
|
|
41
45
|
</CurrentAppInfoProvider>
|
|
42
46
|
);
|
|
43
47
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { registerField, registerGroup, useCurrentAppInfo } from '@nocobase/client';
|
|
2
2
|
import React, { useEffect } from 'react';
|
|
3
3
|
import { fields } from './fields';
|
|
4
|
-
import './locale';
|
|
5
4
|
import { generateNTemplate } from './locale';
|
|
5
|
+
import './locale';
|
|
6
6
|
|
|
7
7
|
export const useRegisterInterface = () => {
|
|
8
8
|
const { data } = useCurrentAppInfo() || {};
|
|
@@ -26,7 +26,7 @@ export const useRegisterInterface = () => {
|
|
|
26
26
|
}, [data]);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export const
|
|
29
|
+
export const MapInitializer: React.FC = (props) => {
|
|
30
30
|
useRegisterInterface();
|
|
31
31
|
return <React.Fragment>{props.children}</React.Fragment>;
|
|
32
32
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { i18n } from '@nocobase/client';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
|
-
|
|
3
|
+
import enUS from './en-US';
|
|
4
|
+
import zhCN from './zh-CN';
|
|
4
5
|
|
|
5
6
|
export const NAMESPACE = 'map';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
i18n.addResources('zh-CN', NAMESPACE, zhCN);
|
|
9
|
+
i18n.addResources('en-US', NAMESPACE, enUS);
|
|
9
10
|
|
|
10
11
|
export function lang(key: string) {
|
|
11
12
|
return i18n.t(key, { ns: NAMESPACE });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const locale = {
|
|
2
|
+
'Map-based geometry': 'Geometria baseada em mapa',
|
|
3
|
+
'Map type': 'Tipo de mapa',
|
|
4
|
+
Point: 'Ponto',
|
|
5
|
+
Line: 'Linha',
|
|
6
|
+
Circle: 'Círculo',
|
|
7
|
+
Polygon: 'Polígono',
|
|
8
|
+
'Access key': 'Chave de acesso',
|
|
9
|
+
'securityJsCode or serviceHost': 'securityJsCode ou serviceHost',
|
|
10
|
+
AMap: 'AMap',
|
|
11
|
+
'Google Maps': 'Google Maps',
|
|
12
|
+
Clear: 'Limpar',
|
|
13
|
+
'Click to select the starting point and double-click to end the drawing': 'Clique para selecionar o ponto de partida e dê um duplo clique para terminar a criação',
|
|
14
|
+
'Clear the canvas': 'Limpar a tela',
|
|
15
|
+
'Are you sure to clear the canvas?': 'Tem certeza de que deseja limpar a tela?',
|
|
16
|
+
Confirm: 'Confirmar',
|
|
17
|
+
Cancel: 'Cancelar',
|
|
18
|
+
'Enter keywords to search': 'Digite palavras-chave para buscar',
|
|
19
|
+
'The AccessKey is incorrect, please check it': 'A chave de acesso está incorreta, por favor verifique',
|
|
20
|
+
'Please configure the AMap securityCode or serviceHost correctly': 'Por favor, configure o securityCode ou serviceHost do AMap corretamente',
|
|
21
|
+
'Map Manager': 'Gerenciador de Mapa',
|
|
22
|
+
Configuration: 'Configuração',
|
|
23
|
+
'Saved successfully': 'Salvo com sucesso',
|
|
24
|
+
'Saved failed': 'Falha ao salvar',
|
|
25
|
+
Edit: 'Editar',
|
|
26
|
+
Save: 'Salvar',
|
|
27
|
+
'Please configure the AccessKey and SecurityJsCode first': 'Por favor, configure a AccessKey e o SecurityJsCode primeiro',
|
|
28
|
+
'Go to the configuration page': 'Ir para a página de configuração',
|
|
29
|
+
Zoom: 'Zoom',
|
|
30
|
+
'Set default zoom level': 'Definir nível de zoom padrão',
|
|
31
|
+
'The default zoom level of the map': 'O nível de zoom padrão do mapa',
|
|
32
|
+
// Designer
|
|
33
|
+
'Edit field title': 'Editar título do campo',
|
|
34
|
+
'Field title': 'Título do campo',
|
|
35
|
+
'Edit tooltip': 'Editar dica de ferramenta',
|
|
36
|
+
'Delete field': 'Excluir campo',
|
|
37
|
+
Required: 'Obrigatório',
|
|
38
|
+
Pattern: 'Padrão',
|
|
39
|
+
"Operator": "Operador",
|
|
40
|
+
Editable: 'Editável',
|
|
41
|
+
Readonly: 'Somente leitura',
|
|
42
|
+
'Easy-reading': 'Apenas leitura (Modo de Leitura)',
|
|
43
|
+
'Edit description': 'Editar descrição',
|
|
44
|
+
'Map field': 'Campo de mapa',
|
|
45
|
+
'Marker field': 'Campo de marcador',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default locale;
|
|
49
|
+
|