├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reader.vue 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="reader-container" :style="readerStyles">
  3. <!-- 顶部导航 -->
  4. <view class="reader-header">
  5. <uni-icons type="arrowleft" size="28" color="#fff" @click="goBack"></uni-icons>
  6. <text class="novel-title">{{ novelTitle }}</text>
  7. <view class="header-actions">
  8. <uni-icons type="more" size="28" color="#fff"></uni-icons>
  9. </view>
  10. </view>
  11. <!-- 阅读区域 -->
  12. <scroll-view scroll-y class="reader-content" :scroll-top="scrollTop" @scroll="onScroll">
  13. <view class="chapter-title">{{ chapterDetail.title }}</view>
  14. <rich-text :nodes="chapterContent" class="content-text"></rich-text>
  15. </scroll-view>
  16. <!-- 底部操作栏 -->
  17. <view class="reader-footer">
  18. <view class="progress">
  19. <text>{{ chapterDetail.chapterNumber }}/{{ totalChapters }}</text>
  20. <text>{{ progress }}%</text>
  21. </view>
  22. <view class="actions">
  23. <button class="action-btn" @click="prevChapter">
  24. <uni-icons type="arrow-up" size="24"></uni-icons>
  25. <text>上一章</text>
  26. </button>
  27. <button class="action-btn" @click="toggleMenu">
  28. <uni-icons type="list" size="24"></uni-icons>
  29. <text>目录</text>
  30. </button>
  31. <button class="action-btn" @click="toggleSettings">
  32. <uni-icons type="gear" size="24"></uni-icons>
  33. <text>设置</text>
  34. </button>
  35. <button class="action-btn" @click="nextChapter">
  36. <uni-icons type="arrow-down" size="24"></uni-icons>
  37. <text>下一章</text>
  38. </button>
  39. </view>
  40. </view>
  41. <!-- 目录抽屉 -->
  42. <uni-drawer ref="drawer" mode="right" :width="300">
  43. <view class="drawer-content">
  44. <text class="drawer-title">目录</text>
  45. <scroll-view scroll-y class="chapter-list">
  46. <view
  47. v-for="chapter in chapters"
  48. :key="chapter.id"
  49. class="chapter-item"
  50. :class="{ active: chapter.id === chapterDetail.id }"
  51. @click="selectChapter(chapter)"
  52. >
  53. <text>{{ chapter.chapterNumber }}. {{ chapter.title }}</text>
  54. </view>
  55. </scroll-view>
  56. </view>
  57. </uni-drawer>
  58. </view>
  59. </template>
  60. <script>
  61. import novelService from '@/services/novelService'
  62. export default {
  63. data() {
  64. return {
  65. novelId: null,
  66. chapterId: null,
  67. novelTitle: '',
  68. chapterDetail: {},
  69. chapterContent: '',
  70. chapters: [],
  71. totalChapters: 0,
  72. progress: 0,
  73. scrollTop: 0,
  74. readerStyles: {
  75. fontSize: '32rpx',
  76. lineHeight: '1.8',
  77. backgroundColor: '#f8f2e0',
  78. color: '#333'
  79. }
  80. }
  81. },
  82. async onLoad(options) {
  83. this.novelId = options.novelId
  84. this.chapterId = options.chapterId || 1
  85. await this.loadNovelData()
  86. await this.loadChapter()
  87. },
  88. methods: {
  89. async loadNovelData() {
  90. // 获取小说基本信息
  91. const novel = await novelService.getNovelDetail(this.novelId)
  92. this.novelTitle = novel.title
  93. // 获取章节列表
  94. this.chapters = await novelService.getChapters(this.novelId)
  95. this.totalChapters = this.chapters.length
  96. },
  97. async loadChapter() {
  98. uni.showLoading({ title: '加载中...' })
  99. try {
  100. const chapter = await novelService.getChapterContent(this.novelId, this.chapterId)
  101. this.chapterDetail = chapter
  102. // 处理章节内容
  103. this.chapterContent = this.formatContent(chapter.content)
  104. // 计算阅读进度
  105. this.progress = Math.round((this.chapterId / this.totalChapters) * 100)
  106. // 保存阅读进度
  107. this.saveReadingProgress()
  108. } catch (error) {
  109. uni.showToast({
  110. title: '加载章节失败',
  111. icon: 'none'
  112. })
  113. } finally {
  114. uni.hideLoading()
  115. }
  116. },
  117. formatContent(content) {
  118. // 将文本内容转换为带格式的HTML
  119. const paragraphs = content.split('\n\n')
  120. return paragraphs.map(p => `<p>${p}</p>`).join('')
  121. },
  122. saveReadingProgress() {
  123. // 保存到本地
  124. uni.setStorageSync('readingProgress', {
  125. novelId: this.novelId,
  126. chapterId: this.chapterId
  127. })
  128. // 如果已登录,同步到服务器
  129. if (uni.getStorageSync('token')) {
  130. this.$http.post('/reading/progress', {
  131. novelId: this.novelId,
  132. chapterId: this.chapterId
  133. })
  134. }
  135. },
  136. prevChapter() {
  137. if (this.chapterId > 1) {
  138. this.chapterId--
  139. this.loadChapter()
  140. } else {
  141. uni.showToast({
  142. title: '已经是第一章',
  143. icon: 'none'
  144. })
  145. }
  146. },
  147. nextChapter() {
  148. if (this.chapterId < this.totalChapters) {
  149. this.chapterId++
  150. this.loadChapter()
  151. } else {
  152. uni.showToast({
  153. title: '已是最新章节',
  154. icon: 'none'
  155. })
  156. }
  157. },
  158. selectChapter(chapter) {
  159. this.chapterId = chapter.id
  160. this.$refs.drawer.close()
  161. this.loadChapter()
  162. },
  163. toggleMenu() {
  164. this.$refs.drawer.open()
  165. },
  166. toggleSettings() {
  167. uni.navigateTo({
  168. url: '/pages/reader/settings'
  169. })
  170. },
  171. goBack() {
  172. uni.navigateBack()
  173. },
  174. onScroll(e) {
  175. // 记录滚动位置
  176. this.scrollTop = e.detail.scrollTop
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped>
  182. .reader-container {
  183. position: relative;
  184. height: 100vh;
  185. padding: 20rpx;
  186. box-sizing: border-box;
  187. }
  188. .reader-header {
  189. position: absolute;
  190. top: 0;
  191. left: 0;
  192. right: 0;
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. padding: 20rpx 30rpx;
  197. background: rgba(0, 0, 0, 0.7);
  198. color: white;
  199. z-index: 100;
  200. }
  201. .novel-title {
  202. font-size: 32rpx;
  203. max-width: 60%;
  204. overflow: hidden;
  205. text-overflow: ellipsis;
  206. white-space: nowrap;
  207. }
  208. .reader-content {
  209. height: calc(100vh - 200rpx);
  210. padding-top: 80rpx;
  211. padding-bottom: 120rpx;
  212. }
  213. .chapter-title {
  214. font-size: 40rpx;
  215. font-weight: bold;
  216. text-align: center;
  217. margin-bottom: 40rpx;
  218. color: #2a5caa;
  219. }
  220. .content-text {
  221. font-size: 32rpx;
  222. line-height: 1.8;
  223. }
  224. .reader-footer {
  225. position: absolute;
  226. bottom: 0;
  227. left: 0;
  228. right: 0;
  229. background: rgba(255, 255, 255, 0.9);
  230. padding: 20rpx;
  231. border-top: 1rpx solid #eee;
  232. }
  233. .progress {
  234. display: flex;
  235. justify-content: space-between;
  236. font-size: 28rpx;
  237. color: #666;
  238. margin-bottom: 20rpx;
  239. }
  240. .actions {
  241. display: flex;
  242. justify-content: space-between;
  243. }
  244. .action-btn {
  245. display: flex;
  246. flex-direction: column;
  247. align-items: center;
  248. background: none;
  249. border: none;
  250. font-size: 24rpx;
  251. padding: 10rpx;
  252. }
  253. .drawer-content {
  254. padding: 30rpx;
  255. }
  256. .drawer-title {
  257. font-size: 36rpx;
  258. font-weight: bold;
  259. display: block;
  260. margin-bottom: 30rpx;
  261. border-bottom: 1rpx solid #eee;
  262. padding-bottom: 20rpx;
  263. }
  264. .chapter-list {
  265. height: calc(100vh - 150rpx);
  266. }
  267. .chapter-item {
  268. padding: 20rpx 10rpx;
  269. border-bottom: 1rpx solid #f0f0f0;
  270. font-size: 28rpx;
  271. }
  272. .chapter-item.active {
  273. color: #2a5caa;
  274. font-weight: bold;
  275. }
  276. </style>