H5端开店增加获取当前店铺位置
This commit is contained in:
@@ -11,6 +11,8 @@ export type StoreCreateForm = {
|
||||
name: string;
|
||||
phone: string;
|
||||
address: string;
|
||||
latitude?: number | null;
|
||||
longitude?: number | null;
|
||||
intro?: string;
|
||||
openTime?: string;
|
||||
closeTime?: string;
|
||||
|
||||
@@ -319,6 +319,7 @@ export default function StoresPage() {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [createStep, setCreateStep] = useState(0);
|
||||
const [createError, setCreateError] = useState('');
|
||||
const [locating, setLocating] = useState(false);
|
||||
const [partners, setPartners] = useState<PartnerOption[]>([]);
|
||||
const [cities, setCities] = useState<CityOption[]>([]);
|
||||
const [categoryTree, setCategoryTree] = useState<CategoryNode[]>([]);
|
||||
@@ -328,6 +329,8 @@ export default function StoresPage() {
|
||||
const selectedRegionCodes = Form.useWatch('regionCodes', createForm);
|
||||
const selectedCityId = Form.useWatch('cityId', createForm);
|
||||
const selectedCategoryParentId = Form.useWatch('categoryParentId', createForm);
|
||||
const watchedLat = Form.useWatch('latitude', createForm);
|
||||
const watchedLng = Form.useWatch('longitude', createForm);
|
||||
|
||||
const categoryParentOptions = useMemo(
|
||||
() =>
|
||||
@@ -465,6 +468,15 @@ export default function StoresPage() {
|
||||
phone: values.phone.trim(),
|
||||
district: values.district.trim(),
|
||||
address: values.address.trim(),
|
||||
...(values.latitude != null &&
|
||||
values.longitude != null &&
|
||||
Number.isFinite(Number(values.latitude)) &&
|
||||
Number.isFinite(Number(values.longitude))
|
||||
? {
|
||||
latitude: Number(values.latitude),
|
||||
longitude: Number(values.longitude),
|
||||
}
|
||||
: {}),
|
||||
intro: values.intro?.trim() || undefined,
|
||||
openTime: values.openTime?.trim() || '10:00',
|
||||
closeTime: values.closeTime?.trim() || '22:00',
|
||||
@@ -854,6 +866,51 @@ export default function StoresPage() {
|
||||
<Form.Item name="address" label="详细地址" rules={[{ required: true, message: '请填写详细地址' }]}>
|
||||
<Input.TextArea rows={2} placeholder="请输入详细门牌号" />
|
||||
</Form.Item>
|
||||
<Form.Item name="latitude" hidden>
|
||||
<InputNumber />
|
||||
</Form.Item>
|
||||
<Form.Item name="longitude" hidden>
|
||||
<InputNumber />
|
||||
</Form.Item>
|
||||
<Space wrap style={{ marginBottom: 16 }}>
|
||||
<Button
|
||||
loading={locating}
|
||||
onClick={() => {
|
||||
if (!navigator.geolocation) {
|
||||
message.error('当前浏览器不支持定位');
|
||||
return;
|
||||
}
|
||||
setLocating(true);
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(pos) => {
|
||||
createForm.setFieldsValue({
|
||||
latitude: pos.coords.latitude,
|
||||
longitude: pos.coords.longitude,
|
||||
});
|
||||
message.success(
|
||||
`已获取坐标 ${pos.coords.latitude.toFixed(6)}, ${pos.coords.longitude.toFixed(6)}`,
|
||||
);
|
||||
setLocating(false);
|
||||
},
|
||||
(err) => {
|
||||
message.error(err.message || '定位失败');
|
||||
setLocating(false);
|
||||
},
|
||||
{ enableHighAccuracy: true, timeout: 10000 },
|
||||
);
|
||||
}}
|
||||
>
|
||||
获取当前位置
|
||||
</Button>
|
||||
<Typography.Text type="secondary">
|
||||
{watchedLat != null &&
|
||||
watchedLng != null &&
|
||||
Number.isFinite(Number(watchedLat)) &&
|
||||
Number.isFinite(Number(watchedLng))
|
||||
? `坐标:${Number(watchedLat).toFixed(6)}, ${Number(watchedLng).toFixed(6)}`
|
||||
: '未定位(可选,便于用户端导航与距离)'}
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
<Space wrap style={{ width: '100%' }}>
|
||||
<Form.Item name="openTime" label="营业开始" rules={[{ required: true, message: '请填写营业开始时间' }]}>
|
||||
<Input type="time" style={{ width: 140 }} />
|
||||
|
||||
Reference in New Issue
Block a user