|
|
@@ -1,7 +1,7 @@
|
|
|
// app.js
|
|
|
// 引入阅读器插件
|
|
|
const novelPlugin = requirePlugin('novel-plugin')
|
|
|
-import { userLogin } from './api/api'
|
|
|
+import { userLogin,getChapterUnlockStatus,getNovelDetail,addBrowsingHistory } from './api/api'
|
|
|
|
|
|
App({
|
|
|
onLaunch() {
|
|
|
@@ -71,31 +71,59 @@ App({
|
|
|
})
|
|
|
|
|
|
// 插件初始化回调
|
|
|
-function onNovelPluginLoad(data) {
|
|
|
+async function onNovelPluginLoad(data) {
|
|
|
// data.id - 阅读器实例 id,每个插件页对应一个阅读器实例
|
|
|
const novelManager = novelPlugin.getNovelManager(data.id)
|
|
|
-
|
|
|
- // 设置目录状态(这里先模拟三章内容,实际应该根据后端数据设置)
|
|
|
- novelManager.setContents({
|
|
|
- contents: [
|
|
|
- {
|
|
|
- index: 0, // 第一章
|
|
|
- status: 0, // 免费
|
|
|
- },
|
|
|
- {
|
|
|
- index: 1, // 第二章
|
|
|
- status: 2, // 未解锁
|
|
|
- },
|
|
|
- {
|
|
|
- index: 2, // 第三章
|
|
|
- status: 1, // 已解锁
|
|
|
- }
|
|
|
- ],
|
|
|
- })
|
|
|
|
|
|
- function startRead() {
|
|
|
- console.log('开始阅读');
|
|
|
- //通报下后端
|
|
|
+
|
|
|
+ let pluginInfo = novelManager.getPluginInfo();
|
|
|
+
|
|
|
+ let innerBookId = pluginInfo.query?.innerBookId;
|
|
|
+ console.log("innerBookId",innerBookId);
|
|
|
+
|
|
|
+ let unlockStatus = await getChapterUnlockStatus({
|
|
|
+ novelId: innerBookId
|
|
|
+ });
|
|
|
+
|
|
|
+ let bookDetail = await getNovelDetail(innerBookId);
|
|
|
+
|
|
|
+ console.log("bookDetail",bookDetail);
|
|
|
+
|
|
|
+ // 设置目录状态(根据unlockStatus数据设置章节状态)
|
|
|
+ if (unlockStatus && Array.isArray(unlockStatus.status)) {
|
|
|
+ // 将unlockStatus.status数组转换为目录状态格式
|
|
|
+ const contents = unlockStatus.status.map((isUnlocked, index) => {
|
|
|
+ return {
|
|
|
+ index: index, // 章节索引
|
|
|
+ status: isUnlocked ? 1 : 2, // true为已解锁(1),false为未解锁(2)
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置第一章为免费(0)状态,如果有其他免费章节也可以在这里设置
|
|
|
+ if (contents.length > 0) {
|
|
|
+ contents[0].status = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置目录状态
|
|
|
+ novelManager.setContents({
|
|
|
+ contents: contents,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function startRead(res) {
|
|
|
+ console.log('开始阅读',res);
|
|
|
+ updateBrowsingHistory(res);
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateBrowsingHistory(res) {
|
|
|
+ let params = {
|
|
|
+ novelAuthor: bookDetail.author,
|
|
|
+ novelCover: bookDetail.cover,
|
|
|
+ novelId: bookDetail.id,
|
|
|
+ novelTitle: bookDetail.title,
|
|
|
+ status: bookDetail.status
|
|
|
+ }
|
|
|
+ addBrowsingHistory(params);
|
|
|
}
|
|
|
|
|
|
// 监听用户行为事件
|
|
|
@@ -107,7 +135,10 @@ function onNovelPluginLoad(data) {
|
|
|
switch(event_id) {
|
|
|
case 'start_read': // 开始阅读
|
|
|
console.log('开始阅读章节:', res.chapter_id);
|
|
|
- startRead();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'click_startread': // 点击开始阅读
|
|
|
+ startRead(res);
|
|
|
break;
|
|
|
|
|
|
case 'leave_readpage': // 离开阅读页
|
|
|
@@ -119,6 +150,7 @@ function onNovelPluginLoad(data) {
|
|
|
break;
|
|
|
|
|
|
case 'get_chapter': // 获取章节数据
|
|
|
+ console.log("get_chapter",res);
|
|
|
console.log('章节状态:', res.pay_status);
|
|
|
break;
|
|
|
|