2025-10-23 16:52:53 +08:00
|
|
|
import { Button, Col, Form, Input, Row } from "antd";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import MapSelector from "./MapSelector";
|
|
|
|
|
|
2025-10-28 15:16:58 +08:00
|
|
|
/**
|
|
|
|
|
* 定位组件
|
|
|
|
|
*/
|
2025-10-23 16:52:53 +08:00
|
|
|
const Map = (props) => {
|
|
|
|
|
const {
|
|
|
|
|
longitudeProps = "longitude",
|
|
|
|
|
latitudeProps = "latitude",
|
|
|
|
|
onConfirm,
|
|
|
|
|
required = true,
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const form = Form.useFormInstance();
|
|
|
|
|
const [mapVisible, setMapVisible] = useState(false);
|
|
|
|
|
const [currentLongitude, setCurrentLongitude] = useState(form.getFieldValue(longitudeProps) || "");
|
|
|
|
|
const [currentLatitude, setCurrentLatitude] = useState(form.getFieldValue(latitudeProps) || "");
|
|
|
|
|
|
|
|
|
|
const handleMapConfirm = (longitudeValue, latitudeValue) => {
|
|
|
|
|
setCurrentLongitude(longitudeValue);
|
|
|
|
|
setCurrentLatitude(latitudeValue);
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
[longitudeProps]: longitudeValue,
|
|
|
|
|
[latitudeProps]: latitudeValue,
|
|
|
|
|
});
|
|
|
|
|
onConfirm?.(longitudeValue, latitudeValue);
|
|
|
|
|
setMapVisible(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Row gutter={24}>
|
|
|
|
|
<Col span={12}>
|
2025-10-30 11:09:12 +08:00
|
|
|
<Form.Item label="经度" name={longitudeProps} rules={[{ required, message: "请选择经度" }]}>
|
2025-10-23 16:52:53 +08:00
|
|
|
<Input disabled />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Col>
|
|
|
|
|
<Col span={12}>
|
2025-10-30 11:09:12 +08:00
|
|
|
<Form.Item label="纬度" required={required} rules={[{ required, message: "请选择纬度" }]}>
|
2025-10-28 13:33:19 +08:00
|
|
|
<div style={{ display: "flex", gap: 10 }}>
|
2025-10-30 11:09:12 +08:00
|
|
|
<Form.Item name={latitudeProps} noStyle rules={[{ required, message: "请选择纬度" }]}>
|
|
|
|
|
<Input disabled />
|
|
|
|
|
</Form.Item>
|
2025-10-23 16:52:53 +08:00
|
|
|
<Button type="primary" onClick={() => setMapVisible(true)}>
|
|
|
|
|
点击定位
|
|
|
|
|
</Button>
|
2025-10-28 13:33:19 +08:00
|
|
|
</div>
|
|
|
|
|
</Form.Item>
|
2025-10-23 16:52:53 +08:00
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
<MapSelector
|
|
|
|
|
visible={mapVisible}
|
|
|
|
|
onClose={() => setMapVisible(false)}
|
|
|
|
|
longitude={currentLongitude}
|
|
|
|
|
latitude={currentLatitude}
|
|
|
|
|
onConfirm={handleMapConfirm}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Map;
|