feat: 引入持久化访问状态管理,优化展品访问逻辑
- 在 Luxun 和 Sunzhongshan 的多个组件中引入 useLuxunStore 和 useSunzhongshanStore,替代原有的访问状态管理方式。 - 通过 markExhibitVisited 方法标记展品为已访问,提升状态管理的效率和一致性。 - 从 store 获取已访问展品的状态,确保数据的持久性和准确性。
This commit is contained in:
1 parent
966b47ede3
commit
ac5a2159a1
15 files changed
+392
-173
No files matched your search
@@ -13,6 +13,7 @@ import { useState } from "react";
|
||||
import SuccessAlert from "@/components/layout/alert/success-alert";
|
||||
import { useCursorController } from "@/hooks/useCursorController";
|
||||
import { usePuzzleAnimation } from "@/contexts/PuzzleAnimationContext";
|
||||
import { useLuxunStore } from "@/store/luxunStore";
|
||||
|
||||
// starName 固定为 luxun
|
||||
const starName = "luxun";
|
||||
@@ -55,7 +56,14 @@ const LuxunPlace3 = () => {
|
||||
const [activeExhibitId, setActiveExhibitId] = useState<
|
||||
1 | 2 | 3 | 4 | 5 | null
|
||||
>(null);
|
||||
const [visited, setVisited] = useState<Set<number>>(new Set());
|
||||
|
||||
// 使用持久化的访问状态
|
||||
const place = "place3";
|
||||
const { markExhibitVisited, getVisitedExhibits } = useLuxunStore();
|
||||
|
||||
// 从 store 获取已访问的展品,转换为 Set 用于兼容现有代码
|
||||
const visitedExhibits = getVisitedExhibits(place);
|
||||
const visited = new Set(visitedExhibits);
|
||||
|
||||
// Cursor 顺序控制:1 -> 2 -> 3 -> 4 -> 5
|
||||
const { isEnabled } = useCursorController({
|
||||
@@ -259,11 +267,7 @@ const LuxunPlace3 = () => {
|
||||
} else {
|
||||
// 其他光标:正常关闭并标记为已读
|
||||
if (activeExhibitId !== null) {
|
||||
setVisited((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.add(activeExhibitId);
|
||||
return next;
|
||||
});
|
||||
markExhibitVisited(place, activeExhibitId);
|
||||
}
|
||||
setActiveExhibitId(null);
|
||||
}
|
||||
@@ -277,11 +281,7 @@ const LuxunPlace3 = () => {
|
||||
setGuide1Visible(visible);
|
||||
if (!visible) {
|
||||
// 对话关闭时,标记光标1为已读
|
||||
setVisited((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.add(1);
|
||||
return next;
|
||||
});
|
||||
markExhibitVisited(place, 1);
|
||||
}
|
||||
}}
|
||||
currentStep={guide1Step}
|
||||
@@ -383,11 +383,7 @@ const LuxunPlace3 = () => {
|
||||
onContinue={() => {
|
||||
setSuccessAlert2Visible(false);
|
||||
// 标记光标2为已读
|
||||
setVisited((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.add(2);
|
||||
return next;
|
||||
});
|
||||
markExhibitVisited(place, 2);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -398,11 +394,7 @@ const LuxunPlace3 = () => {
|
||||
setGuide3Visible(visible);
|
||||
if (!visible) {
|
||||
// 对话关闭时,标记光标3为已读
|
||||
setVisited((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.add(3);
|
||||
return next;
|
||||
});
|
||||
markExhibitVisited(place, 3);
|
||||
}
|
||||
}}
|
||||
currentStep={guide3Step}
|
||||
@@ -432,11 +424,7 @@ const LuxunPlace3 = () => {
|
||||
setGuide4Visible(visible);
|
||||
if (!visible) {
|
||||
// 对话关闭时,标记光标4为已读
|
||||
setVisited((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.add(4);
|
||||
return next;
|
||||
});
|
||||
markExhibitVisited(place, 4);
|
||||
}
|
||||
}}
|
||||
currentStep={guide4Step}
|
||||
@@ -496,11 +484,7 @@ const LuxunPlace3 = () => {
|
||||
onContinue={() => {
|
||||
setSuccessAlert5Visible(false);
|
||||
// 标记光标5为已读
|
||||
setVisited((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.add(5);
|
||||
return next;
|
||||
});
|
||||
markExhibitVisited(place, 5);
|
||||
// 打开光标5的引导对话
|
||||
setGuide5Visible(true);
|
||||
setGuide5Step(0);
|
||||
|
||||
Reference in new issue
Block a user