删除了我不需要的代码,并修改了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) {
const content = element.nextElementSibling;
content.style.display = content.style.display === "none" ? "block" : "none";
@@ -16,112 +36,17 @@ document.addEventListener('DOMContentLoaded', function() {
],
throwOnError: false
});
});
// 分页功能
document.getElementById('prevPageBtn').addEventListener('click', function() {
const currentPage = parseInt(document.getElementById('currentPage').textContent);
if (currentPage > 1) {
loadPage(currentPage - 1);
// 获取页面中的版本号元素
const versionElement = document.querySelector('.version');
// 更新内容(拼接版本号)
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() {
// 保存按钮的引用
var btn = this;
@@ -429,17 +354,7 @@ document.getElementById('downloadBtn').addEventListener('click', function() {
}, 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) {
@@ -572,49 +487,16 @@ document.getElementById('viewDetailsBtn').addEventListener('click', function() {
});
});
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';
}
// 函数用于将日期格式化为 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 形式
}
//稳定度描述映射
@@ -651,8 +533,15 @@ function replaceSuitabilityText(data, type) {
// 默认返回原值
return data;
}
// 初始化时关闭所有面板
document.querySelectorAll('.accordion-content').forEach(content => {
content.style.maxHeight = '0px';
});
// 显示通知
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);
}