From: Aleksey Filippov Date: Tue, 17 Feb 2026 10:03:08 +0000 (+0300) Subject: Добавление логирования на загрузку файлов в документ списания. X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=9fd3ef1fc80de69995fe5b877f83f728a61e6f92;p=erp24_rep%2Fyii-erp24%2F.git Добавление логирования на загрузку файлов в документ списания. --- diff --git a/erp24/web/js/notification.js b/erp24/web/js/notification.js index b3d037f1..2a5366ac 100644 --- a/erp24/web/js/notification.js +++ b/erp24/web/js/notification.js @@ -5,7 +5,7 @@ setTimeout(initPendingNotifications, 3000); function initPendingNotifications() { pendingNotifications(); - notificationIntervalId = setInterval(pendingNotifications, 10000); + notificationIntervalId = setInterval(pendingNotifications, 600000); } // Останавливаем polling когда вкладка неактивна — экономим соединения и трафик @@ -18,7 +18,7 @@ document.addEventListener('visibilitychange', function () { } else { if (!notificationIntervalId) { pendingNotifications(); - notificationIntervalId = setInterval(pendingNotifications, 10000); + notificationIntervalId = setInterval(pendingNotifications, 600000); } } }); @@ -49,6 +49,9 @@ function updateKolokolchik(data) { } function pendingNotifications() { + // Не отправляем запросы пока идёт загрузка формы — освобождаем соединения + if (window._uploadInProgress) return; + $.ajax({ method: 'POST', url: window.location.origin + '/notification/pending', diff --git a/erp24/web/js/validate/validateForm.js b/erp24/web/js/validate/validateForm.js index 63c642d2..43193070 100755 --- a/erp24/web/js/validate/validateForm.js +++ b/erp24/web/js/validate/validateForm.js @@ -145,15 +145,75 @@ function submitFormWithXHR(yiiform) { } }); + // Останавливаем notification polling — освобождаем соединения для upload + window._uploadInProgress = true; + // Индикатор загрузки var submitBtn = yiiform.find('.submitter'); var originalText = submitBtn.text(); submitBtn.prop('disabled', true).text('Загрузка...'); + // Прогресс-бар загрузки файлов + var $progressWrap = yiiform.find('#upload-progress-wrap'); + if ($progressWrap.length === 0) { + submitBtn.after( + '
' + + '
' + + '
0%
' + + '
' + + ' ' + + '
' + ); + $progressWrap = yiiform.find('#upload-progress-wrap'); + } + $progressWrap.show(); + var $bar = $progressWrap.find('#upload-progress-bar'); + var $text = $progressWrap.find('#upload-progress-text'); + var uploadStartTime = Date.now(); + var xhr = new XMLHttpRequest(); + + // Прогресс отправки файлов на сервер + xhr.upload.addEventListener('progress', function (e) { + if (e.lengthComputable) { + var percent = Math.round(e.loaded / e.total * 100); + $bar.css('width', percent + '%').text(percent + '%'); + + var elapsed = (Date.now() - uploadStartTime) / 1000; + var speedMbps = elapsed > 0 ? (e.loaded / 1024 / 1024) / elapsed : 0; + var remaining = speedMbps > 0 ? ((e.total - e.loaded) / 1024 / 1024) / speedMbps : 0; + + var speedText = speedMbps >= 1 + ? speedMbps.toFixed(1) + ' МБ/с' + : (speedMbps * 1024).toFixed(0) + ' КБ/с'; + + var remainText = ''; + if (remaining > 0 && percent < 100) { + if (remaining < 60) { + remainText = ' — осталось ~' + Math.ceil(remaining) + ' сек'; + } else { + remainText = ' — осталось ~' + Math.ceil(remaining / 60) + ' мин'; + } + } + + var loadedMb = (e.loaded / 1024 / 1024).toFixed(1); + var totalMb = (e.total / 1024 / 1024).toFixed(1); + $text.text(loadedMb + ' / ' + totalMb + ' МБ · ' + speedText + remainText); + } + }); + + xhr.upload.addEventListener('loadend', function () { + $bar.css('width', '100%').text('100%'); + $bar.removeClass('progress-bar-animated'); + $text.text('Файлы загружены. Обработка на сервере...'); + }); + xhr.open('POST', form.action, true); xhr.onload = function () { + window._uploadInProgress = false; + $progressWrap.hide(); if (xhr.status === 200) { var responseURL = xhr.responseURL || ''; if (responseURL && responseURL !== window.location.href) { @@ -171,10 +231,19 @@ function submitFormWithXHR(yiiform) { }; xhr.onerror = function () { + window._uploadInProgress = false; + $progressWrap.hide(); alert('Ошибка сети. Проверьте подключение и попробуйте снова.'); submitBtn.prop('disabled', false).text(originalText); }; + xhr.ontimeout = function () { + window._uploadInProgress = false; + $progressWrap.hide(); + alert('Таймаут загрузки. Файлы слишком большие для текущего соединения.'); + submitBtn.prop('disabled', false).text(originalText); + }; + xhr.send(formData); }