From 8a520b84fe97a72a7b60e5c5903a211cfcbb46d9 Mon Sep 17 00:00:00 2001 From: dev Date: Wed, 14 Oct 2026 23:45:35 +0300 Subject: [PATCH] =?UTF-8?q?feat(journal):=20=D1=81=D0=BA=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=BD=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=84=D0=BE=D1=82=D0=BE=20=D0=B2=20=D1=81=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/admin.css | 22 ++++++++++++++++++-- public/js/journal.js | 49 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/public/admin.css b/public/admin.css index f10e154..ebde686 100644 --- a/public/admin.css +++ b/public/admin.css @@ -102,7 +102,6 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;b .grid{display:flex;flex-direction:column;gap:12px} .card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:16px;display:flex;gap:16px;align-items:flex-start} -.card img{width:80px;height:80px;border-radius:8px;object-fit:cover;flex-shrink:0;cursor:pointer} .card .info{flex:1;min-width:0} .card .name{font-weight:600;font-size:.95rem} .card .group{color:var(--accent);font-size:.8rem;margin-top:2px} @@ -136,8 +135,27 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;b .view-toggle button.active{background:var(--accent);color:#fff} .journal-cards{display:grid;grid-template-columns:repeat(4,1fr);gap:16px} .journal-card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;display:flex;flex-direction:column;position:relative} -.journal-card img{width:100%;aspect-ratio:4/3;object-fit:cover;cursor:pointer;display:block;flex-shrink:0} .group-badge{position:absolute;top:8px;left:8px;z-index:2;max-width:calc(100% - 16px);background:rgba(0,0,0,.55);backdrop-filter:blur(4px);color:#fff;font-size:.72rem;font-weight:600;line-height:1.3;padding:3px 9px;border-radius:999px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} + +/* --- Индикатор загрузки фото в журнале --- */ +.img-media{position:relative;overflow:hidden;flex-shrink:0;display:block;background:var(--bg)} +.journal-card .img-media{width:100%;aspect-ratio:4/3} +.card > .img-media{width:80px;height:80px;border-radius:8px} +.img-media img{width:100%;height:100%;object-fit:cover;cursor:pointer;display:block;position:relative;z-index:1;border-radius:inherit;transition:opacity .25s ease} +.journal-card > .img-media img.img-load{opacity:0} +.card > .img-media img.img-load{opacity:0} +.img-media img.img-loaded{opacity:1} +.img-media .img-skeleton{position:absolute;inset:0;z-index:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;background:var(--bg);color:var(--muted);font-size:.62rem;text-align:center;padding:4px;line-height:1.2} +.img-media .img-skeleton::before{content:'';position:absolute;inset:0;background:linear-gradient(100deg,transparent 20%,rgba(37,99,235,.09) 50%,transparent 80%);background-size:220% 100%;animation:imgShimmer 1.4s ease-in-out infinite} +.img-media .img-skeleton .img-spin{position:relative;width:22px;height:22px;border-radius:50%;border:2px solid var(--border);border-top-color:var(--accent);animation:spin .7s linear infinite;flex-shrink:0} +.card > .img-media .img-skeleton .img-spin{width:16px;height:16px;border-width:2px} +.img-media .img-skeleton span{position:relative} +.img-media img.img-error{opacity:0} +.img-media img.img-error ~ .img-skeleton::before{animation:none} +.img-media img.img-error ~ .img-skeleton .img-spin{display:none} +.img-media img.img-error ~ .img-skeleton{color:var(--muted)} +@keyframes imgShimmer{from{background-position:120% 0}to{background-position:-120% 0}} +@media(prefers-reduced-motion:reduce){.img-media .img-skeleton::before,.img-media .img-skeleton .img-spin{animation:none}} .journal-card .no-photo{aspect-ratio:4/3;background:var(--bg);display:flex;align-items:center;justify-content:center;flex-shrink:0} .journal-card .no-photo svg{width:64%;height:64%;color:#c7cbd0} .journal-card .no-photo svg *{fill:currentColor} diff --git a/public/js/journal.js b/public/js/journal.js index 4c9a0e8..7a9c1a2 100644 --- a/public/js/journal.js +++ b/public/js/journal.js @@ -49,6 +49,10 @@ function mainPhotoPath(e) { return null; } +function journalImgHTML(mp) { + return `
Загрузка…
`; +} + const REPORT_CARD_FIELDS = [ { key: 'photo', label: 'Фото' }, { key: 'lastname', label: 'Фамилия' }, @@ -251,7 +255,7 @@ function gridEntryHTML(e) { const mp = mainPhotoPath(e); return `
- ${mp ? `` : ''} + ${mp ? journalImgHTML(mp) : ''}
${esc(e.student_name)}
${esc(e.group_name)}${e.module_name ? ' · ' + esc(e.module_name) : ''}
@@ -272,7 +276,7 @@ function cardEntryHTML(e) { return `
${mp - ? `` + ? journalImgHTML(mp) : `
`} ${e.group_name ? `${esc(e.group_name)}` : ''} ${e.module_name ? `${esc(e.module_name)}` : ''} @@ -320,6 +324,45 @@ function renderGrid() { el.style.animationDelay = `${Math.min(i * 45, 500)}ms`; }); renderIcons(); + settleJournalThumbs(grid); +} + +function settleJournalThumbs(root) { + if (!root) return; + root.querySelectorAll('.img-media img.img-load, .img-media img.img-error').forEach((img) => { + if (img.complete && img.naturalWidth > 0) { + img.classList.remove('img-load', 'img-error'); + img.classList.add('img-loaded'); + } else if (img.complete && img.naturalWidth === 0) { + img.classList.remove('img-load'); + img.classList.add('img-error'); + const sk = img.parentElement && img.parentElement.querySelector('.img-skeleton'); + if (sk) sk.innerHTML = 'Нет фото'; + } + }); +} + +function bindJournalThumbLoading() { + const grid = document.getElementById('grid'); + if (!grid) return; + const settle = (img) => { + if (!img || !img.classList) return; + img.classList.remove('img-load', 'img-error'); + img.classList.add('img-loaded'); + }; + const fail = (img) => { + if (!img || !img.classList) return; + img.classList.remove('img-load'); + img.classList.add('img-error'); + const sk = img.parentElement && img.parentElement.querySelector('.img-skeleton'); + if (sk) sk.innerHTML = 'Нет фото'; + }; + grid.addEventListener('load', (e) => { + if (e.target.tagName === 'IMG') settle(e.target); + }, true); + grid.addEventListener('error', (e) => { + if (e.target.tagName === 'IMG') fail(e.target); + }, true); } function refreshEntryCardDom(e) { @@ -333,6 +376,7 @@ function refreshEntryCardDom(e) { fresh.style.animationDelay = ''; card.replaceWith(fresh); renderIcons(); + settleJournalThumbs(fresh); } async function refreshEntryCard(id) { @@ -1953,6 +1997,7 @@ document.getElementById('linkCopyBtn').addEventListener('click', copyLink); (async () => { if (await checkAuth()) { buildSidebar(document.body.dataset.page); + bindJournalThumbLoading(); document.querySelectorAll('#viewToggle button').forEach(b => { b.classList.toggle('active', b.dataset.view === view); });