|
|
@@ -116,9 +116,6 @@
|
|
116
|
116
|
</template>
|
|
117
|
117
|
|
|
118
|
118
|
<script>
|
|
119
|
|
-import config from '@/config'
|
|
120
|
|
-import novelService from '@/services/novelService'
|
|
121
|
|
-
|
|
122
|
119
|
export default {
|
|
123
|
120
|
data() {
|
|
124
|
121
|
return {
|
|
|
@@ -164,29 +161,51 @@ export default {
|
|
164
|
161
|
// 检查是否达到免费章节限制
|
|
165
|
162
|
reachedFreeLimit() {
|
|
166
|
163
|
const isLoggedIn = this.$store.getters.token
|
|
167
|
|
- return !isLoggedIn && this.readChaptersCount >= config.freeChapters
|
|
|
164
|
+ return !isLoggedIn && this.readChaptersCount >= 5 // 默认5章免费
|
|
168
|
165
|
}
|
|
169
|
166
|
},
|
|
170
|
167
|
async onLoad(options) {
|
|
171
|
|
- this.novelId = options.novelId
|
|
|
168
|
+ console.log('阅读器页面参数:', options)
|
|
|
169
|
+
|
|
|
170
|
+ // 确保参数正确解析
|
|
|
171
|
+ this.novelId = options.novelId || null
|
|
172
|
172
|
this.chapterId = options.chapterId || null
|
|
173
|
173
|
|
|
|
174
|
+ if (!this.novelId) {
|
|
|
175
|
+ uni.showToast({
|
|
|
176
|
+ title: '小说ID参数缺失',
|
|
|
177
|
+ icon: 'none'
|
|
|
178
|
+ })
|
|
|
179
|
+ setTimeout(() => {
|
|
|
180
|
+ uni.navigateBack()
|
|
|
181
|
+ }, 1500)
|
|
|
182
|
+ return
|
|
|
183
|
+ }
|
|
|
184
|
+
|
|
174
|
185
|
// 加载阅读进度
|
|
175
|
186
|
this.loadReadingProgress()
|
|
176
|
187
|
|
|
177
|
|
- await this.loadNovelData()
|
|
178
|
|
-
|
|
179
|
|
- // 如果有指定章节ID,加载该章节,否则加载第一章
|
|
180
|
|
- if (this.chapterId) {
|
|
181
|
|
- await this.loadChapter(this.chapterId)
|
|
182
|
|
- } else {
|
|
183
|
|
- // 尝试从阅读记录中恢复
|
|
184
|
|
- const lastReadChapter = this.getLastReadChapter()
|
|
185
|
|
- if (lastReadChapter) {
|
|
186
|
|
- await this.loadChapter(lastReadChapter.id)
|
|
|
188
|
+ try {
|
|
|
189
|
+ await this.loadNovelData()
|
|
|
190
|
+
|
|
|
191
|
+ // 如果有指定章节ID,加载该章节,否则加载第一章
|
|
|
192
|
+ if (this.chapterId) {
|
|
|
193
|
+ await this.loadChapter(this.chapterId)
|
|
187
|
194
|
} else {
|
|
188
|
|
- await this.loadFirstChapter()
|
|
|
195
|
+ // 尝试从阅读记录中恢复
|
|
|
196
|
+ const lastReadChapter = this.getLastReadChapter()
|
|
|
197
|
+ if (lastReadChapter) {
|
|
|
198
|
+ await this.loadChapter(lastReadChapter.id)
|
|
|
199
|
+ } else {
|
|
|
200
|
+ await this.loadFirstChapter()
|
|
|
201
|
+ }
|
|
189
|
202
|
}
|
|
|
203
|
+ } catch (error) {
|
|
|
204
|
+ console.error('页面初始化失败:', error)
|
|
|
205
|
+ uni.showToast({
|
|
|
206
|
+ title: '页面初始化失败',
|
|
|
207
|
+ icon: 'none'
|
|
|
208
|
+ })
|
|
190
|
209
|
}
|
|
191
|
210
|
|
|
192
|
211
|
// 监听网络状态
|
|
|
@@ -199,51 +218,77 @@ export default {
|
|
199
|
218
|
uni.offNetworkStatusChange(this.handleNetworkChange)
|
|
200
|
219
|
},
|
|
201
|
220
|
methods: {
|
|
|
221
|
+ // 修复响应解析方法
|
|
|
222
|
+ parseResponse(res) {
|
|
|
223
|
+ console.log('原始响应对象:', res)
|
|
|
224
|
+
|
|
|
225
|
+ // 处理不同的响应格式
|
|
|
226
|
+ let responseData = {}
|
|
|
227
|
+
|
|
|
228
|
+ // 如果res有arg属性,使用arg作为响应数据
|
|
|
229
|
+ if (res && res.arg) {
|
|
|
230
|
+ responseData = res.arg
|
|
|
231
|
+ console.log('使用res.arg作为响应数据:', responseData)
|
|
|
232
|
+ }
|
|
|
233
|
+ // 如果res有data属性,使用data作为响应数据
|
|
|
234
|
+ else if (res && res.data) {
|
|
|
235
|
+ responseData = res.data
|
|
|
236
|
+ console.log('使用res.data作为响应数据:', responseData)
|
|
|
237
|
+ }
|
|
|
238
|
+ // 如果res本身就是响应数据
|
|
|
239
|
+ else {
|
|
|
240
|
+ responseData = res
|
|
|
241
|
+ console.log('使用res本身作为响应数据:', responseData)
|
|
|
242
|
+ }
|
|
|
243
|
+
|
|
|
244
|
+ return responseData
|
|
|
245
|
+ },
|
|
|
246
|
+
|
|
202
|
247
|
// 加载小说数据
|
|
203
|
248
|
async loadNovelData() {
|
|
204
|
249
|
try {
|
|
205
|
250
|
uni.showLoading({ title: '加载中...' })
|
|
206
|
251
|
|
|
207
|
|
- // 加载小说基本信息 - 修复API路径
|
|
208
|
|
- const novelRes = await this.$http.get(`/novel/detail/${this.novelId}`)
|
|
209
|
|
-
|
|
210
|
|
- // 使用统一的响应解析方法
|
|
211
|
|
- const novelData = this.parseResponse(novelRes)
|
|
212
|
|
- console.log('小说详情响应:', novelData)
|
|
213
|
|
-
|
|
214
|
|
- if (novelData.code === 200 && novelData.data) {
|
|
215
|
|
- this.novelTitle = novelData.data.title
|
|
216
|
|
- uni.setNavigationBarTitle({ title: this.novelTitle })
|
|
217
|
|
- }
|
|
218
|
|
-
|
|
219
|
|
- // 加载章节列表 - 修复API路径
|
|
220
|
|
- const chapterRes = await this.$http.get(`/chapter/list/${this.novelId}`)
|
|
221
|
|
-
|
|
222
|
|
- // 使用统一的响应解析方法
|
|
223
|
|
- const chapterData = this.parseResponse(chapterRes)
|
|
224
|
|
- console.log('章节列表响应:', chapterData)
|
|
225
|
|
-
|
|
226
|
|
- if (chapterData.code === 200) {
|
|
227
|
|
- // 处理不同的响应格式
|
|
228
|
|
- if (Array.isArray(chapterData.rows)) {
|
|
229
|
|
- this.chapters = chapterData.rows
|
|
230
|
|
- } else if (Array.isArray(chapterData.data)) {
|
|
231
|
|
- this.chapters = chapterData.data
|
|
232
|
|
- }
|
|
233
|
|
-
|
|
234
|
|
- // 初始化当前章节索引
|
|
235
|
|
- if (this.chapterId) {
|
|
236
|
|
- this.currentChapterIndex = this.chapters.findIndex(ch => ch.id === this.chapterId)
|
|
237
|
|
- }
|
|
238
|
|
- }
|
|
239
|
|
- } catch (error) {
|
|
240
|
|
- console.error('加载小说数据失败:', error)
|
|
241
|
|
- uni.showToast({
|
|
242
|
|
- title: '加载失败',
|
|
243
|
|
- icon: 'none'
|
|
244
|
|
- })
|
|
245
|
|
- } finally {
|
|
246
|
|
- uni.hideLoading()
|
|
|
252
|
+ // 加载小说基本信息
|
|
|
253
|
+ const novelRes = await this.$http.get(`/novel/detail/${this.novelId}`)
|
|
|
254
|
+
|
|
|
255
|
+ // 使用统一的响应解析方法
|
|
|
256
|
+ const novelData = this.parseResponse(novelRes)
|
|
|
257
|
+ console.log('小说详情响应:', novelData)
|
|
|
258
|
+
|
|
|
259
|
+ if (novelData.code === 200 && novelData.data) {
|
|
|
260
|
+ this.novelTitle = novelData.data.title
|
|
|
261
|
+ uni.setNavigationBarTitle({ title: this.novelTitle })
|
|
|
262
|
+ }
|
|
|
263
|
+
|
|
|
264
|
+ // 加载章节列表
|
|
|
265
|
+ const chapterRes = await this.$http.get(`/chapter/list/${this.novelId}`)
|
|
|
266
|
+
|
|
|
267
|
+ // 使用统一的响应解析方法
|
|
|
268
|
+ const chapterData = this.parseResponse(chapterRes)
|
|
|
269
|
+ console.log('章节列表响应:', chapterData)
|
|
|
270
|
+
|
|
|
271
|
+ if (chapterData.code === 200) {
|
|
|
272
|
+ // 处理不同的响应格式
|
|
|
273
|
+ if (Array.isArray(chapterData.rows)) {
|
|
|
274
|
+ this.chapters = chapterData.rows
|
|
|
275
|
+ } else if (Array.isArray(chapterData.data)) {
|
|
|
276
|
+ this.chapters = chapterData.data
|
|
|
277
|
+ }
|
|
|
278
|
+
|
|
|
279
|
+ // 初始化当前章节索引
|
|
|
280
|
+ if (this.chapterId) {
|
|
|
281
|
+ this.currentChapterIndex = this.chapters.findIndex(ch => ch.id === this.chapterId)
|
|
|
282
|
+ }
|
|
|
283
|
+ }
|
|
|
284
|
+ } catch (error) {
|
|
|
285
|
+ console.error('加载小说数据失败:', error)
|
|
|
286
|
+ uni.showToast({
|
|
|
287
|
+ title: '加载失败',
|
|
|
288
|
+ icon: 'none'
|
|
|
289
|
+ })
|
|
|
290
|
+ } finally {
|
|
|
291
|
+ uni.hideLoading()
|
|
247
|
292
|
}
|
|
248
|
293
|
},
|
|
249
|
294
|
|
|
|
@@ -260,9 +305,14 @@ export default {
|
|
260
|
305
|
uni.showLoading({ title: '加载中...' })
|
|
261
|
306
|
|
|
262
|
307
|
const res = await this.$http.get(`/chapter/content/${chapterId}`)
|
|
263
|
|
- if (res.data) {
|
|
264
|
|
- this.chapterDetail = res.data
|
|
265
|
|
- this.chapterContent = this.formatContent(res.data.content)
|
|
|
308
|
+
|
|
|
309
|
+ // 使用统一的响应解析方法
|
|
|
310
|
+ const responseData = this.parseResponse(res)
|
|
|
311
|
+ console.log('章节内容响应:', responseData)
|
|
|
312
|
+
|
|
|
313
|
+ if (responseData.code === 200 && responseData.data) {
|
|
|
314
|
+ this.chapterDetail = responseData.data
|
|
|
315
|
+ this.chapterContent = this.formatContent(responseData.data.content)
|
|
266
|
316
|
this.chapterId = chapterId
|
|
267
|
317
|
this.currentChapterIndex = chapterIndex
|
|
268
|
318
|
|
|
|
@@ -323,8 +373,8 @@ export default {
|
|
323
|
373
|
// 已登录用户可以阅读所有章节
|
|
324
|
374
|
if (this.$store.getters.token) return false
|
|
325
|
375
|
|
|
326
|
|
- // 未登录用户只能阅读前N章
|
|
327
|
|
- return chapterIndex >= config.freeChapters
|
|
|
376
|
+ // 未登录用户只能阅读前5章
|
|
|
377
|
+ return chapterIndex >= 5
|
|
328
|
378
|
},
|
|
329
|
379
|
|
|
330
|
380
|
// 加载阅读进度
|