Files
zhangmenu/static/js/utils.js
T

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2026-03-12 11:27:23 +08:00
// 工具函数
// 格式化日期时间
function formatDateTime(date) {
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');
return `${year}-${month}-${day} ${hours}:${minutes}`;
}
// 防抖函数
function debounce(fn, delay) {
let timer;
return function(...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), delay);
};
}
// 生成默认图片
function getDefaultImage() {
return 'data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%2248%22 height=%2248%22><rect fill=%22%23fed7aa%22 width=%2248%22 height=%2248%22/><text x=%2250%25%22 y=%2250%25%22 text-anchor=%22middle%22 dy=%22.3em%22 fill=%22%23c2410c%22>🍳</text></svg>';
}
// 确认对话框
function confirmAction(message) {
return confirm(message);
}
// 显示提示
function showToast(message, type = 'info') {
// 简单实现,实际可以使用更优雅的toast库
alert(message);
}