Compare commits

...
2 Commits
Author SHA1 Message Date
dev ca2ead0afc chore: add html-to-image dependency 2026-10-29 11:23:23 +03:00
dev a97455030a feat: add report card screenshot functionality
- Add screenshot button in journal HTML
- Implement downloadReportCardScreenshot() with html-to-image
- Add styles for screenshot modal
- New dependency: html-to-image.js
2026-10-29 11:23:16 +03:00
4 changed files with 63 additions and 0 deletions
+5
View File
@@ -1226,6 +1226,11 @@ body.report-card-open .report-fields{display:flex}
.report-fields__actions{display:flex;gap:10px}
.report-fields__link{background:none;border:none;color:var(--accent);cursor:pointer;font-size:.78rem;font-weight:600;padding:0;font-family:inherit}
.report-fields__link:hover{text-decoration:underline}
.report-fields__shot{display:flex;align-items:center;justify-content:center;gap:8px;width:100%;margin-top:10px;background:var(--accent);color:#fff;border:none;border-radius:10px;padding:9px 12px;font-family:inherit;font-size:.82rem;font-weight:700;cursor:pointer}
.report-fields__shot svg{width:16px;height:16px;flex:none}
.report-fields__shot:hover{filter:brightness(1.06)}
.report-fields__shot[disabled]{opacity:.6;cursor:default}
.report-fields__shot-text{white-space:nowrap}
.report-fields__list{display:flex;flex-direction:column;gap:2px;max-height:min(56vh,420px);overflow:auto}
.report-fields__item{
display:flex;
+5
View File
@@ -585,6 +585,10 @@
<button type="button" class="report-fields__link" id="reportFieldsNone">Скрыть</button>
</div>
</div>
<button type="button" class="report-fields__shot" id="reportScreenshotBtn">
<i data-lucide="camera"></i>
<span class="report-fields__shot-text">Скриншот карточки</span>
</button>
<div class="report-fields__list" id="reportFieldsList"></div>
<div class="report-fields__row">
<label class="report-fields__toggle">
@@ -617,6 +621,7 @@
<script src="vendor/lucide.min.js"></script>
<script src="js/datetime.js"></script>
<script src="admin.js"></script>
<script src="vendor/html-to-image.js"></script>
<script src="js/journal.js"></script>
</body>
</html>
+51
View File
@@ -3034,6 +3034,57 @@ reportFieldsPanel.addEventListener('change', e => {
});
document.getElementById('reportFieldsAll').addEventListener('click', () => setReportCardFields(REPORT_CARD_FIELDS.map(f => f.key)));
document.getElementById('reportFieldsNone').addEventListener('click', () => setReportCardFields([]));
function reportScreenshotLabel() {
return document.querySelector('#reportScreenshotBtn .report-fields__shot-text');
}
async function downloadReportCardScreenshot() {
const modal = document.getElementById('reportCardModal');
const card = modal ? modal.querySelector('.student-card') : null;
const btn = document.getElementById('reportScreenshotBtn');
const label = reportScreenshotLabel();
if (!card || !modal.classList.contains('open') || !window.htmlToImage || !btn || btn.disabled) return;
const oldLabel = label ? label.textContent : '';
btn.disabled = true;
if (label) label.textContent = 'Готовим...';
const rect = card.getBoundingClientRect();
if (!rect.width || !rect.height) { btn.disabled = false; if (label) label.textContent = oldLabel; return; }
const holder = document.createElement('div');
holder.style.cssText = 'position:fixed;left:-10000px;top:0;';
const stage = document.createElement('div');
const clone = card.cloneNode(true);
clone.removeAttribute('id');
clone.querySelectorAll('[id]').forEach(n => n.removeAttribute('id'));
clone.style.boxShadow = '0 6px 16px rgba(39,91,160,.18)';
stage.style.cssText = `position:relative;left:0;top:0;width:${Math.ceil(rect.width) + 20}px;height:${Math.ceil(rect.height) + 20}px;padding:10px;box-sizing:border-box;background:linear-gradient(160deg,#E8F2FF 0%,#F6FAFF 55%,#D9EAFE 100%);border-radius:30px;`;
try {
stage.appendChild(clone);
holder.appendChild(stage);
document.body.appendChild(holder);
const blob = await window.htmlToImage.toBlob(stage, { pixelRatio: 2, skipFonts: true });
if (!blob) throw new Error('empty blob');
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const nm = (document.getElementById('reportCardName').textContent || '').trim().replace(/\s+/g, ' ').replace(/[\\/:*?"<>|]+/g, '').slice(0, 60);
a.href = url;
a.download = `card-${nm || 'student'}-${todayIso()}.png`;
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(() => URL.revokeObjectURL(url), 4000);
showToast('Скриншот карточки сохранён');
} catch (err) {
console.error('report card screenshot failed', err);
showToast('Не удалось сделать скриншот', true);
} finally {
holder.remove();
btn.disabled = false;
if (label) label.textContent = oldLabel;
}
}
document.getElementById('reportScreenshotBtn').addEventListener('click', downloadReportCardScreenshot);
document.addEventListener('click', e => {
if (!reportFieldsRoot.contains(e.target)) setReportFieldsOpen(false);
});
File diff suppressed because one or more lines are too long