|
|
@@ -1,7 +1,7 @@
|
|
|
// index.js
|
|
|
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
|
|
|
const testCover = '/assets/images/bg-book.png'
|
|
|
-import { getBannerList, getCardNovels } from '../../api/api'
|
|
|
+import { getBannerList, getCardNovels, getBrowsingHistory } from '../../api/api'
|
|
|
import { goToBookDetail } from '../../utils/util'
|
|
|
|
|
|
const app = getApp()
|
|
|
@@ -33,6 +33,12 @@ Page({
|
|
|
showStrongRecommend: false, // 控制强力推荐模块显示/隐藏
|
|
|
strongBooks: [],
|
|
|
|
|
|
+ // 最近阅读书籍
|
|
|
+ recentBook: null, // 最近阅读的书籍
|
|
|
+ showRecentBook: false, // 是否显示最近阅读
|
|
|
+ isRecentBookHidden: false, // 最近阅读是否隐藏
|
|
|
+ recentBookAnimation: {}, // 最近阅读动画数据
|
|
|
+
|
|
|
motto: 'Hello World',
|
|
|
userInfo: {
|
|
|
avatarUrl: defaultAvatarUrl,
|
|
|
@@ -45,12 +51,19 @@ Page({
|
|
|
|
|
|
onLoad() {
|
|
|
this.autoLogin();
|
|
|
+ // 创建动画实例
|
|
|
+ this.recentBookAnimator = wx.createAnimation({
|
|
|
+ duration: 300,
|
|
|
+ timingFunction: 'ease',
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
onShow() {
|
|
|
// 每次页面显示时检查是否需要更新数据
|
|
|
if (this.data.isLoggedIn) {
|
|
|
this.checkAndUpdateGender();
|
|
|
+ // 每次页面显示时获取最近阅读
|
|
|
+ this.getRecentReadBook();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -61,6 +74,64 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 页面滚动触发
|
|
|
+ onPageScroll(e) {
|
|
|
+ // 清除之前的定时器
|
|
|
+ if (this.scrollTimer) {
|
|
|
+ clearTimeout(this.scrollTimer);
|
|
|
+ this.scrollTimer = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 滚动时隐藏最近阅读
|
|
|
+ if (e.scrollTop > 300 && !this.data.isRecentBookHidden && this.data.showRecentBook) {
|
|
|
+ this.hideRecentBook();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置滑动停止后的定时器
|
|
|
+ this.lastScrollTop = e.scrollTop;
|
|
|
+ this.scrollTimer = setTimeout(() => {
|
|
|
+ // 2秒后检查是否已经停止滚动
|
|
|
+ if (this.lastScrollTop === e.scrollTop && this.data.isRecentBookHidden && this.data.showRecentBook) {
|
|
|
+ this.showRecentBook();
|
|
|
+ }
|
|
|
+ }, 1500); // 2秒后执行
|
|
|
+ },
|
|
|
+
|
|
|
+ // 隐藏最近阅读
|
|
|
+ hideRecentBook() {
|
|
|
+ // 计算移动距离,只漏出10px
|
|
|
+ const windowWidth = wx.getSystemInfoSync().windowWidth;
|
|
|
+ const rpxToPx = windowWidth / 750; // rpx到px的转换比例
|
|
|
+ const btnWidth = 90 * rpxToPx; // 悬浮按钮宽度,90rpx转换为px
|
|
|
+ const moveX = -(btnWidth + 40); // 只漏出10px
|
|
|
+
|
|
|
+ this.recentBookAnimator.translateX(moveX).step();
|
|
|
+ this.setData({
|
|
|
+ recentBookAnimation: this.recentBookAnimator.export(),
|
|
|
+ isRecentBookHidden: true
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 显示最近阅读
|
|
|
+ showRecentBook() {
|
|
|
+ this.recentBookAnimator.translateX(0).step();
|
|
|
+ this.setData({
|
|
|
+ recentBookAnimation: this.recentBookAnimator.export(),
|
|
|
+ isRecentBookHidden: false
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 点击隐藏的最近阅读
|
|
|
+ toggleRecentBook() {
|
|
|
+ if (this.data.isRecentBookHidden) {
|
|
|
+ // 隐藏状态点击展开
|
|
|
+ this.showRecentBook();
|
|
|
+ } else {
|
|
|
+ // 展开状态点击跳转
|
|
|
+ this.goToRecentBook();
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 自动登录
|
|
|
async autoLogin() {
|
|
|
try {
|
|
|
@@ -70,6 +141,8 @@ Page({
|
|
|
this.setData({ isLoggedIn: true });
|
|
|
// 获取性别设置并加载数据
|
|
|
this.initGenderAndLoadData();
|
|
|
+ // 获取最近阅读记录
|
|
|
+ this.getRecentReadBook();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -78,6 +151,8 @@ Page({
|
|
|
this.setData({ isLoggedIn: true });
|
|
|
// 登录成功后获取性别设置并加载数据
|
|
|
this.initGenderAndLoadData();
|
|
|
+ // 获取最近阅读记录
|
|
|
+ this.getRecentReadBook();
|
|
|
|
|
|
} catch (error) {
|
|
|
console.error('登录失败:', error);
|
|
|
@@ -104,6 +179,50 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 获取最近阅读的书籍
|
|
|
+ async getRecentReadBook() {
|
|
|
+ try {
|
|
|
+ const historyList = await getBrowsingHistory();
|
|
|
+ if (Array.isArray(historyList) && historyList.length > 0) {
|
|
|
+ // 取第一本作为最近阅读
|
|
|
+ const recentBook = historyList[0];
|
|
|
+ this.setData({
|
|
|
+ recentBook: recentBook,
|
|
|
+ showRecentBook: true,
|
|
|
+ isRecentBookHidden: false
|
|
|
+ });
|
|
|
+
|
|
|
+ // 重置动画
|
|
|
+ if (this.recentBookAnimator) {
|
|
|
+ this.recentBookAnimator.translateX(0).step();
|
|
|
+ this.setData({
|
|
|
+ recentBookAnimation: this.recentBookAnimator.export()
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ showRecentBook: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取最近阅读失败:', error);
|
|
|
+ this.setData({
|
|
|
+ showRecentBook: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 跳转到最近阅读的书籍
|
|
|
+ goToRecentBook() {
|
|
|
+ if (this.data.recentBook) {
|
|
|
+ goToBookDetail({
|
|
|
+ bookId: this.data.recentBook.novelId,
|
|
|
+ wxBookId: this.data.recentBook.appId,
|
|
|
+ chapterId: this.data.recentBook.novelChapterId
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 加载所有数据
|
|
|
loadAllData() {
|
|
|
wx.showLoading({ title: '加载中...' });
|