const version = "0.1.8"; function toggleFormula(element) { const content = element.nextElementSibling; content.style.display = content.style.display === "none" ? "block" : "none"; element.textContent = element.textContent.includes("▶") ? element.textContent.replace("▶", "▼") : element.textContent.replace("▼", "▶"); } document.addEventListener('DOMContentLoaded', function() { renderMathInElement(document.body, { delimiters: [ {left: "$$", right: "$$", display: true}, {left: "$", right: "$", display: false} ], throwOnError: false }); }); // 分页功能 document.getElementById('prevPageBtn').addEventListener('click', function() { const currentPage = parseInt(document.getElementById('currentPage').textContent); if (currentPage > 1) { loadPage(currentPage - 1); } }); document.getElementById('nextPageBtn').addEventListener('click', function() { const currentPage = parseInt(document.getElementById('currentPage').textContent); const totalPages = parseInt(document.getElementById('totalPages').textContent); if (currentPage < totalPages) { loadPage(currentPage + 1); } }); function loadPage(page) { const urlParams = new URLSearchParams(window.location.search); const user_id = urlParams.get('user_id'); fetch(`/weather?user_id=${user_id}&page=${page}`) .then(response => response.text()) .then(html => { // 创建一个临时DOM元素来 parse 返回的HTML const parser = new DOMParser(); const doc = parser.parseFromString(html, 'text/html'); // 获取新的卡片容器内容 const newCardContainer = doc.getElementById('cardContainer'); if (newCardContainer) { document.getElementById('cardContainer').innerHTML = newCardContainer.innerHTML; } // 更新分页信息 const newCurrentPage = doc.getElementById('currentPage'); const newTotalPages = doc.getElementById('totalPages'); if (newCurrentPage && newTotalPages) { document.getElementById('currentPage').textContent = newCurrentPage.textContent; document.getElementById('totalPages').textContent = newTotalPages.textContent; } // 更新按钮状态 updatePaginationButtons(parseInt(newCurrentPage.textContent), parseInt(newTotalPages.textContent)); // 隐藏详情容器 document.getElementById('detailsContainer').style.display = 'none'; }) .catch(error => { console.error('Error:', error); showNotification('加载页面失败', 'error'); }); } function updatePaginationButtons(currentPage, totalPages) { const prevBtn = document.getElementById('prevPageBtn'); const nextBtn = document.getElementById('nextPageBtn'); prevBtn.disabled = currentPage <= 1; nextBtn.disabled = currentPage >= totalPages; } // 添加删除按钮事件监听 document.getElementById('deleteBtn').addEventListener('click', function() { const selectedRadio = document.querySelector('input[name="selectedData"]:checked'); if (!selectedRadio) { alert('请先选择一条数据'); return; } if (!confirm('确定要删除这条记录吗?此操作不可撤销!')) { return; } const selectedId = selectedRadio.value; fetch('/weather/delete', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: `id=${selectedId}` }) .then(response => response.json()) .then(data => { if (data.error) { showNotification(data.error, 'error'); } else { showNotification(data.message); // 移除已删除的卡片 const card = document.querySelector(`.card[data-id="${selectedId}"]`); if (card) { card.remove(); } // 隐藏详情容器 document.getElementById('detailsContainer').style.display = 'none'; } }) .catch(error => { console.error('Error:', error); showNotification('删除失败', 'error'); }); }); let weatherdata = null; document.getElementById('downloadBtn').addEventListener('click', function() { // 保存按钮的引用 var btn = this; // 隐藏按钮(而不是移除) btn.style.display = 'none'; // const data = weatherdata; const areaTypeMap = { urban: "城市", rural: "农村", }; // 等待一小段时间确保按钮已隐藏 setTimeout(function() { // 假设你的HTML字符串是这样的 var htmlString = ` 总体适宜度测量报表

总体适宜度测量报表

文件编号:
${data.id}
检测类型:
${data.inspectiontype}
委托单号:
${data.assignmentnumber}
项目名称:
${data.title}
经纬度:
E ${data.longitude}, N ${data.latitude}
测试时间:
${formatDateToYYYYMMDD(data.date)}${data.hour}:${data.min}
日期序数:
${data.daysincejanfirst}
太阳倾角:
${data.solardeclination}°
太阳高度角:
${data.sunaltitude}°
总云量:
${data.overallcloudiness}
低云量:
${data.lowcloudiness}
辐射等级:
${data.solarradiationlevel}
平均风速:
${data.averagewindspeed}m/s
风速适宜度:
${data.windspeedsuitability}
平均风向:
${data.averagewinddirection}°
风向标准差:
${data.winddirectionstandarddeviation}°
风向适宜度:
${data.winddirectionsuitability}
大气稳定度:
${data.atmosphericstability}
稳定度适宜度:
${data.suitabilitydegree}
总体适宜度:
${replaceSuitabilityText(data.overallsuitability, "overall")}
十次风速值:
${data.windspeed}
十次风向值:
${data.winddirection}
` // 根据条件显示相应的数据 if (data.hasmeasuredwindspeed === true) { htmlString+=`
实测风速:
${data.measuredwindspeed} m/s
转换风速:
${data.convertedwindspeed} m/s
` } else { htmlString+=`
区域类型:
${areaTypeMap[data.areatype]}
测点高度:
${data.measurementheight} m
点位风速:
${data.pointwindspeed} m/s
推算风速:
${data.calculatedwindspeed} m/s
` }; htmlString += `

