From 9fd3ef1fc80de69995fe5b877f83f728a61e6f92 Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Tue, 17 Feb 2026 13:03:08 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?utf8?q?=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80?= =?utf8?q?=D1=83=D0=B7=D0=BA=D1=83=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= =?utf8?q?=20=D0=B2=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=20?= =?utf8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/web/js/notification.js | 7 ++- erp24/web/js/validate/validateForm.js | 69 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) 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); } -- 2.39.5