read.blade.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. @extends('library.layouts.app')
  2. @section('title', '阅读: ' . $book['title'])
  3. @section('content')
  4. <div class="page-body">
  5. <div class="container-xl">
  6. <div class="row">
  7. <div class="col-md-3">
  8. <div class="card position-sticky" style="top: 1rem;">
  9. <div class="card-header">
  10. <h4 class="card-title">目录</h4>
  11. </div>
  12. <div class="card-body p-0">
  13. <div class="list-group list-group-flush">
  14. @if(isset($book['contents']))
  15. @foreach($book['contents'] as $chapter)
  16. <a href="#chapter-{{ $loop->iteration }}"
  17. class="list-group-item list-group-item-action">
  18. {{ $chapter['title'] }}
  19. </a>
  20. @endforeach
  21. @endif
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="col-md-9">
  27. <div class="card">
  28. <div class="card-header d-flex justify-content-between align-items-center">
  29. <div>
  30. <h3 class="card-title">{{ $book['title'] }}</h3>
  31. <div class="text-muted">{{ $book['author'] }}</div>
  32. </div>
  33. <div class="btn-group">
  34. <button class="btn btn-outline-secondary btn-sm" onclick="adjustFontSize(-1)">
  35. <svg class="icon" width="24" height="24">
  36. <use xlink:href="#tabler-minus"></use>
  37. </svg>
  38. </button>
  39. <button class="btn btn-outline-secondary btn-sm" onclick="adjustFontSize(1)">
  40. <svg class="icon" width="24" height="24">
  41. <use xlink:href="#tabler-plus"></use>
  42. </svg>
  43. </button>
  44. </div>
  45. </div>
  46. <div class="card-body" id="reading-content" style="font-size: 16px; line-height: 1.8;">
  47. @if(isset($book['contents']))
  48. @foreach($book['contents'] as $chapter)
  49. <div id="chapter-{{ $loop->iteration }}" class="mb-5">
  50. <h4 class="mb-3">{{ $chapter['title'] }}</h4>
  51. <div class="text-justify">
  52. {!! nl2br(e($chapter['content'])) !!}
  53. </div>
  54. </div>
  55. @endforeach
  56. @else
  57. <div class="text-justify">
  58. <p>这是《{{ $book['title'] }}》的正文内容。在这里显示完整的书籍内容,支持章节导航和字体大小调整。</p>
  59. <p>本书由{{ $book['author'] }}著,是巴利语系佛教的重要典籍之一。内容深奥,值得反复研读。</p>
  60. </div>
  61. @endif
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. @push('scripts')
  69. <script>
  70. function adjustFontSize(delta) {
  71. const content = document.getElementById('reading-content');
  72. const currentSize = parseInt(window.getComputedStyle(content).fontSize);
  73. const newSize = Math.max(12, Math.min(24, currentSize + delta));
  74. content.style.fontSize = newSize + 'px';
  75. }
  76. // 平滑滚动
  77. document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  78. anchor.addEventListener('click', function(e) {
  79. e.preventDefault();
  80. const target = document.querySelector(this.getAttribute('href'));
  81. if (target) {
  82. target.scrollIntoView({
  83. behavior: 'smooth',
  84. block: 'start'
  85. });
  86. }
  87. });
  88. });
  89. </script>
  90. @endpush
  91. @endsection