可以正常使用get_weather_details获取前端指定的数据了

This commit is contained in:
2025-09-29 11:20:21 +08:00
parent 8cc75be7cd
commit 56844a537f
6 changed files with 212 additions and 146 deletions

View File

@@ -1,7 +1,5 @@
const version = "0.1.9";
let weatherdata = null;
//公式相关
function toggleAccordion(header) {
@@ -54,7 +52,20 @@ document.getElementById('downloadBtn').addEventListener('click', function() {
// 隐藏按钮(而不是移除)
btn.style.display = 'none';
//
// 从 api 中取得 weatherdata
let weatherdata = null;
selectedId = 300;
fetch(`/weather/details?id=${selectedId}`)
.then(response => response.json())
.then(data => {
//更新全局变量
weatherdata = data;
})
.catch(error => {
console.error('Error:', error);
alert('获取详细信息失败');
});
const data = weatherdata;
const areaTypeMap = {
@@ -356,135 +367,6 @@ document.getElementById('downloadBtn').addEventListener('click', function() {
// 获取记录内容
document.getElementById('viewDetailsBtn').addEventListener('click', function() {
const selectedRadio = document.querySelector('input[name="selectedData"]:checked');
if (!selectedRadio) {
alert('请先选择一条数据');
return;
}
const selectedId = selectedRadio.value;
fetch(`/weather/details?id=${selectedId}`)
.then(response => response.json())
.then(data => {
//更新全局变量
weatherdata = data;
const detailsTable = document.getElementById('detailsTable');
detailsTable.innerHTML = '';
const row = document.createElement('div');
row.innerHTML = `
<div class="card">
<div class="card-header">
<h3>${data.title}</h3>
<h3>${data.inspectiontype}</h3>
<h3>${data.assignmentnumber}</h3>
</div>
<div class="card-body">
<div class="info-item">
<span class="info-label">时间:</span>
<span class="info-value">${formatDateToYYYYMMDD(data.date)} ${data.hour}${data.min}分</span>
</div>
<div class="info-item">
<span class="info-label">经纬度:</span>
<span class="info-value">位置: 经度 ${data.longitude}, 纬度 ${data.latitude}</span>
</div>
<div class="info-item">
<span class="info-label">地球公转角:</span>
<span class="info-value">${data.theta}</span>
</div>
<div class="info-item">
<span class="info-label">太阳倾角:</span>
<span class="info-value">${data.solardeclination}</span>
</div>
<div class="info-item">
<span class="info-label">太阳高度角:</span>
<span class="info-value">${data.sunaltitude}</span>
</div>
<div class="info-item">
<span class="info-label">云量指数:${data.cloudindex}</span>
<span class="info-value">低云 ${data.lowcloudiness}, 总云量 ${data.overallcloudiness}</span>
</div>
<div class="info-item">
<span class="info-label">太阳辐射等级:</span>
<span class="info-value">${data.solarradiationlevel}</span>
</div>
<div id="measured-data" style="display: none;">
<div class="info-item">
<span class="info-label">测量风速:</span>
<span class="info-value" id="measured-windspeed">${data.measuredwindspeed}</span>
</div>
<div class="info-item">
<span class="info-label">转换风速:</span>
<span class="info-value" id="converted-windspeed">${data.convertedwindspeed}</span>
</div>
</div>
<div id="calculated-data" style="display: none;">
<div class="info-item">
<span class="info-label">测量高度:</span>
<span class="info-value" id="measurement-height">${data.measurementheight}</span>
</div>
<div class="info-item">
<span class="info-label">区域类型:</span>
<span class="info-value" id="area-type">${data.areatype}</span>
</div>
<div class="info-item">
<span class="info-label">测点风速:</span>
<span class="info-value" id="point-windspeed">${data.pointwindspeed}</span>
</div>
</div>
<div class="info-item">
<span class="info-label">大气稳定度:</span>
<span class="info-value">${data.atmosphericstability}</span>
</div>
<div class="info-item">
<span class="info-label">适宜度:</span>
<span class="info-value">${data.suitabilitydegree}</span>
</div>
<div class="info-item">
<span class="info-label">风速:${data.windspeed}</span>
<span class="info-value">平均风速:${data.averagewindspeed}</span>
<span class="info-value">适宜度:${data.windspeedsuitability}</span>
</div>
<div class="info-item">
<span class="info-label">风向:${data.winddirection}</span>
<span class="info-value">平均风向 ${data.averagewinddirection} 风向标准差 ${data.winddirectionstandarddeviation}</span>
<span class="info-value">适宜度:${data.winddirectionsuitability}</span>
</div>
<div class="info-item">
<span class="info-label">整体适宜度:</span>
<span class="info-value rating-high">${data.overallsuitability}</span>
</div>
</div>
</div>
`;
detailsTable.appendChild(row);
// 根据条件显示相应的数据
if (data.hasmeasuredwindspeed==='true') {
document.getElementById('measured-data').style.display = 'block';
document.getElementById('calculated-data').style.display = 'none';
document.getElementById('measured-windspeed').textContent = data.measuredwindspeed;
document.getElementById('converted-windspeed').textContent = data.convertedwindspeed;
} else {
document.getElementById('measured-data').style.display = 'none';
document.getElementById('calculated-data').style.display = 'block';
document.getElementById('measurement-height').textContent = data.measurementheight;
document.getElementById('area-type').textContent = data.areatype;
document.getElementById('point-windspeed').textContent = data.pointwindspeed;
};
document.getElementById('detailsContainer').style.display = 'block';
})
.catch(error => {
console.error('Error:', error);
alert('获取详细信息失败');
});
});
// 工具函数