|
|
@@ -1,5 +1,5 @@
|
|
|
import {
|
|
|
- SendEvent,
|
|
|
+ SendEvent,
|
|
|
} from '/utils/util.js'
|
|
|
|
|
|
// import {
|
|
|
@@ -10,217 +10,218 @@ import {
|
|
|
// 引入阅读器插件
|
|
|
const novelPlugin = requirePlugin('novel-plugin')
|
|
|
|
|
|
-import { userLogin,getChapterUnlockStatus,getNovelDetail,addBrowsingHistory } from './api/api'
|
|
|
+import {userLogin, getChapterUnlockStatus, getNovelDetail, addBrowsingHistory} from './api/api'
|
|
|
import {apple} from './config/config'
|
|
|
|
|
|
App({
|
|
|
- onLaunch(options) {
|
|
|
- console.log('场景值:', options, options.scene);
|
|
|
- novelPlugin.setLoggerConfig({
|
|
|
- info: true,
|
|
|
- debug: true,
|
|
|
- log: true,
|
|
|
- warn: true,
|
|
|
- error: true,
|
|
|
- })
|
|
|
+ onLaunch(options) {
|
|
|
+ console.log('场景值:', options, options.scene);
|
|
|
+ novelPlugin.setLoggerConfig({
|
|
|
+ info: true,
|
|
|
+ debug: true,
|
|
|
+ log: true,
|
|
|
+ warn: true,
|
|
|
+ error: true,
|
|
|
+ })
|
|
|
|
|
|
- // 监听进入插件页事件
|
|
|
- novelPlugin.onPageLoad(onNovelPluginLoad)
|
|
|
-
|
|
|
- // 展示本地存储能力
|
|
|
- const logs = wx.getStorageSync('logs') || []
|
|
|
- logs.unshift(Date.now())
|
|
|
- wx.setStorageSync('logs', logs)
|
|
|
- },
|
|
|
-
|
|
|
- // 登录方法
|
|
|
- login(promotionid) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
-
|
|
|
- // 检查登录状态
|
|
|
- if (this.checkLoginStatus()) {
|
|
|
- resolve();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- wx.login({
|
|
|
- success: res => {
|
|
|
- userLogin({
|
|
|
- "appid": apple.appid,
|
|
|
- "channel": 1,
|
|
|
- "srcType": "0",
|
|
|
- "srcAppId": "",
|
|
|
- "srcId": "",
|
|
|
- "cusId": "",
|
|
|
- "inviter": "",
|
|
|
- "promotionId": "",
|
|
|
- "inviterPromotionId": promotionid,
|
|
|
- "system": "pc",
|
|
|
- "type": "inner",
|
|
|
- "inner": 1,
|
|
|
- code: res.code,
|
|
|
- }).then(res => {
|
|
|
- console.log(res);
|
|
|
- wx.setStorageSync('accessToken', res.accessToken);
|
|
|
- this.globalData.isLogin = true;
|
|
|
- this.globalData.userCode = res.userCode;
|
|
|
- console.log('登录成功', this.globalData)
|
|
|
- resolve(res);
|
|
|
- }).catch(err => {
|
|
|
- this.globalData.isLogin = false;
|
|
|
- reject(err);
|
|
|
- })
|
|
|
- },
|
|
|
- fail: err => {
|
|
|
- this.globalData.isLogin = false;
|
|
|
- reject(err);
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- // 检查登录状态
|
|
|
- checkLoginStatus() {
|
|
|
- const token = wx.getStorageSync('accessToken');
|
|
|
- return !!token && this.globalData.isLogin;
|
|
|
- },
|
|
|
-
|
|
|
- globalData: {
|
|
|
- userInfo: null,
|
|
|
- isLogin: false,
|
|
|
- novelManager: {},
|
|
|
- uuid: '',
|
|
|
- isShowDialog: false,
|
|
|
- novelId: '',
|
|
|
- unlockChapterNum: 1,
|
|
|
- bookmarkAdNum: 3
|
|
|
- }
|
|
|
-})
|
|
|
+ // 监听进入插件页事件
|
|
|
+ novelPlugin.onPageLoad(onNovelPluginLoad)
|
|
|
|
|
|
-// 插件初始化回调
|
|
|
-async function onNovelPluginLoad(data) {
|
|
|
- // data.id - 阅读器实例 id,每个插件页对应一个阅读器实例
|
|
|
- const novelManager = novelPlugin.getNovelManager(data.id)
|
|
|
- getApp().globalData.novelManager = novelManager
|
|
|
-
|
|
|
- novelManager.setFullScreenComponentStatus({
|
|
|
- show: true,
|
|
|
- })
|
|
|
-
|
|
|
- let pluginInfo = novelManager.getPluginInfo();
|
|
|
- let innerBookId = pluginInfo.query?.innerBookId;
|
|
|
- let unlockStatus = await getChapterUnlockStatus({
|
|
|
- novelId: innerBookId
|
|
|
- });
|
|
|
-
|
|
|
- let bookDetail = await getNovelDetail(innerBookId);
|
|
|
- getApp().globalData.novelId = bookDetail.id
|
|
|
- console.log("bookDetail", bookDetail);
|
|
|
-
|
|
|
- if (unlockStatus && Array.isArray(unlockStatus.status)) {
|
|
|
- const contents = unlockStatus.status.map((lockState, index) => {
|
|
|
- return {
|
|
|
- index: index,
|
|
|
- status: lockState,
|
|
|
- };
|
|
|
- });
|
|
|
+ // 展示本地存储能力
|
|
|
+ const logs = wx.getStorageSync('logs') || []
|
|
|
+ logs.unshift(Date.now())
|
|
|
+ wx.setStorageSync('logs', logs);
|
|
|
+ wx.setStorageSync('scene', options.scene)// 储存场景值
|
|
|
+ },
|
|
|
|
|
|
- novelManager.setContents({
|
|
|
- contents: contents,
|
|
|
- });
|
|
|
+ // 登录方法
|
|
|
+ login(promotionid) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
|
- novelManager.setChargeWay({
|
|
|
- globalConfig: {
|
|
|
- mode: 1,
|
|
|
- buttonText: '解锁',
|
|
|
- showButton: true,
|
|
|
- tip: '看完广告之后可继续阅读',
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- let chapterConfigs = []
|
|
|
- for (let index = 0; index < bookDetail.latestChapterNo; index++) {
|
|
|
- if ((index + 1) % getApp().globalData.bookmarkAdNum === 0) {
|
|
|
- chapterConfigs.push({
|
|
|
- chapterIndex: index,
|
|
|
- blocks: [
|
|
|
- {
|
|
|
- type: 3,
|
|
|
- unitId: apple.ads.bookmarkAdId
|
|
|
+ // 检查登录状态
|
|
|
+ if (this.checkLoginStatus()) {
|
|
|
+ resolve();
|
|
|
+ return;
|
|
|
}
|
|
|
- ]
|
|
|
+
|
|
|
+ wx.login({
|
|
|
+ success: res => {
|
|
|
+ userLogin({
|
|
|
+ "appid": apple.appid,
|
|
|
+ "channel": 1,
|
|
|
+ "srcType": "0",
|
|
|
+ "srcAppId": "",
|
|
|
+ "srcId": "",
|
|
|
+ "cusId": "",
|
|
|
+ "inviter": "",
|
|
|
+ "promotionId": "",
|
|
|
+ "inviterPromotionId": promotionid,
|
|
|
+ "system": "pc",
|
|
|
+ "type": "inner",
|
|
|
+ "inner": 1,
|
|
|
+ code: res.code,
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res);
|
|
|
+ wx.setStorageSync('accessToken', res.accessToken);
|
|
|
+ this.globalData.isLogin = true;
|
|
|
+ this.globalData.userCode = res.userCode;
|
|
|
+ console.log('登录成功', this.globalData)
|
|
|
+ resolve(res);
|
|
|
+ }).catch(err => {
|
|
|
+ this.globalData.isLogin = false;
|
|
|
+ reject(err);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: err => {
|
|
|
+ this.globalData.isLogin = false;
|
|
|
+ reject(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
- }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 检查登录状态
|
|
|
+ checkLoginStatus() {
|
|
|
+ const token = wx.getStorageSync('accessToken');
|
|
|
+ return !!token && this.globalData.isLogin;
|
|
|
+ },
|
|
|
+
|
|
|
+ globalData: {
|
|
|
+ userInfo: null,
|
|
|
+ isLogin: false,
|
|
|
+ novelManager: {},
|
|
|
+ uuid: '',
|
|
|
+ isShowDialog: false,
|
|
|
+ novelId: '',
|
|
|
+ unlockChapterNum: 1,
|
|
|
+ bookmarkAdNum: 3
|
|
|
}
|
|
|
+})
|
|
|
+
|
|
|
+// 插件初始化回调
|
|
|
+async function onNovelPluginLoad(data) {
|
|
|
+ // data.id - 阅读器实例 id,每个插件页对应一个阅读器实例
|
|
|
+ const novelManager = novelPlugin.getNovelManager(data.id)
|
|
|
+ getApp().globalData.novelManager = novelManager
|
|
|
|
|
|
- novelManager.setAdBlock({
|
|
|
- chapterConfigs: chapterConfigs
|
|
|
+ novelManager.setFullScreenComponentStatus({
|
|
|
+ show: true,
|
|
|
})
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- // 监听用户行为事件
|
|
|
- novelManager.onUserTriggerEvent(res => {
|
|
|
- const {
|
|
|
- event_id
|
|
|
- } = res;
|
|
|
- console.log('用户行为:', event_id, res);
|
|
|
-
|
|
|
- // 根据不同的事件类型处理
|
|
|
- switch (event_id) {
|
|
|
- case 'start_read': // 开始阅读
|
|
|
- console.log('开始阅读章节:', res.chapter_id);
|
|
|
- SendEvent('start_read', {
|
|
|
- page: '开始阅读'
|
|
|
- })
|
|
|
- break;
|
|
|
|
|
|
- case 'click_startread': // 点击开始阅读
|
|
|
- SendEvent('click_startread', {
|
|
|
- page: '点击开始阅读'
|
|
|
- })
|
|
|
- startRead(res);
|
|
|
- break;
|
|
|
+ let pluginInfo = novelManager.getPluginInfo();
|
|
|
+ let innerBookId = pluginInfo.query?.innerBookId;
|
|
|
+ let unlockStatus = await getChapterUnlockStatus({
|
|
|
+ novelId: innerBookId
|
|
|
+ });
|
|
|
|
|
|
- case 'leave_readpage': // 离开阅读页
|
|
|
- SendEvent('leave_readpage', {
|
|
|
- page: '离开阅读页'
|
|
|
+ let bookDetail = await getNovelDetail(innerBookId);
|
|
|
+ getApp().globalData.novelId = bookDetail.id
|
|
|
+ console.log("bookDetail", bookDetail);
|
|
|
+
|
|
|
+ if (unlockStatus && Array.isArray(unlockStatus.status)) {
|
|
|
+ const contents = unlockStatus.status.map((lockState, index) => {
|
|
|
+ return {
|
|
|
+ index: index,
|
|
|
+ status: lockState,
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ novelManager.setContents({
|
|
|
+ contents: contents,
|
|
|
+ });
|
|
|
+
|
|
|
+ novelManager.setChargeWay({
|
|
|
+ globalConfig: {
|
|
|
+ mode: 1,
|
|
|
+ buttonText: '解锁',
|
|
|
+ showButton: true,
|
|
|
+ tip: '看完广告之后可继续阅读',
|
|
|
+ }
|
|
|
})
|
|
|
- console.log('阅读时长:', res.read_time);
|
|
|
- break;
|
|
|
|
|
|
- case 'change_chapter': // 切换章节
|
|
|
- SendEvent('change_chapter', {
|
|
|
- page: '切换到章节'
|
|
|
- })
|
|
|
- console.log('切换到章节:', res.chapter_id);
|
|
|
- break;
|
|
|
+ let chapterConfigs = []
|
|
|
+ for (let index = 0; index < bookDetail.latestChapterNo; index++) {
|
|
|
+ if ((index + 1) % getApp().globalData.bookmarkAdNum === 0) {
|
|
|
+ chapterConfigs.push({
|
|
|
+ chapterIndex: index,
|
|
|
+ blocks: [
|
|
|
+ {
|
|
|
+ type: 3,
|
|
|
+ unitId: apple.ads.bookmarkAdId
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- case 'get_chapter': // 获取章节数据
|
|
|
- SendEvent('get_chapter', {
|
|
|
- page: '获取章节数据'
|
|
|
+ novelManager.setAdBlock({
|
|
|
+ chapterConfigs: chapterConfigs
|
|
|
})
|
|
|
- console.log("get_chapter", res);
|
|
|
- console.log('章节状态:', res.pay_status);
|
|
|
- break;
|
|
|
+ }
|
|
|
+
|
|
|
+ function startRead(res) {
|
|
|
+ console.log('开始阅读', res);
|
|
|
+ updateBrowsingHistory(res);
|
|
|
+ }
|
|
|
|
|
|
- default:
|
|
|
- break;
|
|
|
+ function updateBrowsingHistory(res) {
|
|
|
+ let params = {
|
|
|
+ novelAuthor: bookDetail.author,
|
|
|
+ novelCover: bookDetail.cover,
|
|
|
+ novelId: bookDetail.id,
|
|
|
+ novelTitle: bookDetail.title,
|
|
|
+ status: bookDetail.status
|
|
|
+ }
|
|
|
+ addBrowsingHistory(params);
|
|
|
}
|
|
|
- })
|
|
|
+
|
|
|
+ // 监听用户行为事件
|
|
|
+ novelManager.onUserTriggerEvent(res => {
|
|
|
+ const {
|
|
|
+ event_id
|
|
|
+ } = res;
|
|
|
+ console.log('用户行为:', event_id, res);
|
|
|
+
|
|
|
+ // 根据不同的事件类型处理
|
|
|
+ switch (event_id) {
|
|
|
+ case 'start_read': // 开始阅读
|
|
|
+ console.log('开始阅读章节:', res.chapter_id);
|
|
|
+ SendEvent('start_read', {
|
|
|
+ page: '开始阅读'
|
|
|
+ })
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'click_startread': // 点击开始阅读
|
|
|
+ SendEvent('click_startread', {
|
|
|
+ page: '点击开始阅读'
|
|
|
+ })
|
|
|
+ startRead(res);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'leave_readpage': // 离开阅读页
|
|
|
+ SendEvent('leave_readpage', {
|
|
|
+ page: '离开阅读页'
|
|
|
+ })
|
|
|
+ console.log('阅读时长:', res.read_time);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'change_chapter': // 切换章节
|
|
|
+ SendEvent('change_chapter', {
|
|
|
+ page: '切换到章节'
|
|
|
+ })
|
|
|
+ console.log('切换到章节:', res.chapter_id);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'get_chapter': // 获取章节数据
|
|
|
+ SendEvent('get_chapter', {
|
|
|
+ page: '获取章节数据'
|
|
|
+ })
|
|
|
+ console.log("get_chapter", res);
|
|
|
+ console.log('章节状态:', res.pay_status);
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|