` const filename = `${data.id}-${version}.pdf` var opt = { margin: 10, filename: filename, image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2 }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } }; // 执行下载,使用htmlString作为内容源 html2pdf().set(opt).from(htmlString).save(); }, 100); // 下载完成后恢复按钮显示 setTimeout(function() { btn.style.display = ''; }, 2000); // 假设下载需要2秒完成,你可以根据实际情况调整 }); // 函数用于将日期格式化为 xxxx-xx-xx 形式 function formatDateToYYYYMMDD(date) { // 使用Date对象解析这个日期字符串 var date = new Date(date); var year = date.getFullYear(); // 获取年份 var month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份,并确保两位数 var day = date.getDate().toString().padStart(2, '0'); // 获取日期,并确保两位数 return year + '-' + month + '-' + day; // 组合成 xxxx-xx-xx 形式 } 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 = `

${data.title}

${data.inspectiontype}

${data.assignmentnumber}

时间: ${formatDateToYYYYMMDD(data.date)} ${data.hour}时 ${data.min}分
经纬度: 位置: 经度 ${data.longitude}, 纬度 ${data.latitude}
地球公转角: ${data.theta}
太阳倾角: ${data.solardeclination}
太阳高度角: ${data.sunaltitude}
云量指数:${data.cloudindex} 低云 ${data.lowcloudiness}, 总云量 ${data.overallcloudiness}
太阳辐射等级: ${data.solarradiationlevel}
大气稳定度: ${data.atmosphericstability}
适宜度: ${data.suitabilitydegree}
风速:${data.windspeed} 平均风速:${data.averagewindspeed} 适宜度:${data.windspeedsuitability}
风向:${data.winddirection} 平均风向 ${data.averagewinddirection} 风向标准差 ${data.winddirectionstandarddeviation} 适宜度:${data.winddirectionsuitability}
整体适宜度: ${data.overallsuitability}
`; 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('获取详细信息失败'); }); }); function selectCard(card) { // 获取所有卡片 const allCards = document.querySelectorAll('.card'); // 移除所有卡片的选中状态 allCards.forEach(c => { c.classList.remove('selected'); const radio = c.querySelector('input[type="radio"]'); if (radio) radio.checked = false; }); // 添加当前卡片的选中状态 card.classList.add('selected'); const radio = card.querySelector('input[type="radio"]'); if (radio) radio.checked = true; } // 显示通知 function showNotification(message, type = 'success') { const notification = document.getElementById('notification'); notification.textContent = message; notification.style.backgroundColor = type === 'success' ? '#4CAF50' : '#f44336'; notification.style.display = 'block'; setTimeout(() => { notification.style.display = 'none'; }, 3000); } //公式相关 function toggleAccordion(header) { const content = header.nextElementSibling; const isOpen = content.style.maxHeight !== '0px' && content.style.maxHeight !== ''; // 关闭所有其他面板 document.querySelectorAll('.accordion-content').forEach(item => { item.style.maxHeight = '0px'; }); // 切换当前面板 if (!isOpen) { content.style.maxHeight = content.scrollHeight + 'px'; } } //稳定度描述映射 function replaceSuitabilityText(data, type) { // 定义映射关系 const suitabilityMap = { 'a': '不利于污染物的扩散和稀释,适宜于进行无组织排放监测', 'b': '较不利于污染物的扩散和稀释,较适宜于进行无组织排放监测', 'c': '有利于污染物的扩散和稀释,较不适宜于进行无组织排放监测', 'd': '很有利于污染物的扩散和稀释,不适宜于进行无组织排放监测', 'wind0': '静风', 'overall0': '取消监测或改期' }; // 将输入转换为小写(或大写)以实现大小写不敏感 const normalizedData = String(data).toLowerCase(); // 处理特殊类型 if (type === 'wind' && normalizedData === '0') return suitabilityMap['wind0']; if (type === 'overall' && normalizedData === '0') return suitabilityMap['overall0']; // 处理普通类型 if (type === 'normal' || type === "wind" || type === "overall") { // 检查映射表中是否存在转换后的小写字段 if (suitabilityMap[normalizedData]) { return suitabilityMap[normalizedData]; } // 如果找不到,返回原值 return data; } // 默认返回原值 return data; } // 初始化时关闭所有面板 document.querySelectorAll('.accordion-content').forEach(content => { content.style.maxHeight = '0px'; });