reader-catalog.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="catalog-container" v-if="show">
  3. <view class="catalog-header">
  4. <text class="title">目录</text>
  5. <text class="close-btn" @tap="onClose">×</text>
  6. </view>
  7. <scroll-view scroll-y class="chapter-list">
  8. <view
  9. v-for="chapter in chapters"
  10. :key="chapter.id"
  11. class="chapter-item"
  12. :class="{ active: currentChapterId === chapter.id }"
  13. @tap="onSelect(chapter)"
  14. >
  15. <text>{{ chapter.title }}</text>
  16. </view>
  17. </scroll-view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'ReaderCatalog',
  23. props: {
  24. show: {
  25. type: Boolean,
  26. default: false
  27. },
  28. chapters: {
  29. type: Array,
  30. default: () => []
  31. },
  32. currentChapterId: {
  33. type: Number,
  34. default: 1
  35. }
  36. },
  37. methods: {
  38. onClose() {
  39. this.$emit('close')
  40. },
  41. onSelect(chapter) {
  42. this.$emit('select', chapter)
  43. }
  44. }
  45. }
  46. </script>
  47. <style scoped>
  48. .catalog-container {
  49. position: fixed;
  50. top: 0;
  51. left: 0;
  52. width: 80%;
  53. height: 100%;
  54. background-color: #fff;
  55. z-index: 300;
  56. display: flex;
  57. flex-direction: column;
  58. box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  59. }
  60. .catalog-header {
  61. display: flex;
  62. justify-content: space-between;
  63. align-items: center;
  64. padding: 30rpx;
  65. border-bottom: 1px solid #eee;
  66. }
  67. .title {
  68. font-size: 36rpx;
  69. font-weight: bold;
  70. }
  71. .close-btn {
  72. font-size: 40rpx;
  73. padding: 0 20rpx;
  74. }
  75. .chapter-list {
  76. flex: 1;
  77. padding: 20rpx 0;
  78. }
  79. .chapter-item {
  80. padding: 30rpx;
  81. border-bottom: 1px solid #f5f5f5;
  82. font-size: 30rpx;
  83. }
  84. .chapter-item.active {
  85. color: #007aff;
  86. background-color: #f0f0f0;
  87. }
  88. </style>