timeline.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {% extends "base.html" %}
  2. {% block title %}时间线 - 满意错题本{% endblock %}
  3. {% block page_title %}时间线{% endblock %}
  4. {% block content %}
  5. <!-- Date nav -->
  6. <div class="bg-white rounded-2xl border border-gray-100 p-4 mb-6 flex items-center gap-3">
  7. {% if prev_date %}
  8. <a href="?date={{ prev_date }}" class="flex-shrink-0 w-9 h-9 rounded-xl bg-gray-50 hover:bg-gray-100 flex items-center justify-center text-gray-500 transition" title="前一天">
  9. <i class="fa-solid fa-chevron-left text-sm"></i>
  10. </a>
  11. {% else %}
  12. <span class="flex-shrink-0 w-9 h-9 rounded-xl bg-gray-50 flex items-center justify-center text-gray-200">
  13. <i class="fa-solid fa-chevron-left text-sm"></i>
  14. </span>
  15. {% endif %}
  16. <div class="flex items-center gap-2 overflow-x-auto flex-1 pb-1">
  17. {% for d in all_dates %}
  18. <a href="?date={{ d }}" class="date-chip flex-shrink-0 px-3 py-1.5 rounded-xl text-xs font-medium transition {% if d == current_date %}bg-primary text-white shadow-sm{% else %}bg-gray-50 text-gray-500 hover:bg-gray-100{% endif %}">
  19. {{ d }}
  20. </a>
  21. {% endfor %}
  22. </div>
  23. {% if next_date %}
  24. <a href="?date={{ next_date }}" class="flex-shrink-0 w-9 h-9 rounded-xl bg-gray-50 hover:bg-gray-100 flex items-center justify-center text-gray-500 transition" title="后一天">
  25. <i class="fa-solid fa-chevron-right text-sm"></i>
  26. </a>
  27. {% else %}
  28. <span class="flex-shrink-0 w-9 h-9 rounded-xl bg-gray-50 flex items-center justify-center text-gray-200">
  29. <i class="fa-solid fa-chevron-right text-sm"></i>
  30. </span>
  31. {% endif %}
  32. <input type="date" value="{{ current_date }}" onchange="location.href='/timeline?date='+this.value"
  33. class="border border-gray-200 rounded-xl px-3 py-1.5 text-xs focus:outline-none focus:ring-2 focus:ring-primary/30 text-gray-500 flex-shrink-0">
  34. </div>
  35. {% if timeline_data %}
  36. <div class="space-y-5">
  37. {% for item in timeline_data %}
  38. <div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden" data-subject="{{ item.subject.id }}">
  39. <div class="px-5 py-3.5 flex items-center gap-3 border-b border-gray-50">
  40. <span class="w-3 h-3 rounded-full flex-shrink-0" style="background-color:{{ item.subject.color }};box-shadow:0 0 0 3px {{ item.subject.color }}20"></span>
  41. <span class="font-bold text-gray-800 text-sm">{{ item.subject.name }}</span>
  42. <span class="text-xs text-gray-400 ml-auto" id="count-{{ item.subject.id }}">加载中...</span>
  43. <a href="/subject/{{ item.subject.id }}?date={{ current_date }}" class="text-xs text-primary hover:underline ml-2 flex items-center gap-1"><i class="fa-solid fa-arrow-right"></i>进入科目</a>
  44. </div>
  45. {% set txt_list = [] %}
  46. {% set img_list = [] %}
  47. {% for img in item.images %}{% if img.filename %}{% set x = img_list.append(img) %}{% else %}{% set x = txt_list.append(img) %}{% endif %}{% endfor %}
  48. <div class="p-4">
  49. {% if img_list %}
  50. <div class="grid grid-cols-5 gap-3 mb-3">
  51. {% for img in img_list %}
  52. <div class="group relative aspect-[3/4] rounded-xl overflow-hidden bg-gray-100 cursor-pointer" onclick="openLightbox('/static/uploads/{{ img.filename }}','{{ img.original_name }}',lbImg{{ item.subject.id }},{{ loop.index0 }})">
  53. <img src="/static/uploads/{{ img.filename }}" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300" loading="lazy">
  54. <div class="absolute inset-0 bg-black/0 group-hover:bg-black/20 transition"></div>
  55. <div class="absolute bottom-1.5 left-1.5 right-1.5">
  56. <p class="text-[10px] text-white/80 truncate px-1 py-0.5 bg-black/30 rounded">{{ img.original_name }}</p>
  57. </div>
  58. </div>
  59. {% endfor %}
  60. </div>
  61. {% endif %}
  62. {% if txt_list %}
  63. <div class="border-t border-gray-50 pt-3 mt-1">
  64. <div class="text-xs text-gray-400 mb-2 flex items-center gap-1"><i class="fa-solid fa-keyboard"></i>{{ txt_list|length }} 条文字记录</div>
  65. <div class="grid grid-cols-5 gap-3">
  66. {% for txt in txt_list %}
  67. <div class="rounded-xl overflow-hidden bg-violet-50 border border-violet-100 cursor-pointer hover:shadow-sm transition" onclick="toggleTimelineAnswer(this)">
  68. <div class="p-3">
  69. <p class="text-xs font-medium text-gray-700 line-clamp-2 leading-relaxed">{{ txt.question[:40] }}</p>
  70. </div>
  71. <div class="timeline-answer hidden px-3 pb-3">
  72. <p class="text-[11px] text-gray-500 leading-relaxed">{{ txt.answer }}</p>
  73. </div>
  74. </div>
  75. {% endfor %}
  76. </div>
  77. </div>
  78. {% endif %}
  79. </div>
  80. <div class="px-5 py-2 bg-gray-50 border-t border-gray-50 flex items-center gap-3">
  81. <span class="text-xs text-gray-400">{{ img_list|length }} 张错题{% if txt_list %} · {{ txt_list|length }} 条文字{% endif %}</span>
  82. </div>
  83. </div>
  84. {% endfor %}
  85. </div>
  86. {% else %}
  87. <div class="bg-white rounded-2xl border border-gray-100 p-16 text-center">
  88. <div class="text-6xl text-gray-200 mb-4"><i class="fa-regular fa-calendar-xmark"></i></div>
  89. <p class="text-gray-400 mb-2">该日期暂无错题记录</p>
  90. <p class="text-sm text-gray-300">请选择其他日期或前往科目页上传错题</p>
  91. </div>
  92. {% endif %}
  93. {% endblock %}
  94. {% block extra_js %}
  95. <script>
  96. {% for item in timeline_data %}
  97. const lbImg{{ item.subject.id }} = [
  98. {% for img in item.images %}{% if img.filename %}" /static/uploads/{{ img.filename }}",{% endif %}
  99. {% endfor %}
  100. ];
  101. {% endfor %}
  102. document.querySelectorAll('[id^="count-"]').forEach(function(el) {
  103. var id = el.id.replace('count-', '');
  104. var items = document.querySelectorAll('#timeline-subject-' + id + ' .timeline-entry');
  105. var imgCount = document.querySelectorAll('#timeline-subject-' + id + ' .img-entry').length;
  106. var txtCount = document.querySelectorAll('#timeline-subject-' + id + ' .txt-entry').length;
  107. if (txtCount > 0 && imgCount > 0) el.textContent = imgCount + ' 张错题 · ' + txtCount + ' 条文字';
  108. else if (txtCount > 0) el.textContent = txtCount + ' 条文字';
  109. else el.textContent = imgCount + ' 张错题';
  110. });
  111. function toggleTimelineAnswer(el) {
  112. var answer = el.querySelector('.timeline-answer');
  113. if (answer) answer.classList.toggle('hidden');
  114. }
  115. </script>
  116. {% endblock %}