@nocobase/plugin-map 0.8.1-alpha.3
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/LICENSE +201 -0
- package/client.d.ts +4 -0
- package/client.js +30 -0
- package/lib/client/components/AMap.d.ts +13 -0
- package/lib/client/components/AMap.js +502 -0
- package/lib/client/components/Configuration.d.ts +2 -0
- package/lib/client/components/Configuration.js +167 -0
- package/lib/client/components/Designer.d.ts +2 -0
- package/lib/client/components/Designer.js +308 -0
- package/lib/client/components/Map.d.ts +6 -0
- package/lib/client/components/Map.js +65 -0
- package/lib/client/components/ReadPretty.d.ts +2 -0
- package/lib/client/components/ReadPretty.js +81 -0
- package/lib/client/components/Search.d.ts +6 -0
- package/lib/client/components/Search.js +155 -0
- package/lib/client/constants.d.ts +4 -0
- package/lib/client/constants.js +17 -0
- package/lib/client/fields/circle.d.ts +2 -0
- package/lib/client/fields/circle.js +37 -0
- package/lib/client/fields/index.d.ts +2 -0
- package/lib/client/fields/index.js +22 -0
- package/lib/client/fields/lineString.d.ts +2 -0
- package/lib/client/fields/lineString.js +37 -0
- package/lib/client/fields/point.d.ts +2 -0
- package/lib/client/fields/point.js +37 -0
- package/lib/client/fields/polygon.d.ts +2 -0
- package/lib/client/fields/polygon.js +37 -0
- package/lib/client/fields/schema.d.ts +99 -0
- package/lib/client/fields/schema.js +79 -0
- package/lib/client/hooks/index.d.ts +1 -0
- package/lib/client/hooks/index.js +18 -0
- package/lib/client/hooks/useMapConfiguration.d.ts +2 -0
- package/lib/client/hooks/useMapConfiguration.js +33 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.js +80 -0
- package/lib/client/initialize.d.ts +4 -0
- package/lib/client/initialize.js +67 -0
- package/lib/client/locales/en-US.d.ts +2 -0
- package/lib/client/locales/en-US.js +9 -0
- package/lib/client/locales/index.d.ts +4 -0
- package/lib/client/locales/index.js +56 -0
- package/lib/client/locales/zh-CN.d.ts +43 -0
- package/lib/client/locales/zh-CN.js +51 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +15 -0
- package/lib/server/actions/index.d.ts +3 -0
- package/lib/server/actions/index.js +66 -0
- package/lib/server/collections/mapConfiguration.d.ts +3 -0
- package/lib/server/collections/mapConfiguration.js +30 -0
- package/lib/server/constants.d.ts +1 -0
- package/lib/server/constants.js +8 -0
- package/lib/server/fields/circle.d.ts +13 -0
- package/lib/server/fields/circle.js +84 -0
- package/lib/server/fields/index.d.ts +4 -0
- package/lib/server/fields/index.js +57 -0
- package/lib/server/fields/lineString.d.ts +13 -0
- package/lib/server/fields/lineString.js +91 -0
- package/lib/server/fields/point.d.ts +13 -0
- package/lib/server/fields/point.js +95 -0
- package/lib/server/fields/polygon.d.ts +13 -0
- package/lib/server/fields/polygon.js +89 -0
- package/lib/server/helpers/index.d.ts +6 -0
- package/lib/server/helpers/index.js +44 -0
- package/lib/server/index.d.ts +1 -0
- package/lib/server/index.js +15 -0
- package/lib/server/plugin.d.ts +11 -0
- package/lib/server/plugin.js +88 -0
- package/package.json +19 -0
- package/server.d.ts +4 -0
- package/server.js +30 -0
- package/src/client/components/AMap.tsx +369 -0
- package/src/client/components/Configuration.tsx +91 -0
- package/src/client/components/Designer.tsx +260 -0
- package/src/client/components/Map.tsx +29 -0
- package/src/client/components/ReadPretty.tsx +34 -0
- package/src/client/components/Search.tsx +93 -0
- package/src/client/constants.ts +6 -0
- package/src/client/fields/circle.ts +23 -0
- package/src/client/fields/index.ts +16 -0
- package/src/client/fields/lineString.ts +23 -0
- package/src/client/fields/point.ts +24 -0
- package/src/client/fields/polygon.ts +23 -0
- package/src/client/fields/schema.ts +57 -0
- package/src/client/hooks/index.ts +1 -0
- package/src/client/hooks/useMapConfiguration.ts +15 -0
- package/src/client/index.tsx +43 -0
- package/src/client/initialize.tsx +33 -0
- package/src/client/locales/en-US.ts +5 -0
- package/src/client/locales/index.ts +22 -0
- package/src/client/locales/zh-CN.ts +45 -0
- package/src/index.ts +1 -0
- package/src/server/__tests__/fields.test.ts +168 -0
- package/src/server/actions/index.ts +46 -0
- package/src/server/collections/mapConfiguration.ts +27 -0
- package/src/server/constants.ts +1 -0
- package/src/server/fields/.gitkeep +0 -0
- package/src/server/fields/circle.ts +50 -0
- package/src/server/fields/index.ts +4 -0
- package/src/server/fields/lineString.ts +56 -0
- package/src/server/fields/point.ts +59 -0
- package/src/server/fields/polygon.ts +56 -0
- package/src/server/helpers/index.ts +25 -0
- package/src/server/index.ts +1 -0
- package/src/server/plugin.ts +46 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useAPIClient, useCompile, useRequest } from '@nocobase/client';
|
|
2
|
+
import { useBoolean } from 'ahooks';
|
|
3
|
+
import { Form, Input, Tabs, Button, Card, message } from 'antd';
|
|
4
|
+
import React, { useMemo, useEffect } from 'react';
|
|
5
|
+
import { MapTypes } from '../constants';
|
|
6
|
+
import { MapConfigurationResourceKey, useMapConfiguration } from '../hooks';
|
|
7
|
+
import { useMapTranslation } from '../locales';
|
|
8
|
+
|
|
9
|
+
const AMapConfiguration = ({ type }) => {
|
|
10
|
+
const { t } = useMapTranslation();
|
|
11
|
+
const [isDisabled, disableAction] = useBoolean(false);
|
|
12
|
+
const apiClient = useAPIClient();
|
|
13
|
+
const [form] = Form.useForm();
|
|
14
|
+
const data = useMapConfiguration(type);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (data) {
|
|
17
|
+
form.setFieldsValue(data);
|
|
18
|
+
disableAction.toggle();
|
|
19
|
+
}
|
|
20
|
+
}, [data]);
|
|
21
|
+
|
|
22
|
+
const resource = useMemo(() => {
|
|
23
|
+
return apiClient.resource(MapConfigurationResourceKey);
|
|
24
|
+
}, [apiClient]);
|
|
25
|
+
|
|
26
|
+
const onSubmit = (values) => {
|
|
27
|
+
resource
|
|
28
|
+
.set({
|
|
29
|
+
...values,
|
|
30
|
+
type,
|
|
31
|
+
})
|
|
32
|
+
.then((res) => {
|
|
33
|
+
message.success(t('Saved successfully'));
|
|
34
|
+
})
|
|
35
|
+
.catch((err) => {
|
|
36
|
+
message.success(t('Saved failed'));
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return (
|
|
40
|
+
<Form form={form} layout="vertical" onFinish={onSubmit}>
|
|
41
|
+
<Form.Item required name="accessKey" label={t('Access key')}>
|
|
42
|
+
<Input disabled={isDisabled} />
|
|
43
|
+
</Form.Item>
|
|
44
|
+
<Form.Item required name="securityJsCode" label={t('securityJsCode or serviceHost')}>
|
|
45
|
+
<Input disabled={isDisabled} />
|
|
46
|
+
</Form.Item>
|
|
47
|
+
{isDisabled ? (
|
|
48
|
+
<Button onClick={disableAction.toggle} type="ghost">
|
|
49
|
+
{t('Edit')}
|
|
50
|
+
</Button>
|
|
51
|
+
) : (
|
|
52
|
+
<Form.Item>
|
|
53
|
+
<Button type="primary" htmlType="submit">
|
|
54
|
+
{t('Save')}
|
|
55
|
+
</Button>
|
|
56
|
+
</Form.Item>
|
|
57
|
+
)}
|
|
58
|
+
</Form>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const components = {
|
|
63
|
+
amap: AMapConfiguration,
|
|
64
|
+
google: () => <div>Coming soon</div>,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const tabList = MapTypes.map((item) => {
|
|
68
|
+
return {
|
|
69
|
+
...item,
|
|
70
|
+
component: components[item.value],
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const Configuration = () => {
|
|
75
|
+
const compile = useCompile();
|
|
76
|
+
return (
|
|
77
|
+
<Card bordered>
|
|
78
|
+
<Tabs type="card">
|
|
79
|
+
{tabList.map((tab) => {
|
|
80
|
+
return (
|
|
81
|
+
<Tabs.TabPane key={tab.value} tab={compile(tab.label)}>
|
|
82
|
+
<tab.component type={tab.value} />
|
|
83
|
+
</Tabs.TabPane>
|
|
84
|
+
);
|
|
85
|
+
})}
|
|
86
|
+
</Tabs>
|
|
87
|
+
</Card>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default Configuration;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Field } from '@formily/core';
|
|
2
|
+
import { ISchema, useField, useFieldSchema } from '@formily/react';
|
|
3
|
+
import {
|
|
4
|
+
GeneralSchemaDesigner,
|
|
5
|
+
SchemaSettings,
|
|
6
|
+
useCollection,
|
|
7
|
+
useCollectionManager,
|
|
8
|
+
useDesignable,
|
|
9
|
+
useFormBlockContext,
|
|
10
|
+
} from '@nocobase/client';
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { useMapTranslation } from '../locales';
|
|
14
|
+
|
|
15
|
+
const Designer = () => {
|
|
16
|
+
const { getCollectionJoinField } = useCollectionManager();
|
|
17
|
+
const { getField } = useCollection();
|
|
18
|
+
const { form } = useFormBlockContext();
|
|
19
|
+
const field = useField<Field>();
|
|
20
|
+
const fieldSchema = useFieldSchema();
|
|
21
|
+
const { t } = useMapTranslation();
|
|
22
|
+
const { dn, refresh } = useDesignable();
|
|
23
|
+
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
|
24
|
+
const originalTitle = collectionField?.uiSchema?.title;
|
|
25
|
+
const initialValue = {
|
|
26
|
+
title: field.title === originalTitle ? undefined : field.title,
|
|
27
|
+
};
|
|
28
|
+
if (!field.readPretty) {
|
|
29
|
+
initialValue['required'] = field.required;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let readOnlyMode = 'editable';
|
|
33
|
+
if (fieldSchema['x-disabled'] === true) {
|
|
34
|
+
readOnlyMode = 'readonly';
|
|
35
|
+
}
|
|
36
|
+
if (fieldSchema['x-read-pretty'] === true) {
|
|
37
|
+
readOnlyMode = 'read-pretty';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<GeneralSchemaDesigner>
|
|
42
|
+
<SchemaSettings.ModalItem
|
|
43
|
+
key="edit-field-title"
|
|
44
|
+
title={t('Edit field title')}
|
|
45
|
+
schema={
|
|
46
|
+
{
|
|
47
|
+
type: 'object',
|
|
48
|
+
title: t('Edit field title'),
|
|
49
|
+
properties: {
|
|
50
|
+
title: {
|
|
51
|
+
title: t('Field title'),
|
|
52
|
+
default: field?.title,
|
|
53
|
+
description: `${t('Original field title: ')}${collectionField?.uiSchema?.title}`,
|
|
54
|
+
'x-decorator': 'FormItem',
|
|
55
|
+
'x-component': 'Input',
|
|
56
|
+
'x-component-props': {},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
} as ISchema
|
|
60
|
+
}
|
|
61
|
+
onSubmit={({ title }) => {
|
|
62
|
+
if (title) {
|
|
63
|
+
field.title = title;
|
|
64
|
+
fieldSchema.title = title;
|
|
65
|
+
dn.emit('patch', {
|
|
66
|
+
schema: {
|
|
67
|
+
'x-uid': fieldSchema['x-uid'],
|
|
68
|
+
title: fieldSchema.title,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
dn.refresh();
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
{!field.readPretty && (
|
|
76
|
+
<SchemaSettings.ModalItem
|
|
77
|
+
key="edit-description"
|
|
78
|
+
title={t('Edit description')}
|
|
79
|
+
schema={
|
|
80
|
+
{
|
|
81
|
+
type: 'object',
|
|
82
|
+
title: t('Edit description'),
|
|
83
|
+
properties: {
|
|
84
|
+
description: {
|
|
85
|
+
// title: t('Description'),
|
|
86
|
+
default: field?.description,
|
|
87
|
+
'x-decorator': 'FormItem',
|
|
88
|
+
'x-component': 'Input.TextArea',
|
|
89
|
+
'x-component-props': {},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
} as ISchema
|
|
93
|
+
}
|
|
94
|
+
onSubmit={({ description }) => {
|
|
95
|
+
field.description = description;
|
|
96
|
+
fieldSchema.description = description;
|
|
97
|
+
dn.emit('patch', {
|
|
98
|
+
schema: {
|
|
99
|
+
'x-uid': fieldSchema['x-uid'],
|
|
100
|
+
description: fieldSchema.description,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
dn.refresh();
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
{field.readPretty && (
|
|
108
|
+
<SchemaSettings.ModalItem
|
|
109
|
+
key="edit-tooltip"
|
|
110
|
+
title={t('Edit tooltip')}
|
|
111
|
+
schema={
|
|
112
|
+
{
|
|
113
|
+
type: 'object',
|
|
114
|
+
title: t('Edit description'),
|
|
115
|
+
properties: {
|
|
116
|
+
tooltip: {
|
|
117
|
+
default: fieldSchema?.['x-decorator-props']?.tooltip,
|
|
118
|
+
'x-decorator': 'FormItem',
|
|
119
|
+
'x-component': 'Input.TextArea',
|
|
120
|
+
'x-component-props': {},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
} as ISchema
|
|
124
|
+
}
|
|
125
|
+
onSubmit={({ tooltip }) => {
|
|
126
|
+
field.decoratorProps.tooltip = tooltip;
|
|
127
|
+
fieldSchema['x-decorator-props'] = fieldSchema['x-decorator-props'] || {};
|
|
128
|
+
fieldSchema['x-decorator-props']['tooltip'] = tooltip;
|
|
129
|
+
dn.emit('patch', {
|
|
130
|
+
schema: {
|
|
131
|
+
'x-uid': fieldSchema['x-uid'],
|
|
132
|
+
'x-decorator-props': fieldSchema['x-decorator-props'],
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
dn.refresh();
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
{!field.readPretty && (
|
|
140
|
+
<SchemaSettings.SwitchItem
|
|
141
|
+
key="required"
|
|
142
|
+
title={t('Required')}
|
|
143
|
+
checked={fieldSchema.required as boolean}
|
|
144
|
+
onChange={(required) => {
|
|
145
|
+
const schema = {
|
|
146
|
+
['x-uid']: fieldSchema['x-uid'],
|
|
147
|
+
};
|
|
148
|
+
field.required = required;
|
|
149
|
+
fieldSchema['required'] = required;
|
|
150
|
+
schema['required'] = required;
|
|
151
|
+
dn.emit('patch', {
|
|
152
|
+
schema,
|
|
153
|
+
});
|
|
154
|
+
refresh();
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
)}
|
|
158
|
+
{form && !form?.readPretty && fieldSchema?.['x-component-props']?.['pattern-disable'] != true && (
|
|
159
|
+
<SchemaSettings.SelectItem
|
|
160
|
+
key="pattern"
|
|
161
|
+
title={t('Pattern')}
|
|
162
|
+
options={[
|
|
163
|
+
{ label: t('Editable'), value: 'editable' },
|
|
164
|
+
{ label: t('Readonly'), value: 'readonly' },
|
|
165
|
+
{ label: t('Easy-reading'), value: 'read-pretty' },
|
|
166
|
+
]}
|
|
167
|
+
value={readOnlyMode}
|
|
168
|
+
onChange={(v) => {
|
|
169
|
+
const schema: ISchema = {
|
|
170
|
+
['x-uid']: fieldSchema['x-uid'],
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
switch (v) {
|
|
174
|
+
case 'readonly': {
|
|
175
|
+
fieldSchema['x-read-pretty'] = false;
|
|
176
|
+
fieldSchema['x-disabled'] = true;
|
|
177
|
+
schema['x-read-pretty'] = false;
|
|
178
|
+
schema['x-disabled'] = true;
|
|
179
|
+
field.readPretty = false;
|
|
180
|
+
field.disabled = true;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case 'read-pretty': {
|
|
184
|
+
fieldSchema['x-read-pretty'] = true;
|
|
185
|
+
fieldSchema['x-disabled'] = false;
|
|
186
|
+
schema['x-read-pretty'] = true;
|
|
187
|
+
schema['x-disabled'] = false;
|
|
188
|
+
field.readPretty = true;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
default: {
|
|
192
|
+
fieldSchema['x-read-pretty'] = false;
|
|
193
|
+
fieldSchema['x-disabled'] = false;
|
|
194
|
+
schema['x-read-pretty'] = false;
|
|
195
|
+
schema['x-disabled'] = false;
|
|
196
|
+
field.readPretty = false;
|
|
197
|
+
field.disabled = false;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
dn.emit('patch', {
|
|
203
|
+
schema,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
dn.refresh();
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
)}
|
|
210
|
+
<SchemaSettings.ModalItem
|
|
211
|
+
key="map-zoom"
|
|
212
|
+
title={t('Set default zoom level')}
|
|
213
|
+
schema={
|
|
214
|
+
{
|
|
215
|
+
type: 'object',
|
|
216
|
+
title: t('Set default zoom level'),
|
|
217
|
+
properties: {
|
|
218
|
+
zoom: {
|
|
219
|
+
title: t('Zoom'),
|
|
220
|
+
default: field.componentProps.zoom || 13,
|
|
221
|
+
description: t('The default zoom level of the map'),
|
|
222
|
+
'x-decorator': 'FormItem',
|
|
223
|
+
'x-component': 'InputNumber',
|
|
224
|
+
'x-component-props': {
|
|
225
|
+
precision: 0,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
} as ISchema
|
|
230
|
+
}
|
|
231
|
+
onSubmit={({ zoom }) => {
|
|
232
|
+
if (zoom) {
|
|
233
|
+
_.set(fieldSchema, 'x-component-props.zoom', zoom);
|
|
234
|
+
Object.assign(field.componentProps, fieldSchema['x-component-props']);
|
|
235
|
+
|
|
236
|
+
dn.emit('patch', {
|
|
237
|
+
schema: {
|
|
238
|
+
'x-uid': fieldSchema['x-uid'],
|
|
239
|
+
'x-component-props': field.componentProps,
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
dn.refresh();
|
|
244
|
+
}}
|
|
245
|
+
/>
|
|
246
|
+
<SchemaSettings.Remove
|
|
247
|
+
key="remove"
|
|
248
|
+
removeParentsIfNoChildren
|
|
249
|
+
confirm={{
|
|
250
|
+
title: t('Delete field'),
|
|
251
|
+
}}
|
|
252
|
+
breakRemoveOn={{
|
|
253
|
+
'x-component': 'Grid',
|
|
254
|
+
}}
|
|
255
|
+
/>
|
|
256
|
+
</GeneralSchemaDesigner>
|
|
257
|
+
);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export default Designer;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { connect, mapReadPretty } from '@formily/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import AMapComponent from './AMap';
|
|
4
|
+
import ReadPretty from './ReadPretty';
|
|
5
|
+
import { css } from '@emotion/css';
|
|
6
|
+
import Designer from './Designer';
|
|
7
|
+
|
|
8
|
+
const InternalMap = connect((props) => {
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
className={css`
|
|
12
|
+
border: 1px solid transparent;
|
|
13
|
+
.ant-formily-item-error & {
|
|
14
|
+
border: 1px solid #ff4d4f;
|
|
15
|
+
}
|
|
16
|
+
`}
|
|
17
|
+
>
|
|
18
|
+
{props.mapType ? <AMapComponent {...props} /> : null}
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}, mapReadPretty(ReadPretty));
|
|
22
|
+
|
|
23
|
+
const Map = InternalMap as typeof InternalMap & {
|
|
24
|
+
Designer: typeof Designer;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
Map.Designer = Designer;
|
|
28
|
+
|
|
29
|
+
export default Map;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useField, useFieldSchema } from '@formily/react';
|
|
2
|
+
import { useCollection } from '@nocobase/client';
|
|
3
|
+
import React, { useEffect } from 'react';
|
|
4
|
+
import AMapComponent from './AMap';
|
|
5
|
+
|
|
6
|
+
const ReadPretty = (props) => {
|
|
7
|
+
const { value, readOnly } = props;
|
|
8
|
+
const fieldSchema = useFieldSchema();
|
|
9
|
+
const { getField } = useCollection();
|
|
10
|
+
const collectionField = getField(fieldSchema.name);
|
|
11
|
+
const mapType = props.mapType || collectionField?.uiSchema['x-component-props']?.mapType;
|
|
12
|
+
const field = useField();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!field.title) {
|
|
16
|
+
field.title = collectionField.uiSchema.title;
|
|
17
|
+
}
|
|
18
|
+
}, collectionField.title);
|
|
19
|
+
|
|
20
|
+
if (!readOnly)
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
style={{
|
|
24
|
+
whiteSpace: 'pre-wrap',
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
{value?.map((item) => (Array.isArray(item) ? `(${item.join(',')})` : item)).join(',')}
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return mapType === 'amap' ? <AMapComponent mapType={mapType} {...props}></AMapComponent> : null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default ReadPretty;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { message, Select } from 'antd';
|
|
2
|
+
import { css } from '@emotion/css';
|
|
3
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { useDebounceFn } from 'ahooks';
|
|
5
|
+
import { useMapTranslation } from '../locales';
|
|
6
|
+
|
|
7
|
+
interface SearchProps {
|
|
8
|
+
aMap: any;
|
|
9
|
+
toCenter: (p: any) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Search = (props: SearchProps) => {
|
|
13
|
+
const { aMap, toCenter } = props;
|
|
14
|
+
const { t } = useMapTranslation();
|
|
15
|
+
const placeSearch = useRef<any>();
|
|
16
|
+
const [options, setOptions] = useState([]);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
aMap?.plugin('AMap.PlaceSearch', () => {
|
|
20
|
+
placeSearch.current = new aMap.PlaceSearch({
|
|
21
|
+
city: '全国',
|
|
22
|
+
pageSize: 30,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}, [aMap]);
|
|
26
|
+
|
|
27
|
+
const { run: onSearch } = useDebounceFn(
|
|
28
|
+
(keyword) => {
|
|
29
|
+
if (!placeSearch.current) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
placeSearch.current.search(keyword || ' ', (status, result) => {
|
|
33
|
+
if (status === 'complete') {
|
|
34
|
+
setOptions(
|
|
35
|
+
result.poiList.pois.map((item) => {
|
|
36
|
+
return {
|
|
37
|
+
...item,
|
|
38
|
+
label: `${item.name}-${item.address}`,
|
|
39
|
+
value: item.id,
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
} else {
|
|
44
|
+
if (status === 'no_data') {
|
|
45
|
+
setOptions([]);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
message.error(t('Please configure the AMap securityCode or securityHost correctly'));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
wait: 300,
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const onSelect = (value) => {
|
|
58
|
+
const place = options.find((o) => {
|
|
59
|
+
return o.value === value;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (place?.location) {
|
|
63
|
+
toCenter(place.location);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
className={css`
|
|
70
|
+
position: absolute;
|
|
71
|
+
top: 10px;
|
|
72
|
+
left: 10px;
|
|
73
|
+
z-index: 10;
|
|
74
|
+
width: calc(100% - 20px);
|
|
75
|
+
`}
|
|
76
|
+
>
|
|
77
|
+
<Select
|
|
78
|
+
showSearch
|
|
79
|
+
allowClear
|
|
80
|
+
style={{
|
|
81
|
+
background: 'rgba(255, 255, 255, 0.8)',
|
|
82
|
+
}}
|
|
83
|
+
placeholder={t('Enter keywords to search')}
|
|
84
|
+
filterOption={false}
|
|
85
|
+
onSearch={onSearch}
|
|
86
|
+
onSelect={onSelect}
|
|
87
|
+
options={options}
|
|
88
|
+
></Select>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export default Search;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IField } from '@nocobase/client';
|
|
2
|
+
import { generateNTemplate } from '../locales';
|
|
3
|
+
import { commonSchema } from './schema';
|
|
4
|
+
|
|
5
|
+
export const circle: IField = {
|
|
6
|
+
name: 'circle',
|
|
7
|
+
type: 'object',
|
|
8
|
+
group: 'map',
|
|
9
|
+
order: 3,
|
|
10
|
+
title: generateNTemplate('Circle'),
|
|
11
|
+
description: generateNTemplate('Circle'),
|
|
12
|
+
sortable: true,
|
|
13
|
+
default: {
|
|
14
|
+
type: 'circle',
|
|
15
|
+
uiSchema: {
|
|
16
|
+
type: 'void',
|
|
17
|
+
'x-component': 'Map',
|
|
18
|
+
'x-component-designer': 'Map.Designer',
|
|
19
|
+
'x-component-props': {},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
...commonSchema,
|
|
23
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { circle } from './circle'
|
|
2
|
+
import { lineString } from './lineString'
|
|
3
|
+
import { point } from './point'
|
|
4
|
+
import { polygon } from './polygon'
|
|
5
|
+
|
|
6
|
+
export const fields = [
|
|
7
|
+
point,
|
|
8
|
+
polygon,
|
|
9
|
+
lineString,
|
|
10
|
+
circle
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
export const interfaces = fields.reduce((ins, field) => {
|
|
14
|
+
ins[field.name] = field
|
|
15
|
+
return ins
|
|
16
|
+
}, {})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IField } from '@nocobase/client';
|
|
2
|
+
import { generateNTemplate } from '../locales';
|
|
3
|
+
import { commonSchema } from './schema';
|
|
4
|
+
|
|
5
|
+
export const lineString: IField = {
|
|
6
|
+
name: 'lineString',
|
|
7
|
+
type: 'object',
|
|
8
|
+
group: 'map',
|
|
9
|
+
order: 2,
|
|
10
|
+
title: generateNTemplate('Line'),
|
|
11
|
+
description: generateNTemplate('Line'),
|
|
12
|
+
sortable: true,
|
|
13
|
+
default: {
|
|
14
|
+
type: 'lineString',
|
|
15
|
+
uiSchema: {
|
|
16
|
+
type: 'void',
|
|
17
|
+
'x-component': 'Map',
|
|
18
|
+
'x-component-designer': 'Map.Designer',
|
|
19
|
+
'x-component-props': {},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
...commonSchema,
|
|
23
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ISchema } from '@formily/react';
|
|
2
|
+
import { IField } from '@nocobase/client';
|
|
3
|
+
import { generateNTemplate } from '../locales';
|
|
4
|
+
import { commonSchema } from './schema';
|
|
5
|
+
|
|
6
|
+
export const point: IField = {
|
|
7
|
+
name: 'point',
|
|
8
|
+
type: 'object',
|
|
9
|
+
group: 'map',
|
|
10
|
+
order: 1,
|
|
11
|
+
title: generateNTemplate('Point'),
|
|
12
|
+
description: generateNTemplate('Point'),
|
|
13
|
+
sortable: true,
|
|
14
|
+
default: {
|
|
15
|
+
type: 'point',
|
|
16
|
+
uiSchema: {
|
|
17
|
+
type: 'void',
|
|
18
|
+
'x-component': 'Map',
|
|
19
|
+
'x-component-designer': 'Map.Designer',
|
|
20
|
+
'x-component-props': {},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
...commonSchema,
|
|
24
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IField } from '@nocobase/client';
|
|
2
|
+
import { generateNTemplate } from '../locales';
|
|
3
|
+
import { commonSchema } from './schema';
|
|
4
|
+
|
|
5
|
+
export const polygon: IField = {
|
|
6
|
+
name: 'polygon',
|
|
7
|
+
type: 'object',
|
|
8
|
+
group: 'map',
|
|
9
|
+
order: 4,
|
|
10
|
+
title: generateNTemplate('Polygon'),
|
|
11
|
+
description: generateNTemplate('Polygon'),
|
|
12
|
+
sortable: true,
|
|
13
|
+
default: {
|
|
14
|
+
type: 'polygon',
|
|
15
|
+
uiSchema: {
|
|
16
|
+
type: 'void',
|
|
17
|
+
'x-component': 'Map',
|
|
18
|
+
'x-component-designer': 'Map.Designer',
|
|
19
|
+
'x-component-props': {},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
...commonSchema,
|
|
23
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ISchema } from '@formily/react';
|
|
2
|
+
import { interfacesProperties } from '@nocobase/client';
|
|
3
|
+
import { MapTypes } from '../constants';
|
|
4
|
+
import { generateNTemplate } from '../locales';
|
|
5
|
+
|
|
6
|
+
const { defaultProps } = interfacesProperties;
|
|
7
|
+
|
|
8
|
+
if (Array.isArray(defaultProps.type.enum)) {
|
|
9
|
+
defaultProps.type.enum.push(
|
|
10
|
+
{
|
|
11
|
+
label: 'Point',
|
|
12
|
+
value: 'point',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: 'LineString',
|
|
16
|
+
value: 'lineString',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
label: 'Polygon',
|
|
20
|
+
value: 'polygon',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: 'Circle',
|
|
24
|
+
value: 'circle',
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const commonSchema = {
|
|
30
|
+
properties: {
|
|
31
|
+
...defaultProps,
|
|
32
|
+
'uiSchema.x-component-props.mapType': {
|
|
33
|
+
title: generateNTemplate('Map type'),
|
|
34
|
+
type: 'string',
|
|
35
|
+
required: true,
|
|
36
|
+
'x-decorator': 'FormItem',
|
|
37
|
+
'x-component': 'Select',
|
|
38
|
+
'x-component-props': {
|
|
39
|
+
showSearch: false,
|
|
40
|
+
allowClear: false,
|
|
41
|
+
},
|
|
42
|
+
'x-disabled': '{{ isOverride || !createOnly }}',
|
|
43
|
+
default: 'amap',
|
|
44
|
+
enum: MapTypes
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
schemaInitialize(schema: ISchema, { readPretty, block }) {
|
|
48
|
+
if (block === 'Form') {
|
|
49
|
+
Object.assign(schema, {
|
|
50
|
+
'x-component-props': {
|
|
51
|
+
readOnly: readPretty ? true : false
|
|
52
|
+
},
|
|
53
|
+
'x-designer': 'Map.Designer',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useMapConfiguration'
|