140 lines
4.4 KiB
TypeScript
140 lines
4.4 KiB
TypeScript
Page({
|
|
data: {
|
|
activeTab: 'notes',
|
|
notes: [
|
|
{
|
|
bookTitle: '大爱仙尊',
|
|
chapter: 1,
|
|
selectedText: '"方源,乖乖地交出春秋蝉,我给你个痛快!"',
|
|
content: '反派的第一句台词,霸气十足。',
|
|
time: '2024-03-17 15:30'
|
|
},
|
|
{
|
|
bookTitle: '大爱仙尊',
|
|
chapter: 1,
|
|
selectedText: '"方老魔,你不要妄图反抗了,今日我们正道各大派联手起来,就是要踏破你的魔窟。这里早已经布下天罗地网,这次你必定身首异处!"',
|
|
content: '正派群起而攻之,场面宏大。',
|
|
time: '2024-03-17 16:45'
|
|
},
|
|
{
|
|
bookTitle: '大爱仙尊',
|
|
chapter: 2,
|
|
selectedText: '一直静如雕塑的方源,慢慢转身。群雄顿时一阵骚动,齐齐后退一大步。',
|
|
content: '反派气场强大,一个转身就震慑群雄。',
|
|
time: '2024-03-17 17:00'
|
|
}
|
|
],
|
|
bookmarks: [
|
|
{
|
|
bookTitle: '大爱仙尊',
|
|
chapter: 1,
|
|
content: '围攻他的正道群雄,不是堂堂一派之长者尊贵,就是名动四方之少年英豪。此时军军包围着方源,有的在咆哮,有的在冷笑,有的双眼眯起闪着警惕的光,有的捂着伤口恨恨地望着。',
|
|
page: 0,
|
|
time: '2024-03-17 15:20'
|
|
},
|
|
{
|
|
bookTitle: '大爱仙尊',
|
|
chapter: 3,
|
|
content: '他们没有动手,都忌惮着方源的临死反扑。就这样紧张地对峙了三个时辰,夕阳西下,落日的余晖将山边的晚霞点燃,一时间绚烂如火。',
|
|
page: 2,
|
|
time: '2024-03-17 17:00'
|
|
},
|
|
{
|
|
bookTitle: '大爱仙尊',
|
|
chapter: 5,
|
|
content: '方源站在悬崖边上,背后是万丈深渊。他的黑袍在风中猎猎作响,长发飞扬,眼神中透露出一丝决绝。',
|
|
page: 1,
|
|
time: '2024-03-17 17:30'
|
|
}
|
|
]
|
|
},
|
|
|
|
onLoad(options) {
|
|
// 如果从书签跳转过来,自动切换到书签标签
|
|
if (options.tab === 'bookmarks') {
|
|
this.setData({ activeTab: 'bookmarks' });
|
|
}
|
|
},
|
|
|
|
// 切换标签
|
|
switchTab(e: any) {
|
|
const tab = e.currentTarget.dataset.tab;
|
|
this.setData({ activeTab: tab });
|
|
},
|
|
|
|
// 编辑笔记
|
|
editNote(e: any) {
|
|
const note = e.currentTarget.dataset.note;
|
|
wx.showModal({
|
|
title: '编辑笔记',
|
|
editable: true,
|
|
content: note.content,
|
|
success: (res) => {
|
|
if (res.confirm && res.content) {
|
|
const notes = this.data.notes.map(item => {
|
|
if (item.time === note.time) {
|
|
return { ...item, content: res.content };
|
|
}
|
|
return item;
|
|
});
|
|
this.setData({ notes });
|
|
wx.showToast({ title: '编辑成功', icon: 'success' });
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
// 删除笔记
|
|
deleteNote(e: any) {
|
|
const note = e.currentTarget.dataset.note;
|
|
wx.showModal({
|
|
title: '删除笔记',
|
|
content: '确定要删除这条笔记吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
const notes = this.data.notes.filter(item => item.time !== note.time);
|
|
this.setData({ notes });
|
|
wx.showToast({ title: '删除成功', icon: 'success' });
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
// 跳转到书签位置
|
|
jumpToBookmark(e: any) {
|
|
const bookmark = e.currentTarget.dataset.bookmark;
|
|
wx.navigateTo({
|
|
url: `/pages/reader/reader?bookTitle=${bookmark.bookTitle}&chapter=${bookmark.chapter}&page=${bookmark.page}`
|
|
});
|
|
},
|
|
|
|
// 删除书签
|
|
deleteBookmark(e: any) {
|
|
const bookmark = e.currentTarget.dataset.bookmark;
|
|
wx.showModal({
|
|
title: '删除书签',
|
|
content: '确定要删除这个书签吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
const bookmarks = this.data.bookmarks.filter(item => item.time !== bookmark.time);
|
|
this.setData({ bookmarks });
|
|
wx.showToast({ title: '删除成功', icon: 'success' });
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
// 跳转到阅读器
|
|
navigateToReader() {
|
|
wx.navigateTo({
|
|
url: '/pages/reader/reader'
|
|
});
|
|
},
|
|
|
|
onShow() {
|
|
// 从本地存储获取最新数据
|
|
const notes = wx.getStorageSync('all_notes') || this.data.notes;
|
|
const bookmarks = wx.getStorageSync('all_bookmarks') || this.data.bookmarks;
|
|
this.setData({ notes, bookmarks });
|
|
}
|
|
});
|