Добавление общих складов и удаление пустых ни разу не использованных общих складов
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// Вспомогательная функция для показа уведомлений с использованием Bootstrap Toasts
|
||||
export function showInfo(message, type = 'info') {
|
||||
// Создаем контейнер для тостов если его нет
|
||||
let toastContainer = document.getElementById('toast-container');
|
||||
if (!toastContainer) {
|
||||
toastContainer = document.createElement('div');
|
||||
toastContainer.id = 'toast-container';
|
||||
toastContainer.className = 'toast-container position-fixed top-0 end-0 p-3';
|
||||
toastContainer.style.cssText = `
|
||||
z-index: 99999;
|
||||
max-width: 350px;
|
||||
`;
|
||||
document.body.appendChild(toastContainer);
|
||||
}
|
||||
|
||||
// Создаем уникальный ID для тоста
|
||||
const toastId = 'toast-' + Date.now();
|
||||
|
||||
// Определяем классы в зависимости от типа
|
||||
const typeConfig = {
|
||||
'success': { bgClass: 'bg-success', icon: 'bi-check-circle', delay: 5000 },
|
||||
'error': { bgClass: 'bg-danger', icon: 'bi-exclamation-circle', delay: 10000 },
|
||||
'info': { bgClass: 'bg-info', icon: 'bi-info-circle', delay: 3000 },
|
||||
'warning': { bgClass: 'bg-warning', icon: 'bi-exclamation-triangle', delay: 8000 }
|
||||
};
|
||||
|
||||
const config = typeConfig[type] || typeConfig.info;
|
||||
|
||||
// Создаем тост
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast ${config.bgClass} text-white`;
|
||||
toast.id = toastId;
|
||||
toast.setAttribute('role', 'alert');
|
||||
toast.setAttribute('aria-live', 'assertive');
|
||||
toast.setAttribute('aria-atomic', 'true');
|
||||
|
||||
toast.innerHTML = `
|
||||
<div class="toast-header ${config.bgClass} text-white">
|
||||
<i class="bi ${config.icon} me-2"></i>
|
||||
<strong class="me-auto">Уведомление</strong>
|
||||
<small>Только что</small>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="toast"></button>
|
||||
</div>
|
||||
<div class="toast-body">
|
||||
${message}
|
||||
</div>
|
||||
`;
|
||||
|
||||
toastContainer.appendChild(toast);
|
||||
|
||||
// Инициализируем и показываем тост
|
||||
const bsToast = new bootstrap.Toast(toast, {
|
||||
animation: true,
|
||||
autohide: true,
|
||||
delay: config.delay
|
||||
});
|
||||
|
||||
bsToast.show();
|
||||
|
||||
// Удаляем тост после скрытия
|
||||
toast.addEventListener('hidden.bs.toast', function () {
|
||||
setTimeout(() => {
|
||||
if (toast.parentNode) {
|
||||
toast.remove();
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user