docs: package week 4 demo and architecture

This commit is contained in:
2026-04-18 22:14:22 +08:00
parent 70efaf3ccf
commit d5a173aa0d
9 changed files with 317 additions and 5 deletions

View File

@@ -87,6 +87,9 @@ const currentStoryId = computed(() => {
return Number.isFinite(parsed) ? parsed : null
})
const storybookTraceId = computed(() => storybook.value?.id ?? currentStoryId.value)
const readingPositionKey = computed(() => (
storybookTraceId.value ? `dreamweaver:storybook:${storybookTraceId.value}:page` : null
))
function goHome() {
store.clearStorybook()
@@ -105,6 +108,22 @@ function prevPage() {
}
}
function restoreReadingPosition() {
const key = readingPositionKey.value
if (!key || !totalPages.value) {
currentPageIndex.value = -1
return
}
const savedValue = Number(window.localStorage.getItem(key))
if (!Number.isFinite(savedValue)) {
currentPageIndex.value = -1
return
}
currentPageIndex.value = Math.min(Math.max(savedValue, -1), totalPages.value - 1)
}
async function loadStorybook() {
loading.value = true
error.value = ''
@@ -125,6 +144,7 @@ async function loadStorybook() {
}
if (cachedStorybook?.id === storyId) {
restoreReadingPosition()
loading.value = false
await generationTraceRef.value?.refresh()
return
@@ -155,6 +175,7 @@ async function loadStorybook() {
last_error: detail.last_error,
retryable_assets: detail.retryable_assets,
})
restoreReadingPosition()
await generationTraceRef.value?.refresh()
} catch (e) {
error.value = e instanceof Error ? e.message : '绘本加载失败'
@@ -208,6 +229,13 @@ watch(
},
{ immediate: true },
)
watch(currentPageIndex, (pageIndex) => {
const key = readingPositionKey.value
if (key) {
window.localStorage.setItem(key, String(pageIndex))
}
})
</script>
<template>