fix(admin,partner): replace Tencent iframe picker with server LBS search
CI / verify (pull_request) Has been cancelled
CI / verify (pull_request) Has been cancelled
Avoid locpicker formatted_addresses crash; proxy suggest/nearby/reverse via /common/lbs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -17,7 +17,7 @@ export class ClientConfigController {
|
||||
mockSms: cfg.mockSms,
|
||||
mockWechat: cfg.mockWechat,
|
||||
wxAuthorize: cfg.wxAuthorize,
|
||||
/** 浏览器地图选点用;建议在腾讯控制台按域名限制 Key */
|
||||
/** 可选暴露;选点已改为服务端 /common/lbs,前端可不依赖此字段 */
|
||||
tencentLbsKey: cfg.tencentLbsKey || undefined,
|
||||
miniHome: {
|
||||
banners: parseMiniHomeBanners(env.MINI_HOME_BANNERS),
|
||||
|
||||
@@ -14,6 +14,7 @@ import { TicketController } from './ticket.controller';
|
||||
import { ThirdPartyLogController } from './third-party-log.controller';
|
||||
import { WechatController } from './wechat.controller';
|
||||
import { ClientConfigController } from './client-config.controller';
|
||||
import { LbsController } from './lbs.controller';
|
||||
import { WechatLocationService } from './wechat-location.service';
|
||||
|
||||
@Module({
|
||||
@@ -25,6 +26,7 @@ import { WechatLocationService } from './wechat-location.service';
|
||||
ThirdPartyLogController,
|
||||
WechatController,
|
||||
ClientConfigController,
|
||||
LbsController,
|
||||
],
|
||||
providers: [
|
||||
ResourceService,
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Get,
|
||||
Query,
|
||||
ServiceUnavailableException,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { TencentLbsProvider } from '../../integrations/map/tencent-lbs.provider';
|
||||
|
||||
function parseCoord(raw: string | undefined, label: string): number | undefined {
|
||||
if (raw == null || raw === '') return undefined;
|
||||
const n = Number(raw);
|
||||
if (!Number.isFinite(n)) throw new BadRequestException(`${label}无效`);
|
||||
return n;
|
||||
}
|
||||
|
||||
@Controller('common/lbs')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class LbsController {
|
||||
constructor(private readonly tencentLbs: TencentLbsProvider) {}
|
||||
|
||||
@Get('suggest')
|
||||
async suggest(
|
||||
@Query('keyword') keyword?: string,
|
||||
@Query('region') region?: string,
|
||||
@Query('lat') lat?: string,
|
||||
@Query('lng') lng?: string,
|
||||
) {
|
||||
if (!this.tencentLbs.isEnabled()) {
|
||||
throw new ServiceUnavailableException('未配置腾讯位置服务 Key(TENCENT_LBS_KEY)');
|
||||
}
|
||||
const q = (keyword ?? '').trim();
|
||||
if (!q) return { items: [] };
|
||||
const latitude = parseCoord(lat, '纬度');
|
||||
const longitude = parseCoord(lng, '经度');
|
||||
const result = await this.tencentLbs.suggestPlaces(q, {
|
||||
region: region?.trim() || undefined,
|
||||
latitude,
|
||||
longitude,
|
||||
});
|
||||
if (result.error && !result.items.length) {
|
||||
throw new BadRequestException(result.error);
|
||||
}
|
||||
return { items: result.items };
|
||||
}
|
||||
|
||||
@Get('nearby')
|
||||
async nearby(@Query('lat') lat?: string, @Query('lng') lng?: string, @Query('radius') radius?: string) {
|
||||
if (!this.tencentLbs.isEnabled()) {
|
||||
throw new ServiceUnavailableException('未配置腾讯位置服务 Key(TENCENT_LBS_KEY)');
|
||||
}
|
||||
const latitude = parseCoord(lat, '纬度');
|
||||
const longitude = parseCoord(lng, '经度');
|
||||
if (latitude == null || longitude == null) {
|
||||
throw new BadRequestException('请提供 lat、lng');
|
||||
}
|
||||
const r = radius != null && radius !== '' ? Number(radius) : 1000;
|
||||
const result = await this.tencentLbs.exploreNearby(latitude, longitude, Number.isFinite(r) ? r : 1000);
|
||||
if (result.error && !result.items.length) {
|
||||
throw new BadRequestException(result.error);
|
||||
}
|
||||
return { items: result.items };
|
||||
}
|
||||
|
||||
@Get('reverse')
|
||||
async reverse(@Query('lat') lat?: string, @Query('lng') lng?: string) {
|
||||
if (!this.tencentLbs.isEnabled()) {
|
||||
throw new ServiceUnavailableException('未配置腾讯位置服务 Key(TENCENT_LBS_KEY)');
|
||||
}
|
||||
const latitude = parseCoord(lat, '纬度');
|
||||
const longitude = parseCoord(lng, '经度');
|
||||
if (latitude == null || longitude == null) {
|
||||
throw new BadRequestException('请提供 lat、lng');
|
||||
}
|
||||
const result = await this.tencentLbs.reverseGeocodeDetail(latitude, longitude);
|
||||
if (!result.item) {
|
||||
throw new BadRequestException(result.error || '逆地理编码失败');
|
||||
}
|
||||
return {
|
||||
latitude: result.item.latitude,
|
||||
longitude: result.item.longitude,
|
||||
address: result.item.address,
|
||||
name: result.item.name,
|
||||
province: result.item.province,
|
||||
city: result.item.city,
|
||||
district: result.item.district,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user