删除了我不需要的代码,并修改了version 的显示逻辑

This commit is contained in:
2025-09-28 16:24:38 +08:00
parent 892cface67
commit 8cc75be7cd
2 changed files with 51 additions and 187 deletions

View File

@@ -1,5 +1,25 @@
const version = "0.1.8"; const version = "0.1.9";
let weatherdata = null;
//公式相关
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 toggleFormula(element) { function toggleFormula(element) {
const content = element.nextElementSibling; const content = element.nextElementSibling;
content.style.display = content.style.display === "none" ? "block" : "none"; content.style.display = content.style.display === "none" ? "block" : "none";
@@ -16,112 +36,17 @@ document.addEventListener('DOMContentLoaded', function() {
], ],
throwOnError: false throwOnError: false
}); });
});
// 分页功能 // 获取页面中的版本号元素
document.getElementById('prevPageBtn').addEventListener('click', function() { const versionElement = document.querySelector('.version');
const currentPage = parseInt(document.getElementById('currentPage').textContent);
if (currentPage > 1) { // 更新内容(拼接版本号)
loadPage(currentPage - 1); if (versionElement) {
versionElement.textContent = `版本号: ${version}`;
} }
}); });
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() { document.getElementById('downloadBtn').addEventListener('click', function() {
// 保存按钮的引用 // 保存按钮的引用
var btn = this; var btn = this;
@@ -429,17 +354,7 @@ document.getElementById('downloadBtn').addEventListener('click', function() {
}, 2000); // 假设下载需要2秒完成你可以根据实际情况调整 }, 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() { document.getElementById('viewDetailsBtn').addEventListener('click', function() {
const selectedRadio = document.querySelector('input[name="selectedData"]:checked'); const selectedRadio = document.querySelector('input[name="selectedData"]:checked');
if (!selectedRadio) { if (!selectedRadio) {
@@ -572,49 +487,16 @@ document.getElementById('viewDetailsBtn').addEventListener('click', function() {
}); });
}); });
function selectCard(card) { // 工具函数
// 获取所有卡片
const allCards = document.querySelectorAll('.card');
// 移除所有卡片的选中状态 // 函数用于将日期格式化为 xxxx-xx-xx 形式
allCards.forEach(c => { function formatDateToYYYYMMDD(date) {
c.classList.remove('selected'); // 使用Date对象解析这个日期字符串
const radio = c.querySelector('input[type="radio"]'); var date = new Date(date);
if (radio) radio.checked = false; 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 形式
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';
}
} }
//稳定度描述映射 //稳定度描述映射
@@ -652,7 +534,14 @@ function replaceSuitabilityText(data, type) {
return data; return data;
} }
// 初始化时关闭所有面板 // 显示通知
document.querySelectorAll('.accordion-content').forEach(content => { function showNotification(message, type = 'success') {
content.style.maxHeight = '0px'; 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);
}

View File

@@ -62,31 +62,6 @@
</div> </div>
<div> <div>
<div class="container">
<h1>历史数据</h1>
<div class="card-container" id="cardContainer">
{% for data in weather %}
<div class="card" data-id="{{ data[0] }}" onclick="selectCard(this)">
<div class="card-header">
<input type="radio" name="selectedData" value="{{ data[0] }}" id="radio-{{ data[0] }}">
<h3 class="card-title">{{ data[1] }}</h3>
</div>
<p class="card-date">{{ data[2] }} {{ data[3] }}:{{ data[4] }} </p>
</div>
{% endfor %}
</div>
</div>
<button id="viewDetailsBtn">查看详情</button>
<button id="deleteBtn">删除记录</button>
<!-- 分页导航 -->
<div class="pagination">
<button id="prevPageBtn" {% if current_page <= 1 %}disabled{% endif %}>上一页</button>
<span><span id="currentPage">{{ current_page }}</span> 页 / 共 <span id="totalPages">{{ total_pages }}</span></span>
<button id="nextPageBtn" {% if current_page >= total_pages %}disabled{% endif %}>下一页</button>
</div>
<div id="detailsContainer" style="margin-top: 20px; display: none;"> <div id="detailsContainer" style="margin-top: 20px; display: none;">
<h2>详细信息</h2> <h2>详细信息</h2>
<div id="detailsTable"> <div id="detailsTable">
@@ -104,7 +79,7 @@
</body> </body>
<footer> <footer>
<p class="version">版本号: 0.1.8-6</p> <p class="version">版本号: </p>
</footer> </footer>
</html> </html>