'; if (gpsError) { gpsErrorSpan.textContent = gpsError; gpsErrorSpan.style.color = '#dc3545'; } else { gpsErrorSpan.textContent = '-'; } } // IP定位状态 var ipStatusSpan = debugInfoDiv.querySelector('[data-home-info="ip-status"]'); if (ipStatusSpan) { if (homeCurrentLocation.method === 'ip') { ipStatusSpan.textContent = homeCurrentLocation.is_fallback ? '失败(已回退)' : '成功'; ipStatusSpan.style.color = homeCurrentLocation.is_fallback ? '#dc3545' : '#28a745'; } else { ipStatusSpan.textContent = '未使用'; ipStatusSpan.style.color = '#6c757d'; } } // IP失败原因 var ipErrorSpan = debugInfoDiv.querySelector('[data-home-info="ip-error"]'); if (ipErrorSpan) { var ipError = ''; // 优先显示详细的错误信息 if (homeCurrentLocation.debug_info && homeCurrentLocation.debug_info.ip_location_error) { var errorInfo = homeCurrentLocation.debug_info.ip_location_error; if (errorInfo.error_message) { ipError = errorInfo.error_message; if (errorInfo.error_code) { ipError = '[' + errorInfo.error_code + '] ' + ipError; } } } else if (homeCurrentLocation.ip_location_error) { var errorInfo = homeCurrentLocation.ip_location_error; if (errorInfo.error_message) { ipError = errorInfo.error_message; if (errorInfo.error_code) { ipError = '[' + errorInfo.error_code + '] ' + ipError; } } } else if (homeCurrentLocation.fallback_reason) { ipError = homeCurrentLocation.fallback_reason; } else if (homeCurrentLocation.is_fallback) { ipError = '定位失败,已回退默认城市'; } if (ipError) { ipErrorSpan.textContent = ipError; ipErrorSpan.style.color = '#dc3545'; ipErrorSpan.style.wordBreak = 'break-word'; } else { ipErrorSpan.textContent = '-'; } } // Source var sourceSpan = debugInfoDiv.querySelector('[data-home-info="source"]'); if (sourceSpan) { sourceSpan.textContent = homeCurrentLocation.source || '-'; } // 是否回退 var isFallbackSpan = debugInfoDiv.querySelector('[data-home-info="is-fallback"]'); if (isFallbackSpan) { isFallbackSpan.textContent = homeCurrentLocation.is_fallback ? '是' : '否'; isFallbackSpan.style.color = homeCurrentLocation.is_fallback ? '#dc3545' : '#28a745'; } } else { debugInfoDiv.style.display = 'none'; } } } function applyHomeSubstationStatus(info, message) { var statusSpan = document.querySelector('#home-substation-status'); var btnHolder = document.querySelector('#home-substation-holder'); var systemSpan = document.querySelector('[data-home-info="system"]'); var cityEnableSpan = document.querySelector('[data-home-info="city-enable"]'); var domainSpan = document.querySelector('[data-home-info="domain"]'); updateHomeLocationInfoFields(); if (!statusSpan || !btnHolder) { return; } btnHolder.innerHTML = ''; if (info) { if (systemSpan) { systemSpan.textContent = info.system_enabled ? '已启用' : '未启用'; } if (cityEnableSpan) { cityEnableSpan.textContent = info.city_enabled ? '已启用' : '未启用'; } if (domainSpan) { domainSpan.textContent = info.domain_label || '未启用独立域名'; } statusSpan.textContent = info.message || ''; var previewUrl = info.preview_url_web || info.preview_url || info.preview_url_wap || info.fallback_url_web || info.fallback_url_wap || info.fallback_url; if (previewUrl && info.system_enabled && info.city_enabled) { var btn = document.createElement('a'); btn.href = 'javascript:void(0)'; btn.className = 'home-substation-btn pc-theme-button'; btn.textContent = '跳转到定位分站'; btn.onclick = function(){ if (info.flags && parseInt(info.flags.jump_confirm || 0, 10) === 1) { var confirmText = info.message ? info.message + '\n是否跳转到分站?' : '是否跳转到分站?'; if (!window.confirm(confirmText)) { return; } } window.location.href = previewUrl; }; btnHolder.appendChild(btn); } } else { statusSpan.textContent = message || '检测中…'; if (systemSpan) { systemSpan.textContent = '检测中…'; } if (cityEnableSpan) { cityEnableSpan.textContent = '检测中…'; } if (domainSpan) { domainSpan.textContent = '检测中…'; } } } // 显示城市选择器函数 window.showPcCitySelector = function(event) { if (event) { event.preventDefault(); event.stopPropagation(); } console.log('显示PC端城市选择器...'); // 检查是否已存在选择器 if (document.getElementById('pc-city-selector')) { return; } // 创建简单的城市选择弹窗 const modal = document.createElement('div'); modal.id = 'pc-city-selector'; modal.style.cssText = ` position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 9999; display: flex; align-items: center; justify-content: center; `; modal.innerHTML = `

