feat(flashcards): ИИ-генерация карточек по теме/тексту с предпросмотром в текущую колоду
This commit is contained in:
@@ -398,6 +398,7 @@
|
||||
Колоды
|
||||
</button>
|
||||
<h1 class="fc-title" id="cards-deck-title">Название колоды</h1>
|
||||
<button class="fc-btn fc-btn-ghost" id="cards-ai-btn" onclick="openAiGenModal()">Сгенерировать ИИ</button>
|
||||
<button class="fc-btn fc-btn-ghost" onclick="openBulkModal()">Добавить список</button>
|
||||
<button class="fc-btn fc-btn-primary" id="cards-study-btn" onclick="startStudy()">Начать изучение</button>
|
||||
</div>
|
||||
@@ -536,6 +537,29 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── AI generate Modal ── -->
|
||||
<div class="fc-modal" id="modal-aigen">
|
||||
<div class="fc-modal-bg" onclick="closeModal('modal-aigen')"></div>
|
||||
<div class="fc-modal-box" style="max-width:560px">
|
||||
<div class="fc-modal-title">Сгенерировать карточки ИИ</div>
|
||||
<div class="fc-modal-field">
|
||||
<div class="fc-modal-label">Тема или текст</div>
|
||||
<textarea class="fc-modal-input" id="aigen-text" rows="6" style="resize:vertical"
|
||||
placeholder="Например: Теорема Пифагора — или вставьте параграф / конспект, по которому сделать карточки"></textarea>
|
||||
</div>
|
||||
<div class="fc-modal-field" style="display:flex;align-items:center;gap:10px">
|
||||
<span class="fc-modal-label" style="margin:0">Сколько карточек</span>
|
||||
<select class="fc-modal-input" id="aigen-count" style="width:auto;padding:8px 12px">
|
||||
<option>4</option><option selected>6</option><option>8</option><option>10</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="fc-modal-actions">
|
||||
<button class="fc-btn fc-btn-ghost" onclick="closeModal('modal-aigen')">Отмена</button>
|
||||
<button class="fc-btn fc-btn-primary" id="aigen-btn" onclick="runAiGen()">Сгенерировать</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Formula (KaTeX) Modal ── -->
|
||||
<div class="fc-modal" id="modal-formula">
|
||||
<div class="fc-modal-bg" onclick="closeModal('modal-formula')"></div>
|
||||
@@ -1204,6 +1228,41 @@ async function saveBulk() {
|
||||
closeModal('modal-bulk');
|
||||
}
|
||||
|
||||
/* ════ Генерация карточек ИИ (тема/текст → предпросмотр bulk → текущая колода) ════
|
||||
Переиспользует экран предпросмотра bulk-импорта: ИИ заполняет _bulkCards,
|
||||
пользователь правит и сохраняет в текущую колоду через saveBulk(). */
|
||||
function openAiGenModal() {
|
||||
if (!_curDeck) { LS.toast('Сначала откройте колоду', 'error'); return; }
|
||||
document.getElementById('aigen-text').value = '';
|
||||
document.getElementById('modal-aigen').classList.add('open');
|
||||
setTimeout(() => { try { document.getElementById('aigen-text').focus(); } catch (e) {} }, 50);
|
||||
}
|
||||
|
||||
async function runAiGen() {
|
||||
const text = document.getElementById('aigen-text').value.trim();
|
||||
if (text.length < 3) { LS.toast('Введите тему или текст'); return; }
|
||||
const count = Number(document.getElementById('aigen-count').value) || 6;
|
||||
const btn = document.getElementById('aigen-btn');
|
||||
btn.disabled = true; btn.textContent = 'Генерирую…';
|
||||
try {
|
||||
const r = await LS.assistantFlashcards(text, (_curDeck && _curDeck.title) || 'Карточки', count);
|
||||
const cards = (r && r.cards) || [];
|
||||
if (!cards.length) throw new Error('ИИ не вернул карточек');
|
||||
_bulkCards = cards.map(c => ({ front: c.front || '', back: c.back || '', front_image: '', back_image: '' }));
|
||||
closeModal('modal-aigen');
|
||||
// открыть bulk-модалку сразу на шаге предпросмотра
|
||||
document.getElementById('bulk-text').value = '';
|
||||
document.getElementById('bulk-step-text').style.display = 'none';
|
||||
document.getElementById('bulk-step-preview').style.display = '';
|
||||
document.getElementById('modal-bulk').classList.add('open');
|
||||
renderBulkPreview();
|
||||
} catch (e) {
|
||||
LS.toast(e && e.message ? ('ИИ: ' + e.message) : 'Не удалось сгенерировать', 'error');
|
||||
} finally {
|
||||
btn.disabled = false; btn.textContent = 'Сгенерировать';
|
||||
}
|
||||
}
|
||||
|
||||
/* ════ Formula insert (KaTeX) ════
|
||||
Палитра символов перенесена из редактора теории (lesson-editor.html).
|
||||
Текст карточки свободный — вставляем \( … \) (в строке) или \[ … \] (блоком)
|
||||
|
||||
Reference in New Issue
Block a user