feat: 添加断点续读功能,优化用户体验
- 在 chenyunStore 中引入 lastVisitedPlace 和 setLastVisitedPlace 方法,支持记录用户上次访问的场景。 - 在各个场景组件中使用 useEffect 设置 lastVisitedPlace,确保用户在返回时能继续上次访问的地点。 - 更新相关组件,确保在导航时能够正确使用 lastVisitedPlace,提升用户交互体验。 - 在 puzzleStore 中添加保存用户定义的功能,增强数据持久性。
This commit is contained in:
1 parent
76c67b492e
commit
b1d55b9464
17 files changed
+147
-54
No files matched your search
@@ -28,19 +28,21 @@ const Chenyun = () => {
|
||||
// starName 固定为 chenyun
|
||||
const starName = 'chenyun'
|
||||
|
||||
const { lastVisitedPlace } = useChenyunStore()
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
console.log('1233')
|
||||
try {
|
||||
const raw = await getUserDefine(CHENYUN_LESSON_ID, CHENYUN_KEY)
|
||||
console.log(raw)
|
||||
if (!raw) return
|
||||
|
||||
const data = JSON.parse(raw) as {
|
||||
visitedExhibits?: Record<string, number[]>
|
||||
isYinyuanSolved?: boolean
|
||||
isMimianSolved?: boolean
|
||||
lastVisitedPlace?: string | null
|
||||
}
|
||||
console.log(data)
|
||||
|
||||
useChenyunStore.setState((prev) => ({
|
||||
...prev,
|
||||
@@ -49,6 +51,8 @@ const Chenyun = () => {
|
||||
data.isYinyuanSolved !== undefined ? data.isYinyuanSolved : prev.isYinyuanSolved,
|
||||
isMimianSolved:
|
||||
data.isMimianSolved !== undefined ? data.isMimianSolved : prev.isMimianSolved,
|
||||
lastVisitedPlace:
|
||||
data.lastVisitedPlace !== undefined ? data.lastVisitedPlace : prev.lastVisitedPlace,
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error('Failed to load Chenyun store', error)
|
||||
@@ -79,7 +83,7 @@ const Chenyun = () => {
|
||||
<Image
|
||||
button
|
||||
src={getStaticImage('star/一-解锁')}
|
||||
onClick={() => navigate(`/${moduleName}/${starName}/place1`)}
|
||||
onClick={() => navigate(`/${moduleName}/${starName}/${lastVisitedPlace ?? 'place1'}`)}
|
||||
/>
|
||||
{/* 体悟 */}
|
||||
<Image
|
||||
|
||||
Reference in new issue
Block a user