2022-12-14 21:45:43 +08:00
|
|
|
import { useField, useFieldSchema } from '@formily/react';
|
|
|
|
import { useCollection } from '@nocobase/client';
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import AMapComponent from './AMap';
|
|
|
|
|
|
|
|
const ReadPretty = (props) => {
|
|
|
|
const { value, readOnly } = props;
|
|
|
|
const fieldSchema = useFieldSchema();
|
|
|
|
const { getField } = useCollection();
|
|
|
|
const collectionField = getField(fieldSchema.name);
|
|
|
|
const mapType = props.mapType || collectionField?.uiSchema['x-component-props']?.mapType;
|
|
|
|
const field = useField();
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-02-15 15:58:09 +08:00
|
|
|
if (!field.title && collectionField?.uiSchema?.title) {
|
2022-12-14 21:45:43 +08:00
|
|
|
field.title = collectionField.uiSchema.title;
|
|
|
|
}
|
2023-02-15 15:58:09 +08:00
|
|
|
}, collectionField?.title);
|
2022-12-14 21:45:43 +08:00
|
|
|
|
|
|
|
if (!readOnly)
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
whiteSpace: 'pre-wrap',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{value?.map((item) => (Array.isArray(item) ? `(${item.join(',')})` : item)).join(',')}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return mapType === 'amap' ? <AMapComponent mapType={mapType} {...props}></AMapComponent> : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ReadPretty;
|