├── php-api/ # 改造后的PHP接口层 ├── java-ad-service/ # 若依框架微服务(广告+VIP+分账) ├── uniapp-reader/ # UniApp前端项目 │ ├── pages/ # 各端页面 │ └──
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

detail.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view>
  3. <!-- 章节间广告 -->
  4. <ad-banner v-if="showMidAd" :ads="midAds" />
  5. <scroll-view scroll-y>
  6. <!-- 章节内容 -->
  7. <view v-for="chapter in chapters" :key="chapter.id">
  8. <text>{{ chapter.title }}</text>
  9. <rich-text :nodes="chapter.content" />
  10. </view>
  11. <!-- 章节底部广告 -->
  12. <ad-banner :ads="chapterAds" />
  13. </scroll-view>
  14. <!-- 底部操作栏 -->
  15. <view class="action-bar">
  16. <button @click="prevChapter">上一章</button>
  17. <button @click="showCatalog">目录</button>
  18. <button @click="nextChapter">下一章</button>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import AdBanner from '@/components/AdBanner';
  24. export default {
  25. components: { AdBanner },
  26. data() {
  27. return {
  28. novelId: null,
  29. chapters: [],
  30. currentChapter: 0,
  31. midAds: [],
  32. chapterAds: [],
  33. showMidAd: false
  34. };
  35. },
  36. onLoad(options) {
  37. this.novelId = options.id;
  38. this.loadNovelData();
  39. this.scheduleMidAd();
  40. },
  41. methods: {
  42. async loadNovelData() {
  43. // 加载章节列表
  44. const chapterRes = await this.$http.get(`/php-api/novel/chapters?id=${this.novelId}`);
  45. this.chapters = chapterRes.data;
  46. // 加载当前章节内容
  47. await this.loadChapterContent(0);
  48. // 加载章节广告
  49. const adRes = await this.$http.get('/java-api/ad/position?code=CHAPTER_FOOTER');
  50. this.chapterAds = adRes.data;
  51. },
  52. async loadChapterContent(index) {
  53. if (index < 0 || index >= this.chapters.length) return;
  54. const chapterId = this.chapters[index].id;
  55. const res = await this.$http.get(`/php-api/novel/chapter?id=${chapterId}`);
  56. // 更新章节内容
  57. this.$set(this.chapters, index, {
  58. ...this.chapters[index],
  59. content: res.data.content
  60. });
  61. this.currentChapter = index;
  62. },
  63. // 定时显示中间广告
  64. scheduleMidAd() {
  65. setTimeout(async () => {
  66. const res = await this.$http.get('/java-api/ad/position?code=MID_CHAPTER');
  67. this.midAds = res.data;
  68. this.showMidAd = true;
  69. // 10秒后隐藏
  70. setTimeout(() => this.showMidAd = false, 10000);
  71. }, 30000); // 30秒后显示
  72. },
  73. prevChapter() {
  74. this.loadChapterContent(this.currentChapter - 1);
  75. },
  76. nextChapter() {
  77. this.loadChapterContent(this.currentChapter + 1);
  78. },
  79. showCatalog() {
  80. uni.navigateTo({
  81. url: `/pages/novel/catalog?id=${this.novelId}`
  82. });
  83. }
  84. }
  85. }
  86. </script>