Skip to content

Commit

Permalink
feat: 章节内容预加载 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed Jul 17, 2024
1 parent 085e068 commit e184828
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/web/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
"recommendations": [
"Vue.volar",
"Vue.vscode-typescript-vue-plugin",
"antfu.unocss"
]
}
18 changes: 18 additions & 0 deletions packages/web/src/pages/common/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ export function useContent(contentRef: Ref<HTMLElement>) {
return item?.chapterPath || '';
});

function preload(chapterPath: string) {
const key = 'preload@' + chapterPath;
if (!sessionStorage.getItem(key)) {
sessionStorage.setItem(key, '1');
getContent({
...route.query,
chapterPath
});
}
}

// 初始化
async function init() {
const { chapterPath: _chapterPath, filePath, ruleId, percentage } = route.query as Record<string, string>;
Expand All @@ -68,6 +79,13 @@ export function useContent(contentRef: Ref<HTMLElement>) {
const chapterInfo = chaptersStore.chapters.find((e) => e.chapterPath === route.query.chapterPath);
readStore.setPath(chapterInfo?.chapterPath || '');
readStore.setTitle(chapterInfo?.name || '');

if (lastChapter.value) {
preload(lastChapter.value);
}
if (nextChapter.value) {
preload(nextChapter.value);
}
});
if (res?.code === 0) {
content.value = res?.data?.content || '';
Expand Down

0 comments on commit e184828

Please sign in to comment.