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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <view class="reader-container" :class="{ 'night-mode': nightMode }">
  3. <!-- 顶部导航栏 -->
  4. <view class="reader-header" v-if="showHeader">
  5. <view class="header-left">
  6. <text class="iconfont icon-back" @click="goBack"></text>
  7. <text class="novel-title">{{novelTitle}}</text>
  8. </view>
  9. <view class="header-right">
  10. <text class="iconfont icon-menu" @click="showMenu"></text>
  11. </view>
  12. </view>
  13. <!-- 阅读内容区域 -->
  14. <scroll-view
  15. class="reader-content"
  16. scroll-y
  17. :scroll-top="scrollTop"
  18. @scroll="onScroll"
  19. @touchstart="onTouchStart"
  20. @touchend="onTouchEnd"
  21. >
  22. <view class="chapter-title">{{chapterTitle}}</view>
  23. <view class="content-text">
  24. <text>{{content}}</text>
  25. </view>
  26. <!-- 加载状态 -->
  27. <view v-if="loading" class="loading-container">
  28. <text>加载中...</text>
  29. </view>
  30. <!-- 错误状态 -->
  31. <view v-if="error" class="error-container">
  32. <text>{{error}}</text>
  33. <button @click="loadChapterContent">重试</button>
  34. </view>
  35. </scroll-view>
  36. <!-- 底部控制栏 -->
  37. <view class="reader-footer" v-if="showFooter">
  38. <view class="progress-text">
  39. 第{{currentChapter}}章 {{progress}}%
  40. </view>
  41. <view class="control-buttons">
  42. <text class="iconfont icon-catalog" @click="showCatalog"></text>
  43. <text class="iconfont icon-font" @click="showFontSettings"></text>
  44. <text class="iconfont icon-night" @click="toggleNightMode"></text>
  45. <text class="iconfont icon-download" @click="downloadChapter"></text>
  46. </view>
  47. </view>
  48. <!-- 广告位 -->
  49. <ad v-if="showAd" unit-id="您的广告单元ID" class="reader-ad"></ad>
  50. <!-- 设置面板 -->
  51. <view class="settings-panel" v-if="showSettings">
  52. <view class="font-size-controls">
  53. <text class="iconfont icon-font-small" @click="decreaseFontSize"></text>
  54. <text>字体大小: {{fontSize}}px</text>
  55. <text class="iconfont icon-font-large" @click="increaseFontSize"></text>
  56. </view>
  57. <view class="background-options">
  58. <view
  59. v-for="bg in backgroundOptions"
  60. :key="bg.value"
  61. class="bg-option"
  62. :class="{ active: backgroundColor === bg.value }"
  63. :style="{ backgroundColor: bg.value }"
  64. @click="changeBackground(bg.value)"
  65. ></view>
  66. </view>
  67. </view>
  68. <!-- 目录面板 -->
  69. <view class="catalog-panel" v-if="showCatalogPanel">
  70. <view class="catalog-header">
  71. <text class="catalog-title">目录</text>
  72. <text class="iconfont icon-close" @click="showCatalogPanel = false"></text>
  73. </view>
  74. <scroll-view class="chapter-list" scroll-y>
  75. <view
  76. v-for="chapter in chapterList"
  77. :key="chapter.id"
  78. class="chapter-item"
  79. :class="{ active: chapter.id === chapterId }"
  80. @click="selectChapter(chapter.id)"
  81. >
  82. <text>{{chapter.title}}</text>
  83. </view>
  84. </scroll-view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. export default {
  90. data() {
  91. return {
  92. novelId: '',
  93. chapterId: '',
  94. novelTitle: '加载中...',
  95. chapterTitle: '加载中...',
  96. content: '正在加载内容...',
  97. currentChapter: 1,
  98. totalChapters: 0,
  99. progress: 0,
  100. scrollTop: 0,
  101. showHeader: false,
  102. showFooter: false,
  103. showSettings: false,
  104. showCatalogPanel: false,
  105. showAd: false,
  106. nightMode: false,
  107. touchStartX: 0,
  108. touchStartY: 0,
  109. lastScrollPosition: 0,
  110. loading: false,
  111. error: null,
  112. fontSize: 18,
  113. backgroundColor: '#f5f0e1',
  114. backgroundOptions: [
  115. { value: '#f5f0e1', name: '羊皮纸' },
  116. { value: '#e8f5e9', name: '护眼绿' },
  117. { value: '#e3f2fd', name: '天空蓝' },
  118. { value: '#fce4ec', name: '粉红' },
  119. { value: '#1a1a1a', name: '夜间' }
  120. ],
  121. chapterList: []
  122. }
  123. },
  124. onLoad(options) {
  125. console.log('阅读器页面加载,参数:', options);
  126. // 确保参数获取方式正确
  127. this.novelId = options.novelId || '';
  128. this.chapterId = options.chapterId || '1';
  129. console.log('novelId:', this.novelId, 'chapterId:', this.chapterId);
  130. if (!this.novelId) {
  131. console.error('小说ID参数缺失');
  132. this.error = '小说ID参数缺失';
  133. uni.showToast({
  134. title: '小说ID参数缺失',
  135. icon: 'none'
  136. });
  137. return;
  138. }
  139. // 显示加载提示
  140. uni.showLoading({
  141. title: '加载中...',
  142. mask: true
  143. });
  144. this.loadChapterContent();
  145. },
  146. onShow() {
  147. console.log('reader onShow');
  148. // 确保页面显示时也能处理参数
  149. const pages = getCurrentPages();
  150. const currentPage = pages[pages.length - 1];
  151. if (currentPage && currentPage.options) {
  152. const options = currentPage.options;
  153. console.log('当前页面参数:', options);
  154. if (options.novelId && (!this.novelId || this.novelId !== options.novelId)) {
  155. this.novelId = options.novelId;
  156. this.chapterId = options.chapterId || '1';
  157. this.loadChapterContent();
  158. }
  159. }
  160. },
  161. // 添加所有生命周期钩子进行调试
  162. beforeCreate() {
  163. console.log('reader beforeCreate');
  164. },
  165. created() {
  166. console.log('reader created');
  167. },
  168. beforeMount() {
  169. console.log('reader beforeMount');
  170. },
  171. mounted() {
  172. console.log('reader mounted');
  173. },
  174. onReady() {
  175. console.log('reader onReady');
  176. },
  177. onHide() {
  178. console.log('reader onHide');
  179. },
  180. onUnload() {
  181. console.log('reader onUnload');
  182. },
  183. methods: {
  184. async loadChapterContent() {
  185. console.log('开始加载章节内容');
  186. this.loading = true;
  187. this.error = null;
  188. try {
  189. console.log('开始请求章节内容,章节ID:', this.chapterId);
  190. // 确保$http对象可用
  191. if (!this.$http || typeof this.$http.get !== 'function') {
  192. throw new Error('网络请求不可用');
  193. }
  194. // 使用若依框架的API调用方式
  195. const res = await this.$http.get(`/novel/chapter/${this.chapterId}`);
  196. console.log('章节内容响应:', res);
  197. if (res.code === 200) {
  198. this.novelTitle = res.data.novelTitle || '未知小说';
  199. this.chapterTitle = res.data.chapterTitle || '未知章节';
  200. this.content = res.data.content || '';
  201. this.currentChapter = res.data.chapterIndex || 1;
  202. this.totalChapters = res.data.totalChapters || 0;
  203. uni.showToast({
  204. title: '加载成功',
  205. icon: 'success',
  206. duration: 1500
  207. });
  208. } else {
  209. console.error('API返回错误状态码:', res.code);
  210. this.error = '加载失败: ' + (res.msg || '未知错误');
  211. uni.showToast({
  212. title: res.msg || '加载失败',
  213. icon: 'none'
  214. });
  215. }
  216. } catch (error) {
  217. console.error('加载章节内容失败:', error);
  218. this.error = '加载失败,请检查网络连接';
  219. uni.showToast({
  220. title: '加载失败,请检查网络连接',
  221. icon: 'none'
  222. });
  223. } finally {
  224. this.loading = false;
  225. uni.hideLoading();
  226. }
  227. }
  228. }}
  229. </script>
  230. <style>
  231. .reader-container {
  232. position: relative;
  233. height: 100vh;
  234. display: flex;
  235. flex-direction: column;
  236. background-color: v-bind(backgroundColor);
  237. transition: background-color 0.3s ease;
  238. }
  239. .reader-header {
  240. height: 44px;
  241. padding: 0 15px;
  242. display: flex;
  243. justify-content: space-between;
  244. align-items: center;
  245. background: rgba(0, 0, 0, 0.8);
  246. color: white;
  247. position: fixed;
  248. top: 0;
  249. left: 0;
  250. right: 0;
  251. z-index: 1000;
  252. }
  253. .reader-content {
  254. flex: 1;
  255. padding: 20px;
  256. box-sizing: border-box;
  257. line-height: 1.8;
  258. font-size: v-bind(fontSize + 'px');
  259. color: #333;
  260. margin-top: 44px;
  261. margin-bottom: 50px;
  262. }
  263. .chapter-title {
  264. text-align: center;
  265. font-size: 20px;
  266. font-weight: bold;
  267. margin-bottom: 20px;
  268. }
  269. .content-text {
  270. text-indent: 2em;
  271. line-height: 1.8;
  272. }
  273. .reader-footer {
  274. height: 50px;
  275. padding: 0 15px;
  276. display: flex;
  277. justify-content: space-between;
  278. align-items: center;
  279. background: rgba(0, 0, 0, 0.8);
  280. color: white;
  281. position: fixed;
  282. bottom: 0;
  283. left: 0;
  284. right: 0;
  285. z-index: 1000;
  286. }
  287. .reader-ad {
  288. height: 90px;
  289. margin-bottom: 10px;
  290. }
  291. .loading-container, .error-container {
  292. display: flex;
  293. flex-direction: column;
  294. align-items: center;
  295. justify-content: center;
  296. padding: 50px 0;
  297. }
  298. .error-container button {
  299. margin-top: 20px;
  300. background-color: var(--primary-color);
  301. color: white;
  302. border: none;
  303. padding: 10px 20px;
  304. border-radius: 5px;
  305. }
  306. .settings-panel {
  307. position: fixed;
  308. bottom: 50px;
  309. left: 0;
  310. right: 0;
  311. background: rgba(255, 255, 255, 0.95);
  312. padding: 20px;
  313. z-index: 999;
  314. box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  315. }
  316. .font-size-controls {
  317. display: flex;
  318. justify-content: space-between;
  319. align-items: center;
  320. margin-bottom: 20px;
  321. }
  322. .background-options {
  323. display: flex;
  324. justify-content: space-around;
  325. }
  326. .bg-option {
  327. width: 40px;
  328. height: 40px;
  329. border-radius: 50%;
  330. border: 2px solid transparent;
  331. cursor: pointer;
  332. }
  333. .bg-option.active {
  334. border-color: var(--primary-color);
  335. }
  336. .catalog-panel {
  337. position: fixed;
  338. top: 0;
  339. left: 0;
  340. right: 0;
  341. bottom: 0;
  342. background: white;
  343. z-index: 1001;
  344. }
  345. .catalog-header {
  346. display: flex;
  347. justify-content: space-between;
  348. align-items: center;
  349. padding: 15px;
  350. border-bottom: 1px solid #eee;
  351. }
  352. .chapter-list {
  353. height: calc(100vh - 60px);
  354. }
  355. .chapter-item {
  356. padding: 15px;
  357. border-bottom: 1px solid #eee;
  358. }
  359. .chapter-item.active {
  360. color: var(--primary-color);
  361. font-weight: bold;
  362. }
  363. /* 夜间模式样式 */
  364. .night-mode .reader-content {
  365. color: #888;
  366. }
  367. .night-mode .content-text {
  368. color: #888;
  369. }
  370. </style>