Files
ylt_diy/public/static/js/common.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

// 全局错误处理,防止JavaScript错误中断执行
window.onerror = function(msg, url, line, col, error) {
console.error('JavaScript错误:', msg, 'at', url, 'line:', line);
return true; // 阻止错误传播
};
// 全局变量
let editingConfigId = null;
let allFields = [];
let currentPage = 1;
let pageSize = 10;
let currentEntityType = '';
let currentSearch = '';
let entityPage = 1;
let entityPageSize = 20;
let selectedEntityIds = new Set();
let fieldCustomNames = {};
// 标签切换
function switchTab(tabName) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
document.querySelector(`.tab[onclick="switchTab('${tabName}')"]`).classList.add('active');
document.getElementById(`${tabName}-tab`).classList.add('active');
if (tabName === 'config') {
loadConfigs();
} else if (tabName === 'generate') {
loadGenerateConfigs();
} else if (tabName === 'history') {
loadHistory();
}
}
// 格式化日期时间
function formatDateTime(dateStr) {
if (!dateStr) return '';
const date = new Date(dateStr);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
// 显示错误提示
function showError(message) {
alert('错误:' + message);
}
// 显示成功提示
function showSuccess(message) {
alert('成功:' + message);
}
// 页面加载时自动加载配置列表
document.addEventListener('DOMContentLoaded', function() {
loadConfigs();
});