From 26eabf0cfaf568ada591e79baa2e2664c0b6e025 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Fri, 27 Mar 2026 17:16:57 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20Base64=20encoding=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20JSON=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B2=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Используем base64_encode() в Blade ✅ Используем atob() + JSON.parse() в JavaScript ✅ Обработка null значений для matching/ordering Co-authored-by: Qwen-Coder --- .../views/admin/questions/index.blade.php | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/resources/views/admin/questions/index.blade.php b/resources/views/admin/questions/index.blade.php index a746205..c6a4947 100644 --- a/resources/views/admin/questions/index.blade.php +++ b/resources/views/admin/questions/index.blade.php @@ -35,10 +35,10 @@ + data-question-text="{{ base64_encode($question->question_text) }}" + data-answers="{{ base64_encode($question->answers->toJson()) }}" + data-matching-pairs="{{ base64_encode($question->matchingPairs->toJson()) }}" + data-ordering-items="{{ base64_encode($question->orderingItems->toJson()) }}"> {{ Str::limit(strip_tags($question->question_text), 100) }} @@ -89,10 +89,10 @@ document.addEventListener('DOMContentLoaded', function() { previewModal.addEventListener('show.bs.modal', function(event) { const button = event.relatedTarget; const questionType = button.getAttribute('data-question-type'); - const questionText = button.getAttribute('data-question-text'); - const answers = JSON.parse(button.getAttribute('data-answers')); - const matchingPairs = JSON.parse(button.getAttribute('data-matching-pairs') || '[]'); - const orderingItems = JSON.parse(button.getAttribute('data-ordering-items') || '[]'); + const questionText = atob(button.getAttribute('data-question-text')); + const answers = JSON.parse(atob(button.getAttribute('data-answers'))); + const matchingPairs = JSON.parse(atob(button.getAttribute('data-matching-pairs') || 'bnVsbA==')); + const orderingItems = JSON.parse(atob(button.getAttribute('data-ordering-items') || 'bnVsbA==')); // Отображаем текст вопроса document.getElementById('modalQuestionText').innerHTML = questionText; @@ -123,19 +123,27 @@ document.addEventListener('DOMContentLoaded', function() { answersContainer.appendChild(div); }); } else if (questionType === 'matching') { - let html = ''; - matchingPairs.forEach((pair, index) => { - html += ``; - }); - html += '
Левая частьПравая часть
${pair.left_text}${pair.right_text}
'; - answersContainer.innerHTML = html; + if (matchingPairs && matchingPairs.length > 0) { + let html = ''; + matchingPairs.forEach((pair, index) => { + html += ``; + }); + html += '
Левая частьПравая часть
${pair.left_text}${pair.right_text}
'; + answersContainer.innerHTML = html; + } else { + answersContainer.innerHTML = '

Нет пар для соответствия

'; + } } else if (questionType === 'ordering') { - let html = '
    '; - orderingItems.sort((a, b) => a.correct_order - b.correct_order).forEach((item, index) => { - html += `
  1. ${index + 1}. ${item.item_text}
  2. `; - }); - html += '
'; - answersContainer.innerHTML = html; + if (orderingItems && orderingItems.length > 0) { + let html = '
    '; + orderingItems.sort((a, b) => a.correct_order - b.correct_order).forEach((item, index) => { + html += `
  1. ${index + 1}. ${item.item_text}
  2. `; + }); + html += '
'; + answersContainer.innerHTML = html; + } else { + answersContainer.innerHTML = '

Нет элементов для сортировки

'; + } } }); });