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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <view class="reader-container">
  3. <!-- 顶部操作栏 -->
  4. <view class="reader-header">
  5. <view class="left-actions">
  6. <button class="back-btn" @click="goBack">
  7. <uni-icons type="arrowleft" size="24" color="#333"></uni-icons>
  8. </button>
  9. <text class="chapter-title">{{ chapterTitle }}</text>
  10. </view>
  11. <view class="right-actions">
  12. <button class="action-btn" @click="toggleTheme">
  13. <uni-icons type="color" size="20"></uni-icons>
  14. </button>
  15. <button class="action-btn" @click="toggleFontSize">
  16. <uni-icons type="font" size="20"></uni-icons>
  17. </button>
  18. <button class="action-btn" @click="toggleMode">
  19. <uni-icons :type="readingMode === 'scroll' ? 'list' : 'grid'" size="20"></uni-icons>
  20. </button>
  21. </view>
  22. </view>
  23. <!-- 阅读模式选择器 -->
  24. <view v-if="showModeSelector" class="mode-selector">
  25. <button
  26. v-for="mode in readingModes"
  27. :key="mode.value"
  28. :class="['mode-btn', { active: readingMode === mode.value }]"
  29. @click="changeMode(mode.value)"
  30. >
  31. {{ mode.label }}
  32. </button>
  33. </view>
  34. <!-- 字体大小选择器 -->
  35. <view v-if="showFontSizeSelector" class="font-size-selector">
  36. <button class="size-btn" @click="decreaseFontSize">A-</button>
  37. <slider
  38. :value="fontSize"
  39. min="14"
  40. max="24"
  41. step="2"
  42. @change="changeFontSize"
  43. class="font-slider"
  44. />
  45. <button class="size-btn" @click="increaseFontSize">A+</button>
  46. </view>
  47. <!-- 滚动阅读模式 -->
  48. <scroll-view
  49. v-if="readingMode === 'scroll'"
  50. scroll-y
  51. class="scroll-reader"
  52. :style="{ fontSize: fontSize + 'px' }"
  53. :scroll-top="scrollTop"
  54. @scroll="onScroll"
  55. @scrolltolower="loadNextChapter"
  56. >
  57. <rich-text :nodes="formatContent(chapterContent)" />
  58. </scroll-view>
  59. <!-- 翻页阅读模式 -->
  60. <swiper
  61. v-else
  62. :current="currentPage"
  63. circular
  64. class="page-reader"
  65. @change="onPageChange"
  66. >
  67. <swiper-item v-for="(page, index) in paginatedContent" :key="index">
  68. <view :style="{ fontSize: fontSize + 'px', padding: '20px' }">
  69. <rich-text :nodes="page" />
  70. </view>
  71. </swiper-item>
  72. </swiper>
  73. <!-- 底部操作栏 -->
  74. <view class="reader-footer">
  75. <button class="footer-btn" @click="prevChapter">上一章</button>
  76. <button class="footer-btn" @click="showChapterList">目录</button>
  77. <button class="footer-btn" @click="nextChapter">下一章</button>
  78. </view>
  79. <!-- 底部广告 -->
  80. <view v-if="showBottomAd && !isVIP" class="bottom-ad">
  81. <ad :unit-id="bottomAdUnitId" ad-type="feed" />
  82. </view>
  83. </view>
  84. </template>
  85. <script setup>
  86. import { ref, computed, onMounted, watch } from 'vue'
  87. import { useAdManager } from '@/utils/adManager'
  88. import { useUserStore } from '@/stores/user'
  89. import { useThemeStore } from '@/stores/theme'
  90. import { useReadingProgress } from '@/composables/useReadingProgress'
  91. import { cleanNovelContent, paginateContent } from '@/utils/contentUtils'
  92. // 导入清洗工具
  93. import { contentCleaner } from '@/utils/contentCleaner'
  94. //import { useAdManager } from '@/utils/adManager'
  95. import { useVipStore } from '@/stores/vip'
  96. import { cleanMonitor } from '@/utils/cleanMonitor'
  97. import { readingService } from '@/services/readingService'
  98. // 保存阅读进度
  99. const saveProgress = () => {
  100. const progress = {
  101. novelId: props.novelId,
  102. chapterId: props.chapterId,
  103. page: currentPage.value,
  104. scrollTop: lastScrollPosition.value,
  105. timestamp: new Date().toISOString()
  106. }
  107. readingService.saveProgress(progress)
  108. }
  109. // 恢复阅读进度
  110. const restoreReadingPosition = async () => {
  111. const progress = await readingService.getProgress(props.novelId, props.chapterId)
  112. if (progress) {
  113. if (readingMode.value === 'scroll') {
  114. scrollTop.value = progress.scrollTop
  115. } else {
  116. currentPage.value = progress.page
  117. }
  118. }
  119. }
  120. const props = defineProps({
  121. chapterId: {
  122. type: Number,
  123. required: true
  124. },
  125. novelId: {
  126. type: Number,
  127. required: true
  128. },
  129. chapterTitle: {
  130. type: String,
  131. default: '加载中...'
  132. }
  133. })
  134. const emit = defineEmits(['back', 'prev', 'next', 'show-chapters'])
  135. const vipStore = useVipStore()
  136. const { showRewardAd, showFeedAd } = useAdManager()
  137. const userStore = useUserStore()
  138. const themeStore = useThemeStore()
  139. //const { showRewardAd } = useAdManager()
  140. const { saveProgress, loadProgress } = useReadingProgress()
  141. // 阅读状态
  142. const readingMode = ref('scroll') // 'scroll' | 'page'
  143. const readingModes = ref([
  144. { label: '滚动模式', value: 'scroll' },
  145. { label: '翻页模式', value: 'page' }
  146. ])
  147. const showModeSelector = ref(false)
  148. const showFontSizeSelector = ref(false)
  149. const fontSize = ref(18)
  150. const chapterContent = ref('')
  151. const paginatedContent = ref([])
  152. const currentPage = ref(0)
  153. const scrollTop = ref(0)
  154. const lastScrollPosition = ref(0)
  155. const showBottomAd = ref(true)
  156. const bottomAdUnitId = ref('')
  157. const isVIP = computed(() => userStore.isVIP)
  158. // 获取章节内容
  159. const fetchChapterContent = async () => {
  160. try {
  161. const res = await uni.request({
  162. url: `https://php-backend.aiyadianzi.ltd/chapter/${props.chapterId}`,
  163. method: 'GET'
  164. })
  165. // 清洗内容并监控质量
  166. chapterContent.value = cleanMonitor.cleanAndMonitor(
  167. res.data.content,
  168. props.chapterId
  169. )
  170. if (res.statusCode === 200) {
  171. // 清洗内容并移除原始网站信息
  172. chapterContent.value = cleanNovelContent(res.data.content)
  173. // 分页处理
  174. paginatedContent.value = paginateContent(chapterContent.value, 800)
  175. // 恢复阅读位置
  176. restoreReadingPosition()
  177. } else {
  178. throw new Error('章节加载失败')
  179. }
  180. } catch (error) {
  181. uni.showToast({
  182. title: error.message || '加载章节失败',
  183. icon: 'none'
  184. })
  185. }
  186. }
  187. // 恢复阅读位置
  188. const restoreReadingPosition = async () => {
  189. const progress = await loadProgress(props.novelId, props.chapterId)
  190. if (progress) {
  191. if (readingMode.value === 'scroll') {
  192. scrollTop.value = progress.scrollTop
  193. } else {
  194. currentPage.value = progress.page
  195. }
  196. }
  197. }
  198. // 翻页事件处理
  199. const onPageChange = (e) => {
  200. currentPage.value = e.detail.current
  201. saveReadingPosition()
  202. // VIP用户跳过广告
  203. if (vipStore.hasPrivilege('免广告')) return
  204. // 每5页触发广告
  205. if (currentPage.value % 5 === 0) {
  206. showRewardAd(props.chapterId)
  207. }
  208. }
  209. // 滚动事件处理
  210. const onScroll = (e) => {
  211. lastScrollPosition.value = e.detail.scrollTop
  212. saveReadingPosition()
  213. }
  214. // 保存阅读位置
  215. const saveReadingPosition = () => {
  216. saveProgress(props.novelId, props.chapterId, {
  217. page: currentPage.value,
  218. scrollTop: lastScrollPosition.value
  219. })
  220. }
  221. // 切换阅读模式
  222. const toggleMode = () => {
  223. showModeSelector.value = !showModeSelector.value
  224. }
  225. // 改变阅读模式
  226. const changeMode = (mode) => {
  227. readingMode.value = mode
  228. showModeSelector.value = false
  229. saveReadingPosition()
  230. }
  231. // 切换字体大小选择器
  232. const toggleFontSize = () => {
  233. showFontSizeSelector.value = !showFontSizeSelector.value
  234. }
  235. // 改变字体大小
  236. const changeFontSize = (e) => {
  237. fontSize.value = e.detail.value
  238. }
  239. // 增大字体
  240. const increaseFontSize = () => {
  241. if (fontSize.value < 24) fontSize.value += 2
  242. }
  243. // 减小字体
  244. const decreaseFontSize = () => {
  245. if (fontSize.value > 14) fontSize.value -= 2
  246. }
  247. // 切换主题
  248. const toggleTheme = () => {
  249. const themes = Object.keys(themeStore.themes)
  250. const currentIndex = themes.indexOf(themeStore.currentTheme)
  251. const nextIndex = (currentIndex + 1) % themes.length
  252. themeStore.setTheme(themes[nextIndex])
  253. }
  254. // 加载下一章
  255. const loadNextChapter = () => {
  256. emit('next')
  257. }
  258. // 返回
  259. const goBack = () => {
  260. emit('back')
  261. }
  262. // 上一章
  263. const prevChapter = () => {
  264. emit('prev')
  265. }
  266. // 下一章
  267. const nextChapter = () => {
  268. emit('next')
  269. }
  270. // 显示章节列表
  271. const showChapterList = () => {
  272. emit('show-chapters')
  273. }
  274. // 初始化
  275. onMounted(() => {
  276. // VIP用户不显示广告
  277. if (vipStore.hasPrivilege('免广告')) return
  278. // 显示底部广告
  279. feedAd.value = showFeedAd()
  280. fetchChapterContent()
  281. // 设置广告单元ID
  282. // #ifdef MP-WEIXIN
  283. bottomAdUnitId.value = 'wechat_feed_ad_123456'
  284. // #endif
  285. // #ifdef MP-TOUTIAO
  286. bottomAdUnitId.value = 'douyin_feed_ad_654321'
  287. // #endif
  288. // #ifdef H5
  289. bottomAdUnitId.value = 'h5_feed_ad_789012'
  290. // #endif
  291. // 监听VIP状态变化
  292. watch(() => userStore.isVIP, (isVip) => {
  293. showBottomAd.value = !isVip
  294. })
  295. })
  296. // 在获取章节内容后清洗
  297. const fetchChapterContent = async () => {
  298. const res = await uni.request({
  299. url: `https://php-backend.aiyadianzi.ltd/chapter/${props.chapterId}`,
  300. method: 'GET'
  301. })
  302. // 清洗内容
  303. chapterContent.value = contentCleaner.clean(res.data.content)
  304. // 分页处理
  305. paginatedContent.value = paginateContent(chapterContent.value)
  306. }
  307. </script>
  308. <style scoped>
  309. .reader-container {
  310. display: flex;
  311. flex-direction: column;
  312. height: 100vh;
  313. background-color: var(--reader-bg-color);
  314. color: var(--reader-text-color);
  315. }
  316. .reader-header {
  317. display: flex;
  318. justify-content: space-between;
  319. align-items: center;
  320. padding: 10px 15px;
  321. background-color: var(--header-bg-color);
  322. border-bottom: 1px solid var(--border-color);
  323. height: 50px;
  324. box-sizing: border-box;
  325. }
  326. .left-actions {
  327. display: flex;
  328. align-items: center;
  329. flex: 1;
  330. }
  331. .back-btn {
  332. margin-right: 15px;
  333. background: none;
  334. border: none;
  335. padding: 0;
  336. }
  337. .chapter-title {
  338. font-size: 16px;
  339. font-weight: bold;
  340. white-space: nowrap;
  341. overflow: hidden;
  342. text-overflow: ellipsis;
  343. max-width: 60vw;
  344. }
  345. .right-actions {
  346. display: flex;
  347. }
  348. .action-btn {
  349. background: none;
  350. border: none;
  351. padding: 5px 10px;
  352. margin-left: 10px;
  353. }
  354. .mode-selector {
  355. display: flex;
  356. padding: 10px;
  357. background-color: var(--header-bg-color);
  358. justify-content: center;
  359. border-bottom: 1px solid var(--border-color);
  360. }
  361. .mode-btn {
  362. margin: 0 10px;
  363. padding: 5px 15px;
  364. border-radius: 15px;
  365. background-color: var(--button-bg);
  366. color: var(--button-color);
  367. border: none;
  368. font-size: 14px;
  369. }
  370. .mode-btn.active {
  371. background-color: var(--primary-color);
  372. color: white;
  373. }
  374. .font-size-selector {
  375. display: flex;
  376. align-items: center;
  377. padding: 10px 15px;
  378. background-color: var(--header-bg-color);
  379. border-bottom: 1px solid var(--border-color);
  380. }
  381. .size-btn {
  382. background: none;
  383. border: 1px solid var(--border-color);
  384. border-radius: 4px;
  385. width: 40px;
  386. height: 40px;
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. font-weight: bold;
  391. }
  392. .font-slider {
  393. flex: 1;
  394. margin: 0 15px;
  395. }
  396. .scroll-reader {
  397. flex: 1;
  398. padding: 20px;
  399. overflow-y: auto;
  400. line-height: 1.8;
  401. }
  402. .page-reader {
  403. flex: 1;
  404. }
  405. .reader-footer {
  406. display: flex;
  407. justify-content: space-between;
  408. padding: 10px 15px;
  409. background-color: var(--header-bg-color);
  410. border-top: 1px solid var(--border-color);
  411. }
  412. .footer-btn {
  413. flex: 1;
  414. margin: 0 5px;
  415. padding: 8px 0;
  416. border-radius: 4px;
  417. background-color: var(--button-bg);
  418. color: var(--button-color);
  419. border: none;
  420. font-size: 14px;
  421. }
  422. .bottom-ad {
  423. height: 100px;
  424. background-color: #f5f5f5;
  425. }
  426. </style>