选择城市

定位方式:检测中…
定位类型:检测中…
定位城市:检测中…
获取的IP:检测中…
系统分站:检测中…
城市分站:检测中…
域名模式:检测中…
检测中…

手动选择

搜索城市

`; document.body.appendChild(modal); // 确保DOM渲染完成后再更新(使用setTimeout确保DOM已渲染) setTimeout(function() { // 如果还没有定位信息,立即请求 if (!homeCurrentLocation || !homeCurrentLocation.city_id) { // 如果已经在定位中,不要重复调用 if (homeIPLocating) { console.log('弹窗打开:IP定位正在进行中,等待结果'); updateHomeLocationInfoFields(); applyHomeSubstationStatus(null, '检测中…'); return; } console.log('弹窗打开:没有定位信息,开始请求'); updateHomeLocationInfoFields(); // 先显示"检测中…" applyHomeSubstationStatus(null, '检测中…'); requestCityByIP(); return; } console.log('弹窗打开:已有定位信息', homeCurrentLocation); // 立即更新定位信息字段 updateHomeLocationInfoFields(); // 显示分站状态 if (homeSubstationStatusCache) { console.log('弹窗打开:使用缓存的分站状态'); applyHomeSubstationStatus(homeSubstationStatusCache); } else if (homeCurrentLocation.city_id > 0) { console.log('弹窗打开:请求分站状态'); homeSubstationStatusMessage = '检测中…'; applyHomeSubstationStatus(null, homeSubstationStatusMessage); fetchHomeSubstationStatus(homeCurrentLocation.city_id); } else { applyHomeSubstationStatus(null, '城市ID无效'); } }, 10); // 加载数据 loadPcSelectorData(); // 点击遮罩关闭 modal.addEventListener('click', function(e) { if (e.target === modal) { hidePcCitySelector(); } }); // 搜索框回车事件 document.getElementById('pc-city-search').addEventListener('keypress', function(e) { if (e.which === 13) { searchPcCities(); } }); }; // 加载PC端选择器数据 function loadPcSelectorData() { loadPcProvinces(); loadPcHotCities(); } function loadPcProvinces() { $.getJSON('/index.php?g=Home&m=LocationApi&a=getProvinceList', function(result){ if (result && result.success) { var select = $('#pc-province-select'); if (select.length) { var html = ''; $.each(result.data, function(_, province){ html += ''; }); select.html(html).off('change.pc').on('change.pc', function(){ loadPcCitiesByProvince(this.value); }); } } }); } function loadPcCitiesByProvince(provinceId) { var citySelect = $('#pc-city-select'); if (!provinceId) { citySelect.html(''); return; } $.getJSON('/index.php?g=Home&m=LocationApi&a=getCitiesByProvince&province_id=' + provinceId, function(result){ var html = ''; if (result && result.success) { $.each(result.data, function(_, city){ html += ''; }); } citySelect.html(html); }).fail(function(){ citySelect.html(''); }); } // 加载PC端热门城市 function loadPcHotCities() { $.getJSON('/index.php?g=Home&m=LocationApi&a=getCityList', function(result){ if (result && result.success) { var container = $('#pc-hot-cities'); if (container.length) { var html = ''; $.each(result.data.slice(0, 18), function(_, city){ html += '
' + city.city_name + '
'; }); container.html(html).off('click.hot').on('click.hot', '.pc-hot-city', function(){ selectPcCity($(this).data('id'), $(this).data('name')); }); } } }); } // 搜索PC端城市 function searchPcCities() { var keyword = $('#pc-city-search').val().trim(); var container = $('#pc-search-results'); var list = container.find('.pc-search-list'); if (!keyword) { list.empty(); container.hide(); return; } $.getJSON('/index.php?g=Home&m=LocationApi&a=searchCity&keyword=' + encodeURIComponent(keyword), function(result){ var html = ''; if (result && result.success && result.data && result.data.length) { $.each(result.data, function(_, city){ html += '
' + 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