317f910f3c
Store create/edit on HQ and partner can pick coords via Tencent locpicker; client-config exposes TENCENT_LBS_KEY; seed empty system settings from env. Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
export type TencentPickedLocation = {
|
|
latitude: number;
|
|
longitude: number;
|
|
address?: string;
|
|
name?: string;
|
|
cityname?: string;
|
|
};
|
|
|
|
type LocPickerMessage = {
|
|
module?: string;
|
|
latlng?: { lat?: number; lng?: number };
|
|
poiaddress?: string;
|
|
poiname?: string;
|
|
cityname?: string;
|
|
};
|
|
|
|
const REFERER = 'dukang-haoke';
|
|
|
|
export function buildTencentLocPickerUrl(
|
|
key: string,
|
|
options?: { latitude?: number; longitude?: number },
|
|
): string {
|
|
const params = new URLSearchParams({
|
|
search: '1',
|
|
type: '1',
|
|
key,
|
|
referer: REFERER,
|
|
policy: '1',
|
|
});
|
|
const lat = options?.latitude;
|
|
const lng = options?.longitude;
|
|
if (
|
|
lat != null &&
|
|
lng != null &&
|
|
Number.isFinite(lat) &&
|
|
Number.isFinite(lng) &&
|
|
!(lat === 0 && lng === 0)
|
|
) {
|
|
params.set('coord', `${lat},${lng}`);
|
|
params.set('coordtype', '5');
|
|
}
|
|
return `https://apis.map.qq.com/tools/locpicker?${params.toString()}`;
|
|
}
|
|
|
|
export function parseTencentLocPickerMessage(data: unknown): TencentPickedLocation | null {
|
|
const loc = data as LocPickerMessage;
|
|
if (!loc || loc.module !== 'locationPicker') return null;
|
|
const lat = Number(loc.latlng?.lat);
|
|
const lng = Number(loc.latlng?.lng);
|
|
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return null;
|
|
// 列表滑动过程中偶发空 POI,忽略无名称且无地址的噪声
|
|
if (!loc.poiname && !loc.poiaddress) return null;
|
|
return {
|
|
latitude: lat,
|
|
longitude: lng,
|
|
address: loc.poiaddress?.trim() || undefined,
|
|
name: loc.poiname?.trim() || undefined,
|
|
cityname: loc.cityname?.trim() || undefined,
|
|
};
|
|
}
|