diff --git a/src/js/config/api.config.js b/src/js/config/api.config.js index 4f9b50b..ba4b765 100644 --- a/src/js/config/api.config.js +++ b/src/js/config/api.config.js @@ -32,6 +32,9 @@ export const API_CONFIG = { // 区域数据接口 AREA_LIST: '/api/partnerh5/area_list', + + // IP定位接口 + IP_LOCATION: '/api/partnerh5/ip_location', }, // 请求超时配置(毫秒) diff --git a/src/js/ui/city-picker.js b/src/js/ui/city-picker.js index cc8186b..b6af9d9 100644 --- a/src/js/ui/city-picker.js +++ b/src/js/ui/city-picker.js @@ -4,6 +4,7 @@ */ import { AreaService } from '../services/area.service.js'; +import { API_CONFIG } from '../config/api.config.js'; // 热门城市列表(12个核心城市) const HOT_CITIES = [ @@ -660,7 +661,7 @@ export class CityPicker { try { // 调用后端IP定位接口 - const response = await fetch('/pub/partnerh5/ip_location'); + const response = await fetch(API_CONFIG.ENDPOINTS.IP_LOCATION); const result = await response.json(); if (result.retcode === 0 && result.result) { @@ -705,80 +706,6 @@ export class CityPicker { } } - /** - * 逆地理编码,将经纬度转换为城市信息 - * 使用免费的逆地理编码服务 - * @param {number} latitude - 纬度 - * @param {number} longitude - 经度 - * @returns {Promise} - 城市信息对象 - */ - async reverseGeocode(latitude, longitude) { - try { - // 使用免费的 Nominatim API(OpenStreetMap) - // 注意:该服务有速率限制(每秒最多1次请求) - const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}&accept-language=zh-CN`; - - const response = await fetch(url, { - headers: { - 'User-Agent': 'CityPicker/1.0' - } - }); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - const data = await response.json(); - - if (data && data.address) { - const address = data.address; - - // 获取城市信息(优先级:city > town > village > state) - let cityName = address.city || address.town || address.village || address.state || ''; - let provinceName = address.state || ''; - - // 处理直辖市的特殊情况 - const municipalities = ['北京市', '上海市', '天津市', '重庆市']; - if (municipalities.includes(provinceName)) { - cityName = provinceName; - } - - // 如果城市名为空,尝试从county字段获取 - if (!cityName && address.county) { - // 移除"市"、"区"、"县"等后缀 - cityName = address.county.replace(/[市区县]$/, '') + '市'; - } - - if (cityName) { - // 查找城市代码 - const cityCode = await this.findCityCode(provinceName, cityName); - - if (cityCode) { - return { - name: cityName, - province: provinceName, - code: cityCode.cityCode, - provinceCode: cityCode.provinceCode - }; - } else { - // 如果找不到代码,返回基本信息(代码为空) - return { - name: cityName, - province: provinceName, - code: '', - provinceCode: '' - }; - } - } - } - - return null; - } catch (error) { - console.error('[CityPicker] 逆地理编码失败:', error); - return null; - } - } - /** * 查找城市代码 * @param {string} provinceName - 省份名称 diff --git a/static/image.zip b/static/image.zip new file mode 100644 index 0000000..8d9e1d6 Binary files /dev/null and b/static/image.zip differ