您好,欢迎访问陈氏家族网 |注册 下载手机客户端

合肥市 = 2) { locationType = sourceParts[1]; // ip2region, gaode, baidu等 } } // 如果还是没有,尝试从debug_info获取 if (!locationType && locationData.debug_info && locationData.debug_info.location_type) { locationType = locationData.debug_info.location_type; } homeCurrentLocation = { city_id: parseInt(locationData.city_id), city_name: locationData.city_name, province_name: locationData.province_name || '', method: method || 'ip', location_type: locationType || '', source: locationData.source || '', // 保存调试信息 client_ip: locationData.client_ip || (locationData.debug_info && locationData.debug_info.ip) || '', debug_info: locationData.debug_info || {}, is_fallback: locationData.is_fallback || false, fallback_reason: locationData.fallback_reason || '' }; console.log('更新城市显示:', homeCurrentLocation); // 更新页面上的城市显示 const cityName = homeCurrentLocation.city_name; const provinceName = homeCurrentLocation.province_name; const cityElements = document.querySelectorAll('.current-city, #changeCity-current-city'); cityElements.forEach(el => { if (el) el.textContent = cityName; }); const provinceElements = document.querySelectorAll('.province-info, #changeCity-province-info'); provinceElements.forEach(el => { if (el) el.textContent = provinceName ? (provinceName + ' • 当前城市') : cityName; }); // 更新弹窗中的信息(如果弹窗已打开) updateHomeLocationInfoFields(); // 获取分站状态 if (homeCurrentLocation.city_id > 0) { homeSubstationStatusCache = null; homeSubstationStatusMessage = '检测中…'; applyHomeSubstationStatus(null, homeSubstationStatusMessage); fetchHomeSubstationStatus(homeCurrentLocation.city_id); } else { applyHomeSubstationStatus(null, '城市ID无效'); } } function fetchHomeSubstationStatus(cityId) { $.getJSON('/index.php?g=Wap&m=LocationApi&a=getSubstationStatus&city_id=' + encodeURIComponent(cityId), function(res){ if (res && res.success && res.data) { homeSubstationStatusCache = res.data; homeSubstationStatusMessage = ''; applyHomeSubstationStatus(homeSubstationStatusCache); } else { homeSubstationStatusCache = null; homeSubstationStatusMessage = res && res.message ? res.message : '无法获取分站状态'; applyHomeSubstationStatus(null, homeSubstationStatusMessage); } }).fail(function(){ homeSubstationStatusCache = null; homeSubstationStatusMessage = '无法获取分站状态'; applyHomeSubstationStatus(null, homeSubstationStatusMessage); }); } function getHomeLocationMethodText() { if (!homeCurrentLocation) { return '检测中…'; } // 获取定位方式和定位类型 var method = homeCurrentLocation.method || ''; var locationType = homeCurrentLocation.location_type || ''; var source = homeCurrentLocation.source || ''; var libraryMismatch = homeCurrentLocation.library_mismatch || false; var configuredLibrary = homeCurrentLocation.configured_library || ''; // 如果locationType为空,尝试从source解析 if (!locationType && source) { var sourceParts = source.split(':'); if (sourceParts.length >= 2) { locationType = sourceParts[1]; // ip2region, gaode, baidu等 } } var methodMap = { gps: 'GPS定位', wechat: '微信定位', ip: 'IP定位', manual: '手动选择', cache: '缓存定位', default: '默认城市', server: '服务器位置' }; var methodText = methodMap[method] || 'IP定位'; // 如果是IP定位,必须显示定位类型(本地、百度、高德等) if (method === 'ip') { var typeMap = { 'ip2region': '本地', 'gaode': '高德', 'baidu': '百度', 'tencent': '腾讯', 'free': '免费API' }; // 如果配置的库和实际使用的库不一致,使用配置的库显示,但标记为备用 if (libraryMismatch && configuredLibrary) { var configuredType = configuredLibrary === 'ip2region' ? '本地' : (typeMap[configuredLibrary] || configuredLibrary); methodText = 'IP定位(' + configuredType + '备用)'; } else if (locationType && typeMap[locationType]) { methodText = 'IP定位(' + typeMap[locationType] + ')'; } else if (locationType) { methodText = 'IP定位(' + locationType + ')'; } else { methodText = 'IP定位(未知)'; } } return methodText; } function updateHomeLocationInfoFields() { // 只在弹窗打开时更新(弹窗中的元素) var methodSpan = document.querySelector('[data-home-info="method"]'); var typeSpan = document.querySelector('[data-home-info="type"]'); var citySpan = document.querySelector('[data-home-info="city"]'); var ipSpan = document.querySelector('[data-home-info="ip"]'); var debugInfoDiv = document.getElementById('home-debug-info'); if (methodSpan) { var methodText = getHomeLocationMethodText(); methodSpan.textContent = methodText; } if (typeSpan) { var locationType = ''; if (homeCurrentLocation) { // 优先使用location_type var typeValue = homeCurrentLocation.location_type || ''; // 如果location_type为空,尝试从source解析 if (!typeValue && homeCurrentLocation.source) { var sourceParts = homeCurrentLocation.source.split(':'); if (sourceParts.length >= 2) { typeValue = sourceParts[1]; // ip2region, gaode, baidu等 } } // 如果还是没有,尝试从debug_info获取 if (!typeValue && homeCurrentLocation.debug_info && homeCurrentLocation.debug_info.location_type) { typeValue = homeCurrentLocation.debug_info.location_type; } if (typeValue) { var typeMap = { 'ip2region': '本地', 'gaode': '高德', 'baidu': '百度', 'tencent': '腾讯', 'free': '免费API' }; locationType = typeMap[typeValue] || typeValue; } else if (homeCurrentLocation.method === 'ip') { locationType = '未知'; } else { locationType = '-'; } } else { locationType = '检测中…'; } typeSpan.textContent = locationType; } if (citySpan) { var cityText = homeCurrentLocation && homeCurrentLocation.city_name ? homeCurrentLocation.city_name : '检测中…'; citySpan.textContent = cityText; } // 显示获取的IP地址 if (ipSpan) { var ipText = ''; if (homeCurrentLocation) { ipText = homeCurrentLocation.client_ip || (homeCurrentLocation.debug_info && homeCurrentLocation.debug_info.ip) || '未获取'; // 如果是本地IP,标记 if (ipText === '127.0.0.1' || ipText.startsWith('192.168.') || ipText.startsWith('10.') || ipText.startsWith('172.')) { ipText += ' (本地/内网)'; } } else { ipText = '检测中…'; } ipSpan.textContent = ipText; } // 显示调试信息 if (debugInfoDiv) { if (homeCurrentLocation) { debugInfoDiv.style.display = 'block'; // GPS状态 var gpsStatusSpan = debugInfoDiv.querySelector('[data-home-info="gps-status"]'); if (gpsStatusSpan) { if (homeCurrentLocation.method === 'gps' && !homeCurrentLocation.is_fallback) { gpsStatusSpan.textContent = '成功'; gpsStatusSpan.style.color = '#28a745'; } else if (homeGPSError) { gpsStatusSpan.textContent = '失败'; gpsStatusSpan.style.color = '#dc3545'; } else { gpsStatusSpan.textContent = '未使用'; gpsStatusSpan.style.color = '#6c757d'; } } // GPS失败原因 var gpsErrorSpan = debugInfoDiv.querySelector('[data-home-info="gps-error"]'); if (gpsErrorSpan) { var gpsError = homeGPSError || (homeCurrentLocation.debug_info && homeCurrentLocation.debug_info.failure_reason) || 'ame="' + city.city_name + '">' + city.city_name + ' - ' + city.province_name + '

'; }); } else { html = '
未找到匹配的城市
'; } list.html(html).off('click.search').on('click.search', '.pc-search-item', function(){ selectPcCity($(this).data('id'), $(this).data('name')); }); container.show(); }); } // 选择PC端城市 function selectPcCity(cityId, cityName) { if (!cityId) return; $.post('/index.php?g=Home&m=LocationApi&a=setManualCity', { city_id: cityId }, function(result){ if (result && result.success && result.data) { updateCityDisplay(result.data, 'manual'); hidePcCitySelector(); alert('已切换到' + (result.data.city_name || cityName)); setTimeout(function(){ window.location.reload(); }, 800); } else { alert('城市切换失败:' + (result ? result.message : '未知错误')); } }, 'json').fail(function(){ alert('城市切换失败,请重试'); }); } function confirmPcCitySelection() { var citySelect = $('#pc-city-select'); if (!citySelect.length || !citySelect.val()) { alert('请选择城市'); return; } var cityName = citySelect.find('option:selected').text(); selectPcCity(citySelect.val(), cityName); } window.hidePcCitySelector = function() { $('#pc-city-selector').remove(); };
我要发布信息
  • 本地生活信息
copyright 2013-2113 www.chenshiwang.cn All Rights Reserved 陈氏家族网版权所有
皖ICP备2021016109号-1